@@ -8,4 +8,81 @@ if LUA_SUB
8
8
LUA_SUBDIR = lua
9
9
endif
10
10
11
+ COVERAGE_INFO_FILE = $(top_builddir ) /coverage.info
12
+ COVERAGE_REPORT_DIR = $(top_builddir ) /coverage
13
+
14
+ .PHONY = coverage-requirement-check clean-coverage-report
15
+
16
+ coverage-requirement-check :
17
+ @if test ! -e $(GCOV ) ; then \
18
+ echo " Cannot find $( GCOV) . Please install gcov." ; \
19
+ exit 1; \
20
+ fi
21
+ @if test ! -e $(LCOV ) ; then \
22
+ echo " Cannot find $( LCOV) . Please install lcov." ; \
23
+ exit 1; \
24
+ fi
25
+ @if test ! -e $(GENHTML ) ; then \
26
+ echo " Cannot find $( GENHTML) . Please install lcov." ; \
27
+ exit 1; \
28
+ fi
29
+
30
+ coverage : coverage-requirement-check clean-coverage coverage-build coverage-check coverage-report
31
+ @echo " Please execute 'make clean' before 'make' or 'make check' to remove instrumented object files(compiled with -O0 etc.). Note that 'make clean' also remove coverage data."
32
+
33
+ coverage-build : coverage-requirement-check
34
+ @if test ` find $( top_builddir) -name " *.gcno" | wc -l` -eq 0; then \
35
+ echo " Start to remove old non-instrumented object files..." ; \
36
+ $(MAKE ) $(AM_MAKEFLAGS ) clean; \
37
+ echo " Successfully removed old non-instrumented object files." ; \
38
+ fi
39
+ @echo " Start to build libraries with coverage options..."
40
+ $(MAKE ) $(AM_MAKEFLAGS ) \
41
+ CFLAGS=" $( CFLAGS) $( COVERAGE_CFLAGS) $( COVERAGE_OPTFLAGS) " \
42
+ CXXFLAGS=" $( CXXFLAGS) $( COVERAGE_CXXFLAGS) $( COVERAGE_OPTFLAGS) " \
43
+ LDFLAGS=" $( LDFLAGS) $( COVERAGE_LDFLAGS) " \
44
+ LIBS=" $( LIBS) $( COVERAGE_LIBS) "
45
+ @echo " Successfully built libraries with coverage options."
46
+
47
+ coverage-check : coverage-requirement-check
48
+ @echo " Start to run tests with instrumented libraries..."
49
+ $(MAKE ) $(AM_MAKEFLAGS ) check \
50
+ CFLAGS=" $( CFLAGS) $( COVERAGE_CFLAGS) $( COVERAGE_OPTFLAGS) " \
51
+ CXXFLAGS=" $( CXXFLAGS) $( COVERAGE_CXXFLAGS) $( COVERAGE_OPTFLAGS) " \
52
+ LDFLAGS=" $( LDFLAGS) $( COVERAGE_LDFLAGS) " \
53
+ LIBS=" $( LIBS) $( COVERAGE_LIBS) "
54
+ @echo " Successfully run tests with instrumented libraries."
55
+
56
+ # TODO(Eiichiro Iwata): Remove GNU make extension(abspath function)
57
+ # Automake treat GNU make extension as warning
58
+ # when using -Wall or -Wportability in AM_INIT_AUTOMAKE.
59
+ coverage-report : coverage-requirement-check
60
+ @echo " Start to create coverage reports..."
61
+ $(LCOV ) --capture \
62
+ --directory " $( top_builddir) /" \
63
+ --output-file $(COVERAGE_INFO_FILE ) \
64
+ --gcov-tool $(GCOV ) \
65
+ --compat-libtool --checksum
66
+ $(GENHTML ) --prefix " $( top_srcdir) " \
67
+ --output-directory $(COVERAGE_REPORT_DIR ) \
68
+ --title $(PACKAGE_NAME ) \
69
+ --legend --show-details \
70
+ $(GENHTML_OPTIONS ) \
71
+ $(COVERAGE_INFO_FILE )
72
+ @echo " Successfully created coverage reports into $( COVERAGE_REPORT_DIR) directory."
73
+
74
+ clean-coverage-report :
75
+ -rm -rf $(COVERAGE_INFO_FILE )
76
+ -rm -rf $(COVERAGE_REPORT_DIR )
77
+
78
+ clean-coverage : clean-coverage-report
79
+ -$(LCOV ) --gcov-tool $(GCOV ) --zerocounters --directory $(top_builddir )
80
+ @if xargs --version 2> /dev/null; then \
81
+ find $(top_builddir ) -name " *.gcno" | xargs --no-run-if-empty rm; \
82
+ else \
83
+ find $(top_builddir ) -name " *.gcno" | xargs rm; \
84
+ fi
85
+
86
+ clean-local : clean-coverage
87
+
11
88
SUBDIRS = src tests utils doc $(LUA_SUBDIR )
0 commit comments