#!/bin/sh
# Build "links" for Slackware by <volkerdi@slackware.com>
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-links

# Package version number:
VERSION=2.1pre7
ARCH=i386
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

cd $TMP
tar xjvf $CWD/links-$VERSION.tar.bz2
cd links-$VERSION
chown -R root.root .
# We are configuring this without X as there are MANY browser choices for
# X already.  If you need a browser for X, either use something else or
# recompile.  :-)
CFLAGS="-O2 -march=i386 -mcpu=i686" \
./configure --prefix=/usr \
            --sysconfdir=/etc \
            --enable-javascript \
            --enable-graphics \
            --without-x \
            i386-slackware-linux
make
strip links
mkdir -p $PKG/usr/bin
cat links > $PKG/usr/bin/links
chmod 755 $PKG/usr/bin/links
chown -R root.bin $PKG/usr/bin
mkdir -p $PKG/usr/man/man1
cat links.1 | gzip -9c > $PKG/usr/man/man1/links.1.gz
mkdir -p $PKG/usr/doc/links-$VERSION
cp -a \
  AUTHORS BUGS COPYING INSTALL NEWS README SITES TODO doc/links_cal \
  $PKG/usr/doc/links-$VERSION
chmod 644 $PKG/usr/doc/links-$VERSION/*
cp -a mailcap.pl $PKG/usr/doc/links-$VERSION
chmod 755 $PKG/usr/doc/links-$VERSION/mailcap.pl
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/links-$VERSION-$ARCH-$BUILD.tgz

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/links-$VERSION
  rm -rf $PKG
fi