#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild 
# http://griffith.vasconunes.net/
# http://www.slacky.it

NAME=griffith
VERSION=0.9.8
VERSION_EXTRA=0.9.4
ARCH=${ARCH:-i686}
BUILD=1bj

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-griffith

SOURCE=http://download.berlios.de/griffith/$NAME-$VERSION.tar.gz

if [ ! -e $NAME-$VERSION.tar.gz ]; then
wget -c $SOURCE
fi

SOURCE=http://download.berlios.de/griffith/$NAME-extra-artwork-$VERSION_EXTRA.tar.gz

if [ ! -e $NAME-extra-artwork-$VERSION_EXTRA.tar.gz ]; then
wget -c $SOURCE
fi

cd $TMP
rm -rf $PKG
mkdir -p $PKG
rm -rf $NAME-$VERSION
tar xzvf $CWD/$NAME-$VERSION.tar.gz
tar xzvf $CWD/$NAME-extra-artwork-$VERSION_EXTRA.tar.gz

cd $NAME-$VERSION
chown -R root:root .
make install DESTDIR=$PKG

( cd ../$NAME-extra-artwork-$VERSION_EXTRA
  make install DESTDIR=$PKG
)

# Fix symlink:
( cd $PKG/usr/bin
  rm -rf griffith
  ln -sf ../share/griffith/lib/griffith griffith
)

( cd $PKG/usr/share/applications/
  sed -i "s|Icon=griffith.png|Icon=/usr/share/pixmaps/griffith.png|g" griffith.desktop
)

mv $PKG/usr/share/man $PKG/usr/
find $PKG/usr/man -type f | xargs -r gzip -9

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS ChangeLog COPYING INSTALL NEWS README THANKS TODO TRANSLATORS $PKG/usr/doc/$NAME-$VERSION

cd $PKG
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
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
