#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://freevo.sourceforge.net/
# http://www.slacky.it

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi
NAME=freevo
PKG=$TMP/package-$NAME
VERSION=1.8.3
ARCH=${ARCH:-i486}
BUILD=1lu

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

SOURCE=http://garr.dl.sourceforge.net/sourceforge/freevo/$NAME-$VERSION.tar.gz

if [ ! -e $NAME-$VERSION.tar.gz ]; then
wget -c $SOURCE
fi

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

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

cd $NAME-$VERSION

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 install --prefix=$PKG/usr

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a README $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
mkdir -p $PKG/usr/share/$NAME
cp $TMP/$NAME-$VERSION/local_conf.py.example $PKG/usr/share/$NAME

( 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 /tmp/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$NAME-$VERSION
 rm -rf $PKG
fi
