device: renew dhcp leases on awake for software devices
[NetworkManager.git] / m4 / gnome-code-coverage.m4
1 dnl GNOME_CODE_COVERAGE
2 dnl
3 dnl Defines CODE_COVERAGE_CFLAGS and CODE_COVERAGE_LDFLAGS which should be
4 dnl included in the CFLAGS and LIBS/LDFLAGS variables of every build target
5 dnl (program or library) which should be built with code coverage support.
6 dnl Also defines GNOME_CODE_COVERAGE_RULES which should be substituted in your
7 dnl Makefile; and $enable_code_coverage which can be used in subsequent
8 dnl configure output.
9 dnl
10 dnl Note that all optimisation flags in CFLAGS must be disabled when code
11 dnl coverage is enabled.
12 dnl
13 dnl Derived from Makefile.decl in GLib, originally licenced under LGPLv2.1+.
14 dnl This file is licenced under LGPLv2.1+.
15 dnl
16 dnl Usage example:
17 dnl configure.ac:
18 dnl    GNOME_CODE_COVERAGE
19 dnl
20 dnl Makefile.am:
21 dnl    @GNOME_CODE_COVERAGE_RULES@
22 dnl    my_program_LIBS = … $(CODE_COVERAGE_LDFLAGS) …
23 dnl    my_program_CFLAGS = … $(CODE_COVERAGE_CFLAGS) …
24 dnl
25 dnl This results in a “check-code-coverage” rule being added to any Makefile.am
26 dnl which includes “@GNOME_CODE_COVERAGE_RULES@” (assuming the module has been
27 dnl configured with --enable-code-coverage). Running `make check-code-coverage`
28 dnl in that directory will run the module’s test suite (`make check`) and build
29 dnl a code coverage report detailing the code which was touched, then print the
30 dnl URI for the report.
31
32 AC_DEFUN([GNOME_CODE_COVERAGE],[
33         dnl Check for --enable-code-coverage
34         AC_MSG_CHECKING([whether to build with code coverage support])
35         AC_ARG_ENABLE([code-coverage], AS_HELP_STRING([--enable-code-coverage], [Whether to enable code coverage support]),, enable_code_coverage=no)
36         AM_CONDITIONAL([CODE_COVERAGE_ENABLED], [test x$enable_code_coverage = xyes])
37         AC_SUBST([CODE_COVERAGE_ENABLED], [$enable_code_coverage])
38         AC_MSG_RESULT($enable_code_coverage)
39
40         AS_IF([ test "$enable_code_coverage" = "yes" ], [
41                 dnl Check if gcc is being used
42                 AS_IF([ test "$GCC" = "no" ], [
43                         AC_MSG_ERROR([not compiling with gcc, which is required for gcov code coverage])
44                 ])
45
46                 # List of supported lcov versions.
47                 lcov_version_list="1.6 1.7 1.8 1.9 1.10"
48
49                 AC_CHECK_PROG([LCOV], [lcov], [lcov])
50                 AC_CHECK_PROG([GENHTML], [genhtml], [genhtml])
51
52                 AS_IF([ test "$LCOV" ], [
53                         AC_CACHE_CHECK([for lcov version], gnome_cv_lcov_version, [
54                                 gnome_cv_lcov_version=invalid
55                                 lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
56                                 for lcov_check_version in $lcov_version_list; do
57                                         if test "$lcov_version" = "$lcov_check_version"; then
58                                                 gnome_cv_lcov_version="$lcov_check_version (ok)"
59                                         fi
60                                 done
61                         ])
62                 ], [
63                         lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
64                         AC_MSG_ERROR([$lcov_msg])
65                 ])
66
67                 case $gnome_cv_lcov_version in
68                         ""|invalid[)]
69                                 lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
70                                 AC_MSG_ERROR([$lcov_msg])
71                                 LCOV="exit 0;"
72                         ;;
73                 esac
74
75                 AS_IF([ test -z "$GENHTML" ], [
76                         AC_MSG_ERROR([Could not find genhtml from the lcov package])
77                 ])
78
79                 dnl Build the code coverage flags
80                 CODE_COVERAGE_CFLAGS="-O0 -g -fprofile-arcs -ftest-coverage"
81                 CODE_COVERAGE_LDFLAGS="-lgcov"
82
83                 AC_SUBST([CODE_COVERAGE_CFLAGS])
84                 AC_SUBST([CODE_COVERAGE_LDFLAGS])
85         ])
86
87 GNOME_CODE_COVERAGE_RULES='
88 # Code coverage
89 #
90 # Optional:
91 #  - CODE_COVERAGE_DIRECTORY: Top-level directory for code coverage reporting.
92 #    (Default: $(top_builddir))
93 #  - CODE_COVERAGE_OUTPUT_FILE: Filename and path for the .info file generated
94 #    by lcov for code coverage. (Default:
95 #    $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage.info)
96 #  - CODE_COVERAGE_OUTPUT_DIRECTORY: Directory for generated code coverage
97 #    reports to be created. (Default:
98 #    $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage)
99 #  - CODE_COVERAGE_LCOV_OPTIONS: Extra options to pass to the lcov instance.
100 #    (Default: empty)
101 #  - CODE_COVERAGE_GENHTML_OPTIONS: Extra options to pass to the genhtml
102 #    instance. (Default: empty)
103 #  - CODE_COVERAGE_IGNORE_PATTERN: Extra glob pattern of files to ignore
104 #
105 # The generated report will be titled using the $(PACKAGE_NAME) and
106 # $(PACKAGE_VERSION). In order to add the current git hash to the title,
107 # use the git-version-gen script, available online.
108
109 # Optional variables
110 CODE_COVERAGE_DIRECTORY ?= $(top_builddir)
111 CODE_COVERAGE_OUTPUT_FILE ?= $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage.info
112 CODE_COVERAGE_OUTPUT_DIRECTORY ?= $(PACKAGE_NAME)-$(PACKAGE_VERSION)-coverage
113 CODE_COVERAGE_LCOV_OPTIONS ?=
114 CODE_COVERAGE_GENHTML_OPTIONS ?=
115 CODE_COVERAGE_IGNORE_PATTERN ?=
116
117 code_coverage_quiet = $(code_coverage_quiet_$(V))
118 code_coverage_quiet_ = $(code_coverage_quiet_$(AM_DEFAULT_VERBOSITY))
119 code_coverage_quiet_0 = --quiet
120
121 # Use recursive makes in order to ignore errors during check
122 check-code-coverage:
123 ifeq ($(CODE_COVERAGE_ENABLED),yes)
124         -$(MAKE) $(AM_MAKEFLAGS) -k check
125         $(MAKE) $(AM_MAKEFLAGS) code-coverage-capture
126 else
127         @echo "Need to reconfigure with --enable-code-coverage"
128 endif
129
130 # Capture code coverage data
131 code-coverage-capture: code-coverage-capture-hook
132 ifeq ($(CODE_COVERAGE_ENABLED),yes)
133         $(LCOV) $(code_coverage_quiet) --directory $(CODE_COVERAGE_DIRECTORY) --capture --output-file "$(CODE_COVERAGE_OUTPUT_FILE).tmp" --test-name "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" --no-checksum --compat-libtool $(CODE_COVERAGE_LCOV_OPTIONS)
134         $(LCOV) $(code_coverage_quiet) --directory $(CODE_COVERAGE_DIRECTORY) --remove "$(CODE_COVERAGE_OUTPUT_FILE).tmp" "/tmp/*" $(CODE_COVERAGE_IGNORE_PATTERN) --output-file "$(CODE_COVERAGE_OUTPUT_FILE)"
135         -@rm -f $(CODE_COVERAGE_OUTPUT_FILE).tmp
136         LANG=C $(GENHTML) $(code_coverage_quiet) --prefix $(CODE_COVERAGE_DIRECTORY) --output-directory "$(CODE_COVERAGE_OUTPUT_DIRECTORY)" --title "$(PACKAGE_NAME)-$(PACKAGE_VERSION) Code Coverage" --legend --show-details "$(CODE_COVERAGE_OUTPUT_FILE)" $(CODE_COVERAGE_GENHTML_OPTIONS)
137         @echo "file://$(abs_builddir)/$(CODE_COVERAGE_OUTPUT_DIRECTORY)/index.html"
138 else
139         @echo "Need to reconfigure with --enable-code-coverage"
140 endif
141
142 # Hook rule executed before code-coverage-capture, overridable by the user
143 code-coverage-capture-hook:
144
145 ifeq ($(CODE_COVERAGE_ENABLED),yes)
146 clean: code-coverage-clean
147 code-coverage-clean:
148         -$(LCOV) --directory $(top_builddir) -z
149         -rm -rf $(CODE_COVERAGE_OUTPUT_FILE) $(CODE_COVERAGE_OUTPUT_FILE).tmp $(CODE_COVERAGE_OUTPUT_DIRECTORY)
150         -find . -name "*.gcda" -o -name "*.gcov" -delete
151 endif
152
153 GITIGNOREFILES ?=
154 GITIGNOREFILES += $(CODE_COVERAGE_OUTPUT_FILE) $(CODE_COVERAGE_OUTPUT_DIRECTORY)
155
156 DISTCHECK_CONFIGURE_FLAGS ?=
157 DISTCHECK_CONFIGURE_FLAGS += --disable-code-coverage
158
159 .PHONY: check-code-coverage code-coverage-capture code-coverage-capture-hook code-coverage-clean
160 '
161
162         AC_SUBST([GNOME_CODE_COVERAGE_RULES])
163         m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([GNOME_CODE_COVERAGE_RULES])])
164 ])