#!/bin/bash
# Heavily based on the Slackware 12.1 SlackBuild
# http://www.parallelrealities.co.uk/blobWars.php 

NAME="blobwars"
VERSION="1.08"
SVERSION="1.08.1"
ARCH="i486"
BUILD="2gal"
TMP="/tmp/build-$NAME"
PKG="$TMP/pkg"
CWD="`pwd`"
OPTFLAGS="-O2 -march=$ARCH -mtune=i686"

[ -e $TMP ] && rm -rf $TMP
mkdir $TMP

tar xvzf $NAME-$VERSION-1.tar.gz -C $TMP
cd $TMP/$NAME-$VERSION

CXXFLAGS=$OPTFLAGS make all -j3
make install DESTDIR=$PKG

cd $PKG
mkdir -p $PKG/usr/doc/$NAME-$SVERSION
mv usr/share/doc/$NAME/* usr/doc/$NAME-$SVERSION
rm -rf usr/share/doc
chown -R root:root .

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$SVERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$SVERSION/$NAME.SlackBuild

echo
echo -n "making $NAME package.. "
requiredbuilder -v -y -s $CWD $PKG
makepkg -c n -l y $CWD/$NAME-$SVERSION-$ARCH-$BUILD.tgz &>/dev/null
echo "done"

if [ "$1" == "--cleanup" ]; then
  echo -n "cleaning up.. "
  rm -rf $TMP
  echo "done"
fi

