Makefile: explicitly set target name for autogenerated dependencies
commit69789347134b4b04411ae22f6eb516552b6ac365
authorJonathan Nieder <jrnieder@gmail.com>
Fri, 18 Nov 2011 23:23:24 +0000 (18 17:23 -0600)
committerJunio C Hamano <gitster@pobox.com>
Sat, 2 Feb 2013 02:09:33 +0000 (1 18:09 -0800)
tree37127177980d8ca444160f4ad0429f67a6e6a5e5
parent7e2010537e96d0a1144520222f20ba1dc3d61441
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>
Makefile