#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://elisa.fluendo.com/
# Packager Michelino Chionchio - www.slacky.eu
# Depends on: elisa-plugins-bad, elisa-plugins-good, elisa-plugins-ugly,
#             twisted, pysqlite, pigment, pigment-python, gstreamer, 
#             gst-plugins-base, gst-plugins-ugly, gst-plugins-bad, 
#             gst-python, gst-ffmpeg, libdc1394-2, libvisual-plugins,
#             pyxdg, xdg-user-dirs, setuptools, coherence, beautifulsoup,
#             gdata.py, twill, pythondaap, avahi, gpod-python



CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-elisa
NAME=elisa
VERSION=0.3.5
CHOST=i486
ARCH=${ARCH:-i486}
BUILD=1mch

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

cd $TMP
tar xvzf $CWD/$NAME-$VERSION.tar.gz
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 build || exit 1
python setup.py install --root=$PKG || exit 1

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a API_REVIEW_REMAINING AUTHORS COPYING ChangeLog* FAQ* \
      FIRST_RUN HACKING LICENSE* MANIFEST.in NEWS PKG-INFO \
      README RELEASE TRANSLATORS \
      $PKG/usr/doc/$NAME-$VERSION

mkdir $PKG/usr/man/
mv $PKG/usr/share/man/* $PKG/usr/man
rm -rf $PKG/usr/share/man/
gzip -9 $PKG/usr/man/*/*

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

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
ADD="elisa-plugins-bad >= 0.3.5-i486-1mch,\
elisa-plugins-good >= 0.3.5-i486-1mch,\
elisa-plugins-ugly >= 0.3.5-i486-1mch,\
twisted >= 8.0.1-noarch-1sl,\
pysqlite >= 2.4.1-i486-1sl,\
pigment >= 0.3.5-i486-1mch,\
pigment-python >= 0.3.3-i486-1mch,\
gst-ffmpeg >= 0.10.4-i486-1mch,\
gst-plugins-bad >= 0.10.7-i486-1as,\
gst-plugins-base >= 0.10.19-i486-2as,\
gst-plugins-ugly >= 0.10.8-i486-1as,\
gst-python >= 0.10.11-i486-1mch,\
gstreamer >= 0.10.19-i486-2as,\
libdc1394 >= 2.0.2-i486-1sl,\
libvisual-plugins >= 0.4.0-i486-1mch,\
pyxdg >= 0.15-noarch-1as,\
xdg-user-dirs >= 0.10-i486-1mch,\
setuptools >= 0.6c8-i486-2bj,\
coherence >= 0.5.6-i486-2mch,\
beautifulsoup >= 3.0.6-i486-2mch,\
gdata.py >= 1.0.12.1-i486-1as,\
twill >= 0.9-i486-1mch,\
pythondaap >= 0.7.1-i486-1mch,\
avahi >= 0.6.22-i486-2as,\
gpod-python >= 0.6.0-i486-1mch" \
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
