#!/bin/sh
#
# Heavily based on the Slackware 12.0 SlackBuild

CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi

NAME=extutils-depends
VERSION=0.300
ARCH=noarch
BUILD=1ota
PKG=$TMP/package-$NAME
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG
fi
echo "+=============================================================================="
echo "| $NAME-$VERSION"
echo "+=============================================================================="
cd $TMP
# echo "Downloading $NAME-$VERSION"
# wget http://heanet.dl.sourceforge.net/sourceforge/gtk2-perl/$NAME-$VERSION.tar.gz
echo "Unpacking $NAME..."
tar xzf $CWD/ExtUtils-Depends-$VERSION.tar.gz
cd ExtUtils-Depends-$VERSION

perl Makefile.PL PREFIX=/usr i486-slackware-linux
make
make test
make install DESTDIR=$PKG

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
  Changes META.yml README MANIFEST \
  $PKG/usr/doc/$NAME-$VERSION

chown root:root -R $PKG
chmod 644 $PKG/usr/doc/$NAME-$VERSION/*
mv $PKG/usr/share/man $PKG/usr/
gzip -9 $PKG/usr/man/*/*
rm -rf $PKG/usr/share

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/ExtUtils-Depends-$VERSION
  rm -rf $PKG
  rm -rf $TMP/ExtUtils-Depends-$VERSION.tar.gz*
fi
