%define db_version 4.0.14
%define nocompat_arches sparc64 ia64
Summary: An NSS library for the Berkeley DB.
Name: nss_db
Version: 2.2
Release: 20
Source: ftp://sources.redhat.com/pub/glibc/releases/nss_db-%{version}.tar.gz
Source1: http://www.sleepycat.com/update/%{db_version}/db-%{db_version}.tar.gz
URL: http://sources.redhat.com/glibc/
Patch0: nss_db-2.2-external.patch
Patch1: nss_db-2.2-compat.patch
License: GPL
Group: System Environment/Libraries
PreReq: /sbin/ldconfig
BuildPrereq: autoconf, automake15, libtool
Conflicts: glibc < 2.2
Requires: make
BuildRoot: %{_tmppath}/%{name}-root

%define __find_requires %{_builddir}/%{name}-%{version}/find-requires

%description
Nss_db is a set of C library extensions which allow Berkeley Databases
to be used as a primary source of aliases, ethers, groups, hosts,
networks, protocol, users, RPCs, services, and shadow passwords
(instead of or in addition to using flat files or NIS). Install nss_db
if your flat name service files are too large and lookups are slow.

%package compat
Summary: An NSS compatibility library for Berkeley Databases and glibc 2.0.x.
Group: System Environment/Libraries

%description compat
Nss_db-compat is a set of C library extensions which allow Berkeley
Databases to be used as a primary source of aliases, ethers, groups,
hosts, networks, protocol, users, RPCs, services, and shadow passwords
(instead of or in addition to using flat files or NIS) from programs
linked against glibc 2.0.x.

%prep
%setup -q -a 0 -a 1
%patch0 -p1 -b .external
libtoolize -f
aclocal-1.5
automake-1.5 -a
autoconf

mv %{name}-%{version} %{name}-compat-%{version}
pushd %{name}-compat-%{version}
%patch0 -p1 -b .external
%patch1 -p1 -b .compat
libtoolize -f
aclocal-1.5
automake-1.5 -a
autoconf
popd

find_requires=`rpm --eval %%{__find_requires}`
echo "$find_requires | grep -v GLIBC_PRIVATE" > find-requires
chmod +x find-requires

%build
dbdir=`pwd`/db-instroot
CFLAGS="$RPM_OPT_FLAGS" ; export CFLAGS

pushd db-%{db_version}/dist
%ifarch %{ix86}
echo db_cv_mutex=x86/gcc-assembly > config.cache
%endif
./configure -C \
        --disable-compat185 \
        --disable-cxx \
        --disable-diagnostic \
        --disable-dump185 \
        --disable-java \
        --disable-rpc \
        --disable-tcl \
        --disable-shared \
        --with-pic \
        --with-uniquename=_nssdb \
        --prefix=$dbdir
make
make install
popd

%configure --with-db=${dbdir}
make

pushd %{name}-compat-%{version}
%configure --with-db=${dbdir}
make
popd

%install
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf ${RPM_BUILD_ROOT}
install -m755 -d ${RPM_BUILD_ROOT}/{%{_lib},/var/db,%{_bindir}}
install -m644 db-Makefile ${RPM_BUILD_ROOT}/var/db/Makefile
install -m755 makedb ${RPM_BUILD_ROOT}/%{_bindir}/
install -m755 .libs/libnss_db.so.[0-9]* ${RPM_BUILD_ROOT}/%{_lib}/

%ifnarch %{nocompat_arches}

pushd %{name}-compat-%{version}
install -m755 .libs/libnss_db.so.[0-9]* ${RPM_BUILD_ROOT}/%{_lib}/
popd

%endif

# Remove the sonames which we don't package.
rm -f ${RPM_BUILD_ROOT}/%{_lib}/libnss_db.so.?

%clean
rm -rf ${RPM_BUILD_ROOT}

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%files
%defattr(-,root,root)
%doc AUTHORS COPYING* ChangeLog NEWS README THANKS
/%{_lib}/libnss_db*2.*
%{_bindir}/makedb
%config /var/db/*

%ifnarch %{nocompat_arches}

%files compat
%defattr(-,root,root)
/%{_lib}/libnss_db*1.*

%post compat -p /sbin/ldconfig

%postun compat -p /sbin/ldconfig

%endif

%changelog
* Wed Jan 22 2003 Tim Powers <timp@redhat.com>
- rebuilt

* Tue Jan 14 2003 Nalin Dahyabhai <nalin@redhat.com> 2.2-19
- force use of assembly mutexes on %%{ix86} to avoid dependency on libpthread

* Thu Nov 14 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-18
- disable various language bindings when building the bundled DB library
- remove unpackaged files from the buildroot in %%install
- don't install the compat version on arches where if we don't need one

* Fri Jun 21 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Sun May 26 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Fri May 17 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-15
- rebuild in new environment

* Mon Apr 15 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-14
- rebuild

* Mon Apr 15 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-13
- whoops, __set_errno() is a glibc-internal symbol as well (#63373)

* Wed Apr  3 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-12
- filter out dependency on glibc private symbols

* Tue Apr  2 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-11
- don't use libc-internal symbols and interfaces

* Mon Mar 25 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-10
- rebuild

* Fri Feb 22 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-9
- rebuild

* Mon Feb 18 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-8
- build using a bundled Berkeley DB with a unique name to avoid possible symbol
  collisions with binaries using different versions (mix multiple versions of
  any shared library in a single process, observe as wackiness ensues)

* Wed Jan 23 2002 Nalin Dahyabhai <nalin@redhat.com> 2.2-7
- rebuild against db4-devel

* Mon Aug  6 2001 Nalin Dahyabhai <nalin@redhat.com> 2.2-6
- require db3-devel at build-time, not db3 (#49544)

* Tue May 25 2001 Nalin Dahyabhai <nalin@redhat.com>
- don't include copies of the shared libraries with the soname for their names

* Thu May 24 2001 Nalin Dahyabhai <nalin@redhat.com>
- rebuild in new environment

* Tue Feb 27 2001 Nalin Dahyabhai <nalin@redhat.com>
- don't own /var/db, the filesystem package does

* Tue Feb 13 2001 Nalin Dahyabhai <nalin@redhat.com>
- require make (#27313)
- add the docs to the package

* Tue Dec 19 2000 Nalin Dahyabhai <nalin@redhat.com>
- update to 2.2

* Thu Sep 14 2000 Jakub Jelinek <jakub@redhat.com>
- separate from db3