#!/bin/bash

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

# 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/$PKGNAM
export PORTCWD=$PWD

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

# Temporary build locations:
export TMPBUILD=$TMP/build-$PKGNAM
export PKG=$TMP/package-$PKGNAM
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/$PKGNAM-*.{tgz,txt,asc}
fi

# Stop daemons/processes which tend to modify the contents of the filesystem:
altertrackprep

# Note: [a] we may not always want -O (chmod -R og-w)
#       [b] when building natively, ALTERTRACKOPTS is unset.
# ****  [c] This will touch ALL FILES ON YOUR FILESYSTEM!!  So only run this
#            build script on a disposable development box ****
#
# Launch the compile/install script:
cd $PORTCWD
$TRACKTYPE $ALTERTRACKOPTS \
           --notidy \
           --touch-filesystem-faster \
           -T$TMPBUILD \
           -b$PKGSTORE/$PKGSERIES \
           -OcQp $SLACKPACKAGE ./$PKGNAM.build $VERSION
