#!/bin/bash

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

source /usr/share/slackdev/buildkit.sh

# Package metadata:
export PKGNAM=gcc
export VERSION=${VERSION:-4.4.4}
# The architecture name component of the .tgz package file name:
export PKGARCH=${PKGARCH:-arm}
export BUILD=${BUILD:-1}
export PKGSERIES=${PKGSERIES:-d}
export SLACKPACKAGE=$PKGNAM-$VERSION-$PKGARCH-$BUILD.tgz

## ******************************************************************* ##
# For test packages - best to store in another location rather than
# overwriting the working copy in the main tree:
# export PKGSTORE=/tmp/
# mkdir -vpm755 $PKGSTORE/$PKGSERIES
## ******************************************************************* ##

# 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

# Needs:
# l/gmp
# l/mpfr
# a/infozip


# 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
#  installpkg $ORIGPATH/arm/kernel-headers-2.4.26-arm-1.tgz
#  ln -s asm asm-arm )

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

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

echo "*****************************************"
echo "*** gnat doesn't exist for ARM yet -- ***"
echo "*****************************************"
echo "*** rm -fv ~/tgzstash/d/gcc*gnat*    ****"
