#!/bin/sh
#
# Heavily based on the Slackware 13.0 SlackBuild
#
# Packager: AsPh4lTo aka albatros_la
#

CWD=$(pwd)
TMP=${TMP:-/tmp/txz}
PKG=$TMP/package-matplotlib
NAME=matplotlib
VERSION=0.99.1.2
MAINVER=0.99.1
TARVER=0.99.1.1
ARCH=${ARCH:-i486}
BUILD=1sl

if [ ! -f $CWD/$NAME-$VERSION.tar.gz ]
then
 wget http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-$MAINVER/$NAME-$VERSION.tar.gz?use_mirror=garr
fi 

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-$TARVER
chown -R root:root .
chmod -R u+w,go+r-w,a-s .
patch -p0 < $CWD/setup.cfg_patch.diff
mv setup.cfg.template setup.cfg
python setup.py build
python setup.py install --root=$PKG
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a *.txt CHANGELOG INTERACTIVE KNOWN_BUGS TODO  $PKG/usr/doc/$NAME-$VERSION
cd $PKG
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.txz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP
fi
