#!/bin/sh
# Heavily based on the Slackware 11.0 SlackBuild
# http://www.scons.org
# Packager Vincenzi Loris - slacky@slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-scons
NAME=scons
VERSION=0.97
ARCH=noarch
BUILD=1sl

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

cd $TMP
tar xzvf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
chown -R root:root .
find . -perm 444 -exec chmod 644 {} \;
mkdir -p $PKG/usr/lib
python setup.py install
mv /usr/lib/scons-$VERSION $PKG/usr/lib
mkdir -p $PKG/usr/bin
rm /usr/bin/scons
mv /usr/bin/scons-$VERSION $PKG/usr/bin
ln -sf /usr/bin/scons-$VERSION $PKG/usr/bin/scons
rm /usr/bin/sconsign
mv /usr/bin/sconsign-$VERSION $PKG/usr/bin
ln -sf /usr/bin/sconsign-$VERSION $PKG/usr/bin/sconsign
rm /usr/bin/scons-time
mv /usr/bin/scons-time-$VERSION $PKG/usr/bin
ln -sf /usr/bin/scons-time-$VERSION $PKG/usr/bin/scons-time
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a CHANGES.txt LICENSE.txt MANIFEST PKG-INFO README.txt RELEASE.txt $PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/usr/man/man1
cp -a *.1 $PKG/usr/man/man1
gzip -9 $PKG/usr/man/man1/*
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
cd $PKG
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
