From 574be6d8c0896c8bee0c16224f52c2dbea48a44e Mon Sep 17 00:00:00 2001
From: Dmitri Pal <dpal@redhat.com>
Date: Fri, 24 Dec 2010 22:38:42 -0500
Subject: [PATCH] [BUILD] Allow trace per component

This patch add ability to build tracing
for each component independently.
---
 Makefile.am  |   50 ++++++++++++++++++++++++++++++++++++++++++++++----
 configure.ac |   15 ++++++++++++++-
 2 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 0946169308bab6585c93cca36d45b360b565f6b5..1780e9b234e68006af910413b3e8312c9db72c7b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,7 @@
-TRACE_LEVEL=@TRACE_VAR@
+TRACE_INI=@TRACE_INI@
+TRACE_COLLECTION=@TRACE_COLLECTION@
+TRACE_REFARRAY=@TRACE_REFARRAY@
+TRACE_BASICOBJECTS=@TRACE_BASICOBJECTS@
 
 RPMBUILD ?= $(PWD)/rpmbuild
 
@@ -28,8 +31,7 @@ AM_CPPFLAGS = \
     -I$(srcdir)/ini \
     -I$(srcdir)/basicobjects \
     -I$(srcdir) \
-    -I$(srcdir)/trace \
-    $(TRACE_LEVEL)
+    -I$(srcdir)/trace
 
 ACLOCAL_AMFLAGS = -I m4
 
@@ -132,6 +134,10 @@ libcollection_la_SOURCES = \
 libcollection_la_LDFLAGS = \
     -version-info 3:0:0
 
+libcollection_la_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_COLLECTION)
+
 check_PROGRAMS += \
     collection_ut \
     collection_stack_ut \
@@ -142,11 +148,21 @@ TESTS += \
     collection_queue_ut
 
 collection_ut_SOURCES = collection/collection_ut.c
+collection_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_COLLECTION)
+
 collection_ut_LDADD = libcollection.la
 collection_stack_ut_SOURCES = collection/collection_stack_ut.c
 collection_stack_ut_LDADD = libcollection.la
+collection_stack_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_COLLECTION)
 collection_queue_ut_SOURCES = collection/collection_queue_ut.c
 collection_queue_ut_LDADD = libcollection.la
+collection_queue_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_COLLECTION)
 
 collection-docs:
 if HAVE_DOXYGEN
@@ -167,10 +183,15 @@ libref_array_la_SOURCES = \
     trace/trace.h
 libref_array_la_LDFLAGS = \
     -version-info 1:0:0
-
+libref_array_la_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_REFARRAY)
 check_PROGRAMS += ref_array_ut
 TESTS += ref_array_ut
 ref_array_ut_SOURCES = refarray/ref_array_ut.c
+ref_array_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_REFARRAY)
 ref_array_ut_LDADD = libref_array.la
 
 dist_doc_DATA += refarray/README.ref_array
@@ -194,11 +215,17 @@ libbasicobjects_la_SOURCES = \
     trace/trace.h
 libbasicobjects_la_LDFLAGS = \
     -version-info 1:0:0
+libbasicobjects_la_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_BASICOBJECTS)
 
 check_PROGRAMS += simplebuffer_ut
 TESTS += simplebuffer_ut
 simplebuffer_ut_SOURCES = basicobjects/simplebuffer_ut.c
 simplebuffer_ut_LDADD = libbasicobjects.la
+simplebuffer_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_BASICOBJECTS)
 
 basicobjects-docs:
 if HAVE_DOXYGEN
@@ -243,6 +270,9 @@ libini_config_la_LIBADD = \
     libbasicobjects.la
 libini_config_la_LDFLAGS = \
     -version-info 3:0:0
+libini_config_la_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_INI)
 
 dist_noinst_DATA += \
     ini/ini.conf \
@@ -268,15 +298,27 @@ ini_config_ut_SOURCES = ini/ini_config_ut.c
 ini_config_ut_LDADD = \
     libini_config.la \
     libcollection.la
+ini_config_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_INI)
 
 ini_comment_ut_SOURCES = ini/ini_comment_ut.c
 ini_comment_ut_LDADD = libini_config.la
+ini_comment_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_INI)
 
 ini_valueobj_ut_SOURCES = ini/ini_valueobj_ut.c
 ini_valueobj_ut_LDADD = libini_config.la
+ini_valueobj_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_INI)
 
 ini_parse_ut_SOURCES = ini/ini_parse_ut.c
 ini_parse_ut_LDADD = libini_config.la
+ini_parse_ut_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(TRACE_INI)
 
 ini_config-docs:
 if HAVE_DOXYGEN
diff --git a/configure.ac b/configure.ac
index 2e22e8a6aaac271dfa4841c17f98411967e09fd9..d1b68f5fd76654e899738f6c8a29b516a23592c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,11 +39,24 @@ AC_PATH_PROG([DOXYGEN], [doxygen], [false])
 AM_CONDITIONAL([HAVE_DOXYGEN], [test x$DOXYGEN != xfalse ])
 
 # Enable trace build
+# To turn on the tracing of one of the componenets one has not only
+# to enable it with --enable-trace but to drop a file named "trace"
+# into a corresponding directory.
+# Tracing can be built for collection, ini, refarray or basicobjects.
+# The approach allows building different libraries with trace
+# independent of each other.
 AC_ARG_ENABLE([trace],
               [AS_HELP_STRING([--enable-trace[=LEVEL]],[build with low level tracing enabled])],
               [trace_level="$enableval"],
               [trace_level="0"])
-AS_IF([test ["$trace_level" -gt "0"] -a ["$trace_level" -lt "8"] ],[AC_SUBST([TRACE_VAR],["-DTRACE_LEVEL=$trace_level"])])
+AS_IF([test ["$trace_level" -gt "0"] -a ["$trace_level" -lt "8"] -a [ -e $srcdir/ini/trace] ],
+      [AC_SUBST([TRACE_INI],["-DTRACE_LEVEL=$trace_level"])])
+AS_IF([test ["$trace_level" -gt "0"] -a ["$trace_level" -lt "8"] -a [ -e $srcdir/collection/trace] ],
+      [AC_SUBST([TRACE_COLLECTION],["-DTRACE_LEVEL=$trace_level"])])
+AS_IF([test ["$trace_level" -gt "0"] -a ["$trace_level" -lt "8"] -a [ -e $srcdir/refarray/trace] ],
+      [AC_SUBST([TRACE_REFARRAY],["-DTRACE_LEVEL=$trace_level"])])
+AS_IF([test ["$trace_level" -gt "0"] -a ["$trace_level" -lt "8"] -a [ -e $srcdir/basicobjects/trace] ],
+      [AC_SUBST([TRACE_BASICOBJECTS],["-DTRACE_LEVEL=$trace_level"])])
 
 AC_CHECK_SIZEOF([long])
 AC_CHECK_SIZEOF([long long])
-- 
1.5.5.6

