#!/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 PACKAGE=x11
export PKGSERIES=x
export VERSION=6.9.0
export BUILD=5
export ARCH=arm
export SLACKPACKAGE=$PACKAGE-$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 none of the x11 packages are already installed:
( cd /var/log/packages && removepkg x11-* )

# Finally remove as much X stuff as I can. I'm not sure whether this
# helps but I occasionally have problems with mkfontscale, and I'd
# prefer to build without any existing X clutter:
#rm -rf /usr/X11R? /etc/X11
# Heh, no, don't do that otherwise it deletes tonnes of stuff in other 
# packages (lestif being one of them). *Doh*!
# Besides, the problems with mkfontscale were due to a bug in gcc.
# I've left this note in as a reminder incase I think about doing anything else
# stupid in the future :-)
#
# And it's nice to remove this too since it's also in aaa_elflibs and as such
# won't be removed by removepkg:
#rm -f /usr/lib/libfreetype.*

# Ensure build dependencies:
# This time I can't be bothered doing this just yet.  Before building X I suggest that
# you have a full system installed, cos that's what I'm doing.
slackcheckpkgdeps kernel-headers || installpkg $PKGSTORE/d/kernel-headers-*.tgz
slackcheckpkgdeps gpm            || installpkg $PKGSTORE/a/gpm-*.tgz
slackcheckpkgdeps expat          || installpkg $PKGSTORE/l/expat-*.tgz
slackcheckpkgdeps freetype       || installpkg $PKGSTORE/l/freetype-*.tgz
slackcheckpkgdeps libpng         || installpkg $PKGSTORE/l/libpng-*.tgz
slackcheckpkgdeps ncurses        || installpkg $PKGSTORE/l/ncurses-*.tgz
slackcheckpkgdeps fontconfig     || installpkg $PKGSTORE/x/fontconfig-*.tgz
slackcheckpkgdeps kernel-headers,gpm,expat,freetype,libpng,ncurses,fontconfig || exit 99

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

# Compress the build log:
bzip2 -9f build.$ARCH.log
