Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 19C69431FAF for ; Sat, 7 Apr 2012 21:01:59 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XZmwpt6JB6VA for ; Sat, 7 Apr 2012 21:01:58 -0700 (PDT) Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU [18.9.25.13]) by olra.theworths.org (Postfix) with ESMTP id 6B0BE431FAE for ; Sat, 7 Apr 2012 21:01:58 -0700 (PDT) X-AuditID: 1209190d-b7fbf6d0000008ba-06-4f810db57211 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP id C3.21.02234.5BD018F4; Sun, 8 Apr 2012 00:01:57 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q3841ueP019597; Sun, 8 Apr 2012 00:01:56 -0400 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3841run018608 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 8 Apr 2012 00:01:56 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1SGjK4-0006PU-PN; Sun, 08 Apr 2012 00:01:52 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH] Record dependencies during build instead of before Date: Sun, 8 Apr 2012 00:01:50 -0400 Message-Id: <1333857710-24511-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJIsWRmVeSWpSXmKPExsUixG6noruVt9HfYO5PHovrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoErY/GHT4wFu8UqXixsYm5gnCzUxcjBISFgIjFlXlAXIyeQKSZx 4d56ti5GLg4hgX2MEuuvL2OEcNYzSnRNPsIM4dxjkljRfhKqbD6jRP+Pmawg/WwCGhLb9i9n BLFFBKQldt6dzQqygllATeJPlwqIKSzgLDHjNg9IBYuAqsT/w1fYQWxeAQeJLT3PWCGuUJB4 tu440wRG3gWMDKsYZVNyq3RzEzNzilOTdYuTE/PyUot0jfRyM0v0UlNKNzGCQoBTkncH47uD SocYBTgYlXh4H+5o8BdiTSwrrsw9xCjJwaQkymvE3egvxJeUn1KZkVicEV9UmpNafIhRgoNZ SYT3/mGgct6UxMqq1KJ8mJQ0B4uSOK+q1js/IYH0xJLU7NTUgtQimKwMB4eSBK8UMNSFBItS 01Mr0jJzShDSTBycIMN5gIbzg9TwFhck5hZnpkPkTzEqSonzvucBSgiAJDJK8+B6YTH6ilEc 6BVh3jcgVTzA+IbrfgU0mAlocM2repDBJYkIKakGRglplo06D9Sfxfd7CSeV7bZrKlKZc9vg +Z6tSS65hwt90tffvljwrfZL42kWeT8DTc8Qvs3vDXe6d7pbJPmwM67ZrbZCdNO/fRZn1399 /iDh+OYfxyNjFepWyq1f8z544+G5KmH5t41Ei9hvHha+rXlDR/ob4waVBXwt67yb91Rz5fxX 3xOjqsRSnJFoqMVcVJwIAHwCWW6sAgAA X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Apr 2012 04:01:59 -0000 Previously, the makefile created dependency files in a separate, first pass. In particular, include-ing the dependency files would cause make to attempt to rebuild those files using the dependency-generation rules in the makefile. Unfortunately, this approach required obtuse rules and silently delayed the start of the build process (by quite a bit on a clean tree without any dependency files). Worse, this required the dependency files to themselves depend on all of the headers the source file depended on, which meant that, if a header file was removed, the depedency file could not be updated because of a missing dependency (!), which would cause make to silently fail. This patch eliminates the dependency generation rules and instead generates dependency files as a side-effect of the regular build rule. On the first build, we don't need to know the dependencies beforehand; the object file doesn't exist, so it will be built anyway. On subsequent builds, if a header file is updated, the dependency rules generated by the previous build will force a rebuild. If a source file is updated, the dependency rules may be stale, but it doesn't matter because the updated source file will force a rebuild. In the final case above, the stale dependency rules may refer to a header file that no longer exists but is also no longer needed. In order to prevent this from breaking the build, we also pass gcc the -MP option, which generates phony targets for every depended-on header file, so make won't complain if it can't find them during a later build. --- The description is way more complicated than the patch. Makefile.local | 18 ++++-------------- 1 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Makefile.local b/Makefile.local index 1131dea..525eda0 100644 --- a/Makefile.local +++ b/Makefile.local @@ -256,23 +256,12 @@ endif quiet ?= $($(shell echo $1 | sed -e s'/ .*//')) %.o: %.cc $(global_deps) + @mkdir -p .deps/$(@D) + $(call quiet,CXX $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d - $(call quiet,CXX $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@ %.o: %.c $(global_deps) + @mkdir -p .deps/$(@D) + $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d - $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@ - -.deps/%.d: %.c $(global_deps) - @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \ - $(CC) -M $(CPPFLAGS) $(FINAL_CFLAGS) $< > $@.$$$$ 2>/dev/null ; \ - sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ - -.deps/%.d: %.cc $(global_deps) - @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \ - $(CXX) -M $(CPPFLAGS) $(FINAL_CXXFLAGS) $< > $@.$$$$ 2>/dev/null ; \ - sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ .PHONY : clean clean: -- 1.7.9.1