#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://kisaspellchecker.blogspot.com/
# Packager Michelino Chionchio - Thanks to www.slacky.eu

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-kisa
NAME=kisa
VERSION=0.43
CHOST=${CHOST:-i486}
ARCH=${ARCH:-i486}
BUILD=1mch

SLKCFLAGS="-O2 -march=i486 -mtune=i686"

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

cd $TMP
tar xvjf $CWD/$NAME-$VERSION.tar.bz2
cd $NAME-$VERSION
chown -R root:root .
export PATH=/opt/qt4/bin:$PATH

qmake -unix QMAKE_CFLAGS="$SLKCFLAGS" QMAKE_CXXFLAGS="$SLKCFLAGS" -o makefile kisa.pro 
make -j2 || exit 1

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a ChangeLog  COPYING README $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/usr/bin
cp -a bin/kisa $PKG/usr/bin
strip $PKG/usr/bin/*

mkdir -p $PKG/usr/share/pixmaps/
cp -a src/icons/kisa.png $PKG/usr/share/pixmaps/

mkdir -p $PKG/usr/share/applications/
cp -a kisa.desktop $PKG/usr/share/applications/

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
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
