#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://netpbm.sourceforge.net
# Packagers Andrea Sciucca Gohanz ( gohanz@infinito.it)
# http://www.slacky.it

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp/tgz
fi
PKG=$TMP/package-netpbm
NAME=netpbm
VERSION=10.26.53
ARCH=${ARCH:-i686}
BUILD=1as

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

cd $TMP
tar xvf $CWD/$NAME-$VERSION.tgz

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

cd $NAME-$VERSION

cp -a $CWD/Makefile.config $TMP/$NAME-$VERSION/Makefile.config
make
make package pkgdir=$PKG/usr

( cd lib
  cp -a libnetpbm.a  libnetpbm.so $PKG/usr/lib
)

mkdir -p $PKG/usr/share/misc
mv  $PKG/usr/misc/* $PKG/usr/share/misc
rm -r $PKG/usr/misc

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a README $PKG/usr/doc/$NAME-$VERSION
cp -a $TMP/$NAME-$VERSION/doc/* $PKG/usr/doc/$NAME-$VERSION
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION

( cd $PKG/usr
  mv README VERSION pkginfo $PKG/usr/doc/$NAME-$VERSION
)

rm -r $PKG/usr/link
mv    $PKG/usr/bin/doc.url $PKG/usr/doc/$NAME-$VERSION

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

( 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
)

gzip -9 $PKG/usr/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
