#!/bin/sh
#
# build-ch6-toolchain-2.3.0.sh
#
# Build Pure LFS Toolchain Chapter 6
# ----------------------------------
#
# Authors:  Ryan Oliver  (PHA)(ryan.oliver@pha.com.au)
#           Greg Schafer (ZIP)(gschafer@zip.com.au)
#
# Created:  2003-01-27
#
#                      =========================================================
# Modified: 2003-05-09 - Added calls to function remove_dir
#                        Enabled by specifying REMOVE_PKGDIR=Y in plfs-config
#                        Erik-Jan Post <ej.lfs@xs4all.nl>
#                      =========================================================
#           2003-05-05 - If using --enable-version-specific-runtime-libs, 
#                        a symlink is now created in /usr/include 
#                        pointing to our c++ headers
#                      =========================================================#           2003-05-03 - gcc mmap configure patch now only applied for
#                        gcc-3.2.x
#                      - optionally configue gcc with --program-suffix
#                        if USE_PROGRAM_SUFFIX is set "Y" in build-init
#                      - Create symlinks for gcc etc if above option is used 
#                      =========================================================
#           2003-04-27 - ${GCC_VER} cannot be trusted to supply the actual gcc
#                        version (especially for CVS builds).
#                        Where required the version is now taken from
#                        gcc/version.c
#                      =========================================================
#           2003-04-22 - changes to glibc to cater for NPTL
#                        --with-tls option added if using NPTL
#                        From Zack Winkle's <winkie@linuxfromscratch.org> 
#                        NPTL hint 
#                        ( http://hints.linuxfromscratch.org/hints/nptl.txt )
#                      =========================================================
#           2003-04-20 - Add option to use NPTL
#                      - check for existence of linuxthreads dirs in glibc
#                        ( provided with CVS glibc )
#                        Linuxthreads is only installed if it is not present,
#                        or removed if present for NPTL builds
#                      - gcc specfile location ${SPECFILE} is determined from 
#                        gcc -v throughout the build now.
#                      =========================================================
#           2003-04-19 - Change version number to 2.3.0
#                      =========================================================
#           2003-04-08 - Change version number to 2.2.7
#                      =========================================================
#           2003-04-03 - Change version number to 2.2.6
#                      - Fix bug with devfs detection
#                        Thomas Kalla <xTx@gmx.de>
#                      =========================================================
#           2003-04-02 - Change version number to 2.2.5
#                      - Changes to specfile/linux.h edits to allow for
#                        --dynamic-linker being ld.so.1 on certain archs
#                        Florian Engelhardt <f.engelhardt@gmx.net>
#                      - Reverted the chown -R of / from 2.2.4 
#                        ( Rides roughshod over ${SCRIPTS} ${TARBALLS} etc )
#                        This will have to be revisited later
#                      =========================================================
#           2003-03-31 - Change version number to 2.2.4
#                 
#                      Following from Nicolas Roeser <n-roeser@gmx.net>
#                      (with some modifications), Thanks Nico
#                      - Chown the chrooted tree to 0:0 at the beginning
#                      - Replace the /etc/mtab symlink by a real /etc/mtab file
#                      - Check for devpts (If not using devfs)
#                        DEVPTS is set to Y or N accordingly
#                        and exported so it can be used later and by other
#                        scripts called.
#                        If devpts is used outside the chroot, mount it inside
#                        the chroot, too. This is needed at least for the
#                        binutils test.
#                      - Create log directories if they do not exist
#                      - Get rid of the /usr/{doc,info,man} symlinks
#                      - Create /etc/localtime symlink after glibc installation
#                      =========================================================
#           2003-03-28 - Change version number to 2.2.3
#                      - Add support for powerpc
#                        Update case statement to set ARCH to match build-ch5 
#                        script, even though it isn't used here.
#                        Florian Engelhardt <F.Engelhardt@gmx.net>
#                      =========================================================
#           2003-03-27 - Change version number to 2.2.2
#                      =========================================================
#           2003-03-24 - fix binutils logging for ldscript installation and
#                      - pass location of stage1 install binary to install of
#                        ldscripts (shouldn't be necessary, but cannot hurt)
#                        Andrew Fyfe <a.fyfe@tiscali.co.uk>
#                      - version specific runtime libs now an option for final
#                        gcc build. Set USE_VER_SPEC_RT_LIBS to Y in build-init
#                      - Add mounting of /dev/pts if devfs not used
#                        Michael Labuschke <michael@labuschke.de>
#                      - fix naming of gcc-3.2.2.mmap_test patch (had -mmap :-/)
#                        Archaic <archaic@indy.rr.com>
#                      =========================================================
#           2003-03-22 - Change version number to 2.2.2-beta1
#                      - remove debug symbols from gcc/libstdc++
#                        (seds mimic GS's patch, works for all gcc-3.2 versions)
#                      - hardcode filename for mmap test patch 
#                        (works for all gcc-3.2 versions, 3.2.2 latest to date)
#                      =========================================================
#           2003-03-18 - Change version number to 2.2.1
#                      - Remove gcc/configure hack. Now uses patch
#                        gcc-3.2.2-mmap_test.patch
#                        Greg Schafer and
#                        Donald Smith <dss-lfs@cfl.rr.com>
#           2003-03-17 - Add the option to skip bootstrap of gcc during the
#                        second build.
#                        Set NOBOOTSTRAP=Y in build-init-2.2.1.sh
#                      - Add gcc/configure hack to attempt to avoid race
#                        race conditions in mmap tests when ld.so.cache
#                        < 1 page (GS)
#                      - Added MAKEDEV. 
#                        Script checks for a mounted devfs. If found it sets 
#                        DEVFS=Y (for later use). If not MAKEDEV is used for
#                        creating devices
#           2003-03-15 - Numerous bugfixes
#           2003-03-11 - unpack_tarball ( build-init-2.2.1.sh ) now
#                        a) checks the tarball to determine where it will 
#                           unpack the package source to. Returns this as the
#                           environment var PKGDIR
#                        b) removes the target directory ( ${PKGDIR} ) before
#                           unpacking the tarball
#                        PKGDIR is now used throughout the script(s) when 
#                        cd'ing into the packages source tree.
#                      - move TZ and LC_ALL defs to build-init-2.2.1.sh
#                      =========================================================
#           2003-03-10 - Change version number to 2.2.0 in line with other
#                        scripts
#                      - source build-init-2.2.0.sh
#                      - change LFS from / to ''
#                      =========================================================
#           2003-03-07 - Change version number to 2.1.0
#                      - Create universal binutils build. Should handle both FSF
#                        and HJL binutils.
#                      - check_binutils () (see build-init-2.1.0.sh)
#                        The check_binutils function is called during the first
#                        binutils build to determine cetain features, and if 
#                        necessary patch ld/Makefile.in.
#                      - Binutils final build
#                        The build now adjusts itself depending on
#                        whether or not a 'configure-host' target exists in
#                        Makefile
#                      - added some logic to the specfile editing and srcdir
#                        removing.
#                      =========================================================
#           2003-03-07 - Change version number to 2.0.0
#                      - Common functions between both ch5 and 6 scripts, along
#                        with the package version definitions, have been moved
#                        to the script 'build-init.sh'
#                        This is sourced after the definition of LFS and SCRIPTS
#                      =========================================================
#           2003-03-02 - Change version number to 1.2.0
#                      - Gcc 
#                      - install-no-fixedincludes no longer used,
#                        reverting back to nofixincludes patch functionality
#                        ( Provided by a grep -Ev statement )
#                      - Changing of NATIVE_SYSTEM_HEADER_DIR now redundant
#                        as fixinc.sh script no longer runs.
#                      - no longer require separate install if libstc++-v3
#                        headers
#                      =========================================================
#           2003-03-01 - Change version number to 1.1.2
#                      - Logging Enhancements.
#                      - code minimised between max_log_init and min_log_init.
#                      - max_log_init sets LOGNAME ( passed log with appended
#                        timestamp  eg gcc-init.log-yyyymmdd )
#                      - min_log_init now only takes the log directory as an 
#                        argument. Sets LOGFILE (prepends the log directory
#                        onto LOGNAME) 
#                      - LOGFILE now used throughout the script as the sole
#                        logging target.
#                      =========================================================
#           2003-02-28 - Version number set to 1.0.0
#                      - Numerous changes before this date folded in from
#                        ch5 build script
#
# Modified from
# buildch6.sh
# Ryan Oliver (PHA), 2003-01-27
# (ryan.oliver@pha.com.au)
#
# Builds our final LFS from a chroot gaol
#
# Don't just run this script blindly, you will have to
# patch gcc with the reqd LFS patches for the gcc version
# (will add that at a later date... maybe :-) ),
# also the versions of the packages here could vary from
# what you are using so check...
#

# Set SELF to be name of script called, minus any path...
SELF=$(basename ${0})
echo "Running ${SELF}"
VERSION="2.3.0"
DATE=$(date +'%Y%m%d')

# Set LFS to suit your build tree
export LFS=''

# Set SRC for your sourcedir, TARBALLS for where you store
#  your tarballs

export SRC=${LFS}/usr/src
export TARBALLS=${LFS}/usr/tarballs
export PATCHES=${LFS}/usr/patches
export SCRIPTS=${LFS}/usr/scripts

# Logging
# Set for base of logging tree
export LOGS=${LFS}

export CONFLOGS=${LOGS}/conflogs
export BUILDLOGS=${LOGS}/buildlogs
export INSTLOGS=${LOGS}/instlogs
export TESTLOGS=${LOGS}/testlogs

# Source Functions and definitions
. ${SCRIPTS}/build-init-2.3.0.sh

set +x
unset LD_LIBRARY_PATH
unset LD_PRELOAD

export LDFLAGS="-s"

# set path, /bin first so we pickup our symlinked
# bash first
# ( Commented as PATH is set during chroot)
#export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/stage1/sbin:/stage1/bin

# Try to chown all files another time (perhaps we were not a root user while
#  installing ch5 from outside the chroot)
# chown -R 0:0 /

# mount the proc filesystem and create a real /etc/mtab file
mount proc /proc -t proc
cp /proc/mounts /etc/mtab && chmod 644 /etc/mtab

# If /dev is fstype devfs, set DEVFS=Y
# If not, mount /dev/pts if used outside chroot (not req'd with devfs)

cat /proc/mounts | grep ' devfs ' > /dev/null 2>&1 &&
{
   export DEVFS=Y
} || {
   export DEVFS=N

   # Mount devpts on /dev/pts if it is mounted outside the chroot.
   # We put the output of the first command into a variable so we don't need the
   # /dev/null device (which may not yet exist) for redirecting the output of 
   # grep into it

   DEVPTS=`cat /proc/mounts | cut -d\  -f3 | grep "^devpts$"`
   test -z "${DEVPTS}" && DEVPTS=N || DEVPTS=Y
   export DEVPTS    # for later usage
   test Y = "${DEVPTS}" && mount devpts /dev/pts -t devpts
}

echo '##### Pure-LFS chapter 6 builder version: '${VERSION}
echo ' o Checking for needed sources and tarballs'

check_tarballs
check_patches

# If we are using devfs, dont use MAKEDEV
test Y != "${DEVFS}" &&
{
   ### MAKEDEV ###
   LOG="MAKEDEV.log"
   max_log_init MAKEDEV ${MAKEDEV_VER} "" ${CONFLOGS} ${LOG}
   bzcat <${TARBALLS}/MAKEDEV-${MAKEDEV_VER}.bz2 >/dev/MAKEDEV &&
   echo " o unpacked OK" &&
   cd /dev &&
   chmod 754 MAKEDEV &&
   ./MAKEDEV -v generic-nopty > ${LOGFILE} 2>&1 &&
   echo " o Devices created OK" || echo "XXX Check /dev for errors XXX"
}

#
# Glibc
#
# Need to specify to configure the location of our new binutils
# ( avoid issues with GAS_HIDDEN )
#

BUILD_OK="${REMOVE_PKGDIR}"

cd ${SRC}
LOG="glibc-final.log"

unpack_tarball glibc-${GLIBC_VER} &&
cd ${PKGDIR}
OLDPKGDIR=${PKGDIR}
test "Y" = "${USE_NPTL}" &&
{
   # remove linuxthreads dirs if they exist
   # (CVS source contains linuxthreads)
   test -d linuxthreads && 
      rm -rf linuxthreads*
   unpack_tarball nptl-${NPTL_VER}
   extra_conf_options="--with-tls"
} || {
   # if it doesn't exist, unpack linuxthreads
   test -d ./linuxthreads &&
   test -d ./linuxthreads_db ||
   unpack_tarball glibc-linuxthreads-${GLIBC_VER}
}
PKGDIR=${OLDPKGDIR}

cd ${SRC}/${PKGDIR}

# create ld.so.conf for new glibc
touch /etc/ld.so.conf

test -d ${SRC}/glibc-${GLIBC_VER}-final-build &&
   rm -rf ${SRC}/glibc-${GLIBC_VER}-final-build

mkdir ${SRC}/glibc-${GLIBC_VER}-final-build
cd ${SRC}/glibc-${GLIBC_VER}-final-build

max_log_init Glibc ${GLIBC_VER} final ${CONFLOGS} ${LOG}
CFLAGS="-O2 -pipe" ../${PKGDIR}/configure --prefix=/usr \
   --disable-profile --enable-add-ons \
   --with-headers=/usr/include ${extra_conf_options} \
   --mandir=/usr/share/man --infodir=/usr/share/info \
      >> ${LOGFILE} 2>&1 &&
echo " o Configure OK" &&

min_log_init ${BUILDLOGS} &&
make \
   >> ${LOGFILE} 2>&1 &&
echo " o Build OK" &&

min_log_init ${TESTLOGS} &&
make check \
   >>  ${LOGFILE} 2>&1 &&

########################################################################
# Break the conditional execution to let me continue
########################################################################
if [ $? -eq 0 ] ; then
    echo " o Test OK"
else
    echo "XXXXXX glibc make check NOT OK - CHECK LOGS (${LOG}) XXXXXX"
    exit 1
fi

   echo "-Installing Glibc" &&
   min_log_init ${INSTLOGS} &&
   make install \
      >> ${LOGFILE} 2>&1 &&
echo " o install OK" &&

   make localedata/install-locales \
      >>  ${LOGFILE} 2>&1 &&
echo " o install-locales OK" &&
ln -sf ../usr/share/zoneinfo/${TZ} /etc/localtime &&

BUILD_OK="${BUILD_OK}Y" &&
echo " o ALL OK" || echo "XXXXXX NOT OK - CHECK LOGS (${LOG}) XXXXXX"

cd ${SRC}
test YY = "${BUILD_OK}" && {
   remove_dir ${SRC}/glibc-${GLIBC_VER}-final-build
   remove_dir ${SRC}/glibc-${GLIBC_VER}
}

# pick up the saved BUILD_OK-status of binutils. Should be Y12
BUILD_OK=`cat build_ok.tmp`
rm -f build_ok.tmp

# Install ldscripts created after initial shared binutils build
# Will point ld at /lib and /usr/lib
cd ${SRC}
LOG="binutils-init-ldscripts.log"
cd binutils-${BINUTILS_VER}-init-build
cd ld
max_log_init Binutils ${BINUTILS_VER} "Initial ( shared ) Pass 2 - installing linker scripts" \
   ${INSTLOGS} ${LOG}

make INSTALL=/stage1/bin/install install-data-local \
   >> ${LOGFILE} 2>&1 &&

BUILD_OK="${BUILD_OK}3" &&
echo " o ALL OK" || echo "XXXXXX NOT OK - CHECK LOGS (${LOG}) XXXXXX"

cd ${SRC}
test Y123 = "${BUILD_OK}" && {
   remove_dir ${SRC}/binutils-${BINUTILS_VER}-init-build
   remove_dir ${SRC}/binutils-${BINUTILS_VER}
}

BUILD_OK="${REMOVE_PKGDIR}"

cd ${SRC}

# Change dynamic linker definition in gcc specs file
# to point at our new dynamic linker in /lib.
#

TGT_TRIPLE=`/stage1/bin/gcc -dumpmachine`
SPECFILE=`/stage1/bin/gcc -v 2>&1 | grep specs | sed 's@.* @@'`
grep /stage1/lib ${SPECFILE} > /dev/null 2>&1 &&
{
   cp ${SPECFILE} ./XX
   sed -e 's@/stage1/lib/ld-linux.so.2@/lib/ld-linux.so.2@g' \
       -e 's@/stage1/lib/ld.so.1@/lib/ld.so.1@g' \
       -e 's@/stage1/lib64/ld-linux.so.2@/lib64/ld-linux.so.2@g' \
       -e 's@/stage1/lib64/ld.so.1@/lib64/ld.so.1@g' ./XX > ${SPECFILE}
   rm -f ./XX
}

# Set ARCH so we can script the config/${ARCH}/linux.h stuff
CPU=`echo ${TGT_TRIPLE} | awk -F\- '{print $1}'`

# $ARCH is not used in this script for the gcc build.
# (no need to modify the config/${ARCH}/linux.h file )
# This case statement may be removed in the future.

case ${CPU} in
   i?86 )
      ARCH=i386
   ;;

   sparc* )
      ARCH=sparc
   ;;

   powerpc )
      ARCH=rs6000
   ;;

   alpha* )
      ARCH=alpha
   ;;
   * )
      echo "${CPU} hasn't been included in this script yet..."
      echo "Please update me, and dont forget to contact the authors with your changes :-)"
   ;;
esac

cd ${SRC}
LOG="binutils-final.log"
unpack_tarball binutils-${BINUTILS_VER} &&

# Determine whether this binutils requires
# 'make configure-host' and whether
# ld search path can be set with --with-lib-path.
# Returned in ${BINUTILS_CONF_HOST} and
# ${BINUTILS_WITH_LIB_PATH} respectively

# TODO: check for architecture specific patches in check_binutils
#       ( alpha )
check_binutils 

test -d ${SRC}/binutils-${BINUTILS_VER}-final-build && 
  rm -rf ${SRC}/binutils-${BINUTILS_VER}-final-build

mkdir binutils-${BINUTILS_VER}-final-build
cd binutils-${BINUTILS_VER}-final-build

max_log_init Binutils ${BINUTILS_VER} "final (shared)" ${CONFLOGS} ${LOG}
CFLAGS="-O2 -pipe" ../${PKGDIR}/configure --prefix=/usr \
   --mandir=/usr/share/man --infodir=/usr/share/info \
   >> ${LOGFILE} 2>&1 &&
{
   test Y != "${BINUTILS_CONF_HOST}" ||
   {  
      echo -e "\nmake configure-host\n${BRKLN}" >> ${LOGFILE}
      make configure-host >> ${LOGFILE} 2>&1 
   }
} &&
echo " o Configure OK" &&

min_log_init ${BUILDLOGS} &&
make LDFLAGS="-s" \
   >> ${LOGFILE} 2>&1 &&
echo " o Build OK" &&

min_log_init ${TESTLOGS} &&
make -k check \
   >>  ${LOGFILE} 2>&1 &&
echo " o Test OK" &&

min_log_init ${INSTLOGS} &&
make install \
   >> ${LOGFILE} 2>&1 &&
   rm -f /usr/lib/libiberty.a &&

BUILD_OK="${BUILD_OK}Y" &&
echo " o ALL OK" || echo "XXXXXX NOT OK - CHECK LOGS (${LOG}) XXXXXX"

cd ${SRC}
test YY = "${BUILD_OK}" && {
   remove_dir ${SRC}/binutils-${BINUTILS_VER}-final-build
   remove_dir ${SRC}/binutils-${BINUTILS_VER}
}

#
# Gcc build
# Now we build cc and c++ against our new glibc
# and new binutils
#

BUILD_OK="${REMOVE_PKGDIR}"

cd ${SRC}
LOG=gcc-final.log

unpack_tarball gcc-${GCC_VER} 
cd ${PKGDIR}

#3.0 20030427
# Cannot trust ${GCC_VER} to supply us with the correct
# gcc version (especially if cvs).
# Grab it straight from version.c 
actual_gcc_ver=`grep version_string gcc/version.c | \
         sed 's@.* = "\([0-9.]*\).*@\1@'`

# Check if mmap configure patch is required
case "${actual_gcc_ver}" in
   3.2* )
      # Fix mmap test for race conditions when ld.so.cache < 1 page
      # patch applies to all gcc-3.2 versions (20030322 - latest is 3.2.2)
      apply_patch gcc-3.2.2.mmap_test
   ;;
esac

cd ${SRC}/${PKGDIR}/gcc

# Dont run fixincludes 
# ( Following mimics the nofixincludes patch )
# Also avoid debug symbols in libgcc2

test -f Makefile.in-ORIG ||
   cp Makefile.in Makefile.in-ORIG

grep -Ev '(README| ./fixinc.sh )' Makefile.in-ORIG | \
sed 's@LIBGCC2_DEBUG_CFLAGS = -g@LIBGCC2_DEBUG_CFLAGS =@g' \
   > Makefile.in

# Avoid debug symbols in libstc++
cd ${SRC}/${PKGDIR}/libstdc++-v3
test -f configure-ORIG ||
   cp configure configure-ORIG
sed s@DEBUG_FLAGS=\'-g\'@DEBUG_FLAGS=\'\'@g configure-ORIG > configure

test -d ${SRC}/gcc-${GCC_VER}-final-build &&
   rm -rf ${SRC}/gcc-${GCC_VER}-final-build

mkdir ${SRC}/gcc-${GCC_VER}-final-build &&
cd ${SRC}/gcc-${GCC_VER}-final-build &&

# Set in build-init to enable version specific runtime libs
extra_conf_options=''
test Y = "${USE_VER_SPEC_RT_LIBS}" &&
   extra_conf_options='--enable-version-specific-runtime-libs'

test Y = "${USE_PROGRAM_SUFFIX}" &&
{
   test -z "${extra_conf_options}" &&
   {
      extra_conf_options="--program-suffix=-${actual_gcc_ver}"
   } || {
      extra_conf_options="${extra_conf_options} --program-suffix=-${actual_gcc_ver}"
   }
}

max_log_init Gcc ${GCC_VER} "final (shared)" ${CONFLOGS} ${LOG}
CFLAGS="-O2 -pipe" \
   ../${PKGDIR}/configure --prefix=/usr \
   --enable-languages=c,c++ --enable-shared --enable-threads=posix \
   --enable-__cxa_atexit ${extra_conf_options} \
   --mandir=/usr/share/man --infodir=/usr/share/info \
      >> ${LOGFILE} 2>&1 &&
echo " o Configure OK" &&

min_log_init ${BUILDLOGS} &&
test Y = "${NOBOOTSTRAP}" &&
{
   make LDFLAGS="-s" \
      >> ${LOGFILE} 2>&1 
} || {
   make BOOT_LDFLAGS="-s" BOOT_CFLAGS="-O2 -pipe" \
      STAGE1_CFLAGS="-pipe" bootstrap \
      >> ${LOGFILE} 2>&1
} &&
echo " o Build OK" &&
BUILD_OK="${BUILD_OK}1" &&

min_log_init ${TESTLOGS} &&
make -k check \
   >>  ${LOGFILE} 2>&1

########################################################################
# Break the conditional execution to let me continue
########################################################################
if [ $? -eq 0 ] ; then
    echo " o Test OK"
    BUILD_OK="${BUILD_OK}Y"
else
    BUILD_OK="${BUILD_OK}${REMOVE_PKGDIR_CH6_GCC_FINAL}"
    echo \
"=========================================================================
 gcc make check NOT OK
-----------------------
Versions 3.2, 3.2.1 and 3.2.2.

This is not as bad as it looks, this is expected.

Please check ${LOGFILE} and compare against the following.

libstdc++
---------
All of the above versions will fail libstc++v3 tests due to
26 unexpected passes and a single failure.

FAIL: 26_numerics/c99_classification_macros_c.cc (test for excess errors)

                === libstdc++-v3 Summary ===

# of expected passes            432
# of unexpected failures        1
# of unexpected successes       26

Of real interest though is gcc and g++ tests.

gcc
---
Gcc tests SHOULD pass, no unexpected failures or passes.

g++
---
G++ will have one unexpected pass
   XPASS: g++.other/init5.C  Execution test

This is so far fairly consistent across the 3.2 series

========================================================================="
fi

min_log_init ${INSTLOGS} &&
make install \
   >> ${LOGFILE} 2>&1 &&

BUILD_OK="${BUILD_OK}3" &&
echo " o install OK" &&

ln -s ../usr/bin/cpp /lib &&
ln -sf gcc /usr/bin/cc
rm /usr/lib/libiberty.a

cd ${SRC}
test Y1Y3 = "${BUILD_OK}" && {
   remove_dir ${SRC}/gcc-${GCC_VER}-final-build
   remove_dir ${SRC}/gcc-${GCC_VER}
}

unset BUILD_OK

#3.0 20030503
# Create symlinks if we chose to add a version suffix
test "Y" = "${USE_PROGRAM_SUFFIX}" &&
{
   for progname in gcc g++ c++ ; do
      test -f /usr/bin/${progname}-${actual_gcc_ver} &&
      {
         echo " o Creating ${progname} -> ${progname}-${actual_gcc_ver} symlink ..."
         ln -sf ${progname}-${actual_gcc_ver} /usr/bin/${progname}
      }

      test -f /usr/bin/${TGT_TRIPLE}-${progname}-${actual_gcc_ver} &&
      {
         echo " o Creating ${TGT_TRIPLE}-${progname} -> ${TGT_TRIPLE}-${progname}-${actual_gcc_ver} symlink ..."
         ln -sf ${TGT_TRIPLE}-${progname}-${actual_gcc_ver} \
            /usr/bin/${TGT_TRIPLE}-${progname}
      }
   done

   for progname in cpp c++filt gccbug gcov ; do
      test -f /usr/bin/${progname}-${actual_gcc_ver} &&
      {
         echo " o Creating ${progname} -> ${progname}-${actual_gcc_ver} symlink ..."
         ln -sf ${progname}-${actual_gcc_ver} /usr/bin/${progname}
      }
   done
}
# end of USE_PROGRAM_SUFFIX modifications

# Following req'd when using --enable-version-specific-runtime-libs
test Y = "${USE_VER_SPEC_RT_LIBS}" &&
{
   # Add the path to our new gcc libs in /etc/ld.so.conf
   SPECFILE=`/usr/bin/gcc -v 2>&1 | grep specs | sed 's@.* @@'`
   echo "${SPECFILE}" | sed 's@/specs@@' >> /etc/ld.so.conf
   # Better make a symlink for the c++ includes
   mkdir /usr/include/c++
   ln -s `echo "${SPECFILE}" | sed 's@/specs@/include/c++@'` /usr/include/c++/${actual_gcc_ver}
}

# update /etc/ld.so.cache
/sbin/ldconfig

unset LD_LIBRARY_PATH
unset LD_PRELOAD
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/stage1/sbin:/stage1/bin

# Job Done :-)
#EOF

cd ${SRC}

#TODO: either move this as-is until after ch6 autoconf build,
#      add autoconf ch5 or supply with patch 
#
# GCC2_VER=2.95.3
# max_log_init Gcc ${GCC2_VER} "final (shared)" ${CONFLOGS} ${LOG}
# 
# unpack_tarball gcc-${GCC2_VER}
# cd ${PKGDIR}
# 
# apply_patch gcc-${GCC2_VER}-2
# 
# echo timestamp > gcc/cstamp-h.in &&
# 
# cd gcc
# 
# # program-suffix is broken 
# # Fix 1
# # Assuming autoconf is reasonably uptodate
# # add AC_ARG_PROGRAM to configure.in under
# # AC_CANONICAL_SYSTEM and re-run autoconf
# test -f configure.in-ORIG ||
#    cp configure.in configure.in-ORIG
#    
# sed '/AC_CANONICAL_SYSTEM/a\
# \
# # Set program_transform_name\
# AC_ARG_PROGRAM' configure.in-ORIG > configure.in
# # Hope autoconf is not ancient on host 
# autoconf
# 
# # Fix 2 would be to include the above in the current
# # patch (would need autoconf 2.1.3 to match)
# 
# mkdir ${SRC}/gcc-${GCC2_VER}-final
# cd ${SRC}/gcc-${GCC2_VER}-final
# 
# CFLAGS="-O2 -pipe" \
# ../${PKGDIR}/configure --prefix=/usr \
#    --enable-languages=c,c++ --enable-shared \
#    --enable-version-specific-runtime-libs \
#    --program-suffix="-2.95.3" \
#    --mandir=/usr/share/man --infodir=/usr/share/info \
#       >> ${LOGFILE} 2>&1 &&
# echo " o Configure OK" &&
# 
# min_log_init ${BUILDLOGS} &&
# make BOOT_LDFLAGS="-s" BOOT_CFLAGS="-O2 -pipe" \
#    STAGE1_CFLAGS="-pipe" bootstrap \
#       >> ${LOGFILE} 2>&1 &&
# echo " o Build OK" &&
#  
# min_log_init ${TESTLOGS} &&
# make -k check \
#    >>  ${LOGFILE} 2>&1
# 
# if [ $? -eq 0 ] ; then
#    echo " o Test OK"
# else
#    echo "gcc-${GCC_VER} check NOT OK"
# fi
# 
# make install

