Commit 7a360484 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Pavel Emelyanov

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: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent a9a62403
...@@ -179,6 +179,8 @@ endif ...@@ -179,6 +179,8 @@ endif
# on anything else. # on anything else.
$(eval $(call gen-built-in,images)) $(eval $(call gen-built-in,images))
.PHONY: .FORCE
# #
# CRIU building done in own directory # CRIU building done in own directory
# with slightly different rules so we # with slightly different rules so we
...@@ -187,17 +189,17 @@ $(eval $(call gen-built-in,images)) ...@@ -187,17 +189,17 @@ $(eval $(call gen-built-in,images))
# #
# But note that we're already included # But note that we're already included
# the nmk so we can reuse it there. # the nmk so we can reuse it there.
criu/%: images/built-in.o $(VERSION_HEADER) criu/%: images/built-in.o $(VERSION_HEADER) .FORCE
$(Q) $(MAKE) -C criu $@ $(Q) $(MAKE) $(build)=criu $@
criu: images/built-in.o $(VERSION_HEADER) criu: images/built-in.o $(VERSION_HEADER)
$(Q) $(MAKE) -C criu all $(Q) $(MAKE) $(build)=criu all
.PHONY: criu .PHONY: criu
# #
# Libraries next once criu it ready # Libraries next once criu it ready
# (we might generate headers and such # (we might generate headers and such
# when building criu itself). # when building criu itself).
lib/%: criu lib/%: criu .FORCE
$(Q) $(MAKE) -C lib $@ $(Q) $(MAKE) -C lib $@
lib: criu lib: criu
$(Q) $(MAKE) -C lib all $(Q) $(MAKE) -C lib all
...@@ -215,13 +217,13 @@ subclean: ...@@ -215,13 +217,13 @@ subclean:
clean: subclean clean: subclean
$(Q) $(MAKE) $(build)=images $@ $(Q) $(MAKE) $(build)=images $@
$(Q) $(MAKE) -C criu $@ $(Q) $(MAKE) $(build)=criu $@
.PHONY: clean .PHONY: clean
# mrproper depends on clean in nmk # mrproper depends on clean in nmk
mrproper: subclean mrproper: subclean
$(Q) $(MAKE) $(build)=images $@ $(Q) $(MAKE) $(build)=images $@
$(Q) $(MAKE) -C criu $@ $(Q) $(MAKE) $(build)=criu $@
$(Q) $(RM) $(VERSION_HEADER) $(Q) $(RM) $(VERSION_HEADER)
$(Q) $(RM) cscope.* $(Q) $(RM) cscope.*
$(Q) $(RM) tags TAGS $(Q) $(RM) tags TAGS
......
...@@ -43,7 +43,7 @@ install-lib: lib ...@@ -43,7 +43,7 @@ install-lib: lib
.PHONY: install-lib .PHONY: install-lib
install-criu: criu install-criu: criu
$(Q) $(MAKE) -C criu install $(Q) $(MAKE) $(build)=criu install
.PHONY: install-criu .PHONY: install-criu
install: install-man install-lib install-criu install: install-man install-lib install-criu
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
# 6a8d90f5fec4 "attr: Allow attribute type 0" # 6a8d90f5fec4 "attr: Allow attribute type 0"
WRAPFLAGS += -Wl,--wrap=nla_parse,--wrap=nlmsg_parse WRAPFLAGS += -Wl,--wrap=nla_parse,--wrap=nlmsg_parse
ARCH_DIR := arch/$(SRCARCH) ARCH_DIR := criu/arch/$(SRCARCH)
export ARCH_DIR PIE_DIR := criu/pie
export ARCH_DIR PIE_DIR
# #
# General flags. # General flags.
...@@ -11,8 +12,8 @@ ccflags-y += -fno-strict-aliasing ...@@ -11,8 +12,8 @@ ccflags-y += -fno-strict-aliasing
ccflags-y += -iquote $(SRC_DIR)/criu/include ccflags-y += -iquote $(SRC_DIR)/criu/include
ccflags-y += -iquote $(SRC_DIR)/images ccflags-y += -iquote $(SRC_DIR)/images
ccflags-y += -iquote $(SRC_DIR)/criu/pie ccflags-y += -iquote $(SRC_DIR)/criu/pie
ccflags-y += -iquote $(SRC_DIR)/criu/$(ARCH_DIR) ccflags-y += -iquote $(SRC_DIR)/$(ARCH_DIR)
ccflags-y += -iquote $(SRC_DIR)/criu/$(ARCH_DIR)/include ccflags-y += -iquote $(SRC_DIR)/$(ARCH_DIR)/include
ccflags-y += -iquote $(SRC_DIR)/ ccflags-y += -iquote $(SRC_DIR)/
ccflags-y += -I/usr/include/libnl3 ccflags-y += -I/usr/include/libnl3
...@@ -38,11 +39,14 @@ include $(__nmk_dir)/msg.mk ...@@ -38,11 +39,14 @@ include $(__nmk_dir)/msg.mk
# #
# Needed libraries checks # Needed libraries checks
include Makefile.packages include $(SRC_DIR)/criu/Makefile.packages
# #
# Configure variables. # 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) config: $(VERSION_HEADER)
# #
...@@ -55,84 +59,84 @@ syscalls_lib: config ...@@ -55,84 +59,84 @@ syscalls_lib: config
# #
# Architecture dependant part. # Architecture dependant part.
ARCH-LIB := $(ARCH_DIR)/crtools.built-in.o ARCH-LIB := $(ARCH_DIR)/crtools.built-in.o
arch_lib: syscalls_lib $(ARCH-LIB): syscalls_lib
$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) all $(Q) $(MAKE) $(build)=$(ARCH_DIR) all
.PHONY: arch_lib
# #
# piegen tool needed for PIE code. # piegen tool needed for PIE code.
ifeq ($(piegen-y),y) ifeq ($(piegen-y),y)
piegen-bin := pie/piegen/piegen piegen-bin := criu/pie/piegen/piegen
pie/piegen/%: config criu/pie/piegen/%: config
$(Q) CC=$(HOSTCC) LD=$(HOSTLD) CFLAGS="$(ccflags-y) $(HOSTCFLAGS) $(WARNINGS) $(DEFINES)" $(MAKE) $(build)=pie/piegen $@ $(Q) CC=$(HOSTCC) LD=$(HOSTLD) CFLAGS="$(ccflags-y) $(HOSTCFLAGS) $(WARNINGS) $(DEFINES)" $(MAKE) $(build)=criu/pie/piegen $@
$(piegen-bin): pie/piegen/built-in.o $(piegen-bin): criu/pie/piegen/built-in.o
$(call msg-link, $@) $(call msg-link, $@)
$(Q) $(HOSTCC) $(HOSTCFLAGS) $^ $(LDFLAGS) -o $@ $(Q) $(HOSTCC) $(HOSTCFLAGS) $^ $(LDFLAGS) -o $@
endif endif
# #
# PIE library code. # PIE library code.
pie/lib.a: arch_lib criu/pie/lib.a: $(ARCH-LIB)
$(Q) $(MAKE) $(call build-as,Makefile.library,pie) all $(Q) $(MAKE) $(call build-as,Makefile.library,criu/pie) all
# #
# PIE code blobs themseves. # PIE code blobs themseves.
pie: $(piegen-bin) pie/lib.a pie: $(piegen-bin) criu/pie/lib.a
$(Q) $(MAKE) $(build)=pie all $(Q) $(MAKE) $(build)=criu/pie all
.PHONY: pie .PHONY: pie
# #
# CRIU executable # CRIU executable
PROGRAM-BUILTINS += ../images/built-in.o PROGRAM-BUILTINS += criu/pie/lib.a
PROGRAM-BUILTINS += built-in.o PROGRAM-BUILTINS += images/built-in.o
PROGRAM-BUILTINS += pie/lib.a PROGRAM-BUILTINS += $(obj)/built-in.o
PROGRAM-BUILTINS += $(ARCH-LIB)
built-in.o: pie $(obj)/built-in.o: pie
$(Q) $(MAKE) $(call build-as,Makefile.crtools,.) all $(Q) $(MAKE) $(call build-as,Makefile.crtools,criu) all
criu: $(PROGRAM-BUILTINS) $(obj)/criu: $(PROGRAM-BUILTINS)
$(call msg-link, $@) $(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 # 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 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 # Delete all generated files
mrproper: subclean subproper:
$(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) $@ $(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) mrproper
$(Q) $(MAKE) $(call build-as,Makefile,$(ARCH_DIR)) $@ $(Q) $(MAKE) $(build)=$(ARCH_DIR) mrproper
$(Q) $(MAKE) $(call build-as,Makefile.library,pie) $@ $(Q) $(MAKE) $(call build-as,Makefile.library,$(PIE_DIR)) mrproper
$(Q) $(MAKE) $(call build-as,Makefile.crtools,.) $@ $(Q) $(MAKE) $(call build-as,Makefile.crtools,criu) mrproper
$(Q) $(MAKE) $(build)=pie/piegen $@ $(Q) $(MAKE) $(build)=$(PIE_DIR) mrproper
$(Q) $(MAKE) $(build)=pie $@ $(Q) $(MAKE) $(build)=$(PIE_DIR)/piegen mrproper
$(Q) $(RM) $(CONFIG_HEADER) .PHONY: subproper
.PHONY: mrproper 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
install: criu UAPI_HEADERS += $(SRC_DIR)/criu/include/criu-log.h
$(E) " INSTALL " criu
install: $(obj)/criu
$(E) " INSTALL " $(obj)/criu
$(Q) mkdir -p $(DESTDIR)$(SBINDIR) $(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) mkdir -p $(DESTDIR)$(INCLUDEDIR)
$(Q) install -m 644 $(UAPI_HEADERS) $(DESTDIR)$(INCLUDEDIR) $(Q) install -m 644 $(UAPI_HEADERS) $(DESTDIR)$(INCLUDEDIR)
$(Q) mkdir -p $(DESTDIR)$(LIBEXECDIR)/criu/scripts $(Q) mkdir -p $(DESTDIR)$(LIBEXECDIR)/criu/scripts
...@@ -146,8 +150,4 @@ uninstall: ...@@ -146,8 +150,4 @@ uninstall:
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBEXECDIR)/criu/scripts/,systemd-autofs-restart.sh) $(Q) $(RM) $(addprefix $(DESTDIR)$(LIBEXECDIR)/criu/scripts/,systemd-autofs-restart.sh)
.PHONY: uninstall .PHONY: uninstall
# all-y += check-packages $(obj)/criu
# Final @all target.
all: check-packages criu
@true
.PHONY: all
include $(__nmk_dir)/utils.mk include $(__nmk_dir)/utils.mk
include $(__nmk_dir)msg.mk include $(__nmk_dir)msg.mk
include ../scripts/feature-tests.mak include $(SRC_DIR)/scripts/feature-tests.mak
CONFIG_HEADER := include/config.h
ifeq ($(call try-cc,$(FEATURE_TEST_LIBBSD_DEV),-lbsd),y) ifeq ($(call try-cc,$(FEATURE_TEST_LIBBSD_DEV),-lbsd),y)
LIBS += -lbsd LIBS += -lbsd
...@@ -26,7 +24,7 @@ endif ...@@ -26,7 +24,7 @@ endif
endef endef
define config-header-rule define config-header-rule
$(CONFIG_HEADER): include/config-base.h $(CONFIG_HEADER): $(obj)/include/config-base.h
$$(call msg-gen, $$@) $$(call msg-gen, $$@)
$(Q) @echo '#ifndef __CR_CONFIG_H__' > $$@ $(Q) @echo '#ifndef __CR_CONFIG_H__' > $$@
$(Q) @echo '#define __CR_CONFIG_H__' >> $$@ $(Q) @echo '#define __CR_CONFIG_H__' >> $$@
...@@ -47,6 +45,6 @@ endef ...@@ -47,6 +45,6 @@ endef
$(eval $(config-header-rule)) $(eval $(config-header-rule))
$(CONFIG_HEADER): ../scripts/feature-tests.mak $(CONFIG_HEADER): $(SRC_DIR)/scripts/feature-tests.mak
config: $(CONFIG_HEADER) config: $(CONFIG_HEADER)
.PHONY: config .PHONY: config
ccflags-y += -iquote $(ARCH) ccflags-y += -iquote criu/$(ARCH)
ccflags-y += $(DEFINES) ccflags-y += $(DEFINES)
obj-y += action-scripts.o obj-y += action-scripts.o
obj-y += aio.o obj-y += aio.o
...@@ -86,10 +86,10 @@ endif ...@@ -86,10 +86,10 @@ endif
PROTOBUF_GEN := $(SRC_DIR)/scripts/protobuf-gen.sh 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, $@) $(call msg-gen, $@)
$(Q) $(SH) $(PROTOBUF_GEN) > $@ $(Q) $(SH) $(PROTOBUF_GEN) > $@
mrproper-y += protobuf-desc-gen.h mrproper-y += $(obj)/protobuf-desc-gen.h
...@@ -38,5 +38,6 @@ check-packages-failed: ...@@ -38,5 +38,6 @@ check-packages-failed:
$(error Compilation aborted) $(error Compilation aborted)
check-packages: 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 .PHONY: check-build-packages check-packages-failed check-packages
...@@ -15,7 +15,12 @@ restorer-obj-e += ./$(ARCH_DIR)/syscalls.built-in.o ...@@ -15,7 +15,12 @@ restorer-obj-e += ./$(ARCH_DIR)/syscalls.built-in.o
# applications, which is not the target of the # applications, which is not the target of the
# project. # 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)),) ifneq ($(filter-out ia32,$(ARCH)),)
ccflags-y += -DCR_NOGLIBC -fpie -Wa,--noexecstack -fno-stack-protector ccflags-y += -DCR_NOGLIBC -fpie -Wa,--noexecstack -fno-stack-protector
...@@ -37,7 +42,7 @@ PIELDS := pie.lds.S ...@@ -37,7 +42,7 @@ PIELDS := pie.lds.S
.SECONDARY: .SECONDARY:
ifeq ($(piegen-y),y) ifeq ($(piegen-y),y)
target-name = $(patsubst pie/%-blob.h,%,$(1)) target-name = $(patsubst criu/pie/%-blob.h,%,$(1))
ifeq ($(SRCARCH),ppc64) ifeq ($(SRCARCH),ppc64)
$(obj)/$(PIELDS): $(obj)/pie-reloc.lds.S.in $(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) ...@@ -68,9 +73,9 @@ $(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/lib.a $(obj)/$(PIELDS)
$(call msg-gen, $@) $(call msg-gen, $@)
$(Q) $(LD) -r -T $(obj)/$(PIELDS) -o $@ $< $(obj)/lib.a $(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, $@) $(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 else
......
...@@ -28,7 +28,9 @@ endif ...@@ -28,7 +28,9 @@ endif
# applications, which is not the target of the # applications, which is not the target of the
# project. # 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) CFLAGS := $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS)) $(iquotes)
asflags-y := -D__ASSEMBLY__ $(iquotes) asflags-y := -D__ASSEMBLY__ $(iquotes)
......
...@@ -5,7 +5,7 @@ for x in $(sed -n '/PB_AUTOGEN_START/,/PB_AUTOGEN_STOP/ { ...@@ -5,7 +5,7 @@ for x in $(sed -n '/PB_AUTOGEN_START/,/PB_AUTOGEN_STOP/ {
s/,.*$//; s/,.*$//;
s/\tPB_//; s/\tPB_//;
p; p;
}' include/protobuf-desc.h); do }' criu/include/protobuf-desc.h); do
x_la=$(echo $x | sed $TR) x_la=$(echo $x | sed $TR)
x_uf=$(echo $x | sed -nr 's/^./&#\\\ x_uf=$(echo $x | sed -nr 's/^./&#\\\
/; /;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment