#!/bin/bash

# ifhp.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <stuart@armedslack.org>
# 19-Sep-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="-O1 -march=armv3 -mtune=xscale" ;;
   powerpc) export ARCH_CFLAGS="-O1" ;;
   sparc)   export ARCH_CFLAGS="-O1" ;;
esac

# Extract source:
tar zxvvf $CWD/$PACKAGE-$VERSION.tar.gz
cd $PACKAGE-$VERSION
slackhousekeeping

# Create package framework:
mkdir -p $PKG/{etc,usr/{libexec/filters,man/man8,doc/$PACKAGE-$VERSION}}

CFLAGS="$ARCH_CFLAGS" \
./configure \
   --prefix=/usr \
   --enable-nls \
   --sysconfdir=/etc || failconfig

# Make:
make || failmake

# Install:
install -m644 ifhp.conf $PKG/etc/ifhp.conf.new
( cd src && install -m755 ifhp textps wrapper $PKG/usr/libexec/filters )
( cd man && install -m644 *.8 $PKG/usr/man/man8 )
#( cd ../po
# This doesn't seem to work yet
#for file in *.gmo ; do
#  mkdir -p $PKG/usr/share/locale/`basename $file .gmo`/LC_MESSAGES
#  cat $file > $PKG/usr/share/locale/`basename $file .gmo`/LC_MESSAGES/ifhp.mo
#done )

# Install docs:
cp -a BUGS CHANGES INSTALL LICENSE MIRRORS README README.GhostScriptSecurityProblem \
      README.UTILITYPROGRAMS VERSION HOWTO/IFHP-HOWTO.html HOWTO/*.jpg \
      $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
