[CRIU] [RFC PATCHv2 13/32] zdtm: Makefile: cleanup and deduplicate Makefiles

Ivan Shapovalov intelfx at intelfx.name
Sat Mar 12 00:42:12 PST 2016


Signed-off-by: Ivan Shapovalov <intelfx at intelfx.name>
---
 test/zdtm/Makefile.inc        |   3 +-
 test/zdtm/Makefile.live       |  97 +++++++++++++++++++++++++++++++++++++++
 test/zdtm/lib/Makefile        |   9 ++--
 test/zdtm/static/Makefile     | 104 +++---------------------------------------
 test/zdtm/transition/Makefile |  70 +---------------------------
 5 files changed, 111 insertions(+), 172 deletions(-)
 create mode 100644 test/zdtm/Makefile.live

diff --git a/test/zdtm/Makefile.inc b/test/zdtm/Makefile.inc
index 9993d15..0d8fe23 100644
--- a/test/zdtm/Makefile.inc
+++ b/test/zdtm/Makefile.inc
@@ -18,7 +18,8 @@ endif
 
 SRCARCH ?= $(ARCH)
 
-CPPFLAGS += -iquote $(LIBDIR)/include -iquote $(LIBDIR)/arch/$(SRCARCH)/include
+override CPPFLAGS += -I$(LIBDIR) -iquote $(LIBDIR)/include -iquote $(LIBDIR)/arch/$(SRCARCH)/include
+CFLAGS += -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
 
 ifeq ($(strip $(V)),)
 	E = @echo
diff --git a/test/zdtm/Makefile.live b/test/zdtm/Makefile.live
new file mode 100644
index 0000000..8932c26
--- /dev/null
+++ b/test/zdtm/Makefile.live
@@ -0,0 +1,97 @@
+# this file is ran from test/zdtm/*, hence ../
+
+include ../Makefile.inc
+
+LIBDIR	= ../lib
+LDLIBS	= -lzdtmtst
+override CFLAGS += -fPIC
+override LDFLAGS += -fPIC -pie -rdynamic -L$(LIBDIR) -Wl,-rpath,\$$ORIGIN/$(LIBDIR)
+
+TST     = $(TST_NOFILE) $(TST_FILE) $(TST_DIR) $(TST_DIR_FILE) $(TST_OTHER)
+SRC	= $(TST:%=%.c)
+OBJ	= $(SRC:%.c=%.o)
+DEP	= $(SRC:%.c=%.d)
+PID	= $(TST:%=%.pid)
+OUT	= $(TST:%=%.out)
+STATE	= $(TST_STATE:%=%.state)
+STATE_OUT	= $(TST_STATE:%=%.out)
+
+DEPEND.c = $(COMPILE.c) -MM -MP
+%.d:	%.c
+	$(DEPEND.c) $(OUTPUT_OPTION) $<
+
+all:	$(TST)
+install: all
+.PHONY: all install
+
+$(TST_NOFILE:%=%.pid):	%.pid:	%
+	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out
+
+$(TST_FILE:%=%.pid):	%.pid:	%
+	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --filename=$<.test
+
+$(TST_DIR:%=%.pid):	%.pid:	%
+	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.test
+
+$(TST_DIR_FILE:%=%.pid):	%.pid:	%
+	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.dir.test --filename=$<.test
+
+%.out: %.pid %
+	-kill -TERM `cat $<`
+
+$(STATE): %.state: %
+	$(<D)/$(<F) --statefile=$@ --outfile=$<.out start
+
+$(STATE_OUT): %.out: %
+	-$(<D)/$(<F) --statefile=$<.state --outfile=$@ stop
+
+start: $(PID) $(STATE)
+
+%.is_running: %.pid
+	kill -0 `cat $<`
+
+check_start: $(PID:%.pid=%.is_running)
+
+stop: $(STATE_OUT)
+	-kill -TERM `cat *.pid`
+
+WAIT_TIME=240
+%.stop:	%.pid %
+	kill -TERM `cat $<`; \
+	i=0; \
+	while [ $$i -lt $(WAIT_TIME) ] ; do \
+		kill -0 `cat $< 2>/dev/null` 2>/dev/null || break; \
+		sleep 1; \
+		echo -n .; \
+		i=`expr $$i + 1`; \
+	done; \
+	echo; \
+	[ $$i -lt $(WAIT_TIME) ]
+
+wait_stop:
+		i=0; \
+		while [ $$i -lt $(WAIT_TIME) ] ; do \
+		kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; \
+		sleep 1; \
+		i=`expr $$i + 1`; \
+	done
+
+clean::
+	$(RM) -f $(OBJ) $(TST) *~
+
+cleandep: clean
+	$(RM) -f $(DEP)
+
+cleanout:
+	$(RM) -f -r *.pid *.out* *.test* *.state
+
+%.cleanout: %
+	$(Q) $(RM) -f -r $<.pid* $<.out* *$<.test* $<.*.test $<.state
+
+realclean: cleandep cleanout
+
+.PHONY:	force clean cleandep cleanout realclean start check_start stop wait_stop
+
+ifeq ($(filter-out no-deps-targets, $(MAKECMDGOALS)),)
+-include $(DEP)
+endif
diff --git a/test/zdtm/lib/Makefile b/test/zdtm/lib/Makefile
index 476e733..69fa70a 100644
--- a/test/zdtm/lib/Makefile
+++ b/test/zdtm/lib/Makefile
@@ -1,8 +1,7 @@
 include ../Makefile.inc
 
-CFLAGS	= -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fPIC
-CFLAGS	+= $(USERCFLAGS)
-LDFLAGS = -fPIC
+override CFLAGS	+= -fPIC
+override LDFLAGS += -fPIC
 
 LIBDIR	= .
 LIB	= libzdtmtst.so
@@ -23,9 +22,9 @@ all:	$(LIB) $(GRPS)
 install: all
 .PHONY: all install
 
-$(LIB): LDFLAGS += -shared
+$(LIB): override LDFLAGS += -shared
 $(LIB):	$(LIBOBJ)
-	$(LINK.c) $^ $(OUTPUT_OPTION)
+	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
 
 clean:
 	$(RM) -f $(LIBOBJ) $(LIB) $(GRPS) *~
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 9735d07..21fb6a8 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -1,11 +1,4 @@
-include ../Makefile.inc
-
-LIBDIR	= ../lib
-LDLIBS	= -lzdtmtst
-override CPPFLAGS += -I$(LIBDIR)
-CFLAGS	= -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fPIC
-CFLAGS	+= $(USERCFLAGS)
-LDFLAGS = -fPIC -pie -rdynamic -L$(LIBDIR) -Wl,-rpath,\$$ORIGIN/$(LIBDIR)
+# the include is at the end
 
 TST_NOFILE	=				\
 		busyloop00			\
@@ -236,11 +229,7 @@ TST_DIR_FILE	=				\
 		chroot				\
 		chroot-file
 
-TST		=				\
-		$(TST_NOFILE)			\
-		$(TST_FILE)			\
-		$(TST_DIR)			\
-		$(TST_DIR_FILE)			\
+TST_OTHER	=				\
 		env00				\
 		fifo-rowo-pair			\
 		umask00				\
@@ -251,37 +240,11 @@ TST_STATE	=				\
 		route_rules			\
 
 
-SRC	= $(TST:%=%.c)
-OBJ	= $(SRC:%.c=%.o)
-DEP	= $(SRC:%.c=%.d)
-PID	= $(TST:%=%.pid)
-OUT	= $(TST:%=%.out)
-STATE	= $(TST_STATE:%=%.state)
-STATE_OUT	= $(TST_STATE:%=%.out)
-
-DEPEND.c = $(COMPILE.c) -MM -MP
-%.d:	%.c
-	$(DEPEND.c) $(OUTPUT_OPTION) $<
-
-all:	$(TST) criu-rtc.so
-install: all
-.PHONY: all install
+all: criu-rtc.so
 
 inotify_system_nodel.c: inotify_system.c
 	ln -sf inotify_system.c inotify_system_nodel.c
 
-$(TST_NOFILE:%=%.pid):	%.pid:	%
-	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out
-
-$(TST_FILE:%=%.pid):	%.pid:	%
-	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --filename=$<.test
-
-$(TST_DIR:%=%.pid):	%.pid:	%
-	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.test
-
-$(TST_DIR_FILE:%=%.pid):	%.pid:	%
-	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.dir.test --filename=$<.test
-
 cmdlinenv00.pid: cmdlinenv00
 	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --arg1=arg1 --arg2=arg2 --arg3=arg3
 
@@ -293,46 +256,6 @@ umask00.pid:	umask00
 fifo-rowo-pair.pid: fifo-rowo-pair
 	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --name_master=$<.master.test --name_slave=$<.slave.test
 
-%.out:	%.pid %
-	-kill -TERM `cat $<`
-
-$(TST_STATE:%=%.state):	%.state: %
-	$(<D)/$(<F) --statefile=$@ --outfile=$<.out start
-
-$(TST_STATE:%=%.out): %.out: %
-	-$(<D)/$(<F) --statefile=$<.state --outfile=$@ stop
-
-start:	$(PID) $(STATE)
-
-%.is_running:	%.pid
-	kill -0 `cat $<`
-
-check_start:	$(PID:%.pid=%.is_running)
-
-stop:	$(STATE_OUT)
-	-kill -TERM `cat *.pid`
-
-WAIT_TIME=240
-%.stop:	%.pid %
-	kill -TERM `cat $<`; \
-	i=0; \
-	while [ $$i -lt $(WAIT_TIME) ] ; do \
-		kill -0 `cat $< 2>/dev/null` 2>/dev/null || break; \
-		sleep 1; \
-		echo -n .; \
-		i=`expr $$i + 1`; \
-	done; \
-	echo; \
-	[ $$i -lt $(WAIT_TIME) ]
-
-wait_stop:
-		i=0; \
-		while [ $$i -lt $(WAIT_TIME) ] ; do \
-		kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; \
-		sleep 1; \
-		i=`expr $$i + 1`; \
-	done
-
 aio00:			override LDLIBS += -laio
 different_creds:	override LDLIBS += -lcap
 futex.o:		override CFLAGS += -pthread
@@ -378,19 +301,8 @@ stopped01:	override CFLAGS += -DZDTM_STOPPED_KILL
 stopped02:	override CFLAGS += -DZDTM_STOPPED_TKILL
 stopped12:	override CFLAGS += -DZDTM_STOPPED_KILL -DZDTM_STOPPED_TKILL
 
-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
-
-realclean:	cleandep cleanout
+clean::
+	$(RM) -f criu-rtc.so criu-rtc.pb-c.c criu-rtc.pb-c.h get_smaps_bits.o
 
 rtc.c: criu-rtc.so
 
@@ -400,8 +312,4 @@ criu-rtc.pb-c.c: 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 $(USERCFLAGS)
 
-.PHONY:	force clean cleandep cleanout realclean start check_start stop wait_stop
-
-ifeq ($(filter-out no-deps-targets, $(MAKECMDGOALS)),)
--include $(DEP)
-endif
+include ../Makefile.live
diff --git a/test/zdtm/transition/Makefile b/test/zdtm/transition/Makefile
index 09450f9..6b87072 100644
--- a/test/zdtm/transition/Makefile
+++ b/test/zdtm/transition/Makefile
@@ -1,11 +1,4 @@
-include ../Makefile.inc
-
-LIBDIR	= ../lib
-LDLIBS	= -lzdtmtst
-override CPPFLAGS += -I$(LIBDIR)
-CFLAGS	= -g -O2 -Wall -Werror -fno-strict-aliasing -fPIC
-CFLAGS	+= $(USERCFLAGS)
-LDFLAGS = -fPIC -pie -rdynamic -L$(LIBDIR) -Wl,-rpath,\$$ORIGIN/$(LIBDIR)
+# the include is at the end
 
 TST_NOFILE	=	\
 		ipc		\
@@ -31,47 +24,6 @@ TST_FILE	=	\
 		fifo_loop       \
 
 
-TST	= $(TST_NOFILE) $(TST_FILE)
-SRC	= $(TST:%=%.c)
-OBJ	= $(SRC:%.c=%.o)
-DEP	= $(SRC:%.c=%.d)
-PID	= $(TST:%=%.pid)
-OUT	= $(TST:%=%.out)
-
-DEPEND.c = $(COMPILE.c) -MM -MP
-%.d:	%.c
-	$(DEPEND.c) $(OUTPUT_OPTION) $<
-
-all:	$(TST)
-install: all
-.PHONY: all install
-
-$(TST_NOFILE:%=%.pid):	%.pid:	%
-	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out
-
-$(TST_FILE:%=%.pid):	%.pid:	%
-	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --filename=$<.test
-
-%.out:	%.pid %
-	-kill -TERM `cat $<`
-
-start:	$(PID)
-
-%.is_running:	%.pid
-	kill -0 `cat $<`
-
-check_start:	$(PID:%.pid=%.is_running)
-
-stop:
-	-kill -TERM `cat *.pid`
-
-WAIT_TIME=10
-wait_stop:
-	-for i in `seq 1 $(WAIT_TIME)`; do \
-		kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; \
-		sleep 1; \
-	done
-
 file_aio:	override LDLIBS += -lrt -pthread
 socket-tcp:	override CFLAGS += -D STREAM
 socket-tcp6:	override CFLAGS += -D ZDTM_IPV6 -D STREAM
@@ -83,22 +35,4 @@ thread-bomb:	override LDFLAGS += -pthread
 	cp $< $@
 	chmod +x $@
 
-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
-
-ifeq ($(filter-out no-deps-targets, $(MAKECMDGOALS)),)
--include $(DEP)
-endif
+include ../Makefile.live
-- 
2.7.2



More information about the CRIU mailing list