Dependency file generation - rebuild if a header file is updated

This commit is contained in:
Thomas Lovén 2017-10-24 22:42:29 +02:00
parent dda15ea889
commit de73851481

View File

@ -6,6 +6,7 @@ CC := x86_64-elf-gcc
SRC := $(wildcard **/*.[cS]) SRC := $(wildcard **/*.[cS])
OBJ := $(patsubst %, %.o, $(basename $(SRC))) OBJ := $(patsubst %, %.o, $(basename $(SRC)))
DEP := $(OBJ:.o=.d)
CFLAGS ?= -Wall -Wextra CFLAGS ?= -Wall -Wextra
CFLAGS += -ffreestanding CFLAGS += -ffreestanding
@ -17,6 +18,13 @@ kernel: LDFLAGS += -n -nostdlib -T Link.ld
kernel: $(OBJ) kernel: $(OBJ)
$(LINK.c) $^ -o $@ $(LINK.c) $^ -o $@
DEPFLAGS = -MT $@ -MMD -MP -MF $*.d
%.o: %.c $.d
$(COMPILE.c) $(DEPFLAGS) -o $@ $<
%.o: %.S %.d
$(COMPILE.S) $(DEPFLAGS) -o $@ $<
%.d: ;
# Copy kernel to sysroot # Copy kernel to sysroot
/opt/sysroot/kernel: kernel /opt/sysroot/kernel: kernel
@ -26,6 +34,8 @@ kernel: $(OBJ)
install: /opt/sysroot/kernel install: /opt/sysroot/kernel
clean: clean:
rm -rf $(OBJ) kernel rm -rf $(OBJ) $(DEP) kernel
.PHONY: install .PHONY: install
include $(DEP)