[CRIU] [PATCH 9/9] Makefiles: protect from % rules, don't rebuild

Kir Kolyshkin kir at openvz.org
Wed Feb 22 15:15:49 PST 2017


GNU make tries to rebuild any makefiles it uses. While in general it's
a good idea (and it is used e.g. in autoconf-based builds), in our case
it is not necessary, as all the makefiles are static.

More to say, as we have a few "match anything" rules for subdirectories,
Makefiles in these subdirs are also matching these rules, which leads to
excessive (re)building while a particular makefile is needed.

Protect such Makefiles with explicit (or pattern) rules, so make knows
it should do nothing to rebuild those.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 Makefile        | 16 ++++++++++++++--
 Makefile.compel |  2 ++
 criu/Makefile   |  8 ++++++--
 lib/Makefile    |  3 ++-
 lib/py/Makefile |  1 +
 5 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 114bbb0..87b6759 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,15 @@
-#
-# Import the build engine first
 __nmk_dir=$(CURDIR)/scripts/nmk/scripts/
 export __nmk_dir
 
+#
+# No need to try to remake our Makefiles
+Makefile: ;
+Makefile.%: ;
+scripts/%.mak: ;
+$(__nmk_dir)%.mk: ;
+
+#
+# Import the build engine
 include $(__nmk_dir)include.mk
 include $(__nmk_dir)macro.mk
 
@@ -213,6 +220,7 @@ SOCCR_A := soccr/libsoccr.a
 SOCCR_CONFIG := soccr/config.h
 $(SOCCR_CONFIG): $(CONFIG_HEADER)
 	$(Q) test -f $@ || ln -s ../$(CONFIG_HEADER) $@
+soccr/Makefile: ;
 soccr/%: $(SOCCR_CONFIG) .FORCE
 	$(Q) $(MAKE) $(build)=soccr $@
 soccr/built-in.o: $(SOCCR_CONFIG) .FORCE
@@ -228,6 +236,9 @@ criu-deps	+= $(SOCCR_A)
 #
 # But note that we're already included
 # the nmk so we can reuse it there.
+criu/Makefile: ;
+criu/Makefile.packages: ;
+criu/Makefile.crtools: ;
 criu/%: $(criu-deps) .FORCE
 	$(Q) $(MAKE) $(build)=criu $@
 criu: $(criu-deps)
@@ -238,6 +249,7 @@ criu: $(criu-deps)
 # Libraries next once criu it ready
 # (we might generate headers and such
 # when building criu itself).
+lib/Makefile: ;
 lib/%: criu .FORCE
 	$(Q) $(MAKE) $(build)=lib $@
 lib: criu
diff --git a/Makefile.compel b/Makefile.compel
index 7586ef3..408f0a7 100644
--- a/Makefile.compel
+++ b/Makefile.compel
@@ -31,6 +31,7 @@ criu-deps		+= compel/$(LIBCOMPEL_A)
 
 #
 # Compel itself.
+compel/Makefile: ;
 compel/%: $(compel-deps) $(compel-plugins) .FORCE
 	$(Q) $(MAKE) $(build)=compel $@
 
@@ -38,6 +39,7 @@ criu-deps		+= compel/compel-host-bin
 
 #
 # Plugins
+compel/plugins/Makefile: ;
 compel/plugins/%: $(compel-deps) .FORCE
 	$(Q) $(MAKE) $(build)=compel/plugins $@
 
diff --git a/criu/Makefile b/criu/Makefile
index ada75af..735890e 100644
--- a/criu/Makefile
+++ b/criu/Makefile
@@ -57,6 +57,8 @@ pie: criu/pie/pie.lib.a
 	$(Q) $(MAKE) $(build)=criu/pie all
 .PHONY: pie
 
+criu/pie/Makefile: ;
+criu/pie/Makefile.library: ;
 criu/pie/%: pie ;
 
 #
@@ -71,8 +73,10 @@ PROGRAM-BUILTINS	+= $(COMPEL_LIBS)
 $(obj)/built-in.o: pie
 	$(Q) $(MAKE) $(call build-as,Makefile.crtools,criu) all
 
-$(obj)/Makefile:
-	@true
+
+$(obj)/Makefile: ;
+$(obj)/Makefile.crtools: ;
+$(obj)/Makefile.packages: ;
 
 $(obj)/%: pie
 	$(Q) $(MAKE) $(call build-as,Makefile.crtools,criu) $@
diff --git a/lib/Makefile b/lib/Makefile
index 4bc865a..a8647ce 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -12,8 +12,8 @@ all-y	+= lib-c lib-py
 
 #
 # C language bindings.
+lib/c/Makefile: ;
 lib/c/%: .FORCE
-	$(call msg-gen, $@)
 	$(Q) $(MAKE) $(build)=lib/c $@
 
 cflags-so		+= $(CFLAGS) -rdynamic -Wl,-soname,$(CRIU_SO).$(CRIU_SO_VERSION_MAJOR)
@@ -27,6 +27,7 @@ lib-c: lib/c/$(CRIU_SO)
 
 #
 # Python bindings.
+lib/py/Makefile: ;
 lib/py/%: .FORCE
 	$(call msg-gen, $@)
 	$(Q) $(MAKE) $(build)=lib/py $@
diff --git a/lib/py/Makefile b/lib/py/Makefile
index 413b3da..5eb77d4 100644
--- a/lib/py/Makefile
+++ b/lib/py/Makefile
@@ -2,6 +2,7 @@ all-y	+= libpy-images rpc_pb2.py
 
 .PHONY: .FORCE
 
+$(obj)/images/Makefile: ;
 $(obj)/images/%: .FORCE
 	$(Q) $(MAKE) $(build)=$(obj)/images $@
 
-- 
2.9.3



More information about the CRIU mailing list