#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://qtpfsgui.sourceforge.net

NAME=qtpfsgui
VERSION=1.9.2
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}fr

CWD=`pwd`
QT4PATH=/opt/qt4/bin

SOURCE=http://downloads.sourceforge.net/qtpfsgui/$NAME-$VERSION.tar.gz
if [ ! -e $CWD/$NAME-$VERSION.tar.gz ]; then
wget $SOURCE
fi

if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-$NAME

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf $NAME-$VERSION
tar xzf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
chown -R root:root .

sed --in-place= -e 's/DEFINES += I18NDIR=\\\\\\"$$I18NDIR\\\\\\"/DEFINES += I18NDIR=\\\\\\"\/usr\/share\/qtpfsgui\/i18n\\\\\\"/' project.pro

lrelease project.pro || exit 1
$QT4PATH/qmake PREFIX=$PKG/usr || exit 1
make || exit 1
make install DESTDIR=$PKG || exit 1

echo "====================================================================="
echo "Stripping...."
echo "====================================================================="

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

cd $TMP/$NAME-$VERSION
echo "====================================================================="
echo "Current dir.... = "`pwd`
echo "====================================================================="
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS Changelog INSTALL README TODO $PKG/usr/doc/$NAME-$VERSION
cp $CWD/$NAME.SlackBuild $PKG/usr/doc/$NAME-$VERSION/
chmod 644 $PKG/usr/doc/$NAME-$VERSION/*

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

# Build the package:
cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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