#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# http://smile.tuxfamily.org
# Packager Andrea Sciucca Gohanz ( gohanz at infinito.it)
# http://www.slacky.it
#
# Required: Qt4.x.x , Mencoder/Mplayer,
# Exit on most errors
set -e


CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package/smile
NAME=smile
VERSION=0.9.10
ARCH=${ARCH:-i686}
BUILD=1as
SOURCE=http://download.tuxfamily.org/smiletool/$NAME-$VERSION.tar.gz

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

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

echo -e "\E[0;32m+------------------------+\E[0;0m"
echo -e "\E[0;32m| Start SlackBuild SMILE |\E[0;0m"
echo -e "\E[0;32m+------------------------+\E[0;0m"

cd $NAME

find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;

chown -R root:root .

mkdir -p $PKG/usr/bin
cat << EOF > $PKG/usr/bin/smile
#!/bin/bash
cd /usr/share/smile
exec /usr/share/smile/smile
EOF

chmod 755 $PKG/usr/bin/*

mkdir -p $PKG/usr/share/smile
( /opt/qt4/bin/qmake -unix -o Makefile smile.pro
make )

install -m 755  smile $PKG/usr/share/smile 

cp -a smile_*.{qm,ts} $PKG/usr/share/smile
cp -a -r {BIB_ManSlide,Interface} $PKG/usr/share/smile

mkdir -p $PKG/usr/share/applications
cat << EOF > $PKG/usr/share/applications/$NAME.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Smile
Name[it]=Smile
GenericName=Slideshow creator
GenericName[it]=Creatore di presentazioni
Comment=This is a program to simply create your own slideshow
Icon=/usr/share/pixmaps/logostart.png
Exec=smile
Terminal=false
StartupNotify=true
Categories=AudioVideo
EOF

mkdir -p $PKG/usr/share/pixmaps
cp -a $TMP/$NAME/Interface/Theme/logostart.png  $PKG/usr/share/pixmaps/logostart.png 

mkdir -p $PKG/usr/doc/$NAME-$VERSION
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

strip --strip-unneeded $PKG/usr/share/smile/smile

cd $PKG
ADD="mplayer >= 20090411-x86-1sl, qt4 >= 4.5.1-i686-1as" \
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
