#!/bin/bash

# netpbm.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <stuart@armedslack.org>
# 27-Jul-2004

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/$PKGSERIES/$PACKAGE
export PORTCWD=$PWD

# Temporary build locations:
export TMPBUILD=$TMP/build-$PACKAGE
export PKG=$TMP/package-$PACKAGE
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Determine the CFLAGS for the known architectures:
case $PORTARCH in
   arm)     export ARCH_CFLAGS="-march=armv3 -mtune=xscale" ;;
   powerpc) export ARCH_CFLAGS="" ;;
   sparc)   export ARCH_CFLAGS="" ;;
esac

# Extract source:
tar jxvvf $CWD/$PACKAGE-$VERSION.tar.bz2
cd $PACKAGE-$VERSION
slackhousekeeping

# Apply patches:
zcat $CWD/netpbm.config.diff.gz | patch -p1 --verbose

# Build:
# On ARM and any other arch for which svgalib cannot be built (thus not installed)
# you'll see: ppmsvgalib.c:14:17: vga.h: No such file or directory
# But ARMedslack now uses the svgalib-dummy package from Debian as a work-around.
make CC="gcc $ARCH_CFLAGS" || failmake
rm -rf $PKG # otherwise the installation fails; it likes to make the directory itself
make package pkgdir=$PKG 

# Move the bits into the right place:
( cd $PKG
  mkdir usr
  mv bin usr
  mv include usr
  mv lib usr
  mv link/* usr/lib
  rm -rf link
  # Here we have another dummy who thinks man pages are obsolete.
  # Start by ditching the bogus empty man pages:
  rm -rf man
  # Then add the extensive man pages that existed in the source
  # tarball until the current maintainer decided to remove them:
  ( cd usr && tar xjf $CWD/netpbm-manpages.tar.bz2 )
  # 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 )

# Install docs:
mkdir -p $PKG/usr/doc/$PACKAGE-$VERSION
cp -a README doc/COPYRIGHT.PATENT doc/GPL_LICENSE.txt doc/HISTORY doc/copyright_summary \
      $PKG/usr/doc/$PACKAGE-$VERSION

# Slackware policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown (root:bin), slack644docs
slackdesc       # install slack-desc and doinst.sh

# Build the package:
if [ $PORTARCH = arm ]; then
   . $PORTCWD/arm/pkger
 else
   makepkg -l y -c n $PKGSTORE/$PKGSERIES/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
fi

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links
