#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi

PKG=$TMP/package-kpdftool
NAME=kpdftool
VERSION=0.22
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=3as

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

cd $TMP
unzip $CWD/$NAME-$VERSION.zip

echo "+-------------------------------------+"
echo "| Starting SlackBuild  $NAME-$VERSION   |"
echo "+-------------------------------------+"

cd $NAME-$VERSION
qmake
sed -i "s|-pipe -Wall -W -O2|-O2 -march=i486 -mtune=i686|g" Makefile
make
cd $TMP/$NAME-$VERSION
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a 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
mkdir -p $PKG/usr/bin
cp -f $TMP/$NAME-$VERSION/kpdftool  $PKG/usr/bin
mkdir -p $PKG/usr/share/applications/
cp  -f $CWD/kpdftool.desktop    $PKG/usr/share/applications
strip --strip-unneeded $PKG/usr/bin/*
cd $PKG
chown -R root:root .
requiredbuilder -y -v -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
