Add a configure switch that adds the relevant gcov options to the compiler flags for the core library and tests. Signed-off-by: Bartosz Golaszewski <brgl@xxxxxxxx> --- .gitignore | 4 ++++ configure.ac | 10 ++++++++++ lib/Makefile.am | 1 + tests/Makefile.am | 1 + 4 files changed, 16 insertions(+) diff --git a/.gitignore b/.gitignore index 2d7cc7f..58e1c5f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ libtool *-libtool m4/ stamp-h1 + +# profiling +*.gcda +*.gcno diff --git a/configure.ac b/configure.ac index 8e74104..dc09d70 100644 --- a/configure.ac +++ b/configure.ac @@ -122,6 +122,16 @@ AC_ARG_ENABLE([tests], [with_tests=false]) AM_CONDITIONAL([WITH_TESTS], [test "x$with_tests" = xtrue]) +AC_ARG_ENABLE([profiling], + [AS_HELP_STRING([--enable-profiling], + [enable gcov profiling on the core library and tests [default=no]])], + [if test "x$enableval" = xyes; then with_profiling=true; fi], + [with_profiling=false]) +if test "x$with_profiling" = xtrue +then + AC_SUBST(PROFILING_FLAGS, ["-fprofile-arcs -ftest-coverage"]) +fi + AC_DEFUN([FUNC_NOT_FOUND_TESTS], [ERR_NOT_FOUND([$1()], [tests])]) diff --git a/lib/Makefile.am b/lib/Makefile.am index 5423f72..5219855 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -17,6 +17,7 @@ libgpiod_la_SOURCES = chip.c \ libgpiod_la_CFLAGS = -Wall -Wextra -g -std=gnu89 libgpiod_la_CFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/ libgpiod_la_CFLAGS += -include $(top_builddir)/config.h +libgpiod_la_CFLAGS += $(PROFILING_FLAGS) libgpiod_la_LDFLAGS = -version-info $(subst .,:,$(ABI_VERSION)) pkgconfigdir = $(libdir)/pkgconfig diff --git a/tests/Makefile.am b/tests/Makefile.am index 7bf5e3f..8ec51e9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,6 +7,7 @@ AM_CFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/tests/gpiosim/ AM_CFLAGS += -include $(top_builddir)/config.h AM_CFLAGS += -Wall -Wextra -g -std=gnu89 $(GLIB_CFLAGS) AM_CFLAGS += -DG_LOG_DOMAIN=\"gpiod-test\" +AM_CFLAGS += $(PROFILING_FLAGS) AM_LDFLAGS = -pthread LDADD = $(top_builddir)/lib/libgpiod.la LDADD += $(top_builddir)/tests/gpiosim/libgpiosim.la -- 2.30.1