Merge pull request #457 from vivien/text-variable
[tig.git] / tools / gcov.m4
blob64f00e873e668b5b8cf57b84d212c49b39ce772c
1 # Copyright 2012 Canonical Ltd.
3 # This program is free software: you can redistribute it and/or modify it 
4 # under the terms of the GNU General Public License version 3, as published 
5 # by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful, but 
8 # WITHOUT ANY WARRANTY; without even the implied warranties of 
9 # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
10 # PURPOSE.  See the GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License along 
13 # with this program.  If not, see <http://www.gnu.org/licenses/>.
15 # Checks for existence of coverage tools:
16 #  * gcov
17 #  * lcov
18 #  * genhtml
19 #  * gcovr
20
21 # Sets ac_cv_check_gcov to yes if tooling is present
22 # and reports the executables to the variables LCOV, GCOVR and GENHTML.
23 AC_DEFUN([AC_TDD_GCOV],
25   AC_ARG_ENABLE(gcov,
26   AS_HELP_STRING([--enable-gcov],
27                  [enable coverage testing with gcov]),
28   [use_gcov=yes], [use_gcov=no])
30   AM_CONDITIONAL(HAVE_GCOV, test "x$use_gcov" = "xyes")
32   if test "x$use_gcov" = "xyes"; then
33   # we need gcc:
34   if test "$GCC" != "yes"; then
35     AC_MSG_ERROR([GCC is required for --enable-gcov])
36   fi
38   # Check if ccache is being used
39   AC_CHECK_PROG(SHTOOL, shtool, shtool)
40   if test "$SHTOOL"; then
41     AS_CASE([`$SHTOOL path $CC`],
42                 [*ccache*], [gcc_ccache=yes],
43                 [gcc_ccache=no])
44   fi
46   if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
47     AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
48   fi
50   lcov_version_list="1.6 1.7 1.8 1.9 1.10 1.11"
51   AC_CHECK_PROG(LCOV, lcov, lcov)
52   AC_CHECK_PROG(GENHTML, genhtml, genhtml)
54   if test "$LCOV"; then
55     AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
56       glib_cv_lcov_version=invalid
57       lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
58       for lcov_check_version in $lcov_version_list; do
59         if test "$lcov_version" = "$lcov_check_version"; then
60           glib_cv_lcov_version="$lcov_check_version (ok)"
61         fi
62       done
63     ])
64   else
65     lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
66     AC_MSG_ERROR([$lcov_msg])
67   fi
69   case $glib_cv_lcov_version in
70     ""|invalid[)]
71       lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
72       AC_MSG_ERROR([$lcov_msg])
73       LCOV="exit 0;"
74       ;;
75   esac
77   if test -z "$GENHTML"; then
78     AC_MSG_ERROR([Could not find genhtml from the lcov package])
79   fi
81   # Remove all optimization flags from CFLAGS
82   changequote({,})
83   CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
84   CPPFLAGS=`echo "$CPPFLAGS" | $SED -e 's/-O[0-9]*//g'`
85   changequote([,])
87   # Add the special gcc flags
88   COVERAGE_CFLAGS="--coverage -DDEBUG"
89   COVERAGE_CXXFLAGS="--coverage -DDEBUG"
90   COVERAGE_LDFLAGS="--coverage -lgcov"
93 ]) # AC_TDD_GCOV