#!/bin/bash

# arm/build
# Check package dependencies, set metadata and launch
# package build script.
# by Stuart Winter <stuart@armedslack.org>
#
source /usr/share/slackdev/buildkit.sh

# Package metadata:
export PKGNAM=x11
export VERSION=7.3
export ARCH=arm
export BUILD=1
export PKGSERIES=x
export SLACKPACKAGE=$PKGNAM-$VERSION-$ARCH-$BUILD.tgz

# Reset the ARM file system: restore it to the 'factory settings'
# as it were (this has no effect when building natively):
sboxsysrestore

# Ensure base ARM packages are installed first:
slackbasedeps

# Ensure $PKGNAM isn't already installed:
# Don't do this because the build order in x11.SlackBuild isn't 
# correct -- you need the X packages installed before this will work.
# To rebuilt entirely from scratch, you need to use the xorg build script
# and install onto the filesystem, THEN run x11.SlackBuild:
#( cd /var/log/packages
#  removepkg x11* )

# Ensure specific build dependencies (mainly libraries):
{ slackcheckpkgdeps libgsf   || installpkg $PKGSTORE/l/libgsf-*.tgz || exit 99 ; }
{ slackcheckpkgdeps libdrm   || installpkg $PKGSTORE/x/libdrm-*.tgz || exit 99 ; }
{ slackcheckpkgdeps mesa     || installpkg $PKGSTORE/x/mesa-*.tgz || exit 99 ; }
{ slackcheckpkgdeps dbus     || installpkg $PKGSTORE/l/dbus-*.tgz || exit 99 ; }
{ slackcheckpkgdeps dbus-qt3 || installpkg $PKGSTORE/l/dbus-qt3-*.tgz || exit 99 ; }
# And libwnck is required by compiz to compile gtk-window-decorator, but you
# don't need it to build xorg: build xorg first, then build libwnck,
# then rebuild xorg (or perhaps just compiz).
# So if it's not installed, let's try and install it but continue if the
# package file isn't available.
slackcheckpkgdeps libwnck || installpkg $PKGSTORE/l/libwnck-*.tgz 

# The build of X11 also looks for Mesa in /tmp.
# It's easier to do this than patch the Slackware configure scripts:
#rm -rf /tmp/Mesa*
if [ ! -d /tmp/Mesa-* ]; then
   echo "Unpacking ../mesa/mesa-compiled.tar.bz2 into /tmp - please wait"
   tar xf ../mesa/mesa-compiled.tar.bz2 -C /tmp/
 else
   echo Found /tmp/Mesa-* -- using that rather than unpacking archived copy
   sleep 10
fi

# Launch the package build script:
( ./$PKGNAM.SlackBuild $@ ) >& /dev/stdout | tee build.$ARCH.log

# Compress the build log:
bzip2 -v9f build.$ARCH.log
