summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Taylor <rob.taylor@codethink.co.uk>2008-02-08 18:09:05 +0000
committerRobert James Taylor <robtaylor@src.gnome.org>2008-02-08 18:09:05 +0000
commite2340a78cd657c2398f1076f6f0b87a3dca25540 (patch)
tree17395722d1bda95d39e4b543cd3739fe4314eeec
parentb935261f387dffa2c7006fe1be04820004810e87 (diff)
downloadgobject-introspection-e2340a78cd657c2398f1076f6f0b87a3dca25540.tar.gz
Added:
2008-02-08 Rob Taylor <rob.taylor@codethink.co.uk> * Makefile.am: * configure.ac: * gcov.mak: Added: * girepository/Makefile.am: * m4/Makefile.am: Added: * m4/as-compiler-flag.m4: Added: * m4/gcov.m4: Added: * tools/Makefile.am: Add ability to generate a coverage report. Adds configure option --enable-gcov and make rule 'check-coverage'. svn path=/trunk/; revision=105
-rw-r--r--ChangeLog13
-rw-r--r--Makefile.am40
-rw-r--r--configure.ac9
-rw-r--r--gcov.mak21
-rw-r--r--girepository/Makefile.am3
-rw-r--r--m4/Makefile.am1
-rw-r--r--m4/as-compiler-flag.m433
-rw-r--r--m4/gcov.m447
-rw-r--r--tools/Makefile.am8
9 files changed, 173 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 6caf8838..d4308172 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,19 @@
* Makefile.am:
* configure.ac:
+ * gcov.mak: Added:
+ * girepository/Makefile.am:
+ * m4/Makefile.am: Added:
+ * m4/as-compiler-flag.m4: Added:
+ * m4/gcov.m4: Added:
+ * tools/Makefile.am:
+ Add ability to generate a coverage report.
+ Adds configure option --enable-gcov and make rule 'check-coverage'.
+
+2008-02-08 Rob Taylor <rob.taylor@codethink.co.uk>
+
+ * Makefile.am:
+ * configure.ac:
* gidl/Makefile.am: Added:
* girepository/Makefile.am: Added:
* src/Makefile.am: Renamed to tools/Makefile.am:
diff --git a/Makefile.am b/Makefile.am
index 8a336995..978d2c09 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,45 @@
## Process this file with automake to produce Makefile.in
-
+DIST_SUBDIRS = m4
SUBDIRS = gidl girepository tools tests
+ACLOCAL_AMFLAGS = -I m4
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gobject-introspection.pc
EXTRA_DIST = $(pkgconfig_DATA)
+
+if GI_GCOV_ENABLED
+GCOV_DIRS = girepository tools
+
+clean-gcov:
+ find -name "*.gcda" -o -name "*.gcov" -delete
+
+clean-gcno:
+ find -name "*.gcno" -delete
+
+.PHONEY: gcov-all
+gcov-all:
+ @for dir in $(GCOV_DIRS); do \
+ cd $(abs_srcdir)/$$dir && \
+ for file in *.c; do \
+ gcov -f -p -o `find $(abs_builddir)/$$dir -newer $$file -name "*-$${file/.c/.gcda}" -print0 | sed -e 's/\.gcda/\.o/'` $$file > /dev/null; \
+ done \
+ done
+
+.PHONEY: coverage-report.txt
+coverage-report.txt: clean clean-gcov all check gcov-all
+ @rm -f $(top_builddir)/coverage-report.txt
+ @echo -e "=== Coverage Report ===\n" >> $(top_builddir)/coverage-report.txt
+ @for dir in $(GCOV_DIRS); do \
+ echo "Module '$$dir':" >> $(top_builddir)/coverage-report.txt; \
+ $(MAKE) -C $$dir coverage-report; \
+ done
+
+check-coverage: coverage-report.txt
+ @cat $(top_builddir)/coverage-report.txt
+
+else
+
+check-coverage:
+ @echo "Need to reconfigure with --enable-gcov"
+
+endif
diff --git a/configure.ac b/configure.ac
index 44fe0ab1..906b2399 100644
--- a/configure.ac
+++ b/configure.ac
@@ -8,6 +8,8 @@ AM_MAINTAINER_MODE
AC_CONFIG_SRCDIR([girepository/ginvoke.c])
AC_CONFIG_HEADER([config.h])
+AC_CONFIG_MACRO_DIR([m4])
+
# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
@@ -25,6 +27,8 @@ if test "$YACC" = :; then
fi
# Checks for libraries.
+GI_ENABLE_GCOV
+
AC_CHECK_LIB([dl], [dlopen])
PKG_CHECK_MODULES(GOBJECT, [gobject-2.0])
@@ -74,6 +78,7 @@ if test "$have_ffi_h" = "yes"; then
GIREPO_LIBS="$GIREPO_LIBS $FFI_LIBS"
fi
+GIREPO_CFLAGS="$GIREPO_CFLAGS $GCOV_CFLAGS"
# Checks for header files.
AC_HEADER_STDC
@@ -86,9 +91,11 @@ AC_C_CONST
AC_FUNC_STRTOD
AC_CHECK_FUNCS([memchr strchr strspn strstr strtol strtoull])
+
AC_CONFIG_FILES([Makefile
- gidl/Makefile
+ gidl/Makefile
girepository/Makefile
+ m4/Makefile
tools/Makefile
tests/Makefile
tests/invoke/Makefile
diff --git a/gcov.mak b/gcov.mak
new file mode 100644
index 00000000..74946789
--- /dev/null
+++ b/gcov.mak
@@ -0,0 +1,21 @@
+if GI_GCOV_ENABLED
+
+.PHONEY: coverage-report
+coverage-report:
+ @total_covered=0; total_lines=0; \
+ for file in $(GCOV_SOURCES); do \
+ if test -f $$file.gcov; then \
+ covered=`grep -e '[0-9]\+:' $$file.gcov | wc -l` ; \
+ uncovered=`grep '#####:' $$file.gcov | wc -l`; \
+ lines=$$(($$covered + $$uncovered)); \
+ total_covered=$$((total_covered + covered)); \
+ total_lines=$$((total_lines + lines)); \
+ echo -n " $$file: $$covered / $$lines"; \
+ echo " ($$((($$covered * 100) / $$lines))%)"; \
+ fi \
+ done >> $(top_builddir)/coverage-report.txt; \
+ echo -e " Total coverage:"\
+ "$$((($$total_covered * 100) / $$total_lines))%\n" \
+ >> $(top_builddir)/coverage-report.txt
+
+endif
diff --git a/girepository/Makefile.am b/girepository/Makefile.am
index 480e95f6..c79606ef 100644
--- a/girepository/Makefile.am
+++ b/girepository/Makefile.am
@@ -14,3 +14,6 @@ libgirepository_la_CFLAGS = $(GIREPO_CFLAGS)
girepodir = $(includedir)/glib-2.0/gobject-introspection
girepo_HEADERS = girepository.h
+
+GCOV_SOURCES = $(libgirepository_la_SOURCES)
+include $(top_srcdir)/gcov.mak
diff --git a/m4/Makefile.am b/m4/Makefile.am
new file mode 100644
index 00000000..c2095e8f
--- /dev/null
+++ b/m4/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST=gcov.m4 as-compiler.m4
diff --git a/m4/as-compiler-flag.m4 b/m4/as-compiler-flag.m4
new file mode 100644
index 00000000..aba31b1c
--- /dev/null
+++ b/m4/as-compiler-flag.m4
@@ -0,0 +1,33 @@
+dnl as-compiler-flag.m4 0.1.0
+
+dnl autostars m4 macro for detection of compiler flags
+
+dnl David Schleef <ds@schleef.org>
+
+dnl $Id: as-compiler-flag.m4,v 1.1 2004/06/01 09:33:45 thomasvs Exp $
+
+dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
+dnl Tries to compile with the given CFLAGS.
+dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
+dnl and ACTION-IF-NOT-ACCEPTED otherwise.
+
+AC_DEFUN([AS_COMPILER_FLAG],
+[
+ AC_MSG_CHECKING([to see if compiler understands $1])
+
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $1"
+
+ AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+ CFLAGS="$save_CFLAGS"
+
+ if test "X$flag_ok" = Xyes ; then
+ $2
+ true
+ else
+ $3
+ true
+ fi
+ AC_MSG_RESULT([$flag_ok])
+])
+
diff --git a/m4/gcov.m4 b/m4/gcov.m4
new file mode 100644
index 00000000..c96eddac
--- /dev/null
+++ b/m4/gcov.m4
@@ -0,0 +1,47 @@
+AC_DEFUN([GI_ENABLE_GCOV],
+[
+ AC_ARG_ENABLE(gcov,
+ AC_HELP_STRING([--enable-gcov],
+ [compile with coverage profiling instrumentation (gcc only)]),
+ enable_gcov=$enableval,
+ enable_gcov=no)
+ if test x$enable_gcov = xyes ; then
+ if test "x$GCC" != "xyes"
+ then
+ AC_MSG_ERROR([gcov only works if gcc is used])
+ fi
+
+ AS_COMPILER_FLAG(["-fprofile-arcs"],
+ [GCOV_CFLAGS="$GCOV_CFLAGS -fprofile-arcs"],
+ true)
+ AS_COMPILER_FLAG(["-ftest-coverage"],
+ [GCOV_CFLAGS="$GCOV_CFLAGS -ftest-coverage"],
+ true)
+ dnl libtool 1.5.22 and lower strip -fprofile-arcs from the flags
+ dnl passed to the linker, which is a bug; -fprofile-arcs implicitly
+ dnl links in -lgcov, so we do it explicitly here for the same effect
+ GCOV_LIBS=-lgcov
+ AC_SUBST(GCOV_CFLAGS)
+ AC_SUBST(GCOV_LIBS)
+ GCOV=`echo $CC | sed s/gcc/gcov/g`
+ AC_SUBST(GCOV)
+
+ GI_GCOV_ENABLED=yes
+ AC_DEFINE_UNQUOTED(GI_GCOV_ENABLED, 1,
+ [Defined if gcov is enabled to force a rebuild due to config.h changing])
+ dnl if gcov is used, we do not want default -O2 CFLAGS
+ if test "x$GI_GCOV_ENABLED" = "xyes"
+ then
+ CFLAGS="-g -O0"
+ AC_SUBST(CFLAGS)
+ CXXFLAGS="-g -O0"
+ AC_SUBST(CXXFLAGS)
+ FFLAGS="-g -O0"
+ AC_SUBST(FFLAGS)
+ CCASFLAGS="-g -O0"
+ AC_SUBST(CCASFLAGS)
+ AC_MSG_NOTICE([gcov enabled, setting CFLAGS and friends to $CFLAGS])
+ fi
+ fi
+ AM_CONDITIONAL(GI_GCOV_ENABLED, test x$enable_gcov = xyes)
+])
diff --git a/tools/Makefile.am b/tools/Makefile.am
index eb2d144f..d28eaa2c 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -37,3 +37,11 @@ g_idl_scanner_SOURCES = \
gidlwriter.h
g_idl_scanner_CFLAGS = $(GIREPO_CFLAGS) $(SCANNER_CFLAGS) -I$(top_srcdir)/girepository
g_idl_scanner_LDADD = $(GIREPO_LIBS) $(SCANNER_LIBS) $(top_builddir)/girepository/libgirepository.la libgirepository-parser.la
+
+GCOV_SOURCES = \
+ $(libgirepository_la_SOURCES) \
+ $(g_idl_compiler_SOURCES) \
+ $(g_idl_generate_SOURCES) \
+ $(g_idl_scanner_SOURCES)
+
+include $(top_srcdir)/gcov.mak