[CRIU] [PATCHv2] make: rework lcov building & introduce debug target

Dmitry Safonov dsafonov at virtuozzo.com
Mon Feb 15 04:18:13 PST 2016


This patch fixes building criu without optimizations for coverage.
It introduces target debug which build criu without optimizations and
with coverage (lcov) support.

Now makefile looks nicer and one does not need to remember which
variable to set to build criu with coverage.

>From now to make coverage report on tests, you need to do:
$ make debug
$ make test
$ make gcov

Initially was: https://lists.openvz.org/pipermail/criu/2016-February/025314.html

Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Cc: Sergey Bronnikov <sergeyb at openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
v2: made separate debug target

 Makefile | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/Makefile b/Makefile
index d88c1d0..8b633bb 100644
--- a/Makefile
+++ b/Makefile
@@ -77,12 +77,6 @@ ifeq ($(ARCH),ia32)
 	export PROTOUFIX ldflags-y
 endif
 
-ifeq ($(GCOV),1)
-	LDFLAGS += -lgcov
-	DEBUG := 1	# disable optimization if we want to measure code coverage
-%.o $(PROGRAM): override CFLAGS += --coverage -fno-exceptions -fno-inline
-endif
-
 ifeq ($(shell echo $(ARCH) | sed -e 's/arm.*/arm/'),arm)
 	ARMV         := $(shell echo $(ARCH) | sed -nr 's/armv([[:digit:]]).*/\1/p; t; i7')
 	SRCARCH      := arm
@@ -156,13 +150,6 @@ ifneq ($(WERROR),0)
 	WARNINGS += -Werror
 endif
 
-ifeq ($(DEBUG),1)
-	DEFINES += -DCR_DEBUG
-	CFLAGS	+= -O0 -ggdb3
-else
-	CFLAGS	+= -O2 -g
-endif
-
 ifeq ($(GMON),1)
 	CFLAGS	+= -pg
 	GMONLDOPT := -pg
@@ -198,12 +185,23 @@ build-crtools := -r -R -f scripts/Makefile.build makefile=Makefile.crtools obj
 
 PROGRAM		:= criu
 
-.PHONY: all zdtm test rebuild clean distclean tags cscope	\
+.PHONY: all debug default zdtm test rebuild clean distclean tags cscope	\
 	docs help pie protobuf $(ARCH_DIR) clean-built lib crit
 
-all: config pie $(VERSION_HEADER) $(CRIU-LIB)
-	$(Q) $(MAKE) $(PROGRAM)
-	$(Q) $(MAKE) crit
+all: CFLAGS += -O2 -g
+all: default
+
+debug: DEFINES		+= -DCR_DEBUG
+debug: CFLAGS		+= -O0 -ggdb3
+debug: LDFLAGS		+= -lgcov
+debug: CFLAGS_COVERAGE	:= --coverage -fno-exceptions -fno-inline
+debug: default
+
+%.o $(PROGRAM): CFLAGS += $(CFLAGS_COVERAGE)
+
+default: config pie $(VERSION_HEADER) $(CRIU-LIB)
+	$(Q) $(MAKE) LDFLAGS="$(LDFLAGS)" CFLAGS="$(CFLAGS)" $(PROGRAM)
+	$(Q) $(MAKE) LDFLAGS="$(LDFLAGS)" CFLAGS="$(CFLAGS)" crit
 
 protobuf/%::
 	$(Q) $(MAKE) $(build)=protobuf $@
@@ -358,6 +356,7 @@ help:
 	@echo '      cscope          - Generate cscope database'
 	@echo '      rebuild         - Force-rebuild of [*] targets'
 	@echo '      test            - Run zdtm test-suite'
+	@echo '      debug           - Build all [*] without optimizations'
 	@echo '      gcov	     - Make code coverage report'
 
 gcov:
-- 
2.7.1



More information about the CRIU mailing list