From 84a71c68effa7e54e0be757ea81c13f6d937bc5b Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Thu, 7 Jan 2010 15:11:07 -0500
Subject: [PATCH] Split off libdhash into a shared library

Right now, the pkg-config checks for the system version of
libdhash are forcibly disabled, requiring the SSSD to build it
from its own tree. In the future, when we split the libraries off
from the SSSD, it will be easy to switch this check to the
external library.
---
 common/dhash/Makefile.am    |   18 ++++++++++--------
 common/dhash/configure.ac   |    2 +-
 contrib/sssd.spec.in        |   36 ++++++++++++++++++++++++++++++++++++
 server/Makefile.am          |   15 ++++++++++-----
 server/configure.ac         |    1 +
 server/external/libdhash.m4 |   12 ++++++++++++
 6 files changed, 70 insertions(+), 14 deletions(-)
 create mode 100644 server/external/libdhash.m4

diff --git a/common/dhash/Makefile.am b/common/dhash/Makefile.am
index de3c34d..1cc151a 100644
--- a/common/dhash/Makefile.am
+++ b/common/dhash/Makefile.am
@@ -8,14 +8,16 @@ endif
 ACLOCAL_AMFLAGS = -I m4
 
 pkgconfigdir = $(libdir)/pkgconfig
-dist_noinst_DATA = \
-    dhash.pc \
-    m4
-
-noinst_LTLIBRARIES = libdhash.la
-libdhash_la_SOURCES = \
-    dhash.c \
-    dhash.h
+dist_pkgconfig_DATA = dhash.pc
+
+dist_noinst_DATA = m4
+
+dist_include_HEADERS = dhash.h
+
+lib_LTLIBRARIES = libdhash.la
+libdhash_la_SOURCES = dhash.c
+libdhash_la_LDFLAGS = \
+    -version-info 1:0:0
 
 check_PROGRAMS = dhash_test dhash_example
 TESTS = $(check_PROGRAMS)
diff --git a/common/dhash/configure.ac b/common/dhash/configure.ac
index bd21028..1012afb 100644
--- a/common/dhash/configure.ac
+++ b/common/dhash/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([dhash], [0.3.3], [jdennis@redhat.com])
+AC_INIT([dhash], [0.4.0], [jdennis@redhat.com])
 AC_CONFIG_SRCDIR([dhash.c])
 AC_CONFIG_AUX_DIR([build])
 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in
index e3baf04..18fab0e 100644
--- a/contrib/sssd.spec.in
+++ b/contrib/sssd.spec.in
@@ -12,6 +12,8 @@ URL: http://www.freeipa.org/
 Source0: %{name}-%{version}.tar.gz
 BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
 
+%define dhash_version 0.4.0
+
 ### Patches ###
 
 ### Dependencies ###
@@ -19,6 +21,7 @@ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
 Requires: libldb >= 0.9.3
 Requires: libtdb >= 1.1.3
 Requires: sssd-client = %{version}-%{release}
+Requires: libdhash = %{dhash_version}-%{release}
 Requires: cyrus-sasl-gssapi
 Requires(post): python
 Requires(preun):  initscripts chkconfig
@@ -76,6 +79,26 @@ Group: Applications/System
 Provides the libraries needed by the PAM and NSS stacks to connect to the SSSD
 service.
 
+%package -n libdhash
+Summary: Dynamic hash table
+Group: Development/Libraries
+Version: %{dhash_version}
+
+%description -n libdhash
+A hash table which will dynamically resize to achieve optimal storage & access
+time properties
+
+%package -n libdhash-devel
+Summary: Development files for libdhash
+Group: Development/Libraries
+Version: %{dhash_version}
+Requires: libdhash = %{dhash_version}-%{release}
+
+%description -n libdhash-devel
+A hash table which will dynamically resize to achieve optimal storage & access
+time properties
+
+
 %prep
 %setup -q
 
@@ -111,6 +134,7 @@ install -m400 server/config/etc/sssd.api.d/* $RPM_BUILD_ROOT%{_sysconfdir}/sssd/
 rm -f \
     $RPM_BUILD_ROOT/%{_lib}/libnss_sss.la \
     $RPM_BUILD_ROOT/%{_lib}/security/pam_sss.la \
+    $RPM_BUILD_ROOT/%{_libdir}/libdhash.la \
     $RPM_BUILD_ROOT/%{_libdir}/ldb/memberof.la \
     $RPM_BUILD_ROOT/%{_libdir}/sssd/libsss_ldap.la \
     $RPM_BUILD_ROOT/%{_libdir}/sssd/libsss_proxy.la \
@@ -180,6 +204,18 @@ rm -rf $RPM_BUILD_ROOT
 /%{_lib}/security/pam_sss.so
 %{_mandir}/man8/pam_sss.8*
 
+%files -n libdhash
+%defattr(-,root,root,-)
+%{_libdir}/libdhash.so.1
+%{_libdir}/libdhash.so.1.0.0
+
+%files -n libdhash-devel
+%defattr(-,root,root,-)
+%{_includedir}/dhash.h
+%{_libdir}/libdhash.a
+%{_libdir}/libdhash.so
+%{_libdir}/pkgconfig/dhash.pc
+
 %post
 /sbin/ldconfig
 /sbin/chkconfig --add %{servicename}
diff --git a/server/Makefile.am b/server/Makefile.am
index 9d17ee7..9d02386 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -144,11 +144,16 @@ INI_CFG_LIBS = \
     -L$(builddir)/../common/ini/.libs/ \
     -lini_config
 
-DHASH_CFLAGS = \
-    -I$(srcdir)/../common/dhash
-DHASH_LIBS = \
-    -L$(builddir)/../common/dhash/ \
-    -ldhash
+if HAVE_SYSTEM_DHASH
+    DHASH_CFLAGS = $(SYSTEM_DHASH_CFLAGS)
+    DHASH_LIBS = $(SYSTEM_DHASH_LIBS)
+else
+    DHASH_CFLAGS = \
+        -I$(srcdir)/../common/dhash
+    DHASH_LIBS = \
+        -L$(builddir)/../common/dhash/ \
+        -ldhash
+endif
 
 AM_CPPFLAGS = -Wall \
     -Iinclude \
diff --git a/server/configure.ac b/server/configure.ac
index 72b15cd..4f56023 100644
--- a/server/configure.ac
+++ b/server/configure.ac
@@ -62,6 +62,7 @@ m4_include([external/libtalloc.m4])
 m4_include([external/libtdb.m4])
 m4_include([external/libtevent.m4])
 m4_include([external/libldb.m4])
+m4_include([external/libdhash.m4])
 m4_include([external/pam.m4])
 m4_include([external/ldap.m4])
 m4_include([external/libpcre.m4])
diff --git a/server/external/libdhash.m4 b/server/external/libdhash.m4
new file mode 100644
index 0000000..e3afdac
--- /dev/null
+++ b/server/external/libdhash.m4
@@ -0,0 +1,12 @@
+AC_SUBST(SYSTEM_DHASH_OBJ)
+AC_SUBST(SYSTEM_DHASH_CFLAGS)
+AC_SUBST(SYSTEM_DHASH_LIBS)
+
+PKG_CHECK_MODULES(SYSTEM_DHASH, dhash >= 0.4.0,
+    have_system_dhash=true,
+    have_system_dhash=false
+    )
+# This is future-compatible. Right now, we'll force the use of our
+# in-tree copy. When dhash is split off as its own source package, we'll
+# fix this test
+AM_CONDITIONAL(HAVE_SYSTEM_DHASH, test x$have_system_dhash = xtrue_FORCE_IN_TREE)
-- 
1.6.5.2

