#!/bin/sh
#
# matplotlib.SlackBuild
# 2012-10-02
#
# matplotlib is a python 2D plotting library which produces publication
# quality figures in a variety of hardcopy formats and interactive
# environments across platforms.

PRGNAM=matplotlib
VERSION=1.1.1

# automatically determine the architecture
if [ -z "$ARCH" ]; then
  ARCH=$(uname -m)
fi

BUILD=${BUILD:-1}
TAG=${TAG:-scr}

HOMEPAGE="http://matplotlib.sourceforge.net/"
SOURCE="${PRGNAM}-${VERSION}.tar.gz"
DOWNLOAD="http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-${VERSION}/${SOURCE}"
MD5SUM="8cbeaae8ba9da703d926e74c3e7c8a57"

REQUIRES="python numpy"

MAINTAINER="Gernot WALZL"
EMAIL="gernot.walzl@gmx.at"

DESC="matplotlib

is a python 2D plotting library which produces publication
quality figures in a variety of hardcopy formats and
interactive environments across platforms.

${HOMEPAGE}"

DOCS="$(pwd)/$0 CHANGELOG INSTALL README.txt TODO examples"

# EOF info


# set initial variables
CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# exit on error
set -e

# download the source if needed
if [ ! -f $CWD/$SOURCE ]; then
  wget -O $CWD/$SOURCE $DOWNLOAD || exit 1
fi

# check for correct source file
if [ "$(md5sum $CWD/$SOURCE | cut -f 1 -d ' ')" != "$MD5SUM" ]; then
  exit 1
fi

# extract the application source
cd $TMP || exit 1
tar xvf $CWD/$SOURCE || exit 1

# change to the application source directory
cd $PRGNAM-$VERSION || exit 1

# fix permissions
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# compile the source
python setup.py build

# install everything into the package directory
rm -rf $PKG
mkdir -p $PKG/install
python setup.py install --root=$PKG

# add documentation
if [ "$DOCS" != "" ]; then
  mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  cp -a $DOCS $PKG/usr/doc/$PRGNAM-$VERSION
  find $PKG/usr/doc/$PRGNAM-$VERSION -type f -exec chmod 644 {} \;
fi

# strip binaries
find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

# add some description to the package
if [ "$DESC" != "" ]; then
  echo "$DESC" | sed 's/^/'$PRGNAM': /g' > $PKG/install/slack-desc
fi

# append dependency information to the package
if [ "$REQUIRES" != "" ]; then
  for REQ in $REQUIRES; do
    echo "$REQ" >> $PKG/install/slack-required
  done
fi

# build the package
cd $PKG
makepkg -l y -c n \
  $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} \
  || exit 1

# make everything clean
cd $CWD
rm -rf $PKG
rm -rf $TMP/$PRGNAM-$VERSION
