#!/bin/bash

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

# Package metadata:
export PKGNAM=mesa
export VERSION=${VERSION:-7.8.1}
export PKGARCH=${PKGARCH:-arm}
export BUILD=${BUILD:-1}
export PKGSERIES=${PKGSERIES:-x}
export SLACKPACKAGE=$PKGNAM-$VERSION-$PKGARCH-$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:
slackfailpkgdeps $PKGNAM || removepkg $PKGNAM

# Ensure specific build dependencies (mainly libraries):
# You need mesa to be installed before running X11.SlackBuild, but you
# can run it straight after grabbing the git repo of modular xorg and
# then running the build script.
#
{ slackcheckpkgdeps expat       || installpkg $PKGSTORE/l/expat-*.tgz   || exit 99 ; }
{ slackcheckpkgdeps libICE      || installpkg $PKGSTORE/x/libICE-*.tgz  || exit 99 ; }
{ slackcheckpkgdeps libSM       || installpkg $PKGSTORE/x/libSM-*.tgz   || exit 99 ; }
{ slackcheckpkgdeps libX11      || installpkg $PKGSTORE/x/libX11-*.tgz  || exit 99 ; }
{ slackcheckpkgdeps libXext     || installpkg $PKGSTORE/x/libXext-*.tgz || exit 99 ; }
{ slackcheckpkgdeps libXi       || installpkg $PKGSTORE/x/libXi-*.tgz   || exit 99 ; }
{ slackcheckpkgdeps libXmu      || installpkg $PKGSTORE/x/libXmu-*.tgz  || exit 99 ; }
{ slackcheckpkgdeps libXt       || installpkg $PKGSTORE/x/libXt-*.tgz   || exit 99 ; }
{ slackcheckpkgdeps libXxf86vm  || installpkg $PKGSTORE/x/libXxf86vm-*.tgz || exit 99 ; }
{ slackcheckpkgdeps glew        || installpkg $PKGSTORE/x/glew-*.t?z  || exit 99 ; }

# but not this one :-)
{ slackcheckpkgdeps libdrm      || installpkg $PKGSTORE/x/libdrm-*.tgz  || exit 99 ; }

# The Slackware X11 build scripts reference the Mesa source in /tmp.
# Since we're building a new Mesa here (but not in /tmp), we need to remember
# to wipe this, since ARMedslack's scripts either unarchive the compiled
# copy (generated from mesa.SlackBuild), or use an existing copy in /tmp.
# Since we're obviously rebuilding Mesa, let's wipe it out:
rm -rf /tmp/Mesa*

# Launch the package build script:
BUILDLOG=$( basename $SLACKPACKAGE .tgz ).build.log
( ./$PKGNAM.SlackBuild ) >& /dev/stdout | tee $BUILDLOG

# Compress the build log:
bzip2 -9f $BUILDLOG
