#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# http://qwtplot3d.sourceforge.net/
# Packagers Gohanz ( gohanz@infinito.ii)
# http://www.slacky.eu

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-qwtplot3d
NAME=qwtplot3d
VERSION=0.2.7
ARCH=${ARCH:-i686}
BUILD=3as
QMAKE=/opt/qt4/bin/qmake

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

cd $TMP
tar xvzf $CWD/$NAME-$VERSION.tgz
cd $NAME

$QMAKE qwtplot3d.pro
make || exit 1

cd  examples
$QMAKE examples.pro
make || exit 1

mkdir -p $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

mkdir -p $PKG/usr/lib
mkdir -p $PKG/usr/include
mkdir -p $PKG/usr/doc/$NAME-$VERSION/examples

cp -f -d $TMP/$NAME/lib/* $PKG/usr/lib
cp -f $TMP/$NAME/include/* $PKG/usr/include
cp -f $TMP/$NAME/examples/bin/* $PKG/usr/doc/$NAME-$VERSION/examples

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

chown -R root:root .
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
