2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-02 15:25:21 +00:00

build/make: return to make from top directory

It looks like, there is not so much that needs to be fixed for
building criu from a top directory.
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`

Note: I improperly called v1 for this patch as "return to make from
top Makefile" -- but I didn't mean that (and it was friday ;)

This patch doesn't yet switch to top-Makefile building, but that's
a step in that way (building from a top Makefile needs correct pathes
in makefiles) which also adds ability to build objects in subdirectories
and etc.

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
Dmitry Safonov
2016-07-18 22:22:48 +03:00
committed by Pavel Emelyanov
parent a9a6240313
commit 7a3604845d
9 changed files with 88 additions and 80 deletions

View File

@@ -179,6 +179,8 @@ endif
# on anything else.
$(eval $(call gen-built-in,images))
.PHONY: .FORCE
#
# CRIU building done in own directory
# with slightly different rules so we
@@ -187,17 +189,17 @@ $(eval $(call gen-built-in,images))
#
# But note that we're already included
# the nmk so we can reuse it there.
criu/%: images/built-in.o $(VERSION_HEADER)
$(Q) $(MAKE) -C criu $@
criu/%: images/built-in.o $(VERSION_HEADER) .FORCE
$(Q) $(MAKE) $(build)=criu $@
criu: images/built-in.o $(VERSION_HEADER)
$(Q) $(MAKE) -C criu all
$(Q) $(MAKE) $(build)=criu all
.PHONY: criu
#
# Libraries next once criu it ready
# (we might generate headers and such
# when building criu itself).
lib/%: criu
lib/%: criu .FORCE
$(Q) $(MAKE) -C lib $@
lib: criu
$(Q) $(MAKE) -C lib all
@@ -215,13 +217,13 @@ subclean:
clean: subclean
$(Q) $(MAKE) $(build)=images $@
$(Q) $(MAKE) -C criu $@
$(Q) $(MAKE) $(build)=criu $@
.PHONY: clean
# mrproper depends on clean in nmk
mrproper: subclean
$(Q) $(MAKE) $(build)=images $@
$(Q) $(MAKE) -C criu $@
$(Q) $(MAKE) $(build)=criu $@
$(Q) $(RM) $(VERSION_HEADER)
$(Q) $(RM) cscope.*
$(Q) $(RM) tags TAGS

View File

@@ -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

View File

@@ -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)
#
@@ -55,84 +59,84 @@ syscalls_lib: config
#
# Architecture dependant part.
ARCH-LIB := $(ARCH_DIR)/crtools.built-in.o
arch_lib: syscalls_lib
$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) all
.PHONY: arch_lib
$(ARCH-LIB): syscalls_lib
$(Q) $(MAKE) $(build)=$(ARCH_DIR) all
#
# piegen tool needed for PIE code.
ifeq ($(piegen-y),y)
piegen-bin := pie/piegen/piegen
piegen-bin := criu/pie/piegen/piegen
pie/piegen/%: config
$(Q) CC=$(HOSTCC) LD=$(HOSTLD) CFLAGS="$(ccflags-y) $(HOSTCFLAGS) $(WARNINGS) $(DEFINES)" $(MAKE) $(build)=pie/piegen $@
$(piegen-bin): pie/piegen/built-in.o
criu/pie/piegen/%: config
$(Q) CC=$(HOSTCC) LD=$(HOSTLD) CFLAGS="$(ccflags-y) $(HOSTCFLAGS) $(WARNINGS) $(DEFINES)" $(MAKE) $(build)=criu/pie/piegen $@
$(piegen-bin): criu/pie/piegen/built-in.o
$(call msg-link, $@)
$(Q) $(HOSTCC) $(HOSTCFLAGS) $^ $(LDFLAGS) -o $@
endif
#
# PIE library code.
pie/lib.a: arch_lib
$(Q) $(MAKE) $(call build-as,Makefile.library,pie) all
criu/pie/lib.a: $(ARCH-LIB)
$(Q) $(MAKE) $(call build-as,Makefile.library,criu/pie) all
#
# PIE code blobs themseves.
pie: $(piegen-bin) pie/lib.a
$(Q) $(MAKE) $(build)=pie all
pie: $(piegen-bin) criu/pie/lib.a
$(Q) $(MAKE) $(build)=criu/pie all
.PHONY: pie
#
# CRIU executable
PROGRAM-BUILTINS += ../images/built-in.o
PROGRAM-BUILTINS += built-in.o
PROGRAM-BUILTINS += pie/lib.a
PROGRAM-BUILTINS += criu/pie/lib.a
PROGRAM-BUILTINS += images/built-in.o
PROGRAM-BUILTINS += $(obj)/built-in.o
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) $^ $(ARCH-LIB) $(LIBS) $(WRAPFLAGS) $(LDFLAGS) $(GMONLDOPT) -rdynamic -o $@
$(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(WRAPFLAGS) $(LDFLAGS) $(GMONLDOPT) -rdynamic -o $@
subclean:
$(Q) $(RM) ./*.{gcda,gcno,gcov}
$(Q) $(RM) ./pie/*.{gcda,gcno,gcov}
$(Q) $(RM) ./pie/piegen/*.{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) $(obj)/pie/piegen/*.{gcda,gcno,gcov}
$(Q) $(RM) -r $(obj)/gcov
$(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) clean
$(Q) $(MAKE) $(build)=$(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
$(Q) $(MAKE) $(build)=$(PIE_DIR)/piegen 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/piegen $@
$(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/piegen $@
$(Q) $(MAKE) $(build)=pie $@
$(Q) $(RM) $(CONFIG_HEADER)
.PHONY: mrproper
subproper:
$(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) mrproper
$(Q) $(MAKE) $(build)=$(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
$(Q) $(MAKE) $(build)=$(PIE_DIR)/piegen mrproper
.PHONY: subproper
mrproper-y += $(CONFIG_HEADER)
mrproper: subproper
UAPI_HEADERS := include/criu-plugin.h include/criu-log.h
UAPI_HEADERS := $(SRC_DIR)/criu/include/criu-plugin.h
UAPI_HEADERS += $(SRC_DIR)/criu/include/criu-log.h
install: criu
$(E) " INSTALL " criu
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
@@ -146,8 +150,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

View File

@@ -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__' >> $$@
@@ -47,6 +45,6 @@ endef
$(eval $(config-header-rule))
$(CONFIG_HEADER): ../scripts/feature-tests.mak
$(CONFIG_HEADER): $(SRC_DIR)/scripts/feature-tests.mak
config: $(CONFIG_HEADER)
.PHONY: config

View File

@@ -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
@@ -86,10 +86,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

View File

@@ -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

View File

@@ -15,7 +15,12 @@ restorer-obj-e += ./$(ARCH_DIR)/syscalls.built-in.o
# applications, which is not the target of the
# project.
#
CFLAGS := $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS)) -iquote pie/piegen -iquote arch/$(ARCH)/include -iquote $(SRC_DIR) -iquote $(SRC_DIR)/criu/include
CFLAGS := $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS))
CFLAGS += -iquote $(SRC_DIR)/criu/pie/piegen
CFLAGS += -iquote $(SRC_DIR)/criu/arch/$(ARCH)/include
CFLAGS += -iquote $(SRC_DIR)/criu/include
CFLAGS += -iquote $(SRC_DIR)
ifneq ($(filter-out ia32,$(ARCH)),)
ccflags-y += -DCR_NOGLIBC -fpie -Wa,--noexecstack -fno-stack-protector
@@ -37,7 +42,7 @@ PIELDS := pie.lds.S
.SECONDARY:
ifeq ($(piegen-y),y)
target-name = $(patsubst pie/%-blob.h,%,$(1))
target-name = $(patsubst criu/pie/%-blob.h,%,$(1))
ifeq ($(SRCARCH),ppc64)
$(obj)/$(PIELDS): $(obj)/pie-reloc.lds.S.in
@@ -68,9 +73,9 @@ $(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/lib.a $(obj)/$(PIELDS)
$(call msg-gen, $@)
$(Q) $(LD) -r -T $(obj)/$(PIELDS) -o $@ $< $(obj)/lib.a
$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(obj)/$(PIELDS) pie/piegen
$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(obj)/$(PIELDS) criu/pie/piegen
$(call msg-gen, $@)
$(Q) pie/piegen/piegen -f $< -v $(call target-name,$@)_relocs -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob -o $@ $(piegen_stdout)
$(Q) criu/pie/piegen/piegen -f $< -v $(call target-name,$@)_relocs -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob -o $@ $(piegen_stdout)
else

View File

@@ -28,7 +28,9 @@ endif
# applications, which is not the target of the
# project.
#
iquotes := -iquote pie/piegen -iquote arch/$(ARCH)/include -iquote $(SRC_DIR) -iquote $(SRC_DIR)/criu/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)

View File

@@ -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/^./&#\\\
/;