#!/bin/sh
# Heavily based on the Slackware 13.37 SlackBuild
# http://zope.org/Products/ZopeInterface
# Packager Vincenzi Loris - slacky@slacky.it
# http://www.slacky.eu

CWD=`pwd`
TMP=${TMP:-/tmp/txz}
NAME=zope.interface
PKG=$TMP/package/$NAME
VERSION=3.3.0
ARCH=${ARCH:-i686}
BUILD=6sl

SOURCE=http://www.zope.org/Products/ZopeInterface/3.3.0/$NAME-$VERSION.tar.gz

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



if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
 mkdir -p $PKG
fi

cd $TMP
tar xzvf $CWD/$NAME-$VERSION.tar.gz || exit 1
cd $NAME-$VERSION
chown -R root:root .

python setup.py build || exit 1
python setup.py install --root=$PKG || exit 1

mkdir -p $PKG/usr/doc/$NAME-$VERSION/SlackBuild
cp README.txt $PKG/usr/doc/$NAME-$VERSION


( 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
  find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs strip -g 2> /dev/null
)


mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/SlackBuild/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/SlackBuild/$NAME.SlackBuild



cd $PKG
chown -R root:root $PKG
if [ -x "$(which requiredbuilder)" ]; then
requiredbuilder -y -v -s $CWD $PKG
fi
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.txz

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