#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://www.pygame.org
# Packager Andrea Sciucca  Gohanz ( gohanz at infinito.it)
# http://www.slacky.it
# Requirements: Smpeg, Numeric

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-pygame
NAME=pygame
SVERSION=1.8.1release
VERSION=1.8.1
ARCH=${ARCH:-i486}
BUILD=1as

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

cd $TMP
tar xvzf $CWD/$NAME-$SVERSION.tar.gz

echo "+------------------------------------------+"
echo "| Starting SlackBuild  $NAME-$VERSION |"
echo "+------------------------------------------+"

cd $NAME-$SVERSION

find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;

chown -R root.root .

python setup.py build  \

python setup.py install --prefix=$PKG/usr \

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a PKG-INFO WHATSNEW readme.txt $PKG/usr/doc/$NAME-$VERSION
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION
chown -R root:root $PKG/usr/doc/$NAME-$VERSION

( cd $PKG
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

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

cd $PKG
chown -R root:root .
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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