#!/bin/sh
# Build gdbm-$VERSION for Slackware
# by volkerdi@slackware.com, 2/2001
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-gdbm
rm -rf $PKG
mkdir -p $PKG

VERSION=1.8.3
ARCH=${ARCH:-i486}
BUILD=4

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
fi

cd $TMP
rm -rf gdbm-$VERSION
tar xzvf $CWD/gdbm-$VERSION.tar.gz
cd gdbm-$VERSION
chown -R root:root .
find . -perm 700 -exec chmod 755 {} \;
find . -perm 600 -exec chmod 644 {} \;
CFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --build=$ARCH-slackware-linux
make -j4 || exit 1
make install INSTALL_ROOT=$PKG

# I'm not sure what out there would need the "libgdbm_compat" library,
# but it causes versions of ndbm.h and dbm.h to be installed that break
# compiling nearly everything with any dbm support (like python's dbm.so,
# and mod_ssl).  Putting 'em in /usr/include/gdbm/ doesn't isolate them
# enough, either.  File this one under "not worth it".
#make install-compat INSTALL_ROOT=$PKG

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/usr/doc/gdbm-$VERSION
cp -a \
  COPYING ChangeLog NEWS README \
  $PKG/usr/doc/gdbm-$VERSION
gzip -9 $PKG/usr/info/gdbm.info
gzip -9 $PKG/usr/man/man3/gdbm.3
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n ../gdbm-$VERSION-$ARCH-$BUILD.tgz