From 00fef811c1691f2f48783af88053712df19fe860 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Mon, 21 Apr 2014 12:17:53 +0200
Subject: [PATCH 2/3] sss_config: build

---
 Makefile.am               | 17 +++++++++++++++++
 configure.ac              |  5 +++++
 contrib/sssd.spec.in      |  2 ++
 src/external/configlib.m4 | 12 ++++++++++++
 src/external/libaugeas.m4 | 11 +++++++++++
 src/tests/dlopen-tests.c  |  3 +++
 6 files changed, 50 insertions(+)
 create mode 100644 src/external/configlib.m4
 create mode 100644 src/external/libaugeas.m4

diff --git a/Makefile.am b/Makefile.am
index 4f9c11f47ce49751e585a174b15d8f30d14e1877..0b347dbb6008501f3d08635c1006e87cc01ffaf5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -437,6 +437,7 @@ dist_noinst_HEADERS = \
     src/util/sss_ssh.h \
     src/util/sss_ini.h \
     src/util/sss_format.h \
+    src/util/sss_config.h \
     src/util/refcount.h \
     src/util/find_uid.h \
     src/util/user_info_msg.h \
@@ -651,6 +652,22 @@ SSSD_INTERNAL_LTLIBS = \
     libsss_debug.la \
     libsss_child.la
 
+if BUILD_CONFIG_LIB
+pkglib_LTLIBRARIES += libsss_config.la
+libsss_config_la_SOURCES = \
+    src/util/sss_config.c
+libsss_config_la_CFLAGS = \
+    $(AM_CFLAGS) \
+    $(AUGEAS_CFLAGS) \
+    $(TALLOC_CFLAGS)
+libsss_config_la_LIBADD = \
+    $(AUGEAS_LIBS) \
+    $(TALLOC_LIBS) \
+    $(SSSD_INTERNAL_LTLIBS)
+libsss_config_la_LDFLAGS = \
+    -avoid-version
+endif
+
 lib_LTLIBRARIES = libipa_hbac.la libsss_idmap.la libsss_nss_idmap.la
 pkgconfig_DATA += src/providers/ipa/ipa_hbac.pc
 libipa_hbac_la_SOURCES = \
diff --git a/configure.ac b/configure.ac
index 41fa6496553336c73338459eaff639f10fde74f1..65008d41f55aa4e3c6a4b374ec907e729ab92c2e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,6 +159,11 @@ m4_include([src/external/signal.m4])
 m4_include([src/external/inotify.m4])
 m4_include([src/external/libndr_nbt.m4])
 m4_include([src/external/sasl.m4])
+m4_include([src/external/configlib.m4])
+
+if test x$build_config_lib = xyes; then
+    m4_include([src/external/libaugeas.m4])
+fi
 
 WITH_UNICODE_LIB
 if test x$unicode_lib = xlibunistring; then
diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in
index d4ee916591b1a84627ee1ed169e34a88fdb81cc9..ad2a1cddab2b07af91d5fb9e3c72cdca90352640 100644
--- a/contrib/sssd.spec.in
+++ b/contrib/sssd.spec.in
@@ -138,6 +138,7 @@ BuildRequires: systemd-devel
 %if (0%{?with_cifs_utils_plugin} == 1)
 BuildRequires: cifs-utils-devel
 %endif
+BuildRequires: augeas-devel
 
 # RHEL 5 is too old to support samba4 and the PAC responder
 %if !0%{?is_rhel5}
@@ -573,6 +574,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_libdir}/%{name}/libsss_debug.so
 %{_libdir}/%{name}/libsss_ldap_common.so
 %{_libdir}/%{name}/libsss_util.so
+%{_libdir}/%{name}/libsss_config.so
 
 # 3rd party application libraries
 %{_libdir}/sssd/modules/libsss_autofs.so
diff --git a/src/external/configlib.m4 b/src/external/configlib.m4
new file mode 100644
index 0000000000000000000000000000000000000000..ad6c1a943e8d7bf0c38e9163241f0eb11792d82f
--- /dev/null
+++ b/src/external/configlib.m4
@@ -0,0 +1,12 @@
+AC_ARG_ENABLE([config-lib],
+              [AS_HELP_STRING([--disable-config-lib],
+                              [do not build internal config library])],
+              [build_config_lib=$enableval],
+              [build_config_lib=yes])
+
+AM_CONDITIONAL([BUILD_CONFIG_LIB],
+               [test x$build_config_lib = xyes])
+
+AM_COND_IF([BUILD_CONFIG_LIB],
+           [AC_DEFINE_UNQUOTED(HAVE_CONFIG_LIB, 1,
+            [Build with internal config library])])
\ No newline at end of file
diff --git a/src/external/libaugeas.m4 b/src/external/libaugeas.m4
new file mode 100644
index 0000000000000000000000000000000000000000..13f694c5c82b20a4d90d9ffe0af97d0ae1e46b76
--- /dev/null
+++ b/src/external/libaugeas.m4
@@ -0,0 +1,11 @@
+AC_SUBST(AUGEAS_OBJ)
+AC_SUBST(AUGEAS_CFLAGS)
+AC_SUBST(AUGEAS_LIBS)
+
+PKG_CHECK_MODULES(AUGEAS,
+    augeas >= 1.0.0,
+    ,
+    AC_MSG_ERROR([
+Please install augeas-devel or disable this dependency
+by specifying --disable-config-lib when running configure.])
+    )
diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
index 7a218c70ad5ccc640388ac6b933299ceaae384ca..2396aee8a601e53e9d153a69b0a88c0b9fe99a0c 100644
--- a/src/tests/dlopen-tests.c
+++ b/src/tests/dlopen-tests.c
@@ -96,6 +96,9 @@ struct so {
     { "pysss_murmur.so", { LIBPFX"pysss_murmur.so", NULL } },
     { "pysss_nss_idmap.so", { LIBPFX"pysss_nss_idmap.so", NULL } },
 #endif
+#ifdef HAVE_CONFIG_LIB
+    { "libsss_config.so", { LIBPFX"libsss_config.so", NULL } },
+#endif
     { NULL }
 };
 
-- 
1.7.11.7

