#!/bin/sh
# Set initial variables:

VERSION=7.2.5
ARCH=${ARCH:-i386}
BUILD=${BUILD:-1}

CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
PKG=$TMP/package-tcsh

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" = "alpha" ]; then
  SLKCFLAGS="-O2 -mcpu=ev4"
fi

rm -rf $PKG
mkdir -p $PKG
cd $TMP
tar xjvf $CWD/apsfilter-$VERSION.tar.bz2
cd apsfilter
chown -R root.root .
CFLAGS=$SLKCFLAGS ./configure --prefix=/usr --sysconfdir=/etc
make
make DESTDIR=$PKG install
rm -rf $PKG/usr/doc/apsfilter-$VERSION
mv $PKG/usr/doc/apsfilter $PKG/usr/doc/apsfilter-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
# This directory should not be present by default -- SETUP makes it.
rm -rf $PKG/etc/apsfilter

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

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

