[GLib Documentation]
[gnome.gobject-introspection] / m4 / gcov.m4
1 AC_DEFUN([GI_ENABLE_GCOV],
2 [
3   AC_ARG_ENABLE(gcov,
4     AC_HELP_STRING([--enable-gcov],
5       [compile with coverage profiling instrumentation (gcc only)]),
6     enable_gcov=$enableval,
7     enable_gcov=no)
8   if test x$enable_gcov = xyes ; then
9     if test "x$GCC" != "xyes"
10     then
11       AC_MSG_ERROR([gcov only works if gcc is used])
12     fi
13
14     AS_COMPILER_FLAG(["-fprofile-arcs"],
15       [GCOV_CFLAGS="$GCOV_CFLAGS -fprofile-arcs"],
16       true)
17     AS_COMPILER_FLAG(["-ftest-coverage"],
18       [GCOV_CFLAGS="$GCOV_CFLAGS -ftest-coverage"],
19       true)
20     dnl libtool 1.5.22 and lower strip -fprofile-arcs from the flags
21     dnl passed to the linker, which is a bug; -fprofile-arcs implicitly
22     dnl links in -lgcov, so we do it explicitly here for the same effect
23     GCOV_LIBS=-lgcov
24     AC_SUBST(GCOV_CFLAGS)
25     AC_SUBST(GCOV_LIBS)
26     GCOV=`echo $CC | sed s/gcc/gcov/g`
27     AC_SUBST(GCOV)
28
29     GI_GCOV_ENABLED=yes
30     AC_DEFINE_UNQUOTED(GI_GCOV_ENABLED, 1,
31       [Defined if gcov is enabled to force a rebuild due to config.h changing])
32     dnl if gcov is used, we do not want default -O2 CFLAGS
33     if test "x$GI_GCOV_ENABLED" = "xyes"
34     then
35       CFLAGS="-g -O0"
36       AC_SUBST(CFLAGS)
37       CXXFLAGS="-g -O0"
38       AC_SUBST(CXXFLAGS)
39       FFLAGS="-g -O0"
40       AC_SUBST(FFLAGS)
41       CCASFLAGS="-g -O0"
42       AC_SUBST(CCASFLAGS)
43       AC_MSG_NOTICE([gcov enabled, setting CFLAGS and friends to $CFLAGS])
44     fi
45   fi
46   AM_CONDITIONAL(GI_GCOV_ENABLED, test x$enable_gcov = xyes)
47 ])