#!/bin/bash

# arm/build
# Pre-build setup script for ARMedslack Linux's gcc
# by Stuart Winter <stuart@armedslack.org>
# Last modified: 03-Jan-05

source /usr/share/slackdev/buildkit.sh

# Package metadata:
export PACKAGE=gcc
export VERSION=3.4.6
export ARCH=arm
export BUILD=1
export PKGSERIES=d
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 base ARM packages are installed first:
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.
# Note: [03-Jan-05] I think the old scripts have been tidied up, so autoconf-2.13 is
#       no longer required.  I'm not 100% sure, and since it doesn't hurt to have
#       autoconf-2.13 installed temporarily, I'll continue with this for the time being.
if [ ! -d /scratchbox ]; then
   slackcheckpkgdeps autoconf2.13 || installpkg $PKGSTORE/../armedslack-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/../armedslack-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:
ORIGPATH=$PWD # store this location because we change to /usr/include below
( cd /usr/include
  rm -rf linux asm-arm asm-generic asm
  removepkg kernel-headers
# Incase I ever forget and delete them from the main ARMedslack tree, I've copied a working Kernel
# headers from Linux 2.4.26.  In the past I have found 2.6 headers break building gcc.
#  installpkg ~/tgzstash/d/kernel-headers-*.tgz
  installpkg $ORIGPATH/arm/kernel-headers-2.4.26-arm-1.tgz
  ln -s asm asm-arm )

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

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