Name:          db47
Version:       4.7.25
Release:       3mamba
Summary:       The Berkeley DB database library
Group:         System/Libraries
Vendor:        openmamba
Distribution:  openmamba
Packager:      Silvan Calarco <silvan.calarco@mambasoft.it>
URL:           http://www.oracle.com/technology/products/berkeley-db/index.html
Source:        http://download.oracle.com/berkeley-db/db-%{version}.tar.gz
Patch0:        db47-4.7.25-dd_segfaults.patch
Patch1:        db47-4.7.25-fix_master_segv.patch
Patch2:        db47-4.7.25-replication_clients_open_sequence.patch
Patch3:        db47-4.7.25-self_deadlock_fix.patch
License:       GPL
## AUTOBUILDREQ-BEGIN
BuildRequires: glibc-devel
BuildRequires: libgcc
BuildRequires: libstdc++6-devel
## AUTOBUILDREQ-END
%if "%{?stage1}" != "1"
BuildRequires: java-gcj-compat-runtime >= 1.5.0
BuildRequires: sharutils
%endif
BuildRoot:     %{_tmppath}/%{name}-%{version}-root

%description
The Berkeley Database (Berkeley DB) is a programmatic toolkit that provides embedded database support for both traditional and client/server applications.
The Berkeley DB includes B+tree, Extended Linear Hashing, Fixed and Variable-length record access methods, transactions, locking, logging, shared memory caching, and database recovery.
The Berkeley DB supports C, C++, Java, and Perl APIs.
It is used by many applications, including Python and Perl, so this should be installed on all systems.

%package -n libdb47
Summary:       The Berkeley DB database library
Group:         System/Libraries

%description -n libdb47
The Berkeley Database (Berkeley DB) is a programmatic toolkit that provides embedded database support for both traditional and client/server applications.
The Berkeley DB includes B+tree, Extended Linear Hashing, Fixed and Variable-length record access methods, transactions, locking, logging, shared memory caching, and database recovery.
The Berkeley DB supports C, C++, Java, and Perl APIs.
It is used by many applications, including Python and Perl, so this should be installed on all systems.


%package -n libdb47-devel
Summary:       Development files for the Berkeley DB library.
Group:         System/Libraries
Requires:      libdb47 = %{version}-%{release}

%description -n libdb47-devel
The Berkeley Database (Berkeley DB) is a programmatic toolkit that provides embedded database support for both traditional and client/server applications.
This package contains the header files, libraries, and documentation for building programs which use the Berkeley DB.

%package -n libdb47-java
Summary:       Java bindings for the Berkeley DB library
Group:         System/Libraries
Requires:      libdb47 = %{version}-%{release}

%description -n libdb47-java
Java bindings for the Berkeley DB library.

%package -n db47-tools
Summary:       Tools for the managing Berkeley DB
Group:         System/Libraries
Requires:      libdb47 = %{version}-%{release}

%description -n db47-tools
The Berkeley Database (Berkeley DB) is a programmatic toolkit that provides embedded database support for both traditional and client/server applications.
This package contains the tools for managing Berkeley DB.

%prep
[ "%{buildroot}" != / ] && rm -rf "%{buildroot}"

%setup -q -n db-%{version}
%patch0 -p0
%patch1 -p0
%patch2 -p0
%patch3 -p0

%build
cd build_unix

case "%{_target_cpu}" in
   i586) mutex="x86/gcc-assembly" ;;
   ppc) mutex="PPC/gcc-assembly" ;;
   *) mutex="UNIX/fcntl" ;;
esac

JAVA_HOME=/usr/lib/jvm/jjava-1.5.0-gcj-1.5.0.0/ \
../dist/configure \
   --host=%{_host} \
   --build=%{_build} \
   --prefix=%{_prefix} \
   --libdir=%{_libdir} \
   --includedir=%{_includedir} \
   --datadir=%{_datadir} \
   --enable-cxx \
   --enable-compat185 \
%if "%{?stage1}" != "1"
   --enable-java \
%endif
   --with-mutex="$mutex"

%make

%install
cd build_unix
make install \
   prefix=%{buildroot}%{_prefix} \
   libdir=%{buildroot}%{_libdir} \
   includedir=%{buildroot}%{_includedir}/db47/

mkdir -p %{buildroot}%{_datadir}/doc/libdb4-%{version}
mv %{buildroot}%{_prefix}/docs/* \
   %{buildroot}%{_datadir}/doc/libdb4-%{version}
rmdir %{buildroot}%{_prefix}/docs

find %{buildroot}%{_bindir}/* -exec mv {} {}-47 \;
# fix strange permissions
chmod 755 %{buildroot}%{_bindir}/*

ln -s libdb-4.7.so %{buildroot}%{_libdir}/libdb.so.4.7

%if "%{?stage1}" != "1"
ln -s libdb_java-4.7.so %{buildroot}%{_libdir}/libdb_java.so.4.7
mkdir -p %{buildroot}%{_datadir}/java
mv %{buildroot}%{_libdir}/*.jar %{buildroot}%{_datadir}/java/
%endif

rm -f %{buildroot}%{_libdir}/libdb.so
rm -f %{buildroot}%{_libdir}/libdb_cxx.so

%clean
[ "%{buildroot}" != / ] && rm -rf "%{buildroot}"

%files -n db47-tools
%defattr(-,root,root)
%{_bindir}/*

%files -n libdb47
%defattr(-,root,root)
%{_libdir}/libdb-4.7.so
%{_libdir}/libdb_cxx-4.7.so
%{_libdir}/libdb.so.4.7

%files -n libdb47-devel
%defattr(-,root,root)
%{_datadir}/doc/libdb4-%{version}/*
%{_includedir}/db47/*
%{_libdir}/*.a
%{_libdir}/*.la
%{_libdir}/libdb-4.so
%{_libdir}/libdb_cxx-4.so

%if "%{?stage1}" != "1"
%files -n libdb47-java
%defattr(-,root,root)
%{_libdir}/libdb_java.so
%{_libdir}/libdb_java-4.so
%{_libdir}/libdb_java-4.7.so
%{_libdir}/libdb_java-4.7_g.so
%{_libdir}/libdb_java.so.4.7
%{_datadir}/java/*.jar
%endif

%changelog
* Sat Mar 19 2011 Silvan Calarco <silvan.calarco@mambasoft.it> 4.7.25-3mamba
- remove symlink libdb.so (default is now db 5.1)

* Tue Feb 08 2011 Silvan Calarco <silvan.calarco@mambasoft.it> 4.7.25-2mamba
- added patches from http://www.oracle.com/technetwork/database/berkeleydb/patch-088170.html
- install headers in /usr/include/db47
- added db47-tools package

* Thu Jul 03 2008 gil <puntogil@libero.it> 4.7.25-1mamba
- update to version 4.7.25
- removed patches

* Wed Jun 04 2008 Silvan Calarco <silvan.calarco@mambasoft.it> 4.2.52-8mamba
- specfile updated

* Thu Jul 13 2006 Davide Madrisan <davide.madrisan@qilinux.it> 4.2.52-7qilnx
- fixed openldap warning: "BerkeleyDB 4.2.52 library needs TXN patch!"
- official patches applied
- fixed permissions of binary files

* Wed Oct 26 2005 Silvan Calarco <silvan.calarco@mambasoft.it> 4.2.52-6qilnx
- add OpenOffice patch

* Mon Oct 24 2005 Silvan Calarco <silvan.calarco@mambasoft.it> 4.2.52-5qilnx
- do not link against libpthread

* Mon Oct 24 2005 Silvan Calarco <silvan.calarco@mambasoft.it> 4.2.52-4qilnx
- rebuild with gcj

* Wed Feb 02 2005 Silvan Calarco <silvan.calarco@mambasoft.it> 4.2.52-3qilnx
- rebuilt with java bindings

* Tue Jul 27 2004 Silvan Calarco <silvan.calarco@mambasoft.it> 4.2.25-8qilnx
- new version build
- source RPM renamed to db42 (should cohexist with libdb4)

* Sun May 09 2004 Silvan Calarco <silvan.calarco@mambasoft.it> 4.1.25-8qilnx
- added libdb.so provides

* Fri May 07 2004 Silvan Calarco <silvan.calarco@mambasoft.it> 4.1.25-7qilnx
- fixed symlinks for compatibility

* Fri May 07 2004 Silvan Calarco <silvan.calarco@mambasoft.it> 4.1.25-6qilnx
- rebuild with --enable-compat185

* Tue Sep 15 2003 Silvan Calarco <silvan.calarco@mambasoft.it> 4.1.25-5qilnx
- Added symlink /usr/include/db.h so that db4 is system default version 

* Tue Sep 09 2003 Silvan Calarco <silvan.calarco@mambasoft.it> 4.1.25-4qilnx
- Moved includes to /usr/include/db4 for devel packages co-existence

* Fri Jul 25 2003 Silvan Calarco <silvan.calarco@qinet.it> 4.1.25-3qilnx
- Removed compat185 (it looks broken, I'll try to use db2's compat185)

* Thu Jul 24 2003 Silvan Calarco <silvan.calarco@qinet.it> 4.1.25-2qilnx
- Enabled compatibiliy with version 185

* Tue Apr 22 2003 Luca Tinelli <luca.tinelli@qinet.it> 4.1.25-1qilnx
- Creation of db4 package