[CRIU] [PATCH 3/5] make: Add own Makefile.pie for binary blobs we
generate
Cyrill Gorcunov
gorcunov at openvz.org
Wed Apr 18 06:36:16 EDT 2012
Since the blob files are generated a different way
in compare with plain compiling we use for regular
*.c files -- add own Makefile.pie for this target.
This increases readability of general Makefile
and Makefile.pie itself.
The "-include" instead of "include" in Makefile
allow us to be sure that make trigger error if
someone accidentally delete Makefile.pie.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
Makefile | 78 ++++++---------------------------------------------------
Makefile.pie | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 69 deletions(-)
create mode 100644 Makefile.pie
diff --git a/Makefile b/Makefile
index 0a6df29..dea0745 100644
--- a/Makefile
+++ b/Makefile
@@ -23,11 +23,8 @@ PROGRAM := crtools
export CC ECHO MAKE CFLAGS LIBS ARCH DEFINES
-OBJS_GEN_DEP += parasite-syscall.o
-OBJS_GEN_DEP += cr-restore.o
-DEPS_GEN := $(patsubst %.o,%.d,$(OBJS_GEN_DEP))
-
-OBJS += $(OBJS_GEN_DEP)
+OBJS += parasite-syscall.o
+OBJS += cr-restore.o
OBJS += crtools.o
OBJS += proc_parse.o
OBJS += cr-dump.o
@@ -49,68 +46,12 @@ OBJS += namespaces.o
OBJS += uts_ns.o
OBJS += ipc_ns.o
-OBJS-BLOB += parasite.o
-SRCS-BLOB += $(patsubst %.o,%.c,$(OBJS-BLOB))
-
-PIE-LDS := pie.lds.S
-
-HEAD-BLOB-GEN := $(patsubst %.o,%-blob.h,$(OBJS-BLOB))
-HEAD-BIN := $(patsubst %.o,%.bin,$(OBJS-BLOB))
-
-ROBJS-BLOB := restorer.o
-#
-# Everything embedded into restorer as a separate
-# object file should go here.
-ROBJS := $(ROBJS-BLOB)
-ROBJS += restorer-log.o
-
-RSRCS-BLOB += $(patsubst %.o,%.c,$(ROBJS))
+DEPS := $(patsubst %.o,%.d,$(OBJS))
-RSRCS-BLOB += $(patsubst %.o,%.c,$(ROBJS-BLOB))
-
-RHEAD-BLOB-GEN := $(patsubst %.o,%-blob.h,$(ROBJS-BLOB))
-RHEAD-BIN := $(patsubst %.o,%.bin,$(ROBJS-BLOB))
-
-DEPS := $(patsubst %.o,%.d,$(OBJS)) \
- $(patsubst %.o,%.d,$(OBJS-BLOB)) \
- $(patsubst %.o,%.d,$(ROBJS-BLOB))
-
-GEN-OFFSETS := gen-offsets.sh
+-include Makefile.pie
all: $(PROGRAM)
-$(OBJS-BLOB): $(SRCS-BLOB)
- $(E) " CC " $@
- $(Q) $(CC) -c $(CFLAGS) -fpie $< -o $@
-
-parasite-util-net.o: util-net.c
- $(E) " CC " $@
- $(Q) $(CC) -c $(CFLAGS) -fpie $< -o $@
-
-$(HEAD-BIN): $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o
- $(E) " GEN " $@
- $(Q) $(LD) --oformat=binary -T $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o -o $@
- $(Q) $(LD) --oformat=elf64-x86-64 -T $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o -o $@.o
-
-$(HEAD-BLOB-GEN): $(HEAD-BIN) $(GEN-OFFSETS)
- $(E) " GEN " $@
- $(Q) $(SH) $(GEN-OFFSETS) parasite > $@ || rm -f $@
- $(Q) sync
-
-$(ROBJS): $(RSRCS-BLOB)
- $(E) " CC " $@
- $(Q) $(CC) -c $(CFLAGS) -fpie $(patsubst %.o,%.c,$@) -o $@
-
-$(RHEAD-BIN): $(ROBJS) $(PIE-LDS)
- $(E) " GEN " $@
- $(Q) $(LD) --oformat=binary -T $(PIE-LDS) $(ROBJS) -o $@
- $(Q) $(LD) --oformat=elf64-x86-64 -T $(PIE-LDS) $(ROBJS) -o $@.o
-
-$(RHEAD-BLOB-GEN): $(RHEAD-BIN) $(GEN-OFFSETS)
- $(E) " GEN " $@
- $(Q) $(SH) $(GEN-OFFSETS) restorer > $@ || rm -f $@
- $(Q) sync
-
%.o: %.c
$(E) " CC " $@
$(Q) $(CC) -c $(CFLAGS) $< -o $@
@@ -123,12 +64,11 @@ $(RHEAD-BLOB-GEN): $(RHEAD-BIN) $(GEN-OFFSETS)
$(E) " CC " $@
$(Q) $(CC) -S $(CFLAGS) -fverbose-asm $< -o $@
-$(PROGRAM): $(OBJS)
+$(PROGRAM): $(OBJS) | $(PIE-GEN)
$(E) " LINK " $@
$(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
-$(DEPS_GEN): $(HEAD-BLOB-GEN) $(RHEAD-BLOB-GEN)
-%.d: %.c
+%.d: %.c | $(PIE-GEN)
$(Q) $(CC) -M -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
test-legacy: $(PROGRAM)
@@ -150,7 +90,7 @@ rebuild:
$(Q) $(MAKE)
.PHONY: rebuild
-clean:
+clean: cleanpie
$(E) " CLEAN"
$(Q) $(RM) -f ./*.o
$(Q) $(RM) -f ./*.d
@@ -159,8 +99,6 @@ clean:
$(Q) $(RM) -f ./*.out
$(Q) $(RM) -f ./*.bin
$(Q) $(RM) -f ./$(PROGRAM)
- $(Q) $(RM) -f ./$(HEAD-BLOB-GEN)
- $(Q) $(RM) -f ./$(RHEAD-BLOB-GEN)
$(Q) $(RM) -rf ./test/dump/
$(Q) $(MAKE) -C test/legacy clean
$(Q) $(MAKE) -C test/zdtm cleandep
@@ -206,6 +144,8 @@ help:
deps-targets := %.o %.s %.i $(PROGRAM) zdtm test-legacy
+.DEFAULT_GOAL := $(PROGRAM)
+
ifneq ($(filter $(deps-targets), $(MAKECMDGOALS)),)
INCDEPS := 1
endif
diff --git a/Makefile.pie b/Makefile.pie
new file mode 100644
index 0000000..a2885d7
--- /dev/null
+++ b/Makefile.pie
@@ -0,0 +1,65 @@
+GEN-OFFSETS := gen-offsets.sh
+
+POBJS += parasite.o
+PSRCS += $(patsubst %.o,%.c,$(POBJS))
+
+PBLOB-NAME := parasite
+PBLOB-HDR := parasite-blob.h
+PBLOB-BIN := parasite.bin
+PBLOB-LDS := pie.lds.S
+
+ROBJS += restorer.o
+ROBJS += restorer-log.o
+RSRCS += $(patsubst %.o,%.c,$(ROBJS))
+
+RBLOB-NAME := restorer
+RBLOB-HDR := restorer-blob.h
+RBLOB-BIN := restorer.bin
+RBLOB-LDS := pie.lds.S
+
+DEPS += $(patsubst %.o,%.d,$(POBJS))
+DEPS += $(patsubst %.o,%.d,$(ROBJS))
+
+PIEFLAGS := -fpie
+
+$(POBJS): $(PSRCS) $(PASM-OBJS)
+ $(E) " CC " $@
+ $(Q) $(CC) -c $(CFLAGS) $(PIEFLAGS) $(patsubst %.o,%.c,$@) -o $@
+
+parasite-util-net.o: util-net.c
+ $(E) " CC " $@
+ $(Q) $(CC) -c $(CFLAGS) $(PIEFLAGS) $< -o $@
+
+POBJS += parasite-util-net.o
+
+$(PBLOB-BIN): $(PBLOB-LDS) $(POBJS)
+ $(E) " GEN " $@
+ $(Q) $(LD) --oformat=binary -T $(PBLOB-LDS) -o $(PBLOB-BIN) $(POBJS)
+ $(Q) $(LD) --oformat=elf64-x86-64 -T $(PBLOB-LDS) -o $(PBLOB-BIN).o $(POBJS)
+
+$(PBLOB-HDR): $(PBLOB-BIN) $(GEN-OFFSETS)
+ $(E) " GEN " $@
+ $(Q) $(SH) $(GEN-OFFSETS) $(PBLOB-NAME) > $@ || rm -f $@
+
+$(ROBJS): $(RSRCS)
+ $(E) " CC " $@
+ $(Q) $(CC) -c $(CFLAGS) $(PIEFLAGS) $(patsubst %.o,%.c,$@) -o $@
+
+$(RBLOB-BIN): $(RBLOB-LDS) $(ROBJS)
+ $(E) " GEN " $@
+ $(Q) $(LD) --oformat=binary -T $(RBLOB-LDS) -o $(RBLOB-BIN) $(ROBJS)
+ $(Q) $(LD) --oformat=elf64-x86-64 -T $(RBLOB-LDS) -o $(RBLOB-BIN).o $(ROBJS)
+
+$(RBLOB-HDR): $(RBLOB-BIN) $(GEN-OFFSETS)
+ $(E) " GEN " $@
+ $(Q) $(SH) $(GEN-OFFSETS) $(RBLOB-NAME) > $@ || rm -f $@
+
+PIE-GEN := $(PBLOB-HDR) $(RBLOB-HDR)
+
+cleanpie:
+ $(E) " CLEAN PIE"
+ $(Q) $(RM) -f ./$(PBLOB-HDR)
+ $(Q) $(RM) -f ./$(RBLOB-HDR)
+ $(Q) $(RM) -f ./*.bin
+ $(Q) $(RM) -f ./*.bin.o
+.PHONY: cleanpie
--
1.7.7.6
More information about the CRIU
mailing list