#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# http://www.trolltech.com/download/qsa.html
# Packagers Gohanz ( gohanz@infinito.it )
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-qsa-x11-free
NAME=qsa-x11-free
VERSION=1.1.4
TARGET=i686
ARCH=${ARCH:-i686}
BUILD=3as

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
./configure
make

mkdir -p $PKG/usr/lib/qt/lib
mkdir -p $PKG/usr/lib/qt/doc
mkdir -p $PKG/usr/lib/qt/examples/qsa
mkdir -p $PKG/usr/lib/qt/include
mkdir -p $PKG/usr/lib/qt/pics

cp -a /usr/lib/qt/lib/libqsa* $PKG/usr/lib/qt/lib
cd $TMP/$NAME-$VERSION/src/
find -iname '*.h' -exec cp {} $PKG/usr/lib/qt/include \;
cp -a -r $TMP/$NAME-$VERSION/doc $PKG/usr/lib/qt/
find $TMP/$NAME-$VERSION/examples -perm -755 -exec cp {} $PKG/usr/lib/qt/examples/qsa \;
cd $TMP/$NAME-$VERSION/examples
find -iname '*.png' -exec cp {} $PKG/usr/lib/qt/examples/qsa \;
find -iname '*.qs' -exec  cp {} $PKG/usr/lib/qt/examples/qsa \;
find -iname '*.qsa' -exec cp {} $PKG/usr/lib/qt/examples/qsa \;
cd $TMP/$NAME-$VERSION/src/ide/images/
cp -a * $PKG/usr/lib/qt/pics
rm /usr/lib/qt/lib/libqsa*

( 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/usr/doc/$NAME-$VERSION
cd $TMP/$NAME-$VERSION
cp -a INSTALL LICENSE.GPL README $PKG/usr/doc/$NAME-$VERSION
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION
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 $CWD/qsa-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP
fi
