Makefile: explicitly set target name for autogenerated dependencies

"gcc -MF depfile -MMD -MP -c -o path/to/file.o" produces a makefile snippet named "depfile" describing what files are needed to build the target given by "-o". When ccache versions before v3.0pre0~187 (Fix handling of the -MD and -MDD options, 2009-11-01) run, they execute gcc -MF depfile -MMD -MP -E instead to get the final content for hashing. Notice that the "-c -o" combination is replaced by "-E". The result is a target name without a leading path. Thus when building git with such versions of ccache with COMPUTE_HEADER_DEPENDENCIES enabled, the generated makefile snippets define dependencies for the wrong target: $ make builtin/add.o GIT_VERSION = 1.7.8.rc3 * new build flags or prefix CC builtin/add.o $ head -1 builtin/.depend/add.o.d add.o: builtin/add.c cache.h git-compat-util.h compat/bswap.h strbuf.h \ After a change in a header file, object files in a subdirectory are not automatically rebuilt by "make": $ touch cache.h $ make builtin/add.o $ Luckily we can prevent trouble by explicitly supplying the name of the target to ccache and gcc, using the -MQ option. Do so. Reported-and-tested-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Reported-by: : 허종만 <jongman.heo@samsung.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 18, 2011 at 17:23 UTC 69789347134b4b04411ae22f6eb516552b6ac365
1 file changed +3 -2
Makefile
+3 -2
@@ -1388,7 +1388,8 @@ endif
1388
1389 ifeq ($(COMPUTE_HEADER_DEPENDENCIES),auto)
1390 dep_check = $(shell $(CC) $(ALL_CFLAGS) \
1391 - -c -MF /dev/null -MMD -MP -x c /dev/null -o /dev/null 2>&1; \
1391 + -c -MF /dev/null -MQ /dev/null -MMD -MP \
1392 + -x c /dev/null -o /dev/null 2>&1; \
1393 echo $$?)
1394 ifeq ($(dep_check),0)
1395 override COMPUTE_HEADER_DEPENDENCIES = yes
@@ -2211,7 +2212,7 @@ $(dep_dirs):
2212
2213 missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs))
2214 dep_file = $(dir $@).depend/$(notdir $@).d
2214 -dep_args = -MF $(dep_file) -MMD -MP
2215 +dep_args = -MF $(dep_file) -MQ $@ -MMD -MP
2216 ifdef CHECK_HEADER_DEPENDENCIES
2217 $(error cannot compute header dependencies outside a normal build. \
2218 Please unset CHECK_HEADER_DEPENDENCIES and try again)