#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://stani.be/python/spe/

CWD=`pwd`
NAME=spe
VERSION=0.8.4.h
VERSION1=0.8.4.h-wx2.6.1.0
EXT=tar.gz
ARCH=${ARCH:-noarch}
BUILD=1lu
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-$NAME

if [ ! -e $NAME-$VERSION.$EXT ]; then
wget -c http://download.berlios.de/python/$NAME-$VERSION-$EXT
fi

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

if [ "$EXT" = "tar.gz" ]; then
   TARCMD="tar xvzf"
elif [ "$EXT" = "tgz" ]; then
   TARCMD="tar xvzf"
elif [ "$EXT" = "tar.bz2" ]; then
   TARCMD="tar xvjf"
elif [ "$EXT" = "gz" ]; then
   TARCMD="gzip -e"
elif [ "$EXT" = "zip" ]; then
   TARCMD="unzip"
fi

cd $TMP
$TARCMD $CWD/$NAME-$VERSION1.$EXT
cd $NAME-$VERSION
chown -R root:root .
mkdir -p $PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/usr/share/pixmaps
mkdir -p $PKG/usr/share/applications
python setup.py install --root=$PKG
cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild
cp $CWD/spe.png $PKG/usr/share/pixmaps
cp $CWD/spe.desktop $PKG/usr/share/applications
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
