#!/bin/bash

#######################################################################
# Program: trackbuild.lame
# Purpose: Launch the build script via slacktrack/altertrack
# Author : Stuart Winter <stuart@armedslack.org>
#######################################################################

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

# Ensure slacktrack/altertrack is installed:
which slacktrack >/dev/null 2>&1 || { echo "Cannot build without slacktrack" ; exit 1 ;}
TRACKTYPE=slacktrack

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

# Determine the CFLAGS for the known architectures:
case $PORTARCH in
   arm)     export SLKCFLAGS="-O2 -march=armv3 -mtune=xscale" ;;
   powerpc) export SLKCFLAGS="-O2" ;;
   sparc)   export SLKCFLAGS="-O2" ;;
   i486)    export SLKCFLAGS="-O2 -march=i486 -mcpu=pentium4" ;;
   *)       export SLKCFLAGS="-O2" ;;
esac

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

# If specified in slackdev.config, we'll delete the old copy of the
# package from our package store.
if [ "${DELETEOLDPKGS}" = "Yes" ]; then
   rm -f $PKGSTORE/$PKGSERIES/$PACKAGE-*.{tgz,txt}
fi

# Launch the compile/install script:
cd $PORTCWD
# We depend on the Slackware "libvorbis" package being installed for oggvorbis support.
$TRACKTYPE \
   -d "libvorbis" \
   --notidy \
   -T$TMPBUILD \
   -l$PORTCWD/build.log \
   -b$PKGSTORE/$PKGSERIES \
   -Qnp $SLACKPACKAGE "./$PACKAGE.build $VERSION"
