#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# Packager Michelino Chionchio - Thanks to www.slacky.eu
# Depends on qt4

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-freshmemory
NAME=freshmemory
VERSION=0.4
ARCH=${ARCH:-i686}
BUILD=1mch

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

cd $TMP
tar jxvf $CWD/fm-$VERSION.tar.bz2
cd fm-$VERSION
chown -R root:root .
/opt/qt4/bin/qmake -unix -o Makefile $NAME.pro

make release || exit 1

mkdir -p $PKG/usr/bin
install -m 755 -p "freshmemory" "$PKG/usr/bin/freshmemory"
strip "$PKG/usr/bin/freshmemory"

# doxygen || exit 1

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS COPYING ChangeLog README TODO $PKG/usr/doc/$NAME-$VERSION
#cp -a ./doc/doxy/html $PKG/usr/doc/$NAME-$VERSION

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

mkdir -p $PKG/usr/share/applications

cat << EOF > $PKG/usr/share/applications/$NAME.desktop
[Desktop Entry]
Name=Fresh Memory
GenericName=Educational tool for studying foreign words or terms
Comment=Educational tool for studying foreign words or terms from a specific domain
Exec=freshmemory
Type=Application
Categories=Qt;KDE;Education;Languages;
EOF

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
