#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
 TMP=/tmp
fi
PKG=$TMP/package-beecrypt

VERSION=3.1.0
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}

if [ "$ARCH" = "i386" ]; then
 SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
 CONFFLAGS="--with-cpu=i686 --with-arch=i486"
elif [ "$ARCH" = "i486" ]; then
 SLKCFLAGS="-O2 -march=i486 -mcpu=i686"
 CONFFLAGS="--with-cpu=i686 --with-arch=i486"
elif [ "$ARCH" = "s390x" ]; then
 SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
 SLKCFLAGS="-O2"
fi

if [ ! -d $TMP ]; then
 mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG # place for the package to be built

cd $TMP
tar xjvf $CWD/beecrypt-$VERSION.tar.bz2
cd beecrypt-$VERSION
CFLAGS="$SLKCFLAGS" \
/configure \
 --prefix=/usr \
 --enable-shared=no \
 --enable-static=yes \
 "${CONFFLAGS}" \
 --with-pic \
 ${ARCH}-slackware-linux
make
make install DESTDIR=$PKG
strip -g $PKG/usr/lib64/*.a

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

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/beecrypt-$VERSION
 rm -rf $PKG
fi