#!/bin/bash

# traceroute.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <mozes@slackware.com>
# 14-Jul-2004

# 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

# Determine the CFLAGS for the known architectures:
case $ARCH in
   arm)     export SLKCFLAGS="-O2 -march=armv4t"
            export LIBDIRSUFFIX="" ;;
   *)       export SLKCFLAGS="-O2" ;;
esac

# Extract source:
tar xvvf $CWD/$PKGNAM-$VERSION.tar.gz
cd $PKGNAM-$VERSION || exit 1
slackhousekeeping

# Create package framework:
mkdir -pm755 $PKG/usr/{bin,man/man8,doc/$PKGNAM-$VERSION}

# Apply patches:
# This is Debian's.  Slackware uses an older Debian diff. ARMedslack doesn't cos 
# it won't compile without this newer diff - ./configure doesn't know about ARM Linux and
# it all goes down hill from there.
#zcat $PORTCWD/sources/traceroute_1.4a12-15.diff.gz | patch -p1

# Build: 
#make CCOPT="-g -Ilinux-include $SLKCFLAGS -D_GNU_SOURCE -Wall" || failmake
make $NUMJOBS VPATH=/usr/lib${LIBDIRSUFFIX} || make VPATH=/usr/lib${LIBDIRSUFFIX} || exit 1

# Start fakeroot server:
start_fakeroot

# Install binaries:
( cd traceroute 
  #install -m4711 traceroute $PKG/usr/bin
  install -vpm755 traceroute $PKG/usr/bin

  # Install man pages:
  install -pm644 traceroute.8 $PKG/usr/man/man8 )

# Install docs:
cp -a \
  COPYING* CREDITS ChangeLog README* TODO VERSION \
  wrappers \
  $PKG/usr/doc/$PKGNAM-$VERSION

# Slackware policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackchown      # root:bin binaries
slack644docs    # set correct perms on docs
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
