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