#!/bin/bash

# xv.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <stuart@armedslack.org>
# 28-Dec-2004

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

# 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 SLKCFLAGS="-march=armv3 -mtune=xscale" ;;
   powerpc) export SLKCFLAGS="" ;;
   sparc)   export SLKCFLAGS="" ;;
   *)       export SLKCFLAGS="" ;;
esac

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

# Apply patches:
zcat $CWD/xv-3.10a.patch.gz | patch -p0 --verbose --backup --suffix=.orig || failpatch
bzcat $CWD/xv-3.10a-jumbo-fix-patch-20050410.txt.bz2 | patch -p1 --verbose --backup --suffix=.orig || failpatch
bzcat $CWD/xv-3.10a-jumbo-enh-patch-20050501.txt.bz2 | patch -p1 --verbose --backup --suffix=.orig || failpatch
zcat $CWD/xv.prefix.diff.gz | patch -p1 --verbose --backup --suffix=.orig || failpatch

# Build:
make CC="cc $SLKCFLAGS" -f Makefile.std || failmake

# Install:
mkdir -p $PKG/usr/X11R6/bin
install -m755 bggen vdcomp xcmap xv xvpictoppm \
              $PKG/usr/X11R6/bin
mkdir -p $PKG/usr/X11R6/man/man1
for page in docs/xv.man docs/bggen.man docs/xcmap.man docs/xvp2p.man ; do
  cat $page | gzip -9c > $PKG/usr/X11R6/man/man1/`basename $page .man`.1.gz
done

# Install docs:
mkdir -p $PKG/usr/doc/$PACKAGE-$VERSION
cp -a BUGS IDEAS INSTALL README README.jumbo README.pcd \
      $PKG/usr/doc/$PACKAGE-$VERSION
( cd docs
  cp -a penn.policy xv.blurb xv.ann xvdocs.ps \
        $PKG/usr/doc/$PACKAGE-$VERSION
  bzip2 -9 $PKG/usr/doc/$PACKAGE-$VERSION/xvdocs.ps )

# 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 (root:bin), slack644docs
slackdesc       # install slack-desc and doinst.sh

# Build the package:
if [ $PORTARCH = arm ]; then
   slackmp # run makepkg
  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
