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

# Package version number:
VERSION=2.1pre23
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}

if [ "$ARCH" = "i386" ]; then
 SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
 SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "s390x" ]; then
 SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
 SLKCFLAGS="-O2"
fi

if [ ! -d $TMP ]; then
 mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf links-$VERSION
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="$SLKCFLAGS" \
/configure \
 --prefix=/usr \
 --sysconfdir=/etc \
 --enable-javascript \
 --disable-graphics \
 --without-x \
 --without-sdl \
 --without-gpm \
 $ARCH-slackware-linux
make -j2 || exit
mkdir -p $PKG/usr/bin
cat links > $PKG/usr/bin/links
chmod 755 $PKG/usr/bin/links
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
cp -a mailcap.pl $PKG/usr/doc/links-$VERSION
find $PKG/usr/doc/links-$VERSION -type f -exec chmod 644 {} \;
find $PKG/usr/doc/links-$VERSION -type d -exec chmod 755 {} \;
chmod 755 $PKG/usr/doc/links-$VERSION/mailcap.pl
( 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
)
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