#!/bin/bash

# htdig.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <stuart@armedslack.org>
# Bits taken from Mark Post's Slack390's prototype script.
# 08-Sep-2004

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/n/htdig
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="-O2 -march=armv3 -mtune=xscale" ;;
   powerpc) export ARCH_CFLAGS="-O2" ;;
   sparc)   export ARCH_CFLAGS="-O2" ;;
esac

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

# fix the configure script so it works with glibc 2.2.5 and higher
patch -p1 < $PORTCWD/configure.diff 
cp -vp /usr/share/libtool/config.* db/dist/

# Build:
./configure $ARCH-slackware-linux || failconfig

# The "-DHAVE_OSTREAM_H -DHAVE_IOSTREAM_H" is needed for gcc 3.2 and higher.
# The htdig configure script doesn't set them, so we have to do it.
make CXXFLAGS="-DHAVE_OSTREAM_H -DHAVE_IOSTREAM_H" || failmake

# Install:
make install INSTALL_ROOT=$PKG

# Default config file:
mv $PKG/opt/www/htdig/conf/htdig.conf $PKG/opt/www/htdig/conf/htdig.conf.new

# Profile script for $PATH@
mkdir -p $PKG/etc/profile.d
cp -a $CWD/profile.d/* $PKG/etc/profile.d

# Install docs:
mkdir -p $PKG/usr/doc/$PACKAGE-$VERSION
cp -a COPYING README contrib htdoc \
     $PKG/usr/doc/$PACKAGE-$VERSION

( cd $PKG/opt/www/htdig/bin
  rm -f htsearch
  ln -sf ../../cgi-bin/htsearch . )

# 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
