diff --git a/Makefile b/Makefile index 29d5da0..4de8807 100644 --- a/Makefile +++ b/Makefile @@ -180,6 +180,9 @@ CLEAN_PATH_TMPL += clean-sdkdir-tmpl # Enable secondary expansion. .SECONDEXPANSION: +# Include source dependency files. +-include $(call get-deps,$(objs-all)) + # Rule to archive prerequisite objects into a library. $(lib-all): | $$(@D) $(call info-cmd,LIB) diff --git a/README.md b/README.md index d67d65c..e104fec 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,11 @@ source tree is replicated in there, to avoid conflicts between files with the sa you wanted to compile the file `src/foo/bar.c` for an eVic VTC Mini, debug flavor, you could issue `make obj/dbg/evic/src/foo/bar.o`. +#### Source dependency files + +Source dependency files live in the same directory as object files. They have a `.d` extension +and are generated automatically when objects are built. + #### SDK builds SDK output files live in the `lib/FLAVOR/DEVICE` directory. Debug builds enable debug info diff --git a/make/Base.mk b/make/Base.mk index 8f68452..7ac670a 100644 --- a/make/Base.mk +++ b/make/Base.mk @@ -105,6 +105,9 @@ CLEAN_PATH_TMPL += clean-bindir-tmpl # Enable secondary expansion. .SECONDEXPANSION: +# Include source dependency files. +-include $(call get-deps,$(objs-all)) + # Set BUILD_* for all our targets. $(call build-vars-rules,elf-tmpl) $(call build-vars-rules,bin-dec-tmpl) diff --git a/make/Common.mk b/make/Common.mk index 41167b1..50961dd 100644 --- a/make/Common.mk +++ b/make/Common.mk @@ -144,10 +144,12 @@ get-incflags = $(foreach d,$(call fixpath-cc,$1),-I$d) # CXXFLAGS: C++ compiler flags. # ASFLAGS: assembler flags. # Note that those are NOT inclusive of CPU flags. +# The -MMD flag generates source dependency files. Those files +# are never specified as targets to avoid a remake on include. __CC_FLAGS := \ $(call get-incflags,$(INCDIRS)) \ -Os -fdata-sections -ffunction-sections \ - $(if $(CC_IS_CLANG),-nostdinc) + $(if $(CC_IS_CLANG),-nostdinc) -MMD ifndef EVICSDK_FPU_DISABLE __CC_FLAGS += -DEVICSDK_FPU_SUPPORT ASFLAGS += -DEVICSDK_FPU_SUPPORT @@ -253,6 +255,9 @@ clean-devfla-tmpl = clean$(if $1,-$1)$(if $2,-$2) # Gets the paths to all possible sources for the given objects. # Argument 1: object list. get-srcs = $(foreach e,c cpp s,$(patsubst %.o,%.$e,$1)) +# Gets the paths to all source dependency files for the given objects. +# Argument 1: object list. +get-deps = $(addsuffix .d,$(basename $1)) # Gets object and source paths to cache for fixpath. # Argument 1: object list.