Author: robtaylor
Date: Fri Feb  8 18:09:05 2008
New Revision: 105
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=105&view=rev

Log:
2008-02-08  Rob Taylor  <[EMAIL PROTECTED]>

        * 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'.


Added:
   trunk/gcov.mak
   trunk/m4/
   trunk/m4/Makefile.am
   trunk/m4/as-compiler-flag.m4
   trunk/m4/gcov.m4
Modified:
   trunk/ChangeLog
   trunk/Makefile.am
   trunk/configure.ac
   trunk/girepository/Makefile.am
   trunk/tools/Makefile.am

Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am   (original)
+++ trunk/Makefile.am   Fri Feb  8 18:09:05 2008
@@ -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

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac  (original)
+++ trunk/configure.ac  Fri Feb  8 18:09:05 2008
@@ -8,6 +8,8 @@
 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 @@
 fi
 
 # Checks for libraries.
+GI_ENABLE_GCOV
+
 AC_CHECK_LIB([dl], [dlopen])
 
 PKG_CHECK_MODULES(GOBJECT, [gobject-2.0])
@@ -74,6 +78,7 @@
    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_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

Added: trunk/gcov.mak
==============================================================================
--- (empty file)
+++ trunk/gcov.mak      Fri Feb  8 18:09:05 2008
@@ -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

Modified: trunk/girepository/Makefile.am
==============================================================================
--- trunk/girepository/Makefile.am      (original)
+++ trunk/girepository/Makefile.am      Fri Feb  8 18:09:05 2008
@@ -14,3 +14,6 @@
 
 girepodir = $(includedir)/glib-2.0/gobject-introspection
 girepo_HEADERS = girepository.h
+
+GCOV_SOURCES = $(libgirepository_la_SOURCES)
+include $(top_srcdir)/gcov.mak

Added: trunk/m4/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/m4/Makefile.am        Fri Feb  8 18:09:05 2008
@@ -0,0 +1 @@
+EXTRA_DIST=gcov.m4 as-compiler.m4

Added: trunk/m4/as-compiler-flag.m4
==============================================================================
--- (empty file)
+++ trunk/m4/as-compiler-flag.m4        Fri Feb  8 18:09:05 2008
@@ -0,0 +1,33 @@
+dnl as-compiler-flag.m4 0.1.0
+
+dnl autostars m4 macro for detection of compiler flags
+
+dnl David Schleef <[EMAIL PROTECTED]>
+
+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])
+])
+

Added: trunk/m4/gcov.m4
==============================================================================
--- (empty file)
+++ trunk/m4/gcov.m4    Fri Feb  8 18:09:05 2008
@@ -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)
+])

Modified: trunk/tools/Makefile.am
==============================================================================
--- trunk/tools/Makefile.am     (original)
+++ trunk/tools/Makefile.am     Fri Feb  8 18:09:05 2008
@@ -37,3 +37,11 @@
        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
_______________________________________________
SVN-commits-list mailing list (read only)
http://mail.gnome.org/mailman/listinfo/svn-commits-list

Want to limit the commits to a few modules? Go to above URL, log in to edit 
your options and select the modules ('topics') you want.
Module maintainer? It is possible to set the reply-to to your development 
mailing list. Email [EMAIL PROTECTED] if interested.

Reply via email to