#!/bin/bash
# Heavily based on the Slackware 13.0 SlackBuild
# SlackBuild by gallows ~at~ tiscali ~dot~ it

NAME=jam
VERSION=2.5
[ -z "$ARCH" ] && ARCH=i486
[ -z "$TMP" ] && TMP=/tmp
BUILD=4gal
PKG=$TMP/package-$NAME
CWD=`pwd`

TARBALL=$NAME-$VERSION.tar
PACK=$NAME-$VERSION-$ARCH-$BUILD.txz

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

TARGET=i486

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

cat $CWD/makefile.diff | patch -p0

make -j2 || exit 1

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

cp -a RELNOTES README *.html $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

mkdir -p $PKG/usr/bin

cp -a $TMP/$NAME-$VERSION/bin.linuxx86/jam $PKG/usr/bin
cp -a $TMP/$NAME-$VERSION/bin.linuxx86/mkjambase $PKG/usr/bin

chown -R root:root .

strip $PKG/usr/bin/*
chmod 755 $PKG/usr/bin/*

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

echo -ne "\nmaking $NAME package.. "
cd $PKG
requiredbuilder -v -y -s $CWD $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 ##
