From 9049df05330d92c5f94431878d853a98ac9dc262 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Tue, 9 Feb 2010 09:50:40 -0500
Subject: [PATCH 1/2] Build ELAPI against system libini_config and libcollection

---
 .gitignore             |   45 ++++++++++++++++++++
 Makefile.am            |   13 ++++--
 configure.ac           |    4 +-
 elapi_test/Makefile.am |    7 ++-
 libcollection.m4       |    5 ++
 libini_config.m4       |    5 ++
 trace.h                |  105 ++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 176 insertions(+), 8 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 libcollection.m4
 create mode 100644 libini_config.m4
 create mode 100644 trace.h

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5d49978
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,45 @@
+*.[oa]
+configure
+config.log
+config.status
+config.rpath
+config.h
+config.h.in
+cscope.out
+Makefile
+Makefile.in
+Makefile.in.in
+*.so
+*.so.[0-9].[0-9].[0-9]
+*.a
+*.l[oa]
+.deps
+.libs
+*.html
+*.[0-9]
+*.pc
+autom4te.cache
+libtool
+stamp-h1
+m4/
+aclocal.m4
+depcomp
+ltmain.sh
+missing
+.dirstamp
+*.gmo
+*.header
+*.sed
+*.sin
+Makevars.template
+POTFILES
+Rules-quot
+stamp-po
+ABOUT-NLS
+build
+*.patch
+*.swp
+*.X
+tags
+*~
+
diff --git a/Makefile.am b/Makefile.am
index 747a388..bcb2885 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,8 +21,8 @@ if HAVE_GCC
         -Wcast-align -Wwrite-strings
 endif
 
-AM_CPPFLAGS = -I$(topdir) -I$(topdir)/ini -I$(topdir)/trace -I$(topdir)/collection \
-              -I$(topdir)/elapi/providers/file $(TRACE_LEVEL)
+AM_CPPFLAGS = -I$(topdir) -I$(topdir)/elapi/providers/file $(TRACE_LEVEL) \
+              $(COLLECTION_CFLAGS) $(INI_CONFIG_LIBS)
 
 ACLOCAL_AMFLAGS = -I m4
 
@@ -66,9 +66,14 @@ libelapi_la_SOURCES = \
     elapi_fd.h \
     elapi_tm.h \
     elapi_defines.h \
-    elapi.h
+    elapi.h \
+    trace.h
 
-libelapi_la_LIBADD = libprovider.la libelapibasic.la
+libelapi_la_LIBADD = \
+    libprovider.la \
+    libelapibasic.la \
+    $(COLLECTION_LIBS) \
+    $(INI_CONFIG_LIBS)
 
 tests: all
 	for subdir in $(SUBDIRS); do \
diff --git a/configure.ac b/configure.ac
index 82be136..9034f47 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,9 @@ AC_ARG_ENABLE([trace],
 AS_IF([test ["$trace_level" -gt "0"] -a ["$trace_level" -lt "8"] ],[AC_SUBST([TRACE_VAR],["-DTRACE_LEVEL=$trace_level"])])
 
 
-m4_include(conf_macros.m4)
+m4_include([conf_macros.m4])
+m4_include([libcollection.m4])
+m4_include([libini_config.m4])
 
 WITH_CONFIG_DIR
 WITH_CONFIG_APP_DIR
diff --git a/elapi_test/Makefile.am b/elapi_test/Makefile.am
index 8a24b9f..edad981 100644
--- a/elapi_test/Makefile.am
+++ b/elapi_test/Makefile.am
@@ -13,8 +13,9 @@ if HAVE_GCC
         -Wcast-align -Wwrite-strings
 endif
 
-AM_CPPFLAGS = -I$(topdir) -I$(topdir)/ini -I$(topdir)/trace -I$(topdir)/collection -I$(topdir)/elapi \
-              -I$(topdir)/elapi/providers/file $(TRACE_LEVEL)
+AM_CPPFLAGS = -I$(topdir) -I$(topdir)/elapi \
+              -I$(topdir)/elapi/providers/file \
+              $(TRACE_LEVEL)
 
 ACLOCAL_AMFLAGS = -I m4
 
@@ -56,7 +57,7 @@ libelapi_test_la_SOURCES = \
 # Build unit test
 check_PROGRAMS = elapi_ut
 elapi_ut_SOURCES = elapi_ut.c
-elapi_ut_LDADD = libelapi_test.la ../../ini/libini_config.la ../../collection/libcollection.la -ldl
+elapi_ut_LDADD = libelapi_test.la -lini_config -lcollection -ldl
 
 TESTS = elapi_ut
 
diff --git a/libcollection.m4 b/libcollection.m4
new file mode 100644
index 0000000..44aeb5e
--- /dev/null
+++ b/libcollection.m4
@@ -0,0 +1,5 @@
+AC_SUBST(COLLECTION_OBJ)
+AC_SUBST(COLLECTION_CFLAGS)
+AC_SUBST(COLLECTION_LIBS)
+
+PKG_CHECK_MODULES(COLLECTION, collection >= 0.4.0)
diff --git a/libini_config.m4 b/libini_config.m4
new file mode 100644
index 0000000..22564e7
--- /dev/null
+++ b/libini_config.m4
@@ -0,0 +1,5 @@
+AC_SUBST(INI_CONFIG_OBJ)
+AC_SUBST(INI_CONFIG_CFLAGS)
+AC_SUBST(INI_CONFIG_LIBS)
+
+PKG_CHECK_MODULES(INI_CONFIG, ini_config >= 0.4.0)
diff --git a/trace.h b/trace.h
new file mode 100644
index 0000000..c7e375b
--- /dev/null
+++ b/trace.h
@@ -0,0 +1,105 @@
+/*
+    COMMON TRACE
+
+    Common header file for tracing.
+
+    Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef COMMON_TRACE_H
+#define COMMON_TRACE_H
+
+#ifdef TRACE_LEVEL
+#define HAVE_TRACE
+#include <stdio.h>
+
+/* The trace level is a bit mask */
+#define TRACE_FLOW      0x0000001  /* - trace messages that are entry exit into functions */
+#define TRACE_ERROR     0x0000002  /* - trace messages that are errors */
+#define TRACE_INFO      0x0000004  /* - trace things that are informational */
+
+
+#ifdef TRACE_HOME           /* Define this in the module that contains main */
+unsigned trace_level = TRACE_LEVEL;
+#else
+extern unsigned trace_level;
+#endif /* TRACE_HOME */
+#endif /* TRACE_LEVEL */
+
+
+
+#ifdef HAVE_TRACE
+/* Tracing strings */
+#define TRACE_STRING(level, msg, str) \
+    do { \
+        if (level & trace_level) { \
+            printf("[DEBUG] %40s (%4d) %s%s %s\n", \
+                   __FILE__, __LINE__, \
+                   (level == TRACE_ERROR) ? "ERROR-> " : "", \
+                   (msg != NULL) ? msg : "MISSING MESSAGE", \
+                   (str != NULL) ? str : "(null)"); \
+        } \
+    } while(0)
+
+/* Tracing numbers */
+#define TRACE_NUMBER(level, msg, num) \
+    do { \
+        if (level & trace_level) { \
+            printf("[DEBUG] %40s (%4d) %s%s %lu\n", \
+                   __FILE__, __LINE__, \
+                   (level == TRACE_ERROR) ? "ERROR-> " : "", \
+                   (msg != NULL) ? msg : "MISSING MESSAGE", \
+                   (unsigned long int)(num)); \
+        } \
+    } while(0)
+
+/* Tracing doubles */
+#define TRACE_DOUBLE(level, msg, num) \
+    do { \
+        if (level & trace_level) { \
+            printf("[DEBUG] %40s (%4d) %s%s %e\n", \
+                   __FILE__, __LINE__, \
+                   (level == TRACE_ERROR) ? "ERROR-> " : "", \
+                   (msg != NULL) ? msg : "MISSING MESSAGE", \
+                   (double)(num)); \
+        } \
+    } while(0)
+
+/* Assertion */
+#define TRACE_ASSERT(expression) expression ? : printf("ASSERTION FAILED\n")
+#else /* HAVE_TRACE */
+
+/* Noop in case the tracing is disabled */
+#define TRACE_STRING(level, msg, str)
+#define TRACE_NUMBER(level, msg, num)
+#define TRACE_DOUBLE(level, msg, num)
+#endif /* HAVE_TRACE */
+
+
+/* Convenience wrappers for strings */
+#define TRACE_FLOW_STRING(msg, str)  TRACE_STRING(TRACE_FLOW, msg, str)
+#define TRACE_ERROR_STRING(msg, str) TRACE_STRING(TRACE_ERROR, msg, str)
+#define TRACE_INFO_STRING(msg, str)  TRACE_STRING(TRACE_INFO, msg, str)
+
+/* Convenience wrappers for numbers */
+#define TRACE_FLOW_NUMBER(msg, num)  TRACE_NUMBER(TRACE_FLOW, msg, num)
+#define TRACE_ERROR_NUMBER(msg, num) TRACE_NUMBER(TRACE_ERROR, msg, num)
+#define TRACE_INFO_NUMBER(msg, num)  TRACE_NUMBER(TRACE_INFO, msg, num)
+
+/* Convenience wrappers for numbers */
+#define TRACE_FLOW_DOUBLE(msg, num)  TRACE_DOUBLE(TRACE_FLOW, msg, num)
+#define TRACE_ERROR_DOUBLE(msg, num) TRACE_DOUBLE(TRACE_ERROR, msg, num)
+#define TRACE_INFO_DOUBLE(msg, num)  TRACE_DOUBLE(TRACE_INFO, msg, num)
+
+#endif /* COMMON_TRACE_H */
-- 
1.6.6

