# compatibility with legacy rpm
%{!?_lib:%define _lib	lib}

%define	__s		-s
%define	__soversion	3.2
%define	_libdb_a	libdb-%{__soversion}.a
%define	_libcxx_a	libdb_cxx-%{__soversion}.a

Summary:     The Berkeley DB database library for C.
Summary(ja): C 用 Berkeley DB データベースライブラリ
Name:        db3
Version:     3.2.9
Release:     1vl2
Source:      http://www.sleepycat.com/update/%{version}/db-%{version}.tar.gz
URL:         http://www.sleepycat.com
Copyright:   GPL
Group:       System Environment/Libraries

%ifos linux
# XXX written as a file prereq in order to build with glibc-2.1.3
BuildPreReq: /usr/lib/libdb1.a
%endif
BuildPreReq: tcl

BuildRoot:   %{_tmppath}/%{name}-%{version}-root
Prefix:      %{_prefix}


%description
The Berkeley Database (Berkeley DB) is a programmatic toolkit that provides
embedded database support for both traditional and client/server applications.
Berkeley DB is used by many applications, including Python and Perl, so this
should be installed on all systems.


%package utils
Summary:     Command line tools for managing Berkeley DB databases.
Summary(ja): Berkeley DB データベース用コマンドラインツール
Group:       Applications/Databases
Requires:    db3 = %{version}
Prefix:      %{_prefix}


%description utils
The Berkeley Database (Berkeley DB) is a programmatic toolkit that provides
embedded database support for both traditional and client/server applications.
Berkeley DB includes B+tree, Extended Linear Hashing, Fixed and Variable-length
record access methods, transactions, locking, logging, shared memory caching
and database recovery. DB supports C, C++, Java and Perl APIs.

This package contains command line tools for managing Berkeley DB databases.


%package devel
Summary:     Development libraries/header files for the Berkeley DB library.
Summary(ja): Berkeley DB 用開発ライブラリ/ヘッダファイル
Group:       System Environment/Libraries
Requires:    db3 = %{version}
Prefix:      %{_prefix}


%description devel
The Berkeley Database (Berkeley DB) is a programmatic toolkit that provides
embedded database support for both traditional and client/server applications.
Berkeley DB includes B+tree, Extended Linear Hashing, Fixed and Variable-length
record access methods, transactions, locking, logging, shared memory caching
and database recovery. DB supports C, C++, Java and Perl APIs.

This package contains the header files, libraries, and documentation for
building programs which use Berkeley DB.


%prep
%setup -q -n db-%{version}


%build

cd build_unix

# XXX --enable-posixmutexes is useful for threads but useless for interprocess locking.
# XXX --enable-diagnostic should be disabled for production (but is useful).
# XXX --enable-debug_{r,w}op should be disabled for production.
# XXX --enable-java
CFLAGS="$RPM_OPT_FLAGS" ../dist/configure --prefix=%{_prefix} --enable-debug --enable-compat185 --enable-dump185 --enable-shared --enable-static --enable-rpc --enable-tcl --with-tcl=%{_prefix}/lib --enable-cxx --enable-test # --enable-diagnostic --enable-debug --enable-debug_rop --enable-debug_wop # --enable-posixmutexes

make libdb=%{_libdb_a} %{_libdb_a}
make libcxx=%{_libcxx_a} %{_libcxx_a}

# Static link with old db-185 libraries.
/bin/sh ./libtool --mode=compile cc -c -O2 -g -g -I/usr/include/db1 -I../dist/../include -D_REENTRANT  ../dist/../db_dump185/db_dump185.c
cc %{__s} -static -o db_dump185 db_dump185.lo -L%{_libdir} -ldb1

# Compile rest normally.
make libdb=%{_libdb_a} libcxx=%{_libcxx_a} TCFLAGS='-I$(builddir) -I/usr/include' LDFLAGS="%{__s}"

# remove dangling tags symlink from examples.
rm -f examples_cxx/tags
rm -f examples_c/tags


%install
rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}%{_includedir}
mkdir -p ${RPM_BUILD_ROOT}%{_prefix}/lib

cd build_unix

# XXX install_java
make libdb=%{_libdb_a} libcxx=%{_libcxx_a} LDFLAGS="%{__s}" prefix=${RPM_BUILD_ROOT}%{_prefix} install_include install_dynamic install_static install_dynamic_cxx install_static_cxx install_tcl install_utilities

# XXX annoying
set -x
( cd ${RPM_BUILD_ROOT}

%ifos linux
  mkdir -p ./%{_lib}
  mv .%{_prefix}/lib/libdb[-.]*so* ./%{_lib}
  if [ "%{_libdir}" != "%{_prefix}/lib" ]; then
    mkdir -p .%{_libdir}
    mv .%{_prefix}/lib/libdb* .%{_libdir}
  fi
%endif

  mkdir -p .%{_includedir}/db3
  mv .%{_prefix}/include/*.h .%{_includedir}/db3
  ln -sf db3/db.h .%{_includedir}/db.h
# XXX Rather than hack *.la (see below), create /usr/lib/libdb-3.1.so symlink.
  ln -sf ../../lib/libdb-%{__soversion}.so .%{_libdir}/libdb-%{__soversion}.so
# XXX This is needed for packaging db3 for Red Hat 6.x
#  for F in .%{_prefix}/bin/db_* ; do
#    mv $F `echo $F | sed -e 's,/db_,/db3_,'`
#  done
)
set +x

# XXX libdb-3.1.so is in /lib teach libtool as well
#perl -pi -e 's,/usr,,' ${RPM_BUILD_ROOT}%{_libdir}/libdb-%{__soversion}.la


%clean
rm -rf ${RPM_BUILD_ROOT}


%post -p /sbin/ldconfig


%postun -p /sbin/ldconfig


%files
%defattr(-,root,root)
%doc LICENSE README docs/images
%ifos linux
/%{_lib}/libdb-%{__soversion}.so
%else
%{_libdir}/libdb-%{__soversion}.so
%endif
%{_libdir}/libdb_cxx-%{__soversion}.so


%files utils
%defattr(-,root,root)
%doc	docs/utility
%{_libdir}/libdb_tcl.so
%{_libdir}/libdb_tcl-%{__soversion}.la
%{_libdir}/libdb_tcl-%{__soversion}.so
%{_bindir}/berkeley_db_svc
%{_bindir}/db*_archive
%{_bindir}/db*_checkpoint
%{_bindir}/db*_deadlock
%{_bindir}/db*_dump
%{_bindir}/db*_dump185
%{_bindir}/db*_load
%{_bindir}/db*_printlog
%{_bindir}/db*_recover
%{_bindir}/db*_stat
%{_bindir}/db*_upgrade
%{_bindir}/db*_verify


%files devel
%defattr(-,root,root)
%doc	docs/api_c docs/api_cxx docs/api_java docs/api_tcl docs/index.html
%doc	docs/ref docs/sleepycat
%doc	examples_c examples_cxx
%{_libdir}/libdb-%{__soversion}.la
%{_libdir}/libdb_cxx-%{__soversion}.la
%{_libdir}/%{_libdb_a}
%{_libdir}/%{_libcxx_a}
%{_includedir}/db3/db.h
%{_includedir}/db3/db_185.h
%{_includedir}/db3/db_cxx.h
%{_includedir}/db.h
%ifos linux
/%{_lib}/libdb.so
/%{_libdir}/libdb-%{__soversion}.so
%else
%{_libdir}/libdb.so
%endif
%{_libdir}/libdb_cxx.so


%changelog
* Tue Dec 11 2001 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 3.2.9-1vl2
- increased release number for VineSeed main tree :)

* Thu May 10 2001 MATSUBAYASHI 'Shaolin' Kohji <shaolin@vinelinux.org>
- 3.2.9-1vl1
- based on 3.2.9 from Rawhide
- rebuilt for VineSeed

* Mon Mar 19 2001 Jeff Johnson <jbj@redhat.com>
- update to 3.2.9.

* Tue Dec 12 2000 Jeff Johnson <jbj@redhat.com>
- rebuild to remove 777 directories.

* Sat Nov 11 2000 Jeff Johnson <jbj@redhat.com>
- don't build with --enable-diagnostic.
- add build prereq on tcl.
- default value for %%_lib macro if not found.

* Tue Oct 17 2000 Jeff Johnson <jbj@redhat.com>
- add /usr/lib/libdb-3.1.so symlink to %%files.
- remove dangling tags symlink from examples.

* Mon Oct  9 2000 Jeff Johnson <jbj@redhat.com>
- rather than hack *.la (see below), create /usr/lib/libdb-3.1.so symlink.
- turn off --enable-diagnostic for performance.

* Fri Sep 29 2000 Jeff Johnson <jbj@redhat.com>
- update to 3.1.17.
- disable posix mutexes Yet Again.

* Tue Sep 26 2000 Jeff Johnson <jbj@redhat.com>
- add c++ and posix mutex support.

* Thu Sep 14 2000 Jakub Jelinek <jakub@redhat.com>
- put nss_db into a separate package

* Wed Aug 30 2000 Matt Wilson <msw@redhat.com>
- rebuild to cope with glibc locale binary incompatibility, again

* Wed Aug 23 2000 Jeff Johnson <jbj@redhat.com>
- remove redundant strip of libnss_db* that is nuking symbols.
- change location in /usr/lib/libdb-3.1.la to point to /lib (#16776).

* Thu Aug 17 2000 Jeff Johnson <jbj@redhat.com>
- summaries from specspo.
- all of libdb_tcl* (including symlinks) in db3-utils, should be db3->tcl?

* Wed Aug 16 2000 Jakub Jelinek <jakub@redhat.com>
- temporarily build nss_db in this package, should be moved
  into separate nss_db package soon

* Wed Jul 19 2000 Jakub Jelinek <jakub@redhat.com>
- rebuild to cope with glibc locale binary incompatibility

* Wed Jul 12 2000 Prospector <bugzilla@redhat.com>
- automatic rebuild

* Sun Jun 11 2000 Jeff Johnson <jbj@redhat.com>
- upgrade to 3.1.14.
- create db3-utils sub-package to hide tcl dependency, enable tcl Yet Again.
- FHS packaging.

* Mon Jun  5 2000 Jeff Johnson <jbj@redhat.com>
- disable tcl Yet Again, base packages cannot depend on libtcl.so.

* Sat Jun  3 2000 Jeff Johnson <jbj@redhat.com>
- enable tcl, rebuild against tcltk 8.3.1 (w/o pthreads).

* Tue May 30 2000 Matt Wilson <msw@redhat.com>
- include /lib/libdb.so in the devel package

* Wed May 10 2000 Jeff Johnson <jbj@redhat.com>
- put in "System Environment/Libraries" per msw instructions.

* Tue May  9 2000 Jeff Johnson <jbj@redhat.com>
- install shared library in /lib, not /usr/lib.
- move API docs to db3-devel.

* Mon May  8 2000 Jeff Johnson <jbj@redhat.com>
- don't rename db_* to db3_*.

* Tue May  2 2000 Jeff Johnson <jbj@redhat.com>
- disable --enable-test --enable-debug_rop --enable-debug_wop.
- disable --enable-posixmutexes --enable-tcl as well, to avoid glibc-2.1.3
  problems.

* Mon Apr 24 2000 Jeff Johnson <jbj@redhat.com>
- add 3.0.55.1 alignment patch.
- add --enable-posixmutexes (linux threads has not pthread_*attr_setpshared).
- add --enable-tcl (needed -lpthreads).

* Sat Apr  1 2000 Jeff Johnson <jbj@redhat.com>
- add --enable-debug_{r,w}op for now.
- add variable to set shm perms.

* Sat Mar 25 2000 Jeff Johnson <jbj@redhat.com>
- update to 3.0.55

* Tue Dec 29 1998 Jeff Johnson <jbj@redhat.com>
- Add --enable-cxx to configure.

* Thu Jun 18 1998 Jeff Johnson <jbj@redhat.com>
- Create.
