NAME=db4
VERSION=4.3.29
SOURCE=http://downloads.sleepycat.com/db-$VERSION.tar.gz
SOURCE_MD5=13585a20ce32f113b8e8cdb57f52e3bb
BUILD=${BUILD:-1tukaani}

build() {
	_cflags -O2
	_explode 0
	cd db-$VERSION
	rm -rf build-dir
	mkdir build-dir
	cd build-dir
	../dist/configure \
		--prefix=$PREFIX \
		--libdir=$LIBDIR \
		--enable-shared \
		--enable-rpc \
		--enable-compat185 \
		--enable-cxx \
		--with-mutex=x86/gcc-assembly \
		$CONFIGURE_TRIPLET
	make
	make install DESTDIR=$PKG

	# Remove WAY TOO LARGE (and misplaced) docs:
	rm -rf $PKG$PREFIX/docs
	_doc 0 db-$VERSION  ../LICENSE ../README
	cat << EOF > $PKG$DOCDIR/db-$VERSION/README-DOCS

  For a ton of additional documentation (too large to include
  here) on writing source code that uses libdb4, please see
  the source tarball db-$VERSION.tar.bz2, which can be found
  in the Tukaani source tree in source/l/db4/, or on
  Sleepycat's web site:  http://www.sleepycat.com.

EOF

	# These are required so many times that make them short:
	L=${LIBDIR##*/}
	V=${VERSION%.*}

	# Put libdb-4.3.so into /lib since it might be needed
	# before /usr is mounted (eg, nssswitch.conf requires it)
	if [ "$LIBDIR" != "/$L" ]; then
		mkdir -p $PKG/$L
		mv $PKG$LIBDIR/libdb-$V.so $PKG/$L/libdb-$V.so
		ln -s /$L/libdb-$V.so $PKG$LIBDIR/libdb-$V.so
	fi

	# Headers:
	cd $PKG$INCLUDEDIR
	chmod 644 *
	mkdir db4
	mv db.h db_185.h db_cxx.h db4
	ln -sf db4/db.h .
	ln -sf db4/db_185.h .
	ln -sf db4/db_cxx.h .

	cd $PKG$LIBDIR
	ln -sf libdb-$V.a libdb-4.a
	ln -sf libdb-$V.a libdb.a
	# Some things need this name.  Whatta mess!
	ln -sf libdb-4.a libdb4.a
	ln -sf libdb-4.so libdb4.so

	cd $PKG$BINDIR
	mv berkeley_db_svc berkeley_db4_svc
	for file in db_* ; do
		mv $file db4_`echo $file | cut -f 2- -d _`
	done

	_chfix
	_chgrp_bin
}
