#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://smplayer.sourceforge.net
# Packager Andrea Sciucca Gohanz ( gohanz at infinito.it)
# http://www.slacky.it
# Required: Qt4.x.x, Mencoder/Mplayer

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package/smplayer
NAME=smplayer
VERSION=0.6.5.1
ARCH=${ARCH:-i686}
BUILD=1as

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

cd $TMP
tar xvjf $CWD/$NAME-$VERSION.tar.bz2

echo -e "\E[0;32m+----------------------------------+\E[0;0m"
echo -e "\E[0;32m| Start SlackBuild $NAME-$VERSION |\E[0;0m"
echo -e "\E[0;32m+----------------------------------+\E[0;0m"

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 .

make PREFIX=/usr QMAKE=/opt/qt4/bin/qmake

make PREFIX=/usr DESTDIR=$PKG install

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a Changelog *.txt $PKG/usr/doc/$NAME-$VERSION
rm -rf $PKG/usr/share/doc

mkdir -p $PKG/usr/man/man1
cp -a $PKG/usr/share/man/man1/smplayer.1.gz $PKG/usr/man/man1/
rm -rf $PKG/usr/share/man

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

	echo "if [ -x /usr/bin/update-mime-database ]; then
  /usr/bin/update-mime-database /usr/share/mime &> /dev/null
fi" >> $PKG/install/doinst.sh
	echo "" >> $PKG/install/doinst.sh
	echo "if [ -x /usr/bin/update-desktop-database ]; then
  /usr/bin/update-desktop-database &> /dev/null
fi" >> $PKG/install/doinst.sh

strip --strip-unneeded $PKG/usr/bin/*

cd $PKG
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
