[CRIU] [PATCH 7/7] build/make: return to make from top Makefile

Dmitry Safonov dsafonov at virtuozzo.com
Fri Jul 15 05:17:59 PDT 2016


It looks like, there is not so much that needs to be fixed for
building criu from a top Makefile.
After the patch it's possible to do `make criu/mount.o` i.e.
It will build protobuf, compel as dependencies (if they are not built),
but no more from criu objects. If something breaks, you can
do make from vim and jump to error. Nice.
Mostly the patch corrects pathes to objects - I tried to make them
depend on $(obj) or $(SRC_DIR)/criu, where it's possible.

After it tested:
`make -j 10`, `make criu/log.o`, `make clean`, `make mrproper`,
`make install DESTDIR=/tmp/criu`, `make uninstall DESTDIR=/tmp/criu`

Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 Makefile                  |  8 ++--
 Makefile.install          |  2 +-
 criu/Makefile             | 96 +++++++++++++++++++++++------------------------
 criu/Makefile.config      |  6 +--
 criu/Makefile.crtools     |  8 ++--
 criu/Makefile.packages    |  3 +-
 criu/pie/Makefile         |  5 ++-
 criu/pie/Makefile.library |  3 +-
 scripts/protobuf-gen.sh   |  2 +-
 9 files changed, 67 insertions(+), 66 deletions(-)

diff --git a/Makefile b/Makefile
index df36994c3f64..271c39e4832b 100644
--- a/Makefile
+++ b/Makefile
@@ -197,9 +197,9 @@ test/compel/%: .FORCE
 # But note that we're already included
 # the nmk so we can reuse it there.
 criu/%: images/built-in.o compel/compel $(VERSION_HEADER) .FORCE
-	$(Q) $(MAKE) -C criu $@
+	$(Q) $(MAKE) $(build)=criu $@
 criu: images/built-in.o compel/compel $(VERSION_HEADER)
-	$(Q) $(MAKE) -C criu all
+	$(Q) $(MAKE) $(build)=criu all
 .PHONY: criu
 
 #
@@ -226,14 +226,14 @@ subclean:
 clean: subclean
 	$(Q) $(MAKE) $(build)=images $@
 	$(Q) $(MAKE) $(build)=compel $@
-	$(Q) $(MAKE) -C criu $@
+	$(Q) $(MAKE) $(build)=criu $@
 .PHONY: clean
 
 # mrproper depends on clean in nmk
 mrproper: subclean
 	$(Q) $(MAKE) $(build)=images $@
 	$(Q) $(MAKE) $(build)=compel $@
-	$(Q) $(MAKE) -C criu $@
+	$(Q) $(MAKE) $(build)=criu $@
 	$(Q) $(RM) $(VERSION_HEADER)
 	$(Q) $(RM) cscope.*
 	$(Q) $(RM) tags TAGS
diff --git a/Makefile.install b/Makefile.install
index e3dd55141272..dbc22e116f34 100644
--- a/Makefile.install
+++ b/Makefile.install
@@ -43,7 +43,7 @@ install-lib: lib
 .PHONY: install-lib
 
 install-criu: criu
-	$(Q) $(MAKE) -C criu install
+	$(Q) $(MAKE) $(build)=criu install
 .PHONY: install-criu
 
 install: install-man install-lib install-criu
diff --git a/criu/Makefile b/criu/Makefile
index 1aeacbb401ec..c0e31d339db3 100644
--- a/criu/Makefile
+++ b/criu/Makefile
@@ -2,8 +2,9 @@
 # 6a8d90f5fec4 "attr: Allow attribute type 0" 
 WRAPFLAGS		+= -Wl,--wrap=nla_parse,--wrap=nlmsg_parse
 
-ARCH_DIR		:= arch/$(SRCARCH)
-export ARCH_DIR
+ARCH_DIR		:= criu/arch/$(SRCARCH)
+PIE_DIR			:= criu/pie
+export ARCH_DIR PIE_DIR
 
 #
 # General flags.
@@ -11,8 +12,8 @@ ccflags-y		+= -fno-strict-aliasing
 ccflags-y		+= -iquote $(SRC_DIR)/criu/include
 ccflags-y		+= -iquote $(SRC_DIR)/images
 ccflags-y		+= -iquote $(SRC_DIR)/criu/pie
-ccflags-y		+= -iquote $(SRC_DIR)/criu/$(ARCH_DIR)
-ccflags-y		+= -iquote $(SRC_DIR)/criu/$(ARCH_DIR)/include
+ccflags-y		+= -iquote $(SRC_DIR)/$(ARCH_DIR)
+ccflags-y		+= -iquote $(SRC_DIR)/$(ARCH_DIR)/include
 ccflags-y		+= -iquote $(SRC_DIR)/
 ccflags-y		+= -I/usr/include/libnl3
 
@@ -38,11 +39,14 @@ include $(__nmk_dir)/msg.mk
 
 #
 # Needed libraries checks
-include Makefile.packages
+include $(SRC_DIR)/criu/Makefile.packages
 
 #
 # Configure variables.
-include Makefile.config
+CONFIG_HEADER := $(obj)/include/config.h
+ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),)
+include $(SRC_DIR)/criu/Makefile.config
+endif
 config: $(VERSION_HEADER)
 
 #
@@ -65,64 +69,64 @@ $(ARCH-LIB): syscalls_lib
 
 #
 # PIE library code.
-pie/native.lib.a: $(ARCH-LIB)
-	$(Q) $(MAKE) $(call build-as,Makefile.library,pie) all
+$(PIE_DIR)/native.lib.a: $(ARCH-LIB)
+	$(Q) $(MAKE) $(call build-as,Makefile.library,$(PIE_DIR)) all
 
 #
 # PIE code blobs themseves.
-pie: pie/native.lib.a
-	$(Q) $(MAKE) $(build)=pie all
+pie: $(PIE_DIR)/native.lib.a
+	$(Q) $(MAKE) $(build)=$(PIE_DIR) all
 .PHONY: pie
 
 #
 # CRIU executable
-PROGRAM-BUILTINS	+= ../images/built-in.o
-PROGRAM-BUILTINS	+= built-in.o
-PROGRAM-BUILTINS	+= pie/native.lib.a
+PROGRAM-BUILTINS	+= images/built-in.o
+PROGRAM-BUILTINS	+= $(obj)/built-in.o
+PROGRAM-BUILTINS	+= $(PIE_DIR)/native.lib.a
 PROGRAM-BUILTINS	+= $(ARCH-LIB)
 
-built-in.o: pie
-	$(Q) $(MAKE) $(call build-as,Makefile.crtools,.) all
+$(obj)/built-in.o: pie
+	$(Q) $(MAKE) $(call build-as,Makefile.crtools,criu) all
 
-criu: $(PROGRAM-BUILTINS)
+$(obj)/criu: $(PROGRAM-BUILTINS)
 	$(call msg-link, $@)
 	$(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(WRAPFLAGS) $(LDFLAGS) $(GMONLDOPT) -rdynamic -o $@
 
 
-subclean:
-	$(Q) $(RM) ./*.{gcda,gcno,gcov}
-	$(Q) $(RM) ./pie/*.{gcda,gcno,gcov}
-	$(Q) $(RM) -r ./gcov
-	$(Q) $(RM) criu
-.PHONY: subclean
-
 #
 # Clean the most, except generated c files
+subclean:
+	$(Q) $(RM) $(obj)/*.{gcda,gcno,gcov}
+	$(Q) $(RM) $(obj)/pie/*.{gcda,gcno,gcov}
+	$(Q) $(RM) -r $(obj)/gcov
+	$(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) clean
+	$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) clean
+	$(Q) $(MAKE) $(call build-as,Makefile.library,$(PIE_DIR)) clean
+	$(Q) $(MAKE) $(call build-as,Makefile.crtools,criu) clean
+	$(Q) $(MAKE) $(build)=$(PIE_DIR) clean
+.PHONY: subclean
+cleanup-y      += $(obj)/criu
 clean: subclean
-	$(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) $@
-	$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) $@
-	$(Q) $(MAKE) $(call build-as,Makefile.library,pie) $@
-	$(Q) $(MAKE) $(call build-as,Makefile.crtools,.) $@
-	$(Q) $(MAKE) $(build)=pie $@
-.PHONY: clean
 
 #
 # Delete all generated files
-mrproper: subclean
-	$(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) $@
-	$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) $@
-	$(Q) $(MAKE) $(call build-as,Makefile.library,pie) $@
-	$(Q) $(MAKE) $(call build-as,Makefile.crtools,.) $@
-	$(Q) $(MAKE) $(build)=pie $@
-	$(Q) $(RM) $(CONFIG_HEADER)
-.PHONY: mrproper
-
-UAPI_HEADERS := include/criu-plugin.h include/criu-log.h
-
-install: criu
-	$(E) "  INSTALL " criu
+subproper:
+	$(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) mrproper
+	$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) mrproper
+	$(Q) $(MAKE) $(call build-as,Makefile.library,$(PIE_DIR)) mrproper
+	$(Q) $(MAKE) $(call build-as,Makefile.crtools,criu) mrproper
+	$(Q) $(MAKE) $(build)=$(PIE_DIR) mrproper
+.PHONY: subproper
+mrproper-y     += $(CONFIG_HEADER)
+mrproper: subproper
+
+UAPI_HEADERS := $(SRC_DIR)/criu/include/criu-plugin.h
+UAPI_HEADERS += $(SRC_DIR)/criu/include/criu-log.h
+
+install: $(obj)/criu
+	$(E) "  INSTALL " $(obj)/criu
 	$(Q) mkdir -p $(DESTDIR)$(SBINDIR)
-	$(Q) install -m 755 criu $(DESTDIR)$(SBINDIR)
+	$(Q) install -m 755 $(obj)/criu $(DESTDIR)$(SBINDIR)
 	$(Q) mkdir -p $(DESTDIR)$(INCLUDEDIR)
 	$(Q) install -m 644 $(UAPI_HEADERS) $(DESTDIR)$(INCLUDEDIR)
 	$(Q) mkdir -p $(DESTDIR)$(LIBEXECDIR)/criu/scripts
@@ -136,8 +140,4 @@ uninstall:
 	$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBEXECDIR)/criu/scripts/,systemd-autofs-restart.sh)
 .PHONY: uninstall
 
-#
-# Final @all target.
-all: check-packages criu
-	@true
-.PHONY: all
+all-y += check-packages $(obj)/criu
diff --git a/criu/Makefile.config b/criu/Makefile.config
index 236ace5197aa..a5d4828f6496 100644
--- a/criu/Makefile.config
+++ b/criu/Makefile.config
@@ -1,8 +1,6 @@
 include $(__nmk_dir)/utils.mk
 include $(__nmk_dir)msg.mk
-include ../scripts/feature-tests.mak
-
-CONFIG_HEADER := include/config.h
+include $(SRC_DIR)/scripts/feature-tests.mak
 
 ifeq ($(call try-cc,$(FEATURE_TEST_LIBBSD_DEV),-lbsd),y)
         LIBS	+= -lbsd
@@ -26,7 +24,7 @@ endif
 endef
 
 define config-header-rule
-$(CONFIG_HEADER): include/config-base.h
+$(CONFIG_HEADER): $(obj)/include/config-base.h
 	$$(call msg-gen, $$@)
 	$(Q) @echo '#ifndef __CR_CONFIG_H__'				> $$@
 	$(Q) @echo '#define __CR_CONFIG_H__'				>> $$@
diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools
index fbdfa0583168..8e9c3b48d1a3 100644
--- a/criu/Makefile.crtools
+++ b/criu/Makefile.crtools
@@ -1,4 +1,4 @@
-ccflags-y		+= -iquote $(ARCH)
+ccflags-y		+= -iquote criu/$(ARCH)
 ccflags-y		+= $(DEFINES)
 obj-y			+= action-scripts.o
 obj-y			+= aio.o
@@ -87,10 +87,10 @@ endif
 
 PROTOBUF_GEN := $(SRC_DIR)/scripts/protobuf-gen.sh
 
-protobuf-desc.c: protobuf-desc-gen.h
+$(obj)/protobuf-desc.d: $(obj)/protobuf-desc-gen.h
 
-protobuf-desc-gen.h: $(PROTOBUF_GEN) include/protobuf-desc.h
+$(obj)/protobuf-desc-gen.h: $(PROTOBUF_GEN) criu/include/protobuf-desc.h
 	$(call msg-gen, $@)
 	$(Q) $(SH) $(PROTOBUF_GEN) > $@
 
-mrproper-y += protobuf-desc-gen.h
+mrproper-y += $(obj)/protobuf-desc-gen.h
diff --git a/criu/Makefile.packages b/criu/Makefile.packages
index 4c51e8dc7a07..1b4eb1dedff9 100644
--- a/criu/Makefile.packages
+++ b/criu/Makefile.packages
@@ -38,5 +38,6 @@ check-packages-failed:
 	$(error Compilation aborted)
 
 check-packages:
-	$(Q) $(MAKE) check-build-packages || $(MAKE) check-packages-failed
+	$(Q) $(MAKE) -f $(obj)/Makefile.packages check-build-packages || \
+		$(MAKE) -f $(obj)/Makefile.packages check-packages-failed
 .PHONY: check-build-packages check-packages-failed check-packages
diff --git a/criu/pie/Makefile b/criu/pie/Makefile
index e30293692c5e..57c71fb2ab68 100644
--- a/criu/pie/Makefile
+++ b/criu/pie/Makefile
@@ -44,8 +44,9 @@ target			+= $(parasite_target) restorer
 CFLAGS			:= $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS))
 CFLAGS			:= $(filter-out -DCONFIG_X86_64,$(CFLAGS))
 CFLAGS			+= -iquote $(SRC_DIR)/compel/include
-CFLAGS			+= -iquote arch/$(ARCH)/include -iquote $(SRC_DIR)
+CFLAGS			+= -iquote $(SRC_DIR)/criu/arch/$(ARCH)/include
 CFLAGS			+= -iquote $(SRC_DIR)/criu/include
+CFLAGS			+= -iquote $(SRC_DIR)
 
 ccflags-y		+= -DCR_NOGLIBC
 ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),)
@@ -125,7 +126,7 @@ endif # non i386
 endif # non x86 ARCH
 
 # for C files, we need "parasite-native" to be "parasite_native"
-target-name = $(patsubst pie/%_blob.h,%,$(subst -,_,$(1)))
+target-name = $(patsubst criu/pie/%_blob.h,%,$(subst -,_,$(1)))
 
 ifeq ($(piegen-y),y)
 ifeq ($(strip $(V)),)
diff --git a/criu/pie/Makefile.library b/criu/pie/Makefile.library
index 288594a64959..b5825e069a62 100644
--- a/criu/pie/Makefile.library
+++ b/criu/pie/Makefile.library
@@ -53,7 +53,8 @@ $(eval $(call map,gen-compat-objs,$(OBJS)))
 # applications, which is not the target of the
 # project.
 #
-iquotes			:= -iquote pie/piegen -iquote arch/$(ARCH)/include
+iquotes			:= -iquote $(SRC_DIR)/$(PIE_DIR)/piegen
+iquotes			+= -iquote $(SRC_DIR)/$(ARCH_DIR)/include
 iquotes			+= -iquote $(SRC_DIR) -iquote $(SRC_DIR)/criu/include
 CFLAGS			:= $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS)) $(iquotes)
 asflags-y		:= -D__ASSEMBLY__ $(iquotes)
diff --git a/scripts/protobuf-gen.sh b/scripts/protobuf-gen.sh
index fb753c5146f5..29c52cf1a25c 100644
--- a/scripts/protobuf-gen.sh
+++ b/scripts/protobuf-gen.sh
@@ -5,7 +5,7 @@ for x in $(sed -n '/PB_AUTOGEN_START/,/PB_AUTOGEN_STOP/ {
 		s/,.*$//;
 		s/\tPB_//;
 		p;
-	   }' include/protobuf-desc.h); do
+	   }' criu/include/protobuf-desc.h); do
 	x_la=$(echo $x | sed $TR)
 	x_uf=$(echo $x | sed -nr 's/^./&#\\\
 /;
-- 
2.9.0



More information about the CRIU mailing list