#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild 
# Requirements: libxml2,pygtk
# http://www.kerofin.demon.co.uk/rox/ROX-CLib.html
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it 

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

NAME=rox-clib
VERSION=2.1.10
CHOST=i486
ARCH=${ARCH:-i486}
BUILD=1bj

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

SOURCE=http://www.kerofin.demon.co.uk/rox/ROX-CLib-$VERSION.tar.gz

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

rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf $NAME
tar xzvf $CWD/ROX-CLib-$VERSION.tar.gz || exit 1
cd ROX-CLib
chown -R root:root .
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./AppRun --compile \
 --enable-shared \
 --disable-static \
 --disable-debug \
 --build=$CHOST-slackware-linux

mkdir -p -m 755 $PKG/usr/lib
cp -ra $TMP/ROX-CLib $PKG/usr/lib
rm -r $PKG/usr/lib/ROX-CLib/{src,.cvs*}
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -ra $TMP/ROX-CLib/Help/* $PKG/usr/doc/$NAME-$VERSION

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 --strip-debug

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 -v -y -c -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/ROX-CLib
 rm -rf $PKG
fi
