#!/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=gcc
export VERSION=3.3.6
export ARCH=arm
export BUILD=1
#export PKGSERIES=d
export PKGSERIES=../testing/packages/$PACKAGE-$VERSION
export SLACKPACKAGE=$PACKAGE-$VERSION-$ARCH-$BUILD.tgz

# Restore system. I can't build gcc inside Scratchbox 0.9.8 anymore :-(
# I haven't investigated why and I don't have time to either.
sboxsysrestore

# Ensure autoconf is installed properly by removing the 2.13 version and
# the latest
removepkg autoconf2.13 autoconf

# Ensure base ARM packages are installed first (which will reinstall autoconf):
slackbasedeps

# Ensure required packages are installed before proceeding:
# We need this version of autoconf to rebuild configure scripts after we've
# patched gcc -- but ONLY if we're building natively.  Scratchbox already has
# this.
# However, if we're *not* applying Debian's diff then we don't need to regenerate
# the configure scripts, thus autoconf2.13 is not required.
# But I always use Debian's diff now, so autoconf-2.13 is always required.
# Is this required for Debian's gcc-3.3.5?
#if [ ! -d /scratchbox ]; then
#   slackcheckpkgdeps autoconf2.13 || installpkg $PKGSTORE/../unsupported-extra/packages/autoconf2.13-*tgz
#fi

# Ensure build dependencies.  If we are building with Debian's diff
# (which we always do now for ARMedslack) we need dpkg-architecture
# which is contained within dpkg.  Even if we aren't using Debian source it does not
# hurt to have dpkg installed.
if [ ! -d /scratchbox ]; then
   slackcheckpkgdeps dpkg || installpkg $PKGSTORE/../unsupported-extra/packages/dpkg-*.tgz
   slackcheckpkgdeps dpkg || exit 99
fi

# Ensure the kernel headers package is installed.  These should always be installed
# but it doesn't hurt (unless you're in the middle of building something else)
# to do this:
( cd /usr/include
  rm -rf linux asm-arm asm-generic asm
  removepkg kernel-headers
  installpkg ~/tgzstash/d/kernel-headers-*.tgz
  ln -s asm asm-arm )

# Launch package build script:
( ./gcc.SlackBuild ) 2>&1 | tee build.log

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