Makefile: add option to disable automatic dependency generation

Now that the COMPUTE_HEADER_DEPENDENCIES feature is turned on automatically for compilers that support it (see v1.7.8-rc0~142^2~1, 2011-08-18), there is no easy way to force it off. For example, setting COMPUTE_HEADER_DEPENDENCIES to the empty string in config.mak just tells the makefile to treat it as undefined and run a test command to see if the -MMD option is supported. So allow setting COMPUTE_HEADER_DEPENDENCIES=no to explicitly force the feature off. The new semantics: - "yes" means to explicitly enable the feature - "no" means to disable it - "auto" means to autodetect The default is still "auto". Any value other than these three will cause the build to error out with a descriptive message so typos and stale settings in config.mak don't result in mysterious behavior. Makefile:1278: *** please set COMPUTE_HEADER_DEPENDENCIES to yes, no, or auto (not "1"). Stop. So now when someone using a compiler without -MMD support reports trouble building git, you can reproduce it by running "make COMPUTE_HEADER_DEPENDENCIES=no". Suggested-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Improved-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Tested-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 18, 2011 at 03:58 UTC 024c843d472658a3dabb344c843c9242c2f7e4de
1 file changed +24 -7
Makefile
+24 -7
@@ -250,6 +250,12 @@ all::
250 # DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR',
251 # DEFAULT_EDITOR='"C:\Program Files\Vim\gvim.exe" --nofork'
252 #
253 +# Define COMPUTE_HEADER_DEPENDENCIES to "yes" if you want dependencies on
254 +# header files to be automatically computed, to avoid rebuilding objects when
255 +# an unrelated header file changes. Define it to "no" to use the hard-coded
256 +# dependency rules. The default is "auto", which means to use computed header
257 +# dependencies if your compiler is detected to support it.
258 +#
259 # Define CHECK_HEADER_DEPENDENCIES to check for problems in the hard-coded
260 # dependency rules.
261 #
@@ -1246,21 +1252,32 @@ endif
1252 endif
1253
1254 ifdef CHECK_HEADER_DEPENDENCIES
1249 -COMPUTE_HEADER_DEPENDENCIES =
1255 +COMPUTE_HEADER_DEPENDENCIES = no
1256 USE_COMPUTED_HEADER_DEPENDENCIES =
1251 -else
1257 +endif
1258 +
1259 ifndef COMPUTE_HEADER_DEPENDENCIES
1260 +COMPUTE_HEADER_DEPENDENCIES = auto
1261 +endif
1262 +
1263 +ifeq ($(COMPUTE_HEADER_DEPENDENCIES),auto)
1264 dep_check = $(shell $(CC) $(ALL_CFLAGS) \
1265 -c -MF /dev/null -MMD -MP -x c /dev/null -o /dev/null 2>&1; \
1266 echo $$?)
1267 ifeq ($(dep_check),0)
1257 -COMPUTE_HEADER_DEPENDENCIES=YesPlease
1258 -endif
1268 +override COMPUTE_HEADER_DEPENDENCIES = yes
1269 +else
1270 +override COMPUTE_HEADER_DEPENDENCIES = no
1271 endif
1272 endif
1273
1262 -ifdef COMPUTE_HEADER_DEPENDENCIES
1274 +ifeq ($(COMPUTE_HEADER_DEPENDENCIES),yes)
1275 USE_COMPUTED_HEADER_DEPENDENCIES = YesPlease
1276 +else
1277 +ifneq ($(COMPUTE_HEADER_DEPENDENCIES),no)
1278 +$(error please set COMPUTE_HEADER_DEPENDENCIES to yes, no, or auto \
1279 +(not "$(COMPUTE_HEADER_DEPENDENCIES)"))
1280 +endif
1281 endif
1282
1283 ifdef SANE_TOOL_PATH
@@ -1907,7 +1924,7 @@ OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS)
1924 dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
1925 dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS))))
1926
1910 -ifdef COMPUTE_HEADER_DEPENDENCIES
1927 +ifeq ($(COMPUTE_HEADER_DEPENDENCIES),yes)
1928 $(dep_dirs):
1929 @mkdir -p $@
1930
@@ -1920,7 +1937,7 @@ Please unset CHECK_HEADER_DEPENDENCIES and try again)
1937 endif
1938 endif
1939
1923 -ifndef COMPUTE_HEADER_DEPENDENCIES
1940 +ifneq ($(COMPUTE_HEADER_DEPENDENCIES),yes)
1941 ifndef CHECK_HEADER_DEPENDENCIES
1942 dep_dirs =
1943 missing_dep_dirs =