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

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-apache-ant
rm -rf $PKG
mkdir -p $PKG/etc/profile.d
mkdir -p $PKG/usr/{bin,lib/ant}

NAME=apache-ant
VERSION=1.7.0
ARCH=i586
BUILD=bj

cd $TMP
rm -rf $NAME-$VERSION
tar jxvf $CWD/$NAME-$VERSION-bin.tar.bz2
cd $NAME-$VERSION
chown -R root:root .
cp -rf * $PKG/usr/lib/ant

ln -sf /usr/lib/ant/bin/ant $PKG/usr/bin/ant
rm -rf $PKG/usr/lib/ant/bin/{*.bat,*.cmd}
rm -rf $PKG/usr/lib/ant/docs

( cd $PKG/etc/profile.d; tar xzvf $CWD/profile.d.tar.gz
  chmod 755 $PKG/etc/profile.d/*
)

mkdir -p $PKG/usr/doc/$NAME-$VERSION
mv $PKG/usr/lib/ant/{KEYS,LICENS*,README,NOTICE,WHATSNEW,INSTALL} \
   $PKG/usr/doc/$NAME-$VERSION

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

cd $PKG
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

