#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# http://users.tpg.com.au/adslblvi/
# Packager Vincenzi Loris - slacky@slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package/toolame
NAME=toolame
VERSION=02l
ARCH=i686
BUILD=1sl
SOURCE=http://mesh.dl.sourceforge.net/sourceforge/toolame/$NAME-$VERSION.tgz

if [ ! -e $NAME-$VERSION.tgz ]; then
wget -c $SOURCE
fi


rm -rf $PKG
mkdir -p $PKG

cd $TMP
tar xvzf $CWD/$NAME-$VERSION.tgz
cd $NAME-$VERSION
chown -R root:root .
make || exit 1
mkdir -p $PKG/usr/bin
mkdir -p $PKG/usr/include
cp -a  toolame  $PKG/usr/bin
cp -a  $TMP/$NAME-$VERSION/toolame*h $PKG/usr/include
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a  FUTURE HISTORY LGPL.txt README $PKG/usr/doc/$NAME-$VERSION
cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs strip -g 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
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
