#!/bin/bash

# lynx.SlackBuild
# Heavily based on the original Slackware build script,
# Modified by Stuart Winter <stuart@armedslack.org> for the Slackware porting Project.
# 09-Jul-2004

# Version of source archive (not necessarily aligned with the Slackware package name);
# the Slackware package version matches the latest official patch level.
# The package version is stored in <archname>/build
SRCVER=2.8.6rel.5

# Record toolchain & other info for the build log:
slackbuildinfo

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

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

# Extract source:
tar jxvvf $CWD/${PKGNAM}${SRCVER}.tar.bz2
cd $PKGNAM*
slackhousekeeping

# Fix /usr/local paths:
zcat $CWD/lynx.path.diff.gz | patch -p1 --verbose || failpatch
# Apply recolorizing patch:
zcat $CWD/lynx.cfg.diff.gz | patch -p1 --verbose --backup || failpatch

# Configure:
./configure \
   --prefix=/usr \
   --sysconfdir=/etc \
   --datadir=/usr/share/lynx \
   --libdir=/usr/lib/lynx \
   --enable-default-colors \
   --with-screen=ncursesw \
   --enable-widec \
   --enable-gzip-help \
   --with-zlib \
   --enable-read-eta \
   --enable-scrollbar \
   --with-ssl \
   --enable-color-style \
   --enable-prettysrc \
   --enable-source-cache \
   --enable-nsl-fork \
   --enable-nls \
   --enable-persistent-cookies \
   --enable-vertrace \
   --disable-full-paths \
   --enable-addrlist-page \
   --enable-charset-choice \
   --enable-cjk \
   --enable-htmlized-cfg \
   --enable-justify-elts \
   --enable-locale-charset \
   --enable-externs \
   --enable-cgi-links \
   --enable-change-exec \
   --enable-exec-links \
   --enable-exec-scripts \
   --enable-internal-links \
   --with-bzlib \
   --build=$ARCH-slackware-linux || failconfig

# Build:
make -j4 || failmake

# Install into package:
mkdir -pm755 $PKG/usr/lib/lynx
make install DESTDIR=$PKG
make install-help DESTDIR=$PKG
make install-doc DESTDIR=$PKG

# Correct $DESTDIR brokenness:
( cd $PKG/usr/share/lynx/lynx_help
  rm -f COPYHEADER COPYING
  ln -vsf ../lynx_doc/COPYHEADER .
  ln -vsf ../lynx_doc/COPYING .
)
# Add documentation symlinks:
( mkdir -p $PKG/usr/doc/lynx-$VERSION
  cd $PKG/usr/doc/lynx-$VERSION
  ln -vsf /usr/share/lynx/lynx_doc .
  ln -vsf /usr/share/lynx/lynx_help .
)

# If necessary, start the fakeroot server so we can set file/dir ownerships:
start_fakeroot

# Apply generic Slackware packaging 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, slack644docs
slackdesc       # install slack-desc and doinst.sh
slackmp         # run makepkg -l y -c n

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