[CRIU] [PATCH 4/9] test/zdtm: unify common code
Kir Kolyshkin
kir at openvz.org
Wed Mar 29 15:21:15 PDT 2017
This commit expands the success with lib/Makefile to the rest of
ztdm/Makefiles. In particular, it moves the common part to Makefile.inc
and let {lib,static,transition}/Makefile use it.
This results in:
- dependencies being handled properly;
- reduction of makefiles length due to unification;
- possibly more proper dependencies and builds.
While at it, let's also:
- make rules for criu-rtc.so silent;
- set default CC=gcc;
- remove duplicate -m32 from CFLAGS.
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
test/zdtm/.gitignore | 1 +
test/zdtm/Makefile.inc | 56 +++++++++++++++++++++++++++++++++++++++++--
test/zdtm/lib/Makefile | 42 +++++---------------------------
test/zdtm/static/Makefile | 53 +++++++++++++---------------------------
test/zdtm/transition/Makefile | 40 ++++---------------------------
5 files changed, 82 insertions(+), 110 deletions(-)
diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
index 5817013..6471943 100644
--- a/test/zdtm/.gitignore
+++ b/test/zdtm/.gitignore
@@ -1,4 +1,5 @@
/lib/libzdtmtst.a
+/lib/.gitignore
/static/.gitignore
/transition/.gitignore
diff --git a/test/zdtm/Makefile.inc b/test/zdtm/Makefile.inc
index ef7c1b8..c7b40e7 100644
--- a/test/zdtm/Makefile.inc
+++ b/test/zdtm/Makefile.inc
@@ -1,3 +1,5 @@
+MAKEFLAGS += -r
+
ARCH ?= $(shell uname -m | sed \
-e s/i.86/x86/ \
-e s/x86_64/x86/ \
@@ -18,6 +20,9 @@ endif
SRCARCH ?= $(ARCH)
+CC := gcc
+CFLAGS += -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
+CFLAGS += $(USERCFLAGS)
CPPFLAGS += -iquote $(LIBDIR)/arch/$(SRCARCH)/include
ifeq ($(strip $(V)),)
@@ -32,10 +37,57 @@ RM := rm -f --one-file-system
ifeq ($(COMPAT_TEST),y)
ifeq ($(ARCH),x86)
- export USERCFLAGS += -m32
export CFLAGS += -m32
export LDFLAGS += -m32
endif
endif
-export E Q RM
+DEPEND.c = $(COMPILE.c) -MM -MP
+%.d: %.c
+ $(E) " DEP " $*.d
+ $(Q)$(DEPEND.c) $(OUTPUT_OPTION) $<
+
+%.o: %.c | %.d
+ $(E) " CC " $@
+ $(Q)$(COMPILE.c) $(OUTPUT_OPTION) $<
+
+%: %.o $(LDLIBS)
+ @echo $@ >> .gitignore
+ $(E) " LINK " $@
+ $(Q)$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+
+default: all
+.PHONY: default
+
+gitignore-clean:
+ $(RM) .gitignore
+.PHONY: gitignore-clean
+
+clean: gitignore-clean
+ $(RM) $(OBJ) $(TST) *~
+.PHONY: clean
+
+cleandep: clean
+ $(RM) $(DEP)
+.PHONY: cleandep
+
+cleanout:
+ $(RM) -r *.pid *.out* *.test* *.state
+.PHONY: cleanout
+
+%.cleanout: %
+ $(Q) $(RM) -r $<.pid* $<.out* *$<.test* $<.*.test $<.*.state $<.state chew_$<.test*
+
+realclean: cleandep cleanout
+.PHONY: realclean
+
+dep: $(DEP)
+.PHONY: dep
+
+no-deps-targets := clean cleandep cleanout realclean groups.cleanout
+
+ifeq ($(filter $(no-deps-targets), $(MAKECMDGOALS)),)
+-include $(DEP)
+endif
+
+.SECONDARY:
diff --git a/test/zdtm/lib/Makefile b/test/zdtm/lib/Makefile
index 6b37e0d..d2d9f1c 100644
--- a/test/zdtm/lib/Makefile
+++ b/test/zdtm/lib/Makefile
@@ -1,8 +1,5 @@
-MAKEFLAGS += -r
LIBDIR := .
-include ../Makefile.inc
-CFLAGS := -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
CFLAGS += $(USERCFLAGS)
LIB := libzdtmtst.a
@@ -18,43 +15,16 @@ LDLIBS := $(LIB)
TARGETS := $(LIB) $(BIN)
+include ../Makefile.inc
+
all: $(TARGETS)
.PHONY: all
-DEPEND.c = $(COMPILE.c) -MM -MP
-%.d: %.c
- $(E) " DEP " $*.d
- $(Q)$(DEPEND.c) $(OUTPUT_OPTION) $<
-
-%.o: %.c | %.d
- $(E) " CC " $@
- $(Q)$(COMPILE.c) $(OUTPUT_OPTION) $<
-
-%: %.o $(LDLIBS)
- $(E) " LINK " $@
- $(Q)$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+clean-more:
+ $(RM) $(TARGETS)
+.PHONY: clean-more
+clean: clean-more
$(LIB): $(LIBOBJ)
$(E) " AR " $@
$(Q)ar rcs $@ $^
-
-dep: $(DEP)
-.PHONY: dep
-
-clean:
- $(RM) $(OBJ) $(TARGETS)
-
-cleandep: clean
- $(RM) $(DEP)
-
-cleanout: clean ;
-
-realclean: clean cleandep
-
-.PHONY: clean cleandep cleanout realclean
-
-no-deps-targets := clean cleandep cleanout realclean
-
-ifeq ($(filter $(no-deps-targets), $(MAKECMDGOALS)),)
--include $(DEP)
-endif
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 44a2929..0e42273 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -1,12 +1,7 @@
-include ../Makefile.inc
-.SUFFIXES: # No implicit rules
-
-LIBDIR = ../lib
-LIB = $(LIBDIR)/libzdtmtst.a
-LDLIBS += $(LIBDIR)/libzdtmtst.a
+LIBDIR := ../lib
+LIB := $(LIBDIR)/libzdtmtst.a
+LDLIBS += $(LIB)
CPPFLAGS += -I$(LIBDIR)
-CFLAGS = -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
-CFLAGS += $(USERCFLAGS)
TST_NOFILE := \
busyloop00 \
@@ -320,15 +315,7 @@ OUT = $(TST:%=%.out)
STATE = $(TST_STATE:%=%.state)
STATE_OUT = $(TST_STATE:%=%.out)
-%.o: %.c
- @echo $@ >> .gitignore
- $(E) " CC " $@
- $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
-
-%: %.o
- @echo $@ >> .gitignore
- $(E) " LINK " $@
- $(Q)$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+include ../Makefile.inc
all: $(TST) criu-rtc.so
install: all
@@ -455,7 +442,9 @@ stopped01: CFLAGS += -DZDTM_STOPPED_KILL
stopped02: CFLAGS += -DZDTM_STOPPED_TKILL
stopped12: CFLAGS += -DZDTM_STOPPED_KILL -DZDTM_STOPPED_TKILL
clone_fs: LDLIBS += -pthread
-netns_sub_veth: CFLAGS += -I/usr/include/libnl3
+# As generating dependencies won't work without proper includes,
+# we have to explicitly specify both .o and .d for this case:
+netns_sub_veth.o netns_sub_veth.d: CPPFLAGS += -I/usr/include/libnl3
netns_sub_veth: LDLIBS += -lnl-3 -l nl-route-3
socket-tcp-fin-wait1: CFLAGS += -D ZDTM_TCP_FIN_WAIT1
@@ -475,31 +464,21 @@ userns02: CFLAGS += -D USERNS02
$(LIB): force
$(Q) $(MAKE) -C $(LIBDIR)
-gitignore-clean:
- $(RM) -f .gitignore
-
-clean: gitignore-clean
- $(RM) -f $(OBJ) $(TST) *~ criu-rtc.so criu-rtc.pb-c.c criu-rtc.pb-c.h get_smaps_bits.o
-
-cleandep: clean
- $(RM) -f $(DEP)
-
-cleanout:
- $(RM) -f -r *.pid *.out* *.test* *.state
-
-%.cleanout: %
- $(Q) $(RM) -f -r $<.pid* $<.out* *$<.test* $<.*.test $<.*.state $<.state
-
-realclean: cleandep cleanout
+clean-more:
+ $(RM) criu-rtc.so criu-rtc.pb-c.c criu-rtc.pb-c.h get_smaps_bits.o
+.PHONY: clean-more
+clean: clean-more
rtc.c: criu-rtc.so
criu-rtc.pb-c.c: criu-rtc.proto
$(Q)echo $@ >> .gitignore
$(Q)echo $(@:%.c=%.h) >> .gitignore
- protoc-c --proto_path=. --c_out=. criu-rtc.proto
+ $(E) " PBCC " $@
+ $(Q)protoc-c --proto_path=. --c_out=. criu-rtc.proto
criu-rtc.so: criu-rtc.c criu-rtc.pb-c.c
- $(CC) -g -Wall -shared -nostartfiles criu-rtc.c criu-rtc.pb-c.c -o criu-rtc.so -iquote ../../../criu/include -fPIC $(filter-out -m32,$(USERCFLAGS))
+ $(E) " LD " $@
+ $(Q)$(CC) -g -Wall -shared -nostartfiles criu-rtc.c criu-rtc.pb-c.c -o criu-rtc.so -iquote ../../../criu/include -fPIC $(filter-out -m32,$(USERCFLAGS))
-.PHONY: force clean cleandep cleanout realclean start check_start stop wait_stop
+.PHONY: force start check_start stop wait_stop
diff --git a/test/zdtm/transition/Makefile b/test/zdtm/transition/Makefile
index d5efe5f..cd98921 100644
--- a/test/zdtm/transition/Makefile
+++ b/test/zdtm/transition/Makefile
@@ -1,12 +1,7 @@
-include ../Makefile.inc
-.SUFFIXES: # No implicit rules
-
-LIBDIR = ../lib
-LIB = $(LIBDIR)/libzdtmtst.a
-LDLIBS += $(LIBDIR)/libzdtmtst.a
+LIBDIR := ../lib
+LIB := $(LIBDIR)/libzdtmtst.a
+LDLIBS += $(LIB)
CPPFLAGS += -I$(LIBDIR)
-CFLAGS = -g -O2 -Wall -Werror -fno-strict-aliasing
-CFLAGS += $(USERCFLAGS)
TST_NOFILE = \
ipc \
@@ -41,15 +36,7 @@ DEP = $(SRC:%.c=%.d)
PID = $(TST:%=%.pid)
OUT = $(TST:%=%.out)
-%.o: %.c
- @echo $@ >> .gitignore
- $(E) " CC " $@
- $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
-
-%: %.o
- @echo $@ >> .gitignore
- $(E) " LINK " $@
- $(Q)$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+include ../Makefile.inc
all: $(TST)
install: all
@@ -99,21 +86,4 @@ thread-bomb: LDFLAGS += -pthread
$(LIB): force
$(Q) $(MAKE) -C $(LIBDIR)
-gitignore-clean:
- $(RM) -f .gitignore
-
-clean: gitignore-clean
- $(RM) -f $(OBJ) $(TST) *~
-
-cleandep: clean
- $(RM) -f $(DEP)
-
-%.cleanout: %
- $(Q) $(RM) -f -r $<.pid* $<.out* $<.test* chew_$<.test*
-
-cleanout:
- $(RM) -f *.pid *.out* *.test chew*
-
-realclean: cleandep cleanout
-
-.PHONY: force clean cleandep cleanout realclean start check_start stop wait_stop
+.PHONY: force start check_start stop wait_stop
--
2.9.3
More information about the CRIU
mailing list