#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# Requirements: python, chmlib, pychm
# archmage.sf.net
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-archmage
rm -rf $PKG
mkdir -p $PKG/usr/man/man1

NAME=archmage
VERSION=0.1.9
ARCH=${ARCH:-i686}
BUILD=2bj

cd $TMP
rm -rf $NAME-$VERSION
tar xjvf $CWD/$NAME-$VERSION.tar.bz2
cd $NAME-$VERSION
chown -R root:root .
python setup.py install --root=$PKG
cp -a $PKG/usr/share/man/man1/* $PKG/usr/man/man1
rm -rf $PKG/usr/share/man
mv $PKG/etc/archmage/arch.conf $PKG/etc/archmage/arch.conf.new
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a COPYING INSTALL README $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/doinst.sh > $PKG/install/doinst.sh
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
