1 2dnl Macro to add --enable-coverage option (disabled by default) and add 3dnl appropriate compiler flags to permit usage of gcov if that option is 4dnl enabled. If WRAPPER_xFLAGS variables are set then the flags will also be 5dnl added to those variables. 6dnl 7dnl Sets "pac_cv_use_coverage=yes" and AC_DEFINEs USE_COVERAGE if coverage was 8dnl successfully enabled. Also creates an AM_CONDITIONAL with the name 9dnl "BUILD_COVERAGE" that is true iff pac_cv_use_coverage=yes. 10dnl 11dnl Usage: PAC_CONFIG_SUBDIR_ARGS 12dnl 13dnl Assumes that all of the compiler macros have already been invoked 14dnl (AC_PROG_CC and friends). 15AC_DEFUN([PAC_ENABLE_COVERAGE],[ 16 17AC_ARG_VAR([GCOV],[name/path for the gcov utility]) 18AC_CHECK_PROGS([GCOV],[gcov]) 19 20AC_ARG_ENABLE([coverage], 21 [AC_HELP_STRING([--enable-coverage], 22 [Turn on coverage analysis using gcc and gcov])], 23 [],[enable_coverage=no]) 24 25if test "$enable_coverage" = "yes" ; then 26 if test "$ac_cv_prog_gcc" = "yes" ; then 27 CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" 28 if test ${WRAPPER_CFLAGS+set} = set ; then 29 WRAPPER_CFLAGS="$WRAPPER_CFLAGS -fprofile-arcs -ftest-coverage" 30 fi 31 else 32 AC_MSG_WARN([--enable-coverage only supported for GCC]) 33 fi 34 if test "$enable_cxx" = "yes" ; then 35 if test "$ac_cv_cxx_compiler_gnu" = "yes" ; then 36 CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage" 37 if test ${WRAPPER_CXXFLAGS+set} = set ; then 38 WRAPPER_CXXFLAGS="$WRAPPER_CXXFLAGS -fprofile-arcs -ftest-coverage" 39 fi 40 else 41 AC_MSG_WARN([--enable-coverage only supported for GCC]) 42 fi 43 fi 44 # Add similar options for g77 so that the Fortran tests will also 45 # 46 if test "$enable_f77" = yes ; then 47 if test "$ac_cv_f77_compiler_gnu" = "yes" ; then 48 FFLAGS="$FFLAGS -fprofile-arcs -ftest-coverage" 49 if test ${WRAPPER_FFLAGS+set} = set ; then 50 WRAPPER_FFLAGS="$WRAPPER_FFLAGS -fprofile-arcs -ftest-coverage" 51 fi 52 else 53 AC_MSG_WARN([--enable-coverage only supported for G77/GFORTRAN]) 54 fi 55 fi 56 if test "$enable_fc" = yes ; then 57 if test "$ac_cv_fc_compiler_gnu" = "yes" ; then 58 FCFLAGS="$FCFLAGS -fprofile-arcs -ftest-coverage" 59 if test ${WRAPPER_FCFLAGS+set} = set ; then 60 WRAPPER_FCFLAGS="$WRAPPER_FCFLAGS -fprofile-arcs -ftest-coverage" 61 fi 62 else 63 AC_MSG_WARN([--enable-coverage only supported for GFORTRAN]) 64 fi 65 fi 66 # On some platforms (e.g., Mac Darwin), we must also *link* 67 # with the -fprofile-args -ftest-coverage option. 68 AC_MSG_CHECKING([whether compilation with coverage analysis enabled works]) 69 AC_LINK_IFELSE([AC_LANG_SOURCE([int main(int argc, char **argv){return 1;}])], 70 [AC_MSG_RESULT([yes])], 71 [AC_MSG_RESULT([no]) 72 AC_MSG_ERROR([Unable to link programs when coverage analysis enabled])]) 73 74 # Test for the routines that we need to use to ensure that the 75 # data files are (usually) written out 76 # FIXME: Some versions of Linux provide usleep, but it rounds times 77 # up to the next second (!) 78 AC_CHECK_FUNCS([usleep]) 79 80 # NOTE: using a "pac_cv_" prefix but not caching because of xFLAGS "side effects" 81 pac_cv_use_coverage=yes 82 AC_DEFINE([USE_COVERAGE],[1],[Define if performing coverage tests]) 83fi 84AM_CONDITIONAL([BUILD_COVERAGE],[test "X$pac_cv_use_coverage" = "Xyes"]) 85]) 86 87