#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://www.etree.org/shnutils/shorten
# Packagers Gohanz ( gohanz@infinito.it)
# http://www.slacky.it

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

PKG=$TMP/package-shorten
NAME=shorten
VERSION=3.6.1
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=2as

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

cd $TMP
tar xvzf $CWD/$NAME-$VERSION.tar.gz

echo "+------------------------------------+"
echo "| Starting SlackBuild  $NAME-$VERSION |"
echo "+------------------------------------+"

cd $NAME-$VERSION
chown -R root:root .
find -perm 664 -exec chmod 644 {} \;
find -perm 600 -exec chmod 644 {} \;
find -perm 444 -exec chmod 644 {} \;
find -perm 400 -exec chmod 644 {} \;
find -perm 440 -exec chmod 644 {} \;
find -perm 777 -exec chmod 755 {} \;
find -perm 775 -exec chmod 755 {} \;
find -perm 511 -exec chmod 755 {} \;
find -perm 711 -exec chmod 755 {} \;
find -perm 555 -exec chmod 755 {} \;
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure --prefix=/usr \
--disable-debug \
--program-prefix="" \
--program-suffix="" \
--mandir=/usr/man \
--build=$TARGET-slackware-linux
make
make check
make install DESTDIR=$PKG

mkdir $PKG/usr/include
cp -a $TMP/$NAME-$VERSION/include/shorten.h $PKG/usr/include
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS COPYING ChangeLog NEWS README \
$PKG/usr/doc/$NAME-$VERSION
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION
cp -a $TMP/$NAME-$VERSION/doc/* $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

strip --strip-unneeded $PKG/usr/bin/*
gzip -9 $PKG/usr/man/man?/*

cd $PKG
chown -R root:root .
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$NAME-$VERSION
 rm -rf $PKG
fi
