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 83F08431FAF for ; Wed, 11 Apr 2012 13:38:44 -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 7+rNSTTay-Po for ; Wed, 11 Apr 2012 13:38:43 -0700 (PDT) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id CD353431FAE for ; Wed, 11 Apr 2012 13:38:43 -0700 (PDT) X-AuditID: 1209190f-b7f8a6d000000914-9a-4f85ebd3815b Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id 01.EF.02324.3DBE58F4; Wed, 11 Apr 2012 16:38:43 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q3BKcgMb011757; Wed, 11 Apr 2012 16:38:42 -0400 Received: from drake.mit.edu (31-35-38.wireless.csail.mit.edu [128.31.35.38]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3BKcfbs013275 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Wed, 11 Apr 2012 16:38:42 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1SI4JM-0006Ur-KN; Wed, 11 Apr 2012 16:38:40 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2] Record dependencies during build instead of before Date: Wed, 11 Apr 2012 16:38:39 -0400 Message-Id: <1334176719-24781-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1333857710-24511-1-git-send-email-amdragon@mit.edu> References: <1333857710-24511-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixG6nrnv5dau/wepeXovrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoEr49+Br0wFj8Qqrn1uYG1g3CTUxcjJISFgIrF91k02CFtM4sK9 9WC2kMA+RonLDx26GLmA7A2MEhvWd7BAOCeZJBa1v2OEqJrPKHH+CzuIzSagIbFt/3KwuIiA tMTOu7NZuxg5OJgF1CT+dKmAhIUF3CRW3jrCDGKzCKhKnDywEKyVV8BB4u3CB4wQRyhIPFt3 nAnE5hRwlHj5o4MZYpWDxP8lkxgnMPIvYGRYxSibklulm5uYmVOcmqxbnJyYl5dapGuil5tZ opeaUrqJERQynJL8Oxi/HVQ6xCjAwajEw7trQqu/EGtiWXFl7iFGSQ4mJVHeqa+AQnxJ+SmV GYnFGfFFpTmpxYcYJTiYlUR4XWa3+AvxpiRWVqUW5cOkpDlYlMR51bTe+QkJpCeWpGanphak FsFkZTg4lCR4vzwFGipYlJqeWpGWmVOCkGbi4AQZzgM0nPsZUA1vcUFibnFmOkT+FKOilDjv BZBmAZBERmkeXC8spl8xigO9Isx7EaSKB5gO4LpfAQ1mAhr8eTLI1cUliQgpqQbGtGCBGSWb lr19JaZzQ2PJMY1TquvWmL47cD+pKnhWhrXTp2liEn+6/Ux/lwReN+lvXeV+c8nOD0uOCf6o 0fewncr683Ii/w/eXxfNreJMHvqGRVoGy4RNb/kS8sI/eUX3oT0nZL8ueLjw16Xo+nNtvB83 1Juo+n3/Petgm9iCm4beE09cumi2UomlOCPRUIu5qDgRAG2Fw77EAgAA 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: Wed, 11 Apr 2012 20:38:44 -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. --- Sorry, the previous version of this patch was corrupted. Hopefully this one will be correct. 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,22 +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