From ff710ee057f49c28db93070d4eaaf0c85eec839f Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Mon, 1 Feb 2010 11:17:03 -0500
Subject: [PATCH 10/14] Split off libini_config into a shared library

---
 common/ini/Makefile.am           |   21 ++++++++++++++++-----
 common/ini/README                |    1 +
 common/ini/configure.ac          |    2 +-
 common/ini/ini_config.pc.in      |    2 +-
 server/Makefile.am               |   15 ++++++++++-----
 server/configure.ac              |    1 +
 server/external/libini_config.m4 |   12 ++++++++++++
 7 files changed, 42 insertions(+), 12 deletions(-)
 create mode 100644 common/ini/README
 create mode 100644 server/external/libini_config.m4

diff --git a/common/ini/Makefile.am b/common/ini/Makefile.am
index bf993bc..cfaacf9 100644
--- a/common/ini/Makefile.am
+++ b/common/ini/Makefile.am
@@ -1,7 +1,10 @@
 #DEBUG_FLAGS=@DEBUG_VAR@
 TRACE_LEVEL=@TRACE_VAR@
 
+builddir ?= .
+
 topdir=$(srcdir)/..
+topbuilddir=$(builddir)/..
 
 AM_CFLAGS =
 if HAVE_GCC
@@ -16,23 +19,31 @@ ACLOCAL_AMFLAGS = -I m4
 
 # Set up the pkg-config file
 pkgconfigdir = $(libdir)/pkgconfig
+dist_pkgconfig_DATA = ini_config.pc
+
 dist_noinst_DATA = \
-    ini_config.pc \
     ini.conf \
     ini.d/real.conf \
     ini.d/test.conf \
     m4
 
+dist_include_HEADERS = \
+    ini_config.h
+
 # Build library
-noinst_LTLIBRARIES = libini_config.la
+lib_LTLIBRARIES = libini_config.la
 libini_config_la_SOURCES = \
-    ini_config.c \
-    ini_config.h
+    ini_config.c
+libini_config_la_LIBADD = \
+    -L$(topbuilddir)/collection \
+    -lcollection
+libini_config_la_LDFLAGS = \
+    -version-info 1:0:0
 
 # Build unit test
 check_PROGRAMS = ini_config_ut
 ini_config_ut_SOURCES = ini_config_ut.c
-ini_config_ut_LDADD = libini_config.la ../collection/libcollection.la
+ini_config_ut_LDADD = libini_config.la -lcollection
 
 TESTS = ini_config_ut
 
diff --git a/common/ini/README b/common/ini/README
new file mode 100644
index 0000000..2b4d381
--- /dev/null
+++ b/common/ini/README
@@ -0,0 +1 @@
+Documentation for ini_config can be found in ini_config.h
\ No newline at end of file
diff --git a/common/ini/configure.ac b/common/ini/configure.ac
index ef8f0de..c58be24 100644
--- a/common/ini/configure.ac
+++ b/common/ini/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([ini_config],[0.3.3],[sssd-devel@lists.fedorahosted.org])
+AC_INIT([ini_config],[0.4.0],[sssd-devel@lists.fedorahosted.org])
 AC_CONFIG_SRCDIR([ini_config.c])
 AC_CONFIG_AUX_DIR([build])
 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
diff --git a/common/ini/ini_config.pc.in b/common/ini/ini_config.pc.in
index 3ac3b26..efa8da9 100644
--- a/common/ini/ini_config.pc.in
+++ b/common/ini/ini_config.pc.in
@@ -6,6 +6,6 @@ includedir=@includedir@
 Name: @PACKAGE_NAME@
 Description: Library to process config files in INI format into a libcollection data structure
 Version: @PACKAGE_VERSION@
-Libs: -L${libdir} -lini_config
+Libs: -L${libdir} -lini_config -lcollection
 Cflags: -I${includedir}
 URL: http://fedorahosted.org/sssd/
diff --git a/server/Makefile.am b/server/Makefile.am
index 9ebc985..87de065 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -144,11 +144,16 @@ else
         -lcollection
 endif
 
-INI_CFG_CFLAGS = \
-    -I$(srcdir)/../common/ini
-INI_CFG_LIBS = \
-    -L$(builddir)/../common/ini/.libs/ \
-    -lini_config
+if HAVE_SYSTEM_INI_CONFIG
+    INI_CFG_CFLAGS = $(SYSTEM_INI_CONFIG_CFLAGS)
+    INI_CFG_LIBS = $(SYSTEM_INI_CONFIG_LIBS)
+else
+    INI_CFG_CFLAGS = \
+        -I$(srcdir)/../common/ini
+    INI_CFG_LIBS = \
+        -L$(builddir)/../common/ini/ \
+        -lini_config
+endif
 
 if HAVE_SYSTEM_DHASH
     DHASH_CFLAGS = $(SYSTEM_DHASH_CFLAGS)
diff --git a/server/configure.ac b/server/configure.ac
index a67dd15..1e414a3 100644
--- a/server/configure.ac
+++ b/server/configure.ac
@@ -67,6 +67,7 @@ m4_include([external/libtevent.m4])
 m4_include([external/libldb.m4])
 m4_include([external/libdhash.m4])
 m4_include([external/libcollection.m4])
+m4_include([external/libini_config.m4])
 m4_include([external/pam.m4])
 m4_include([external/ldap.m4])
 m4_include([external/libpcre.m4])
diff --git a/server/external/libini_config.m4 b/server/external/libini_config.m4
new file mode 100644
index 0000000..20291ef
--- /dev/null
+++ b/server/external/libini_config.m4
@@ -0,0 +1,12 @@
+AC_SUBST(SYSTEM_INI_CONFIG_OBJ)
+AC_SUBST(SYSTEM_INI_CONFIG_CFLAGS)
+AC_SUBST(SYSTEM_INI_CONFIG_LIBS)
+
+PKG_CHECK_MODULES(SYSTEM_INI_CONFIG, ini_config >= 0.4.0,
+    have_system_ini_config=true,
+    have_system_ini_config=false
+    )
+# This is future-compatible. Right now, we'll force the use of our
+# in-tree copy. When ini_config is split off as its own source package, we'll
+# fix this test
+AM_CONDITIONAL(HAVE_SYSTEM_INI_CONFIG, test x$have_system_ini_config = xtrue_FORCE_IN_TREE)
-- 
1.6.6

