#!/bin/bash

source /usr/share/slackdev/buildkit.sh

# Package metadata:
export PACKAGE=glibc
export PKGSERIES=l
export VERSION=2.3.6
export BUILD=7
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 autoconf works by removing the pesky autoconf2.13 package
# and letting slackbasedeps reinstall the latest autoconf.
# autoconf2.13 is only needed (really) for building gcc and maybe
# minicom (but I haven't checked that recently).  For anything else
# it's just a pain.
#removepkg autoconf2.13 autoconf

# Ensure base ARM packages are installed first:
slackbasedeps

# If we're not inside scratchbox then we need dpkg to patch in the Debian
# glibc diff.
#if [ ! -d /scratchbox ]; then
#   slackcheckpkgdeps dpkg || installpkg $PKGSTORE/../armedslack-extra/packages/dpkg-*.tgz
#   slackcheckpkgdeps dpkg || exit 99
#fi
## Debian switched to using quilt to manage its glibc patches:
#slackcheckpkgdeps quilt || installpkg $PKGSTORE/../armedslack-extra/packages/quilt-*.tgz
#slackcheckpkgdeps quilt || exit 99

# We require ARMedslack's kernel-header package to be installed
# This package replaces Scratchbox's 2.6's headers which RMK stated
# on the armlinux mailing list, cause gcc3.3.2 build failure.
# Ensure the kernel headers package is installed:
# 17-May-2005: Note - for glibc-2.3.5 I have two pre-made 2.4 & 2.6 header
#              archives, so I don't need to faff around with these anymore as
#              there's no chance that my header archives will become polluted
#              during package building (which was the purpose of the code below).
#removepkg kernel-headers
#( cd /usr/include
#  rm -rf linux asm-arm asm-generic asm
#  slackcheckpkgdeps kernel-headers || installpkg $PKGSTORE/d/kernel-headers-*.tgz
#  # This isn't necessary, but I like to reassure myself:
#  ln -s asm asm-arm )

# I still need gcc 3.3 to build glibc on ARM:
#../sysdeps/generic/s_fmax.c:28: internal compiler error: in elim_reg_cond, at flow.c:3267
#Please submit a full bug report,
#with preprocessed source if appropriate.
#See <URL:http://gcc.gnu.org/bugs.html> for instructions.
#[ -d /scratchbox ] || upgradepkg $PKGSTORE/../testing/packages/gcc-3.3.5/*.tgz

# ARMedslack's gcc 3.4 is patched to fix the bug when building glibc:
#[ -d /scratchbox ] || upgradepkg $PKGSTORE/d/gcc*.tgz

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

# Now switch back to the latest compiler:
#[ -d /scratchbox ] || upgradepkg $PKGSTORE/d/gcc*.tgz

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