#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://www.alwins-world.de/programs/kdesvn/
# Packagers Gohanz ( gohanz@infinito.it)
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-kdesvn
NAME=kdesvn
VERSION=0.14.3
ARCH=${ARCH:-i686}
BUILD=1as

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

cd $TMP
tar xjvf $CWD/$NAME-$VERSION.tar.bz2

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

cd $NAME-$VERSION
find . -perm 777 -exec chmod 755 {} \;
chown -R root:root .
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make || exit 1
make install DESTDIR=$PKG || exit 1

( 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/usr/doc/$NAME-$VERSION
cd ..
cp -a AUTHORS COPYING* ChangeLog GPL.txt INSTALL-cmake NEWS README TODO $PKG/usr/doc/$NAME-$VERSION

mv $PKG/usr/share/man $PKG/usr/
find $PKG/usr/man -type f -exec gzip -9 {} \;

cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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