From d7c1f145dc36b4f1f679cb677b6201a204e49c04 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

---
 common/dhash/Makefile.am    |   18 ++++++++++--------
 contrib/sssd.spec.in        |   33 +++++++++++++++++++++++++++++++++
 server/Makefile.am          |   15 ++++++++++-----
 server/configure.ac         |    1 +
 server/external/libdhash.m4 |    9 +++++++++
 5 files changed, 63 insertions(+), 13 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/contrib/sssd.spec.in b/contrib/sssd.spec.in
index e3baf04..dc83092 100644
--- a/contrib/sssd.spec.in
+++ b/contrib/sssd.spec.in
@@ -19,6 +19,8 @@ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
 Requires: libldb >= 0.9.3
 Requires: libtdb >= 1.1.3
 Requires: sssd-client = %{version}-%{release}
+Requires: libdash = %{version}-%{release}
+Requires: libdhash
 Requires: cyrus-sasl-gssapi
 Requires(post): python
 Requires(preun):  initscripts chkconfig
@@ -76,6 +78,24 @@ 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
+
+%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
+Requires: libdhash
+
+%description -n libdhash-devel
+A hash table which will dynamically resize to achieve optimal storage & access
+time properties
+
+
 %prep
 %setup -q
 
@@ -111,6 +131,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 +201,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..7ba3668
--- /dev/null
+++ b/server/external/libdhash.m4
@@ -0,0 +1,9 @@
+AC_SUBST(SYSTEM_DHASH_OBJ)
+AC_SUBST(SYSTEM_DHASH_CFLAGS)
+AC_SUBST(SYSTEM_DHASH_LIBS)
+
+PKG_CHECK_MODULES(SYSTEM_DHASH, dhash >= 0.3.3,
+    have_system_dhash=true,
+    have_system_dhash=false
+    )
+AM_CONDITIONAL(HAVE_SYSTEM_DHASH, test x$have_system_dhash = xtrue)
-- 
1.6.5.2

