#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://psyco.sourceforge.net
# SlackBuild by gall0ws ~at~ tiscali ~dot~ it

NAME=psyco
VERSION=1.6
test -z "$ARCH" && ARCH=i486
test -z "$TMP" && TMP=/tmp
BUILD=2gal
PKG=$TMP/package-$NAME
CWD=`pwd`

TARBALL=$NAME-$VERSION-src.tar.gz
PACK=$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ $ARCH == "i486" ]; then
 OPTFLAGS="-O2 -march=i486 -mtune=i686"
elif [ $ARCH == "athlon-xp" ]; then
 OPTFLAGS="-O2 -march=athlon-xp -fomit-frame-pointer -pipe"
elif [ $ARCH == "pentium4" ]; then
 OPTFLAGS="-O2 -march=pentium4 -fomit-frame-pointer -pipe"
elif [ $ARCH == "pentiumm" ]; then
 OPTFLAGS="-O2 -march=pentium-m -fomit-frame-pointer -pipe"
fi

function get_sources()
{
  wget http://mesh.dl.sourceforge.net/sourceforge/psyco/$TARBALL || exit 1
}

TARGET=i486

test -e $PKG && rm -rf $PKG
test -e $TMP/$NAME-$VERSION && rm -rf $TMP/$NAME-$VERSION

test ! -e $TARBALL && get_sources

tar -xvzf $TARBALL -C $TMP 
cd $TMP/$NAME-$VERSION

CFLAGS=${OPTFLAGS} \
python setup.py install --prefix=$PKG/usr/ || exit 1

mkdir -p -m 755 $PKG/usr/doc/$NAME-$VERSION

cp -a   COPYING.txt \
        INSTALL.txt \
        README.txt \
        MANIFEST \
        doc \
$PKG/usr/doc/$NAME-$VERSION

cd $PKG

chmod 644 $PKG/usr/doc/$NAME-$VERSION/*

cp -a $CWD/slack-desc $CWD/$NAME.SlackBuild $PKG/usr/doc/$NAME-$VERSION

chown -R root:root .

find . -exec file {} \; | grep "shared object" | cut -d : -f1 | xargs strip --strip-unneeded 2> /dev/null

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

echo -ne "\nmaking $NAME package.. "
cd $PKG
makepkg -c n -l y $CWD/$PACK &>/dev/null
echo "done"

[ "$1" = "--cleanup" ] && {
  echo -ne "cleaning up.. "
  rm -rf $TMP/$NAME-$VERSION
  rm -rf $PKG
  echo "done"
}

## EOF ##
