]> git.notmuchmail.org Git - notmuch/commitdiff
Makefile: Fix dependency generation for files in sub-directories.
authorCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 06:24:55 +0000 (22:24 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 06:24:55 +0000 (22:24 -0800)
Otherwise, things in the lib sub-directory weren't getting recompiled
even when lib/notmuch.h was changed.

The original rule we were using came from the GNU Makefile manual, but
only handled files in the current directory, not file in
sub-directories as we use here with our non-recursive Makefile.

So the .deps files being created were being put in the right place,
(such as .deps/lib/database.d), but the compiler was generating a
dependency for "database.o" rather than "lib/database.o" like we
want. We were already trying to do a sed job on that name to add a
dependency for the .d file as well. But the sed job was failing since
the expected pattern wasn't there, (the directory name was missing).

So the fix is simply to use basename to construct the search pattern,
and then use the name with the directory in the replacement (rather
than the back-reference).

Makefile

index 6d1f3d82c5d253078e977518001e2e6c13be9f23..19b51491e1154bc33c61173d03effdfdb51d20c0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -27,13 +27,13 @@ include lib/Makefile.local
 .deps/%.d: %.c
        @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
        $(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@.$$$$; \
 .deps/%.d: %.c
        @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
        $(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@.$$$$; \
-       sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+       sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \
        rm -f $@.$$$$
 
 .deps/%.d: %.cc
        @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
        $(CXX) -M $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
        rm -f $@.$$$$
 
 .deps/%.d: %.cc
        @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
        $(CXX) -M $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
-       sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+       sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \
        rm -f $@.$$$$
 
 DEPS := $(SRCS:%.c=.deps/%.d)
        rm -f $@.$$$$
 
 DEPS := $(SRCS:%.c=.deps/%.d)