
#!/bin/bash
#
# by Stuart Winter
#
# Building individual packages
# -----------------------------
# This script aids with building, unattended, the individual components.
# Before running this script, be sure to wipe the existing packages from the
# 'slackware/x' directory.  This helps determine if any of the builds failed/
# if there packages missing.
# It's a bit clunky, but we love it :)
#
# Build numbers
# -------------
# You can set specific build numbers by creating the
# package name inside build-nums dir:
# echo 2 > build-nums/xinit
#
# The way build numbers are handled in ARMedslack is that
# when building individual components (which is always the way 
# unless you're starting a port from scratch), you:
# 1.  Check if there's a file with the package base name inside the 'build-nums' directory
#     and create one if there isn't.
# 2.  Adjust the build number -- either increasing it if it's a package rebuild,
#     or resetting it to '1' if it's a version update.
# 
# The reason for this is that Slackware build numbers often differ from ARMedslack's
# since it takes AS a while to catch up, and there may have already been several
# rebuilds in Slackware before we even start looking at rebuilding the package.
#################################################################################

source /usr/share/slackdev/buildkit.sh
mkdir -p /tmp/build-x-logs

ORIGCWD=$PWD

function build () {
 INDIPKG=$1
 # If it's an upgrade then we delete any build number, otherwise if it's a rebuild,
 # we'd want to update the build number but I'll leave that until later :)
 if [ "$2" = "U" ]; then
    echo "This is tagged as a package UPGRADE/NEW PACKAGE, set build: 1."
    echo 1 > $ORIGCWD/build-nums/$INDIPKG
  elif [ "$2" = "R" ]; then
    # It's a rebuild & increment the build number:
    if [ -s $ORIGCWD/build-nums/$INDIPKG ]; then
       BN="$( head -n1 $ORIGCWD/build-nums/$INDIPKG )"
       let BN++
       echo "Tagged as a rebuild - will be build: $BN"
       echo $BN > $ORIGCWD/build-nums/$INDIPKG
      else
       # x11.SlackBuild assumes a build number of 1 if there isn't a build stamp file.
       # but if we've not already got a build number, but got a package then we need
       # to assume that this is going to be the 2nd build.
       # This is because we only started creating build stamp files much later in the 
       # evolution of X11 packaging for ARMedslack.       
       echo 2 > $ORIGCWD/build-nums/$INDIPKG
       echo "Tagged as a rebuild but has no build stamp file - setting as build: 2"
    fi
  fi
 # If we don't specify either U or R, then we leave the build number alone
 # since we may be just making some test packages.

 # Determine the section of X where we'll find the source:
 ~/armedslack/dbuild $( basename $( find $SLACKSOURCE/x/x11/src -name "*$INDIPKG*" -printf "%h\n" )) $INDIPKG 2>&1 | tee /tmp/build-x-logs/$INDIPKG.log
}

# Syntax:
#    build <pkgname> [U|R]
# U=Package version upgrade, so the .tgz will be at build '1'
#   do this for NEW packages also
# R=Package rebuild, so the .tgz will be build+1

build xf86-video-geode U


# Rebuild x server:
#echo 3 > build-nums/xorg-server
#~/armedslack/dbuild xserver xorg-server
