#!/bin/sh
CWD=`pwd`
PKG=/tmp/package-netpbm
VERSION=10.23
ARCH=alpha
BUILD=1

rm -rf $PKG
( cd /tmp
rm -rf netpbm-$VERSION
tar xzf $CWD/netpbm-$VERSION.tgz
cd netpbm-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 660 -exec chmod 644 {} \;
zcat $CWD/netpbm.config.diff.gz | patch -p1 --verbose
make
make package pkgdir=$PKG
( cd $PKG
  mkdir usr
  chown -R root.bin bin
  mv bin usr
  mv include usr
  mv lib usr
  mv link/* usr/lib
  rm -r link
  # Here we have another dummy who thinks man pages are obsolete.
  # Start by ditching the bogus empty man pages:
  rm -r man
  # Then add the extensive man pages that existed in the source
  # tarball until the current maintainer decided to remove them:
  # Finally, remove the perl script man replacement that truly *is* useless:
  rm -rf usr/bin/doc.url usr/bin/manweb
  # This stuff is also pretty useless:
  rm -rf misc README VERSION pkginfo
)
mkdir -p $PKG/usr/doc/netpbm-$VERSION 
cp -a README doc/COPYRIGHT.PATENT doc/GPL_LICENSE.txt doc/HISTORY doc/copyright_summary $PKG/usr/doc/netpbm-$VERSION
( 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
)
strip -g $PKG/usr/lib/*.a
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n ../netpbm-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee /tmp/netpbm.build.log
