#!/bin/sh
# Build script for: WvStreams
# Distribution: Slackware Linux 12.0
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it
# Source location: http://open.nit.ca/wiki/?page=WvStreams
# Required: Xplc, Swig, Qdbm, Openslp


CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package/wvstreams
NAME=wvstreams
VERSION=4.4
CHOST=i486
ARCH=${ARCH:-i486}
BUILD=1bj

SOURCE=http://alumnit.ca/download/$NAME-$VERSION.tar.gz

if [ ! -e $NAME-$VERSION.tar.gz ]; then
wget -c $SOURCE
fi


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

rm -rf $PKG
if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
 mkdir -p $PKG
fi

echo "| Start SlackBuild $NAME-$VERSION |"

cd $TMP
rm -rf $NAME-$VERSION
tar xzvf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
chown -R root:root .
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --localstatedir=/var \
  --mandir=/usr/man \
  --with-pam=no \
  --with-openssl \
  --with-bdb \
  --program-prefix= \
  --program-suffix= \
--build=$CHOST-slackware-linux
make
make install DESTDIR=$PKG
rm -f $PKG/var/lib/uniconf/uniconfd.ini
cp -a $TMP/$NAME-$VERSION/uniconf/daemon/uniconfd.ini $PKG/var/lib/uniconf/uniconfd.ini

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -d : -f 1 | xargs -r strip --strip-unneeded
  find . | xargs file | grep "shared object" | grep ELF | cut -d : -f 1 | xargs -r strip --strip-unneeded
  find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs -r strip --strip-debug
)

find $PKG/usr/man -type f -exec gzip -9 {} \;
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a ChangeLog README $PKG/usr/doc/$NAME-$VERSION
mv $PKG/etc/uniconf.conf $PKG/etc/uniconf.conf.new

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild

cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP
fi
