xref: /freebsd/contrib/libucl/m4/gcov.m4 (revision 2008043f386721d58158e37e0d7e50df8095942d)
1# SYNOPSIS
2#
3#   Add code coverage support with gcov/lcov.
4#
5#   AX_CODE_COVERAGE()
6#
7# DESCRIPTION
8#
9#   Provides a --enable-coverage option which checks for available
10#   gcov/lcov binaries and provides ENABLE_CODE_COVERAGE conditional.
11#
12# LAST MODIFICATION
13#
14#   $Id: coverage.m4 40881 2013-08-20 17:54:39Z damon $
15#
16# COPYLEFT
17#
18#   Copyright (c) 2012 Roy H. Stogner <roystgnr@ices.utexas.edu>
19#   Copyright (c) 2010 Karl W. Schulz <karl@ices.utexas.edu>
20#
21#   Copying and distribution of this file, with or without modification, are
22#   permitted in any medium without royalty provided the copyright notice
23#   and this notice are preserved.
24
25AC_DEFUN([AX_CODE_COVERAGE],
26[
27
28AC_ARG_ENABLE(coverage, AC_HELP_STRING([--enable-coverage],[configure code coverage analysis tools]))
29
30HAVE_GCOV_TOOLS=0
31
32GCOV_FLAGS=""
33
34if test "x$enable_coverage" = "xyes"; then
35
36   # ----------------------------
37   # Check for gcov/lcov binaries
38   # ----------------------------
39
40   AC_ARG_VAR([GCOV], [Coverage testing command])
41   if test "x$GCOV" = "x"; then
42    AC_PATH_PROG(GCOV, gcov, no)
43   else
44    AC_PATH_PROG(GCOV, $GCOV, no)
45   fi
46
47   AC_PATH_PROG(LCOV, lcov, no)
48   AC_PATH_PROG(GENHTML, genhtml)
49
50   # ----------------------------------
51   # include coverage compiler options
52   # ----------------------------------
53   AC_MSG_CHECKING([for clang])
54
55   AC_COMPILE_IFELSE(
56   [AC_LANG_PROGRAM([], [[
57 #ifndef __clang__
58   not clang
59 #endif
60 ]])],
61 [CLANG=yes], [CLANG=no])
62
63   AC_MSG_RESULT([$CLANG])
64   HAVE_GCOV_TOOLS=1
65   COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage"
66   COVERAGE_LDFLAGS="--coverage -fprofile-arcs -ftest-coverage"
67   COVERAGE_OPTFLAGS="-O0"
68
69   # Test for C...
70   CFLAGS="${GCOV_FLAGS} ${CFLAGS}"
71   CXXFLAGS="${GCOV_FLAGS} ${CXXFLAGS}"
72   if test "x$GCC" = "xyes" -a "x$CLANG" = "xno"; then
73     COVERAGE_LIBS="-lgcov"
74   else
75     COVERAGE_LIBS=""
76   fi
77fi
78
79AC_SUBST([GCOV])
80AC_SUBST([LCOV])
81AC_SUBST([GENHTML])
82AC_SUBST([GENHTML_OPTIONS])
83AC_SUBST([COVERAGE_CFLAGS])
84AC_SUBST([COVERAGE_OPTFLAGS])
85AC_SUBST([COVERAGE_LDFLAGS])
86AC_SUBST([COVERAGE_LIBS])
87AM_CONDITIONAL(CODE_COVERAGE_ENABLED,test x$HAVE_GCOV_TOOLS = x1)
88
89])
90