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

VERSION=3.1.0
ARCH=sparc
BUILD=1
# TUPLE=i486-slackware-linux
TUPLE=$ARCH-splack-linux

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mcpu=i686"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "sparc" ]; 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

if [ "$ARCH" = "sparc" ]; then
  CFLAGS="$SLKCFLAGS" \
  ./configure \
    --prefix=/usr \
    --enable-shared=no \
    --enable-static=yes \
    --with-arch=sparc \
    --with-pic \
    $TUPLE
else
  CFLAGS="$SLKCFLAGS" \
  ./configure \
    --prefix=/usr \
    --enable-shared=no \
    --enable-static=yes \
    --with-cpu=i686 \
    --with-arch=i486 \
    --with-pic \
    $TUPLE
fi

make
make install DESTDIR=$PKG
strip -g $PKG/usr/lib/*.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
