From 28c8dda7c67ba4e3766b28acec4b0f40738ec139 Mon Sep 17 00:00:00 2001 From: Christophe de Dinechin Date: Mon, 1 May 2017 17:06:28 +0200 Subject: [PATCH] Single-pass dependency generation --- config.gnu.mk | 13 +++++++------ config.mingw.mk | 5 ----- rules.mk | 19 +++++++------------ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/config.gnu.mk b/config.gnu.mk index 9df9147..a1e3592 100644 --- a/config.gnu.mk +++ b/config.gnu.mk @@ -46,7 +46,7 @@ CFLAGS_profile= -pg CFLAGS_cxx= -x c++ LDFLAGS_debug= -g LDFLAGS_profile=-pg - +DEPFLAGS= -MD -MP -MF $(@).d -MT $@ #------------------------------------------------------------------------------ # File extensions @@ -62,8 +62,9 @@ DLL_EXT= .so # Build rules #------------------------------------------------------------------------------ -MAKE_CC= $(CC) $(CFLAGS) $(CPPFLAGS_$*) $(CFLAGS_$*) -c $< -o $@ -MAKE_CXX= $(CXX) $(CXXFLAGS) $(CPPFLAGS_$*) $(CXXFLAGS_$*) -c $< -o $@ +MAKE_CC= $(CC) $(CFLAGS) $(CPPFLAGS_$*) $(CFLAGS_$*) -c $< -o $@ $(DEPFLAGS) +MAKE_CXX= $(CXX) $(CXXFLAGS) $(CPPFLAGS_$*) $(CXXFLAGS_$*) -c $< -o $@ $(DEPFLAGS) +MAKE_AS= $(CC) $(CFLAGS) $(CPPFLAGS_$*) $(CFLAGS_$*) -c $< -o $@ $(DEPFLAGS) MAKE_OBJDIR= mkdir -p $* && touch $@ MAKE_LIB= $(AR) $@ $(LINK_INPUTS)&& $(RANLIB) $@ MAKE_DLL= $(LIBTOOL) -shared $(LINK_INPUTS) -o $@ @@ -74,6 +75,6 @@ MAKE_EXE= $(LD) -o $@ $(LINK_INPUTS) $(LDFLAGS) $(LDFLAGS_$*) # Dependencies #------------------------------------------------------------------------------ -CC_DEPEND= $(CC) $(CPPFLAGS) $(CPPFLAGS_$*) -MM -MF $@ -MT $(@:.d=) $< -CXX_DEPEND= $(CXX) $(CPPFLAGS) $(CPPFLAGS_$*) -MM -MF $@ -MT $(@:.d=) $< -AS_DEPEND= $(CC) $(CPPFLAGS) $(CPPFLAGS_$*) -MM -MF $@ -MT $(@:.d=) $< +CC_DEPEND= $(CC) $(CPPFLAGS) $(CPPFLAGS_$*) -MM -MP -MF $@ -MT $(@:.d=) $< +CXX_DEPEND= $(CXX) $(CPPFLAGS) $(CPPFLAGS_$*) -MM -MP -MF $@ -MT $(@:.d=) $< +AS_DEPEND= $(CC) $(CPPFLAGS) $(CPPFLAGS_$*) -MM -MP -MF $@ -MT $(@:.d=) $< diff --git a/config.mingw.mk b/config.mingw.mk index 4a396de..c2b6b08 100644 --- a/config.mingw.mk +++ b/config.mingw.mk @@ -28,11 +28,6 @@ OS_NAME_mingw=windows include $(BUILD)config.gnu.mk -# We need a special treatment of this on Windows -POSTPROCESS_DEPENDENCY= \ - ( sed -e 's/.*://' -e 's/\\$$//' < $@ | \ - sed -e 's/^ *//' -e 's/$$/:/' -e 's/\\\\:$$/:/' >> $@ ) - # MinGW does not have --line-buffered for colorized builds LINE_BUFFERED= diff --git a/rules.mk b/rules.mk index 34f806a..4e22029 100644 --- a/rules.mk +++ b/rules.mk @@ -314,21 +314,16 @@ OBJDIR_DEPS=$(OBJDIR)/%.deps/.mkdir OBJ_DEPS=$(OBJDIR_DEPS) $(MAKEFILE_DEPS) | hello prebuild -# The following is a trick to avoid errors if a header file appears in a -# generated dependency but no longer in the source code. -# The trick is quite ugly, but fortunately documented here: -# http://scottmcpeak.com/autodepend/autodepend.html -POSTPROCESS_DEPENDENCY?= \ - ( sed -e 's/.*://' -e 's/\\$$//' < $@ | \ - fmt -1 | \ - sed -e 's/^ *//' -e 's/$$/:/' >> $@ ) - +ifndef DEPFLAGS $(OBJDIR)/%.c$(OBJ_EXT).d: %.c $(OBJ_DEPS) - $(PRINT_DEPEND) ( $(CC_DEPEND) && $(POSTPROCESS_DEPENDENCY) ) + $(PRINT_DEPEND) ( $(CC_DEPEND) $(OBJDIR)/%.cpp$(OBJ_EXT).d: %.cpp $(OBJ_DEPS) - $(PRINT_DEPEND) ( $(CXX_DEPEND) && $(POSTPROCESS_DEPENDENCY) ) + $(PRINT_DEPEND) ( $(CXX_DEPEND) $(OBJDIR)/%.s$(OBJ_EXT).d: %.s $(OBJ_DEPS) - $(PRINT_DEPEND) ( $(AS_DEPEND) && $(POSTPROCESS_DEPENDENCY) ) + $(PRINT_DEPEND) ( $(AS_DEPEND) +else +$(OBJDIR)/%$(OBJ_EXT).d: $(OBJDIR)/%$(OBJ_EXT) +endif #------------------------------------------------------------------------------