mk: add 'COVERAGE' option

'COVERAGE=yes' in 'target.mk' adds gcov-specific compiler flags and links the
program with libgcov.

Issue #3048
This commit is contained in:
Christian Prochaska 2018-11-06 19:46:50 +01:00 committed by Christian Helmuth
parent e74771e047
commit 1f985dec38
3 changed files with 37 additions and 0 deletions

View File

@ -16,6 +16,13 @@ include $(BASE_DIR)/mk/util.inc
PRG_DIR := $(dir $(TARGET_MK))
include $(TARGET_MK)
#
# Add libgcov if coverage is requested
#
ifeq ($(COVERAGE),yes)
LIBS += libgcov
endif
#
# Include lib-import description files
#

View File

@ -55,6 +55,10 @@ endif
%.o: %.cc
$(MSG_COMP)$@
$(VERBOSE)$(CXX) $(CXX_DEF) $(CC_CXX_OPT) $(INCLUDES) -c $< -o $@
ifeq ($(COVERAGE),yes)
$(VERBOSE)mkdir -p $(INSTALL_DIR)/gcov_data/$(TARGET)/$(dir $@)
$(VERBOSE)ln -sf $(CURDIR)/$(@:.o=.gcno) $(INSTALL_DIR)/gcov_data/$(TARGET)/$(@:.o=.gcno)
endif
%.o: %.cpp
$(MSG_COMP)$@

View File

@ -103,6 +103,32 @@ ifneq ($(STDLIB),yes)
LD_OPT_NOSTDLIB := -nostdlib -Wl,-nostdlib
endif
#
# Add coverage options
#
# The directory for the coverage data (generated at runtime) is derived from
# the current build directory and is going to look like
#
# '/genodelabs/bin/test-log_gcov/2018-11-13/gcov_data/test-log_gcov'
#
# to match the path where the gcov note files (generated at build time) are
# stored in the depot package of the test program.
#
# If depot packages are not used, the path is going to look like
#
# '/gcov_data/test-log_gcov'
#
ifeq ($(COVERAGE),yes)
ifneq ($(findstring /depot/,$(CURDIR)),)
PROFILE_DIR = $(shell echo $(CURDIR) | \
sed -e 's/^.*\/depot\//\//' \
-e 's/\.build\/.*//')/gcov_data/$(TARGET)
else
PROFILE_DIR = /gcov_data/$(TARGET)
endif
CC_OPT += -fprofile-arcs -ftest-coverage -fprofile-dir=$(PROFILE_DIR)
endif
#
# Default optimization and warning levels
#