Makefile: add missing header dependency rules
cover Makefile: add missing header dependency rules
Hi,
As a side-effect of generating dependency rules during the build locally, it is possible to sanity-check the existing hard-coded header file dependencies. [1] Now the original topic of that thread [2] can be addressed without collateral damage.
That is what patches 1 and 2 do. The remaining patches are small clean-ups that decrease the amount of dependencies again.
These patches are independent of the jn/makefile topic. I sent them before, but I screwed up the sender so nobody received them. Anyway, perhaps they could be useful.
Jonathan Nieder (5):
Makefile: add missing header file dependencies
Makefile: make sure test helpers are rebuilt when headers change
Makefile: remove wt-status.h from LIB_H
Makefile: clean up http-walker.o dependency rules
Makefile: drop */*.h dependency rule
Makefile | 58 +++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 37 insertions(+), 21 deletions(-)
[1] http://thread.gmane.org/gmane.comp.version-control.git/133872/focus=136257
[2] http://thread.gmane.org/gmane.comp.version-control.git/133872/focus=133884
PATCH 1/5 Makefile: add missing header file dependencies
LIB_H is missing exec_cmd.h and color.h. cache.h includes SHA1_HEADER, and thus so does almost everything else, so add that to LIB_H, too. xdiff-interface.h is not included by any header files, but so many source files use xdiff that it is simplest to include it in LIB_H, too.
xdiff-interface.o uses the xdiff library heavily; let it depend on all xdiff headers to avoid needing to keep track of which headers it uses.
--- Makefile | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)
Makefile +18 -1
@@ -447,6 +447,7 @@ LIB_H += blob.h LIB_H += builtin.h LIB_H += cache.h LIB_H += cache-tree.h +LIB_H += color.h LIB_H += commit.h LIB_H += compat/bswap.h LIB_H += compat/cygwin.h
@@ -457,6 +458,7 @@ LIB_H += delta.h LIB_H += diffcore.h LIB_H += diff.h LIB_H += dir.h +LIB_H += exec_cmd.h LIB_H += fsck.h LIB_H += git-compat-util.h LIB_H += graph.h
@@ -499,6 +501,8 @@ LIB_H += unpack-trees.h LIB_H += userdiff.h LIB_H += utf8.h LIB_H += wt-status.h +LIB_H += xdiff-interface.h +LIB_H += xdiff/xdiff.h LIB_OBJS += abspath.o LIB_OBJS += advice.o
@@ -1281,10 +1285,12 @@ endif ifdef BLK_SHA1 SHA1_HEADER = "block-sha1/sha1.h" LIB_OBJS += block-sha1/sha1.o + LIB_H += block-sha1/sha1.h else ifdef PPC_SHA1 SHA1_HEADER = "ppc/sha1.h" LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o + LIB_H += ppc/sha1.h else SHA1_HEADER = <openssl/sha.h> EXTLIBS += $(LIB_4_CRYPTO)
@@ -1637,14 +1643,25 @@ git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS) $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) $(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h) +builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o: branch.h +builtin-bundle.o bundle.o transport.o: bundle.h +builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h +builtin-clone.o builtin-fetch-pack.o transport.o: fetch-pack.h +builtin-send-pack.o transport.o: send-pack.h +builtin-log.o builtin-shortlog.o: shortlog.h builtin-revert.o wt-status.o: wt-status.h +builtin-prune.o builtin-reflog.o reachable.o: reachable.h +builtin-tar-tree.o archive-tar.o: tar.h +builtin-pack-objects.o: thread-utils.h +http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h $(LIB_FILE): $(LIB_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS) XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o -$(XDIFF_OBJS): xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ +xdiff-interface.o $(XDIFF_OBJS): xdiff/xinclude.h \ + xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(XDIFF_LIB): $(XDIFF_OBJS)
Signature · 1 line
1.6.6.rc2
PATCH 2/5 Makefile: make sure test helpers are rebuilt when headers change
In reply to Jonathan NiederIt is not worth the bother to maintain an up-to-date list of which headers each test helper uses, so depend on $(LIB_H) to catch them all.
---
Verified (a few weeks ago) with 'make CHECK_HEADER_DEPENDENCIES=1'.
Makefile | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-)
Makefile +16 -16
@@ -384,6 +384,18 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \ # Empty... EXTRA_PROGRAMS = +TEST_PROGRAMS += test-chmtime$X +TEST_PROGRAMS += test-ctype$X +TEST_PROGRAMS += test-date$X +TEST_PROGRAMS += test-delta$X +TEST_PROGRAMS += test-dump-cache-tree$X +TEST_PROGRAMS += test-genrandom$X +TEST_PROGRAMS += test-match-trees$X +TEST_PROGRAMS += test-parse-options$X +TEST_PROGRAMS += test-path-utils$X +TEST_PROGRAMS += test-sha1$X +TEST_PROGRAMS += test-sigchain$X + # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS += $(EXTRA_PROGRAMS) PROGRAMS += git-fast-import$X
@@ -695,6 +707,8 @@ BUILTIN_OBJS += builtin-verify-pack.o BUILTIN_OBJS += builtin-verify-tag.o BUILTIN_OBJS += builtin-write-tree.o +TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS)) + GITLIBS = $(LIB_FILE) $(XDIFF_LIB) EXTLIBS =
@@ -1641,7 +1655,7 @@ git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) -$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) +$(LIB_OBJS) $(BUILTIN_OBJS) $(TEST_OBJS): $(LIB_H) $(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h) builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o: branch.h builtin-bundle.o bundle.o transport.o: bundle.h
@@ -1732,18 +1746,6 @@ endif ### Testing rules -TEST_PROGRAMS += test-chmtime$X -TEST_PROGRAMS += test-ctype$X -TEST_PROGRAMS += test-date$X -TEST_PROGRAMS += test-delta$X -TEST_PROGRAMS += test-dump-cache-tree$X -TEST_PROGRAMS += test-genrandom$X -TEST_PROGRAMS += test-match-trees$X -TEST_PROGRAMS += test-parse-options$X -TEST_PROGRAMS += test-path-utils$X -TEST_PROGRAMS += test-sha1$X -TEST_PROGRAMS += test-sigchain$X - all:: $(TEST_PROGRAMS) # GNU make supports exporting all variables by "export" without parameters.
@@ -1763,9 +1765,7 @@ test-delta$X: diff-delta.o patch-delta.o test-parse-options$X: parse-options.o -test-parse-options.o: parse-options.h - -.PRECIOUS: $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS)) +.PRECIOUS: $(TEST_OBJS) test-%$X: test-%.o $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
Signature · 1 line
1.6.6.rc2
PATCH 3/5 Makefile: remove wt-status.h from LIB_H
In reply to Jonathan NiederA list of the few translation units using this header is half-populated already. Including the dependency on this header twice (once explicitly, once through LIB_H) makes it difficult to figure out where future headers should be added to the Makefile.
---
I imagine the 'status' output is not used widely enough to consider it a library header yet, but I could be easily convinced otherwise. More important is to avoid the confusing double-dependency.
Makefile | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
Makefile +1 -2
@@ -512,7 +512,6 @@ LIB_H += tree-walk.h LIB_H += unpack-trees.h LIB_H += userdiff.h LIB_H += utf8.h -LIB_H += wt-status.h LIB_H += xdiff-interface.h LIB_H += xdiff/xdiff.h
@@ -1663,7 +1662,7 @@ builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h builtin-clone.o builtin-fetch-pack.o transport.o: fetch-pack.h builtin-send-pack.o transport.o: send-pack.h builtin-log.o builtin-shortlog.o: shortlog.h -builtin-revert.o wt-status.o: wt-status.h +builtin-commit.o builtin-revert.o wt-status.o: wt-status.h builtin-prune.o builtin-reflog.o reachable.o: reachable.h builtin-tar-tree.o archive-tar.o: tar.h builtin-pack-objects.o: thread-utils.h
Signature · 1 line
1.6.6.rc2
PATCH 4/5 Makefile: clean up http-walker.o dependency rules
In reply to Jonathan Niederhttp-walker.o depends on http.h twice: once in the rule listing files that use http.h, and again in the rule explaining how to build it. Messy.
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -1628,7 +1628,7 @@ http.o: http.c GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $< ifdef NO_EXPAT -http-walker.o: http-walker.c http.h GIT-CFLAGS +http-walker.o: http-walker.c GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $< endif
Signature · 1 line
1.6.6.rc2
PATCH 5/5 Makefile: drop dependency on $(wildcard */*.h)
In reply to Jonathan NiederThe files this pulls in are already pulled in by other dependency rules (some recently added).
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -1655,7 +1655,7 @@ git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS) $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIB_OBJS) $(BUILTIN_OBJS) $(TEST_OBJS): $(LIB_H) -$(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h) +$(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o: branch.h builtin-bundle.o bundle.o transport.o: bundle.h builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h
Signature · 1 line
1.6.6.rc2
Quoted 3 lines · Jonathan Nieder
These patches are independent of the jn/makefile topic. I sent them before, but I screwed up the sender so nobody received them. Anyway, perhaps they could be useful.
I found all of them sensible but it seems to be based on version that is a bit behind...
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Jonathan Nieder
These patches are independent of the jn/makefile topic. I sent them before, but I screwed up the sender so nobody received them. Anyway, perhaps they could be useful.
I found all of them sensible but it seems to be based on version that is a bit behind...
Thanks. Patches 1-5 below are those I sent before, rebased against maint. Since last time, remote-curl.o gained a few more dependencies, which are included.
The remainder of this series is based on a merge of master and patches 1-5:
Patch 6 adds another missing header dependency rule. It is not included with the others because it applies to master, not maint.
Patches 7-12 revisit the topic of generating header dependency rules on the fly. I updated them to produce patches 1-6, so I thought, why not get some feedback on their present state?
Patch 7 clumps the header dependency rules together. I think this makes them more readable; more importantly, later this will allow ifdef'ing them out later in one fell swoop.
Patches 8-9 and 11 list all targets that can depend on headers in a new OBJECTS variable, for use in patches 10 and 12.
Patch 10 generates header dependency rules on the fly. The resulting dependency rules contain no useless dependencies (unlike the hard-coded ones where almost everything depends on $(LIB_H)), so this might be interesting to people wishing to speed up the edit-compile-run cycle.
This only works with gcc. It should be possible to teach the relevant options to clink.pl if there is demand, but not SCO cc.
Patch 12 is what I am most interested in: it uses the computed dependencies to check that the hard-coded dependency rules are correct. In the long term, maybe we will be able to get rid of the hard-coded header dep rules altogether; in the short term, I am hoping this checker can be useful for avoiding problems with the hard-coded rules without spending too much human time on it.
Enjoy,
Jonathan Nieder (12):
Makefile: add missing header file dependencies
Makefile: make sure test helpers are rebuilt when headers change
Makefile: remove wt-status.h from LIB_H
Makefile: clean up http-walker.o dependency rules
Makefile: drop dependency on $(wildcard */*.h)
Makefile: transport.o depends on branch.h now
Makefile: rearrange dependency rules
Makefile: disable default implicit rules
Makefile: list generated object files in OBJECTS macro
Makefile: lazily compute header dependencies
Makefile: list standalone program object files in PROGRAM_OBJS Teach Makefile to check header dependencies
PATCH 1/12 Makefile: add missing header file dependencies
LIB_H is missing exec_cmd.h and color.h. cache.h includes SHA1_HEADER, and thus so does almost everything else, so add that to LIB_H, too. xdiff-interface.h is not included by any header files, but so many source files use xdiff that it is simplest to include it in LIB_H, too.
xdiff-interface.o uses the xdiff library heavily; let it depend on all xdiff headers to avoid needing to keep track of which headers it uses.
--- Makefile | 23 ++++++++++++++++++++--- 1 files changed, 20 insertions(+), 3 deletions(-)
Makefile +20 -3
@@ -447,6 +447,7 @@ LIB_H += blob.h LIB_H += builtin.h LIB_H += cache.h LIB_H += cache-tree.h +LIB_H += color.h LIB_H += commit.h LIB_H += compat/bswap.h LIB_H += compat/cygwin.h
@@ -457,6 +458,7 @@ LIB_H += delta.h LIB_H += diffcore.h LIB_H += diff.h LIB_H += dir.h +LIB_H += exec_cmd.h LIB_H += fsck.h LIB_H += git-compat-util.h LIB_H += graph.h
@@ -499,6 +501,8 @@ LIB_H += unpack-trees.h LIB_H += userdiff.h LIB_H += utf8.h LIB_H += wt-status.h +LIB_H += xdiff-interface.h +LIB_H += xdiff/xdiff.h LIB_OBJS += abspath.o LIB_OBJS += advice.o
@@ -1281,10 +1285,12 @@ endif ifdef BLK_SHA1 SHA1_HEADER = "block-sha1/sha1.h" LIB_OBJS += block-sha1/sha1.o + LIB_H += block-sha1/sha1.h else ifdef PPC_SHA1 SHA1_HEADER = "ppc/sha1.h" LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o + LIB_H += ppc/sha1.h else SHA1_HEADER = <openssl/sha.h> EXTLIBS += $(LIB_4_CRYPTO)
@@ -1620,9 +1626,9 @@ git-imap-send$X: imap-send.o $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL) -http.o http-walker.o http-push.o: http.h +http.o http-walker.o http-push.o remote-curl.o: http.h -http.o http-walker.o: $(LIB_H) +http.o http-walker.o remote-curl.o: $(LIB_H) git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
@@ -1637,14 +1643,25 @@ git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS) $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) $(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h) +builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o: branch.h +builtin-bundle.o bundle.o transport.o: bundle.h +builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h +builtin-clone.o builtin-fetch-pack.o transport.o: fetch-pack.h +builtin-send-pack.o transport.o: send-pack.h +builtin-log.o builtin-shortlog.o: shortlog.h +builtin-prune.o builtin-reflog.o reachable.o: reachable.h builtin-revert.o wt-status.o: wt-status.h +builtin-tar-tree.o archive-tar.o: tar.h +builtin-pack-objects.o: thread-utils.h +http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h $(LIB_FILE): $(LIB_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS) XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o -$(XDIFF_OBJS): xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ +xdiff-interface.o $(XDIFF_OBJS): \ + xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(XDIFF_LIB): $(XDIFF_OBJS)
Signature · 1 line
1.6.6
PATCH 2/12 Makefile: make sure test helpers are rebuilt when headers change
In reply to Jonathan NiederIt is not worth the bother to maintain an up-to-date list of which headers each test helper uses, so depend on $(LIB_H) to catch them all.
---
This applies to maint. Please let me know if you are interested in the corresponding patch for master.
Makefile | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-)
Makefile +16 -16
@@ -402,6 +402,18 @@ PROGRAMS += git-upload-pack$X PROGRAMS += git-var$X PROGRAMS += git-http-backend$X +TEST_PROGRAMS += test-chmtime$X +TEST_PROGRAMS += test-ctype$X +TEST_PROGRAMS += test-date$X +TEST_PROGRAMS += test-delta$X +TEST_PROGRAMS += test-dump-cache-tree$X +TEST_PROGRAMS += test-genrandom$X +TEST_PROGRAMS += test-match-trees$X +TEST_PROGRAMS += test-parse-options$X +TEST_PROGRAMS += test-path-utils$X +TEST_PROGRAMS += test-sha1$X +TEST_PROGRAMS += test-sigchain$X + # List built-in command $C whose implementation cmd_$C() is not in # builtin-$C.o but is linked in as part of some other command. BUILT_INS += $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS))
@@ -695,6 +707,8 @@ BUILTIN_OBJS += builtin-verify-pack.o BUILTIN_OBJS += builtin-verify-tag.o BUILTIN_OBJS += builtin-write-tree.o +TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS)) + GITLIBS = $(LIB_FILE) $(XDIFF_LIB) EXTLIBS =
@@ -1642,7 +1656,7 @@ git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS) $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) -$(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h) +$(patsubst git-%$X,%.o,$(PROGRAMS)) $(TEST_OBJS) git.o: $(LIB_H) $(wildcard */*.h) builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o: branch.h builtin-bundle.o bundle.o transport.o: bundle.h builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h
@@ -1732,18 +1746,6 @@ endif ### Testing rules -TEST_PROGRAMS += test-chmtime$X -TEST_PROGRAMS += test-ctype$X -TEST_PROGRAMS += test-date$X -TEST_PROGRAMS += test-delta$X -TEST_PROGRAMS += test-dump-cache-tree$X -TEST_PROGRAMS += test-genrandom$X -TEST_PROGRAMS += test-match-trees$X -TEST_PROGRAMS += test-parse-options$X -TEST_PROGRAMS += test-path-utils$X -TEST_PROGRAMS += test-sha1$X -TEST_PROGRAMS += test-sigchain$X - all:: $(TEST_PROGRAMS) # GNU make supports exporting all variables by "export" without parameters.
@@ -1763,9 +1765,7 @@ test-delta$X: diff-delta.o patch-delta.o test-parse-options$X: parse-options.o -test-parse-options.o: parse-options.h - -.PRECIOUS: $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS)) +.PRECIOUS: $(TEST_OBJS) test-%$X: test-%.o $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
Signature · 1 line
1.6.6
PATCH 3/12 Makefile: remove wt-status.h from LIB_H
In reply to Jonathan NiederA list of the few translation units using this header is half-populated already. Including the dependency on this header twice (once explicitly, once through LIB_H) makes it difficult to figure out where future headers should be added to the Makefile.
--- Makefile | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
Makefile +1 -2
@@ -512,7 +512,6 @@ LIB_H += tree-walk.h LIB_H += unpack-trees.h LIB_H += userdiff.h LIB_H += utf8.h -LIB_H += wt-status.h LIB_H += xdiff-interface.h LIB_H += xdiff/xdiff.h
@@ -1664,7 +1663,7 @@ builtin-clone.o builtin-fetch-pack.o transport.o: fetch-pack.h builtin-send-pack.o transport.o: send-pack.h builtin-log.o builtin-shortlog.o: shortlog.h builtin-prune.o builtin-reflog.o reachable.o: reachable.h -builtin-revert.o wt-status.o: wt-status.h +builtin-commit.o builtin-revert.o wt-status.o: wt-status.h builtin-tar-tree.o archive-tar.o: tar.h builtin-pack-objects.o: thread-utils.h http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
Signature · 1 line
1.6.6
PATCH 4/12 Makefile: clean up http-walker.o dependency rules
In reply to Jonathan Niederhttp-walker.o depends on http.h twice: once in the rule listing files that use http.h, and again in the rule explaining how to build it. Messy.
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -1628,7 +1628,7 @@ http.o: http.c GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $< ifdef NO_EXPAT -http-walker.o: http-walker.c http.h GIT-CFLAGS +http-walker.o: http-walker.c GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $< endif
Signature · 1 line
1.6.6
PATCH 5/12 Makefile: drop dependency on $(wildcard */*.h)
In reply to Jonathan NiederThe files this pulls in are already pulled in by other dependency rules (some recently added).
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -1655,7 +1655,7 @@ git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS) $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) -$(patsubst git-%$X,%.o,$(PROGRAMS)) $(TEST_OBJS) git.o: $(LIB_H) $(wildcard */*.h) +$(patsubst git-%$X,%.o,$(PROGRAMS)) $(TEST_OBJS) git.o: $(LIB_H) builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o: branch.h builtin-bundle.o bundle.o transport.o: bundle.h builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h
Signature · 1 line
1.6.6
PATCH 6/12 Makefile: transport.o depends on branch.h now
In reply to Jonathan NiederSince commit e9fcd1e2 (Add push --set-upstream, 2010-01-16), transport.c uses branch.h.
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -1719,7 +1719,7 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(GITLIBS) $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) $(patsubst git-%$X,%.o,$(PROGRAMS)) $(TEST_OBJS) git.o: $(LIB_H) -builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o: branch.h +builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o transport.o: branch.h builtin-bundle.o bundle.o transport.o: bundle.h builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h builtin-clone.o builtin-fetch-pack.o transport.o: fetch-pack.h
Signature · 1 line
1.6.6
PATCH 7/12 Makefile: rearrange dependency rules
In reply to Jonathan NiederPut rules listing dependencies of compiled objects (.o files) on header files (.h files) in one place, to make them easier to compare and modify all at once.
Add a GIT_OBJS variable listing objects that depend on LIB_H, for similar reasons.
No change in build-time behavior intended.
--- Makefile | 49 +++++++++++++++++++++++++------------------------ 1 files changed, 25 insertions(+), 24 deletions(-)
Makefile +25 -24
@@ -1666,6 +1666,12 @@ git.o git.spec \ $(patsubst %.perl,%,$(SCRIPT_PERL)) \ : GIT-VERSION-FILE +GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(TEST_OBJS) \ + git.o http.o http-walker.o remote-curl.o \ + $(patsubst git-%$X,%.o,$(PROGRAMS)) +XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ + xdiff/xmerge.o xdiff/xpatience.o + %.o: %.c GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< %.s: %.c GIT-CFLAGS FORCE
@@ -1673,6 +1679,25 @@ git.o git.spec \ %.o: %.S GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< +$(GIT_OBJS): $(LIB_H) +builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o transport.o: branch.h +builtin-bundle.o bundle.o transport.o: bundle.h +builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h +builtin-clone.o builtin-fetch-pack.o transport.o: fetch-pack.h +builtin-send-pack.o transport.o: send-pack.h +builtin-log.o builtin-shortlog.o: shortlog.h +builtin-prune.o builtin-reflog.o reachable.o: reachable.h +builtin-commit.o builtin-revert.o wt-status.o: wt-status.h +builtin-tar-tree.o archive-tar.o: tar.h +builtin-pack-objects.o: thread-utils.h +http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h +http.o http-walker.o http-push.o remote-curl.o: http.h + + +xdiff-interface.o $(XDIFF_OBJS): \ + xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ + xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h + exec_cmd.s exec_cmd.o: ALL_CFLAGS += \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \
@@ -1696,10 +1721,6 @@ git-imap-send$X: imap-send.o $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL) -http.o http-walker.o http-push.o remote-curl.o: http.h - -http.o http-walker.o remote-curl.o: $(LIB_H) - git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(CURL_LIBCURL)
@@ -1717,29 +1738,9 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) -$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) -$(patsubst git-%$X,%.o,$(PROGRAMS)) $(TEST_OBJS) git.o: $(LIB_H) -builtin-branch.o builtin-checkout.o builtin-clone.o builtin-reset.o branch.o transport.o: branch.h -builtin-bundle.o bundle.o transport.o: bundle.h -builtin-bisect--helper.o builtin-rev-list.o bisect.o: bisect.h -builtin-clone.o builtin-fetch-pack.o transport.o: fetch-pack.h -builtin-send-pack.o transport.o: send-pack.h -builtin-log.o builtin-shortlog.o: shortlog.h -builtin-prune.o builtin-reflog.o reachable.o: reachable.h -builtin-commit.o builtin-revert.o wt-status.o: wt-status.h -builtin-tar-tree.o archive-tar.o: tar.h -builtin-pack-objects.o: thread-utils.h -http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h - $(LIB_FILE): $(LIB_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS) -XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ - xdiff/xmerge.o xdiff/xpatience.o -xdiff-interface.o $(XDIFF_OBJS): \ - xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ - xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h - $(XDIFF_LIB): $(XDIFF_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(XDIFF_OBJS)
Signature · 1 line
1.6.6
PATCH 8/12 Makefile: disable default implicit rules
In reply to Jonathan NiederThe git makefile never uses any default implicit rules. Unfortunately, if a prerequisite for one of the intended rules is missing, a default rule can be used in its place:
$ make var.s CC var.s $ rm var.c $ make var.o as -o var.o var.s
Avoiding the default rules avoids this hard-to-debug behavior. It also should speed things up a little in the normal case.
Future patches may restrict the scope of the %.o: %.c pattern. This patch would then ensure that for targets not listed, we do not fall back to the default rule.
---
Sadly, this does not really speed things up in the normal case. I am not sure why, but make needs the -r option to avoid considering the default rules, even though clearing the .SUFFIXES:
guarantees it will never use them.
Makefile | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
Makefile +2 -0
@@ -1672,6 +1672,8 @@ GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(TEST_OBJS) \ XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o +.SUFFIXES: + %.o: %.c GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< %.s: %.c GIT-CFLAGS FORCE
Signature · 1 line
1.6.6
PATCH 9/12 Makefile: list generated object files in OBJECTS
In reply to Jonathan NiederSet the OBJECTS variable to a comprehensive list of all object file targets. To make sure it is truly comprehensive, restrict the scope of the %.o pattern rule to only generate objects in this list.
Attempts to build other object files will fail loudly:
$ touch foo.c $ make foo.o make: *** No rule to make target `foo.o'. Stop.
providing a reminder to add the new object to the OBJECTS list.
The new variable is otherwise unused. The intent is for later patches to take advantage of it.
--- Makefile | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
Makefile +7 -2
@@ -1671,14 +1671,19 @@ GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(TEST_OBJS) \ $(patsubst git-%$X,%.o,$(PROGRAMS)) XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o +OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) + +ASM_SRC := $(wildcard $(OBJECTS:o=S)) +ASM_OBJ := $(ASM_SRC:S=o) +C_OBJ := $(filter-out $(ASM_OBJ),$(OBJECTS)) .SUFFIXES: -%.o: %.c GIT-CFLAGS +$(C_OBJ): %.o: %.c GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< %.s: %.c GIT-CFLAGS FORCE $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< -%.o: %.S GIT-CFLAGS +$(ASM_OBJ): %.o: %.S GIT-CFLAGS $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< $(GIT_OBJS): $(LIB_H)
Signature · 1 line
1.6.6
PATCH 10/12 Makefile: lazily compute header dependencies
In reply to Jonathan NiederUse the gcc -MMD -MP -MF options to generate dependency rules as a byproduct when building .o files if the COMPUTE_HEADER_DEPENDENCIES variable is defined. That variable is left undefined by default for now.
As each object file is built, write a makefile fragment containing its dependencies in the deps/ subdirectory of its containing directory. The deps/ directories should be generated if they are missing at the start of each build. So let each object file depend on $(missing_dep_dirs), which lists only the directories of this kind that are missing to avoid needlessly regenerating files when the directories' timestamps change.
gcc learned the -MMD -MP -MF options in version 3.0, so most gcc users should have them by now.
The dependencies this option computes are more specific than the rough estimates hard-coded in the Makefile, greatly speeding up rebuilds when only a little-used header file has changed.
--- .gitignore | 1 + Makefile | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 5 deletions(-)
.gitignore +1 -0
@@ -177,6 +177,7 @@ *.exe *.[aos] *.py[co] +*.o.d *+ /config.mak /autom4te.cache
Makefile +44 -5
80 lines not on this page · raw message
Signature · 1 line
1.6.6
PATCH 11/12 Makefile: list standalone program object files in PROGRAM_OBJS
In reply to Jonathan NiederBecause of new commands like git-remote-http, the OBJECTS list contains fictitious objects such as remote-http.o. Thus any out-of-tree rules that require all $(OBJECTS) to be buildable are broken. Add a list of real program objects to avoid this problem.
---
Preparing for patch 12.
Makefile | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-)
Makefile +15 -9
@@ -341,6 +341,7 @@ COMPAT_CFLAGS = COMPAT_OBJS = LIB_H = LIB_OBJS = +PROGRAM_OBJS = PROGRAMS = SCRIPT_PERL = SCRIPT_PYTHON =
@@ -390,12 +391,15 @@ EXTRA_PROGRAMS = # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS += $(EXTRA_PROGRAMS) -PROGRAMS += git-fast-import$X -PROGRAMS += git-imap-send$X -PROGRAMS += git-shell$X -PROGRAMS += git-show-index$X -PROGRAMS += git-upload-pack$X -PROGRAMS += git-http-backend$X + +PROGRAM_OBJS += fast-import.o +PROGRAM_OBJS += imap-send.o +PROGRAM_OBJS += shell.o +PROGRAM_OBJS += show-index.o +PROGRAM_OBJS += upload-pack.o +PROGRAM_OBJS += http-backend.o + +PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS)) TEST_PROGRAMS_NEED_X += test-chmtime TEST_PROGRAMS_NEED_X += test-ctype
@@ -1139,10 +1143,12 @@ else REMOTE_CURL_PRIMARY = git-remote-http$X REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X REMOTE_CURL_NAMES = $(REMOTE_CURL_PRIMARY) $(REMOTE_CURL_ALIASES) + PROGRAM_OBJS += http-fetch.o PROGRAMS += $(REMOTE_CURL_NAMES) git-http-fetch$X curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p) ifeq "$(curl_check)" "070908" ifndef NO_EXPAT + PROGRAM_OBJS += http-push.o PROGRAMS += git-http-push$X endif endif
@@ -1163,6 +1169,7 @@ endif EXTLIBS += -lz ifndef NO_POSIX_ONLY_PROGRAMS + PROGRAM_OBJS += daemon.o PROGRAMS += git-daemon$X endif ifndef NO_OPENSSL
@@ -1670,9 +1677,8 @@ git.o git.spec \ $(patsubst %.perl,%,$(SCRIPT_PERL)) \ : GIT-VERSION-FILE -GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(TEST_OBJS) \ - git.o http.o http-walker.o remote-curl.o \ - $(patsubst git-%$X,%.o,$(PROGRAMS)) +GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \ + git.o http.o http-walker.o remote-curl.o XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS)
Signature · 1 line
1.6.6
PATCH v2 11/12 Makefile: list standalone program object files in PROGRAM_OBJS
Because of new commands like git-remote-http, the OBJECTS list contains fictitious objects such as remote-http.o. Thus any out-of-tree rules that require all $(OBJECTS) to be buildable are broken. Add a list of real program objects to avoid this problem.
To avoid duplication of effort, calculate the command list in the PROGRAMS variable using the expansion of PROGRAM_OBJS. This calculation occurs at the time $(PROGRAMS) is expanded, so later additions to PROGRAM_OBJS will be reflected in it, provided they occur before the build rules begin on line 1489.
---
The previous version of this patch had a bug: I assumed that
PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
would add to PROGRAMS a list of command names derived from the value of PROGRAM_OBJS at the time that line is first read; but in fact, what matters is the value of PROGRAM_OBJS at expansion time.
More importantly, my process had a bug: I didn’t try 'make install' before sending. Sorry about that. Here’s a fixed patch, at least.
I have pushed out this fix to
git://repo.or.cz/git/jrn.git autodep-rebased
git://repo.or.cz/git/jrn.git autodep
The former has been rerolled to include the fixed patch 11; the latter includes a fixup commit at the end.
Thanks to Junio for the report.
Makefile | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-)
Makefile +16 -12
@@ -341,6 +341,7 @@ COMPAT_CFLAGS = COMPAT_OBJS = LIB_H = LIB_OBJS = +PROGRAM_OBJS = PROGRAMS = SCRIPT_PERL = SCRIPT_PYTHON =
@@ -390,12 +391,15 @@ EXTRA_PROGRAMS = # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS += $(EXTRA_PROGRAMS) -PROGRAMS += git-fast-import$X -PROGRAMS += git-imap-send$X -PROGRAMS += git-shell$X -PROGRAMS += git-show-index$X -PROGRAMS += git-upload-pack$X -PROGRAMS += git-http-backend$X + +PROGRAM_OBJS += fast-import.o +PROGRAM_OBJS += imap-send.o +PROGRAM_OBJS += shell.o +PROGRAM_OBJS += show-index.o +PROGRAM_OBJS += upload-pack.o +PROGRAM_OBJS += http-backend.o + +PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS)) TEST_PROGRAMS_NEED_X += test-chmtime TEST_PROGRAMS_NEED_X += test-ctype
@@ -1139,11 +1143,12 @@ else REMOTE_CURL_PRIMARY = git-remote-http$X REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X REMOTE_CURL_NAMES = $(REMOTE_CURL_PRIMARY) $(REMOTE_CURL_ALIASES) - PROGRAMS += $(REMOTE_CURL_NAMES) git-http-fetch$X + PROGRAM_OBJS += http-fetch.o + PROGRAMS += $(REMOTE_CURL_NAMES) curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p) ifeq "$(curl_check)" "070908" ifndef NO_EXPAT - PROGRAMS += git-http-push$X + PROGRAM_OBJS += http-push.o endif endif ifndef NO_EXPAT
@@ -1163,7 +1168,7 @@ endif EXTLIBS += -lz ifndef NO_POSIX_ONLY_PROGRAMS - PROGRAMS += git-daemon$X + PROGRAM_OBJS += daemon.o endif ifndef NO_OPENSSL OPENSSL_LIBSSL = -lssl
@@ -1670,9 +1675,8 @@ git.o git.spec \ $(patsubst %.perl,%,$(SCRIPT_PERL)) \ : GIT-VERSION-FILE -GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(TEST_OBJS) \ - git.o http.o http-walker.o remote-curl.o \ - $(patsubst git-%$X,%.o,$(PROGRAMS)) +GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \ + git.o http.o http-walker.o remote-curl.o XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS)
Signature · 1 line
1.6.6
PATCH 12/12 Teach Makefile to check header dependencies
In reply to Jonathan NiederAdd a target to use the gcc-generated makefile snippets for dependencies on header files to check the hard-coded dependencies.
With this patch applied, if any dependencies are missing, then
make clean
make COMPUTE_HEADER_DEPENDENCIES=YesPlease make CHECK_HEADER_DEPENDENCIES=YesPlease
will produce an error message like the following:
CHECK fast-import.o missing dependencies: exec_cmd.h make: *** [fast-import.o] Error 1
---
That’s the end of the series. Thanks for reading.
Makefile | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 80 insertions(+), 15 deletions(-)
Makefile +80 -15
@@ -221,6 +221,9 @@ all:: # Define COMPUTE_HEADER_DEPENDENCIES if your compiler supports the -MMD option # and you want to avoid rebuilding objects when an unrelated header file # changes. +# +# Define CHECK_HEADER_DEPENDENCIES to check for problems in the hard-coded +# dependency rules. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1088,6 +1091,14 @@ endif -include config.mak.autogen -include config.mak +ifdef CHECK_HEADER_DEPENDENCIES +USE_COMPUTED_HEADER_DEPENDENCIES = +endif + +ifdef COMPUTE_HEADER_DEPENDENCIES +USE_COMPUTED_HEADER_DEPENDENCIES = YesPlease +endif + ifdef SANE_TOOL_PATH SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH)) BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
@@ -1683,9 +1694,7 @@ XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) -ASM_SRC := $(wildcard $(OBJECTS:o=S)) -ASM_OBJ := $(ASM_SRC:S=o) -C_OBJ := $(filter-out $(ASM_OBJ),$(OBJECTS)) +dep_files := $(foreach f,$(OBJECTS),$(dir $f)deps/$(notdir $f).d) ifdef COMPUTE_HEADER_DEPENDENCIES dep_dirs := $(addsuffix deps,$(sort $(dir $(OBJECTS))))
@@ -1693,33 +1702,89 @@ $(dep_dirs): mkdir -p $@ missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs)) -else +dep_file = $(dir $@)deps/$(notdir $@).d +dep_args = -MF $(dep_file) -MMD -MP +ifdef CHECK_HEADER_DEPENDENCIES +$(error cannot compute header dependencies outside a normal build. \ +Please unset CHECK_HEADER_DEPENDENCIES and try again) +endif +endif + +ifndef COMPUTE_HEADER_DEPENDENCIES +ifndef CHECK_HEADER_DEPENDENCIES dep_dirs = missing_dep_dirs = +dep_args = +endif +endif + +ifdef CHECK_HEADER_DEPENDENCIES +ifndef PRINT_HEADER_DEPENDENCIES +missing_deps = $(filter-out $(notdir $^), \ + $(notdir $(shell $(MAKE) -s $@ \ + CHECK_HEADER_DEPENDENCIES=YesPlease \ + USE_COMPUTED_HEADER_DEPENDENCIES=YesPlease \ + PRINT_HEADER_DEPENDENCIES=YesPlease))) +endif endif +ASM_SRC := $(wildcard $(OBJECTS:o=S)) +ASM_OBJ := $(ASM_SRC:S=o) +C_OBJ := $(filter-out $(ASM_OBJ),$(OBJECTS)) + .SUFFIXES: +ifdef PRINT_HEADER_DEPENDENCIES +$(C_OBJ): %.o: %.c FORCE + echo $^ +$(ASM_OBJ): %.o: %.S FORCE + echo $^ + +ifndef CHECK_HEADER_DEPENDENCIES +$(error cannot print header dependencies during a normal build. \ +Please set CHECK_HEADER_DEPENDENCIES and try again) +endif +endif + +ifndef PRINT_HEADER_DEPENDENCIES +ifdef CHECK_HEADER_DEPENDENCIES +$(C_OBJ): %.o: %.c $(dep_files) FORCE + @set -e; echo CHECK $@; \ + missing_deps="$(missing_deps)"; \ + if test "$$missing_deps"; \ + then \ + echo missing dependencies: $$missing_deps; \ + false; \ + fi +$(ASM_OBJ): %.o: %.S $(dep_files) FORCE + @set -e; echo CHECK $@; \ + missing_deps="$(missing_deps)"; \ + if test "$$missing_deps"; \ + then \ + echo missing dependencies: $$missing_deps; \ + false; \ + fi +endif +endif + +ifndef CHECK_HEADER_DEPENDENCIES $(C_OBJ): %.o: %.c GIT-CFLAGS $(missing_dep_dirs) $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $< -%.s: %.c GIT-CFLAGS FORCE - $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< $(ASM_OBJ): %.o: %.S GIT-CFLAGS $(missing_dep_dirs) $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $< +endif -ifdef COMPUTE_HEADER_DEPENDENCIES +%.s: %.c GIT-CFLAGS FORCE + $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< + +ifdef USE_COMPUTED_HEADER_DEPENDENCIES # Take advantage of gcc's on-the-fly dependency generation # See <http://gcc.gnu.org/gcc-3.0/features.html>. -dep_files := $(wildcard $(foreach f,$(OBJECTS),$(dir f)deps/$(notdir $f).d)) -ifneq ($(dep_files),) -include $(dep_files) +dep_files_present := $(wildcard $(dep_files)) +ifneq ($(dep_files_present),) +include $(dep_files_present) endif - -dep_file = $(dir $@)deps/$(notdir $@).d -dep_args = -MF $(dep_file) -MMD -MP else -dep_args = - # Dependencies on header files, for platforms that do not support # the gcc -MMD option. #
Signature · 1 line
1.6.6
Re: [PATCH 12/12] Teach Makefile to check header dependencies
Quoted 11 lines · Jonathan Nieder
Add a target to use the gcc-generated makefile snippets for dependencies on header files to check the hard-coded dependencies.
With this patch applied, if any dependencies are missing, then
make clean
make COMPUTE_HEADER_DEPENDENCIES=YesPlease make CHECK_HEADER_DEPENDENCIES=YesPleasewill produce an error message like the following:
Quoted 7 lines
CHECK fast-import.o missing dependencies: exec_cmd.h make: *** [fast-import.o] Error 1Signed-off-by Jonathan Nieder <[email protected]>---
That’s the end of the series. Thanks for reading.
Thanks.
Three observations:
* "make distclean" should remove $(dep_files);
* "deps/" should probably be ".depend/" or something less distracting;
* I wish CHECK_HEADER_DEPENDENCIES pointed out unnecessary dependencies hardcoded in the Makefile.
-- >8 --
Subject: [PATCH] Makefile: "make distclean" should remove dependency files
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -2110,7 +2110,7 @@ dist-doc: ### Cleaning rules distclean: clean - $(RM) configure + $(RM) configure $(dep_files) clean: $(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o \
Signature · 1 line
1.7.0.rc1.141.gd3fd2
Re: [PATCH 12/12] Teach Makefile to check header dependencies
Quoted 5 lines · Junio C Hamano
Thanks.
Three observations:
* "make distclean" should remove $(dep_files);
It removes $(dep_dirs) in "make clean". Do you think they should be kept around? Or is this about when COMPUTE_HEADER_DEPENDENCIES is turned off but .o.d files remain?
Quoted 1 line
* "deps/" should probably be ".depend/" or something less distracting;
Good idea.
Quoted 2 lines
* I wish
CHECK_HEADER_DEPENDENCIESpointed out unnecessary dependencies hardcoded in theMakefile.
That would not be hard to do, but wouldn’t the $(GIT_OBJS): $(LIB_H) rule create a lot of noise?
How about if it checks for duplicate dependencies and unnecessary dependencies that are not in LIB_H?
Quoted 13 lines
-- >8 --
Subject: [PATCH]Makefile: "make distclean" should remove dependency filesSigned-off-by Junio C Hamano <[email protected]>--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)Makefile +0
-0
Makefile dist-doc: · line 2113
Quoted 5 lines
Makefile +1
-1@@ -2110,7 +2110,7 @@ dist-doc: ### Cleaning rules distclean: clean - $(RM) configure + $(RM) configure $(dep_files)
This couldn’t hurt, but I wonder whether it is necessary; see above.
Thanks for the feedback,
Jonathan
Re: [PATCH 12/12] Teach Makefile to check header dependencies
Quoted 9 lines · Jonathan Nieder
Junio C Hamano wrote:
...Quoted 3 lines
Three observations:
* "make distclean" should remove $(dep_files);
It removes $(dep_dirs) in "make clean". Do you think they should be kept around? Or is this about when
COMPUTE_HEADER_DEPENDENCIESis turned off but .o.d files remain?
Yes, the last one. After playing around, with or without COMPUTE/CHECK, and then making a final build, it would be nice if "make distclean" removed all the intermediate build products without the same special "debug build" options (and without COMPUTE, dep_dirs is empty so nothing is removed). It is also fine if "make clean" did so.
Quoted 8 lines
Quoted 2 lines
* I wish
CHECK_HEADER_DEPENDENCIESpointed out unnecessary dependencies hardcoded in theMakefile.That would not be hard to do, but wouldn’t the $(GIT_OBJS): $(LIB_H) rule create a lot of noise?
How about if it checks for duplicate dependencies and unnecessary dependencies that are not in
LIB_H?
That would be ideal, I think.
[PATCH 14/12] Makefile: always remove .depend directories on 'make clean'
Even if COMPUTE_HEADER_DEPENDENCIES is not set, some .o.d files might be lying around from previous builds when it was. This is especially likely because using the CHECK_HEADER_DEPENDENCIES feature requires building sometimes with COMPUTE... on and sometimes with it off. At the end of such an exercise, to get a blank slate, the user ought to be able to just run 'make clean'. Make it so.
---
Quoted 5 lines · Junio C Hamano
Yes, the last one. After playing around, with or without COMPUTE/CHECK, and then making a final build, it would be nice if "make distclean" removed all the intermediate build products without the same special "debug build" options (and without COMPUTE,
dep_dirsis empty so nothing is removed).
Another good idea. :)
Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -1693,9 +1693,9 @@ XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d) +dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS)))) ifdef COMPUTE_HEADER_DEPENDENCIES -dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS)))) $(dep_dirs): mkdir -p $@
Signature · 1 line
1.7.0.rc1
[PATCH 13/12] Makefile: tuck away generated makefile fragments in .depend
In reply to Junio C HamanoWhen building with COMPUTE_HEADER_DEPENDENCIES on, save dependency information to .depend/ instead of deps/ so it does not show up in ‘ls’ output. Otherwise, the extra directories can be distracting.
---
Quoted 1 line · Junio C Hamano
* "deps/" should probably be ".depend/" or something less distracting;
Good idea. Here goes...
Makefile | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
@@ -1692,15 +1692,15 @@ XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) -dep_files := $(foreach f,$(OBJECTS),$(dir $f)deps/$(notdir $f).d) +dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d) ifdef COMPUTE_HEADER_DEPENDENCIES -dep_dirs := $(addsuffix deps,$(sort $(dir $(OBJECTS)))) +dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS)))) $(dep_dirs): mkdir -p $@ missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs)) -dep_file = $(dir $@)deps/$(notdir $@).d +dep_file = $(dir $@).depend/$(notdir $@).d dep_args = -MF $(dep_file) -MMD -MP ifdef CHECK_HEADER_DEPENDENCIES $(error cannot compute header dependencies outside a normal build. \
Signature · 1 line
1.7.0.rc1
Quoted 2 lines · Jonathan Nieder
The remainder of this series is based on a merge of master and patches 1-5:
[...]
Quoted 5 lines
Jonathan Nieder (12):
Makefile: add missing header file dependencies
Makefile: make sure test helpers are rebuilt when headers change
Makefile: removewt-status.hfromLIB_H
Makefile: clean up http-walker.o dependency rules
Quoted 8 lines
Makefile: drop dependency on $(wildcard */*.h)
Makefile: transport.o depends onbranch.hnow
Makefile: rearrange dependency rules
Makefile: disable default implicit rules
Makefile: list generated object files in OBJECTS macro
Makefile: lazily compute header dependencies
Makefile: list standalone program object files inPROGRAM_OBJSTeachMakefileto check header dependencies
For those would like to avoid redoing the conflict resolution (and who wouldn’t?), this series is also available in the git repository at
git://repo.or.cz/git/jrn.git autodep
If you’re interested, please take a look around and try it out. I’d be happy to hear about any bugs you find.
Thanks again,
Jonathan