#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it
# Url: http://qps.kldp.net/

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
NAME=qps
VERSION=1.9.21
ARCH=${ARCH:-i486}
BUILD=1bj
PKG=$TMP/package-$NAME
rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf $NAME-$VERSION
tar xjvf $CWD/$NAME-$VERSION.tar.bz2 || exit 1
cd $NAME-$VERSION 
chown -R root:root .
sed -i "s|Icon=qps.xpm|Icon=/usr/share/pixmaps/qps.xpm|g" qps.desktop
qmake -o Makefile $NAME.pro || exit 1
sed -i "s|-pipe -w -O2|-O2 -march=i486 -mtune=i686|g" Makefile
make || exit 1

mkdir -p $PKG/usr/bin
cp -a qps $PKG/usr/bin

mkdir -p $PKG/usr/man/man1
cat qps.1 > $PKG/usr/man/man1/qps.1
gzip -9 $PKG/usr/man/man?/*

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a CHANGES COPYING README_INSTALL $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/usr/{share/applications,share/pixmaps}
cp -a *.desktop $PKG/usr/share/applications
cat icon/icon.xpm > $PKG/usr/share/pixmaps/qps.xpm 

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

cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
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
