diff --git a/.gitignore b/.gitignore index 5dfa53cf1..2a577aedd 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ cquery_log.txt compile_commands.json temp.log temp.errors +.d/ \ No newline at end of file diff --git a/common.mk b/common.mk index 27a333daf..d929614c4 100644 --- a/common.mk +++ b/common.mk @@ -11,6 +11,11 @@ SPACE := SPACE += COMMA := , +DEPDIR := .d +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $$@ -MMD -MP -MF $(DEPDIR)/$$*.Td +RENAMEDEPENDENCYFILE = $(VV)mv -f $(DEPDIR)/$$*.Td $(DEPDIR)/$$*.d && touch $$@ + LIBRARIES+=$(wildcard $(FWDIR)/*.a) # Cannot include newlib and libc because not all of the req'd stubs are implemented EXCLUDE_COLD_LIBRARIES+=$(FWDIR)/libc.a $(FWDIR)/libm.a @@ -171,6 +176,7 @@ all: clean $(DEFAULT_BIN) clean: @echo Cleaning project -$Drm -rf $(BINDIR) + -$Drm -rf $(DEPDIR) ifeq ($(IS_LIBRARY),1) ifeq ($(LIBNAME),libbest) @@ -241,15 +247,21 @@ $(foreach asmext,$(ASMEXTS),$(eval $(call asm_rule,$(asmext)))) define c_rule $(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 +$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 $(DEPDIR)/$(basename $1).d $(VV)mkdir -p $$(dir $$@) - $$(call test_output_2,Compiled $$< ,$(CC) -c $(INCLUDE) -iquote"$(INCDIR)/$$(dir $$*)" $(CFLAGS) $(EXTRA_CFLAGS) -o $$@ $$<,$(OK_STRING)) + $(VV)mkdir -p $(DEPDIR)/$$(dir $$(patsubst bin/%, %, $$@)) + $$(call test_output_2,Compiled $$< ,$(CC) -c $(INCLUDE) -iquote"$(INCDIR)/$$(dir $$*)" $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAGS) -o $$@ $$<,$(OK_STRING)) + $(RENAMEDEPENDENCYFILE) endef $(foreach cext,$(CEXTS),$(eval $(call c_rule,$(cext)))) define cxx_rule $(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 +$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 $(DEPDIR)/$(basename %).d $(VV)mkdir -p $$(dir $$@) - $$(call test_output_2,Compiled $$< ,$(CXX) -c $(INCLUDE) -iquote"$(INCDIR)/$$(dir $$*)" $(CXXFLAGS) $(EXTRA_CXXFLAGS) -o $$@ $$<,$(OK_STRING)) + $(VV)mkdir -p $(DEPDIR)/$$(dir $$(patsubst bin/%, %, $$@)) + $$(call test_output_2,Compiled $$< ,$(CXX) -c $(INCLUDE) -iquote"$(INCDIR)/$$(dir $$*)" $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(DEPFLAGS) -o $$@ $$<,$(OK_STRING)) + $(RENAMEDEPENDENCYFILE) endef $(foreach cxxext,$(CXXEXTS),$(eval $(call cxx_rule,$(cxxext)))) @@ -266,3 +278,8 @@ cc-sysroot: @echo | $(CC) -c -x c $(CFLAGS) $(EXTRA_CFLAGS) --verbose -o /dev/null - cxx-sysroot: @echo | $(CXX) -c -x c++ $(CXXFLAGS) $(EXTRA_CXXFLAGS) --verbose -o /dev/null - + +$(DEPDIR)/%.d: ; +.PRECIOUS: $(DEPDIR)/%.d + +include $(wildcard $(patsubst ./src/%,$(DEPDIR)/%.d,$(basename $(CSRC) $(CXXSRC)))) diff --git a/template-gitignore b/template-gitignore index 5691d7f93..d3cf9e0f5 100644 --- a/template-gitignore +++ b/template-gitignore @@ -12,4 +12,5 @@ bin/ compile_commands.json temp.log temp.errors -*.ini \ No newline at end of file +*.ini +.d/ \ No newline at end of file