#!/bin/sh
# Heavily based on the Slackware 11.0 SlackBuild
# http://psi-im.org/psi.affinix.com/?page=home
# Packager Gohanz ( gohanz@infinito.it )
# http://www.slacky.it

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi
PKG=$TMP/package-psi
NAME=psi
VERSION=0.10
ARCH=${ARCH:-i686}
BUILD=2as

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
cd $NAME-$VERSION
chown -R root:root .
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \

./configure --prefix=/usr
make

mkdir -p $PKG/usr/doc/$NAME-$VERSION

cp -a ChangeLog COPYING INSTALL README TODO $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/opt/kde/share/applnk/Internet/
cp -a $TMP/$NAME-$VERSION/psi.desktop $PKG/opt/kde/share/applnk/Internet/

mkdir -p $PKG/opt/kde/share/icons/hicolor/16x16/apps/
mkdir -p $PKG/opt/kde/share/icons/hicolor/32x32/apps/
mkdir -p $PKG/opt/kde/share/icons/hicolor/48x48/apps/

cp -a $TMP/$NAME-$VERSION/iconsets/system/default/icon_16.png $PKG/opt/kde/share/icons/hicolor/16x16/apps/psi.png
cp -a $TMP/$NAME-$VERSION/iconsets/system/default/icon_32.png $PKG/opt/kde/share/icons/hicolor/32x32/apps/psi.png
cp -a $TMP/$NAME-$VERSION/iconsets/system/default/icon_48.png $PKG/opt/kde/share/icons/hicolor/48x48/apps/psi.png

mkdir -p $PKG/usr/bin
mkdir -p $PKG/usr/share/psi/certs
mkdir -p $PKG/usr/share/psi/designer
mkdir -p $PKG/usr/share/psi/iconsets
mkdir -p $PKG/usr/share/psi/sound

cp -a $TMP/$NAME-$VERSION/src/psi $PKG/usr/bin
cp -a $TMP/$NAME-$VERSION/certs/* $PKG/usr/share/psi/certs
cp -a $TMP/$NAME-$VERSION/libpsi/psiwidgets/*.so $PKG/usr/share/psi/designer
cp -a -r $TMP/$NAME-$VERSION/iconsets $PKG/usr/share/psi/iconsets
cp -a -r $TMP/$NAME-$VERSION/iconsets $PKG/usr/share/psi
cp -a $TMP/$NAME-$VERSION/sound/* $PKG/usr/share/psi/sound

( 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
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/$NAME-$VERSION
  rm -rf $PKG
fi
