#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://www.nongnu.org/atool/
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-atool
rm -rf $PKG
mkdir -p $PKG

NAME=atool
VERSION=0.34.0
ARCH=${ARCH:-noarch}
BUILD=2bj

cd $TMP
rm -rf $NAME-$VERSION
tar xzvf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
chown -R root:root .
./configure --prefix=/usr && make
make install DESTDIR=$PKG
mv $PKG/usr/share/man $PKG/usr
rm -rf $PKG/usr/share
find $PKG/usr/man -type f -exec gzip -9 {} \;
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a COPYING ChangeLog NEWS README TODO $PKG/usr/doc/$NAME-$VERSION
cd $PKG
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 -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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