#!/bin/ksh

HOST="$1"
OS="$2"
OS_VERSION="$3"
OS_VERSION_MINOR="$4"

patch1()
{
/usr/local/bin/patch -p0 -N -b -V numbered <<\EOF
EOF
}

export CC=cc
OPTIONS=

case "$OS/$OS_VERSION/$OS_VERSION_MINOR" in
aix/*/*)
	if [ "$OS_VERSION" = 4 ]; then
		cat >mycc <<-\EOF && chmod 755 mycc
			#!/bin/ksh
			I=0
			for ARG; do
			case "$ARG" in
			-g*)
				;;
			-O*)
				;;
			*)
				ARGV[$I]="$ARG"
				I=$(expr $I + 1)
				;;
			esac
			done
			/usr/vacpp/bin/xlC_r "${ARGV[@]}"
		EOF
		export CC=$PWD/mycc
	else
		export CC=/usr/vacpp/bin/xlC_r
		export CFLAGS='-O'
		OPTIONS="$OPTIONS --with-gnu-as"
		OPTIONS="$OPTIONS --with-as=/usr/local/binutils-2.17/bin/as"
	fi
	OPTIONS="$OPTIONS --disable-nls"
	OPTIONS="$OPTIONS --disable-multilib"
	export CONFIG_SHELL=/usr/local/share/bin/ksh93
	;;
hpux/*/*)
	OPTIONS="$OPTIONS --with-gnu-as"
	OPTIONS="$OPTIONS --with-as=/usr/local/binutils-2.17/bin/as"
	OPTIONS="$OPTIONS hppa1.0-hp-hpux11.00"
	;;
sunos/*/*)
#	OPTIONS="$OPTIONS --with-gnu-as"
#	OPTIONS="$OPTIONS --with-as=/usr/local/binutils-2.17/bin/as"
	export PATH="/opt/SUNWspro/bin:$PATH"
	;;
*/*/*)
	;;
esac

export CONFIG_SHELL=/bin/ksh

HERE=$(HOME= PWD= sh -c pwd) &&
rm -fr ../gcc-4.0.4-build &&
mkdir ../gcc-4.0.4-build &&
cd ../gcc-4.0.4-build &&

ksh "$HERE/configure" \
	--prefix=/usr/local/gcc-4.0.4 $OPTIONS &&

gmake MAKE=gmake bootstrap-lean -j4 &&

gmake MAKE=gmake install &&

rm -fr ../gcc-4.0.4-build &&

true
