#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# http://qsynaptics.sourceforge.net/index.html
# http://www.kde-apps.org/content/show.php/TouchFreeze?content=61442
# Packager Zapotech
# http://www.slacky.eu

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package
NAME=touchfreeze
VERSION=0.2.3
CHOST=i486
ARCH=${ARCH:-i486}
BUILD=1fv
URL=http://qsynaptics.sourceforge.net
URLicon=http://upload.wikimedia.org/wikipedia/commons/9/96
rm -rf $PKG
mkdir -p $PKG

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
fi

if [ ! -e $NAME-$VERSION.tar.gz ]; then
 wget -c $URL/$NAME-$VERSION.tar.gz
fi
if [ ! -e Crystal_Clear_app_Synaptics_touchpad.png ]; then
 wget -c $URLicon/Crystal_Clear_app_Synaptics_touchpad.png
fi

cd $TMP
tar zxvf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
find . \( -perm 777 -o -perm 775 -o -perm 711 \) -exec chmod 755 {} \;
find . \( -perm 700 -o -perm 555 -o -perm 511 \) -exec chmod 755 {} \;
find . \( -perm 666 -o -perm 664 -o -perm 600 \) -exec chmod 644 {} \;
find . \( -perm 444 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
chown -R root:root .
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
/opt/qt4/bin/qmake
make || exit 1

mkdir -p $PKG/usr/bin
 cp touchfreeze $PKG/usr/bin
mkdir -p $PKG/usr/doc/$NAME-$VERSION
 cp -a AUTHORS COPYING README $PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/usr/share/icons
 cp $CWD/Crystal_Clear_app_Synaptics_touchpad.png $PKG/usr/share/icons
mkdir -p $PKG/usr/share/applications/
 cp $CWD/touchfreeze.desktop $PKG/usr/share/applications/

strip --strip-unneeded $PKG/usr/bin/touchfreeze

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/touchfreeze.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/touchfreeze.SlackBuild
requiredbuilder -v -y -s $CWD $PKG
cd $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP
fi
