[PATCH 1/1] build: remove trailing '/.' when doing mkdir -p .deps/.

Tomi Ollila tomi.ollila at iki.fi
Sun Nov 3 13:55:00 PST 2013


On Sun, Nov 03 2013, Jed Brown <jed at 59A2.org> wrote:

> Tomi Ollila <tomi.ollila at iki.fi> writes:
>
>>  %.o: %.cc $(global_deps)
>> -	@mkdir -p .deps/$(@D)
>> +	@mkdir -p $(patsubst %/.,%,.deps/$(@D))
>>  	$(call quiet,CXX $(CPPFLAGS) $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d
>
> An alternative approach is to use directory marker files [1] to clean up
> the recipes that need output directories and to satisfy Paul's second
> rule of makefiles [2].
>
> .SECONDEXPANSION:
>
> %.o: %.cc $(global_deps) | .deps/$$(@D)/.DIR
> 	$(call quiet,CXX $(CPPFLAGS) $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d
>
> %/.DIR:
> 	@mkdir -p $(patsubst %/.,%,$(@D))
> 	@touch $@
>
> .PRECIOUS: %.DIR

Hmm, nice suggestion... the diff to be reviewed is just soo much bigger ;/

Now that I learned new things [11] yet another alternative is:

diff --git a/Makefile.local b/Makefile.local
index 72524eb..cc1a0cb 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -235,12 +235,15 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))
 
-%.o: %.cc $(global_deps)
-	@mkdir -p .deps/$(@D)
+depdirs = $(subdirs:%=.deps/%)
+
+$(depdirs):
+	@mkdir -p $(depdirs)
+
+%.o: %.cc $(global_deps) | $(depdirs)
 	$(call quiet,CXX $(CPPFLAGS) $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d
 
-%.o: %.c $(global_deps)
-	@mkdir -p .deps/$(@D)
+%.o: %.c $(global_deps) | $(depdirs)
 	$(call quiet,CC $(CPPFLAGS) $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d
 
 .PHONY : clean


still, for the time being I'd still use the patch I originally proposed
due to the triviality I change...


[11] http://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html

Tomi


> [1] http://www.cmcrossroads.com/article/making-directories-gnu-make
> [2] http://make.paulandlesley.org/rules.html


More information about the notmuch mailing list