CWD=`pwd`
PKG=/tmp/package-kfiresaver3d
rm -rf $PKG
mkdir -p $PKG/opt/kde/share/applnk/System/ScreenSavers

VERSION=0.6
ARCH=${ARCH:-i486}
BUILD=2

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

cd /tmp
rm -rf kfiresaver3d-$VERSION
tar xjvf $CWD/kfiresaver3d-$VERSION.tar.bz2
cd kfiresaver3d-$VERSION
zcat $CWD/kfiresaver3d.memleak.diff.gz | patch -p1 --verbose
chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure --prefix=/opt/kde
make
make install prefix=$PKG/opt/kde
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd /tmp/package-kfiresaver3d
makepkg -l y -c n ../kfiresaver3d-$VERSION-$ARCH-$BUILD.tgz
