#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# Required to build: swt3, java-sdk >= 1.4.0, apache-ant, gtk
# Required to run: java >= 1.4.0
# WWW: http://www.rssowl.org
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it 

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

NAME=rssowl
SRCNAME=rssowl_1_2_3_src
VERSION=1.2.3
ARCH=${ARCH:-i686}
BUILD=1bj

cd $TMP
rm -rf $SRCNAME
rm -rf swt-M20060921-0945-gtk-linux-x86
rm -rf $PKG
mkdir -p $PKG/usr/{bin,lib,share/$NAME,share/applications,share/pixmaps}
tar xzf $CWD/$SRCNAME.tar.gz
unzip $CWD/swt-3.2.1-gtk-linux-x86.zip
mv swt-M20060921-0945-gtk-linux-x86/*.jar $SRCNAME/lib
mv swt-M20060921-0945-gtk-linux-x86/*.so $SRCNAME

cd $SRCNAME

( cd src
  ant deploy_linux
)

cp $NAME.jar  $PKG/usr/share/$NAME
cp img/rssowl.xpm $PKG/usr/share/pixmaps
cp -rf libswt*.so $PKG/usr/lib
cat $CWD/rssowl > $PKG/usr/bin/rssowl
chmod +x $PKG/usr/bin/rssowl $PKG/usr/lib/*

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -d : -f 1 | xargs -r strip --strip-unneeded
  find . | xargs file | grep "shared object" | grep ELF | cut -d : -f 1 | xargs -r strip --strip-unneeded
  find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs -r strip -g
)

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -ra doc/* $PKG/usr/doc/$NAME-$VERSION
cp -a $CWD/*.desktop $PKG/usr/share/applications

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cp -a $CWD/{*.SlackBuild,slack-desc} $PKG/usr/doc/$NAME-$VERSION

cd $PKG
chown -R root:root .
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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