[RFC PATCH 3] support goals after make *clean, *clean with current Makefile.config

Tomi Ollila tomi.ollila at iki.fi
Wed Jan 11 14:07:05 PST 2017

Makes make clean, make distclean and make dataclean faster if
Makefile.config exists but configure is newer.

After 1st target being *clean, any non-*clean targets may follow
it -- these are built in sub-make -- and when control returns
to main make, it just recognizes targers already made.


goal vs. target terminology is hard always

Makefile       | 15 +++++++++++++++
 Makefile.local | 27 ++++++++++++++++++++-------
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 0ef57fa..7540903 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,22 @@ include Makefile.config
 global_deps = Makefile Makefile.config Makefile.local \
 	$(subdirs:%=%/Makefile) $(subdirs:%=%/Makefile.local)
+ifneq ($(filter clean distclean dataclean, $(word 1, $(MAKECMDGOALS))),)
+ifneq ($(filter clean distclean dataclean, $(wordlist 2, 99, $(MAKECMDGOALS))),)
+$(error With "$(word 1, $(MAKECMDGOALS))" no further *clean targets works)
+WITH_CLEAN := yes
+# Potentially speedup make clean, distclean and dataclean ; avoid
+# re-creation of Makefile.config if it exists but configure is newer.
+ifeq ($(WITH_CLEAN),yes)
+Makefile.config: | $(srcdir)/configure
 Makefile.config: $(srcdir)/configure
 ifeq ($(configure_options),)
 	@echo ""
 	@echo "Note: Calling ./configure with no command-line arguments. This is often fine,"
diff --git a/Makefile.local b/Makefile.local
index 3548ed9..e33af45 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -198,18 +198,31 @@ quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))
 	@mkdir -p $(patsubst %/.,%,.deps/$(@D))
 	$(call quiet,CC $(CPPFLAGS) $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d
-.PHONY : clean
-	rm -rf $(CLEAN); rm -rf .deps
+.PHONY: _clean
+	rm -rf $(CLEAN)
+	rm -rf .deps
-.PHONY: distclean
-distclean: clean
+.PHONY: _distclean
+_distclean: _clean
 	rm -rf $(DISTCLEAN)
-.PHONY: dataclean
-dataclean: distclean
+.PHONY: _dataclean
+_dataclean: _distclean
 	rm -rf $(DATACLEAN)
+clean: _clean
+distclean: _distclean
+dataclean: _dataclean
+ifeq ($(WITH_CLEAN),yes)
+ifneq ($(word 2, $(MAKECMDGOALS)),)
+clean distclean dataclean: goals_after_clean
+	$(MAKE) $(wordlist 2, 99, $(MAKECMDGOALS)) configure_options=$(configure_options)
 notmuch_client_srcs =		\
 	debugger.c		\

More information about the notmuch mailing list