#!/bin/sh

ANT_OPTS=-Xmx1000M; export ANT_OPTS
os=""
ws=""
arch=""
target=""
bootclasspath=""
java5home=""

usage="usage: $0 -os <osType> -ws <windowingSystemType> -arch <architecture> -java5home <path to root of 1.5 JDK (parent to /bin/javadoc)> [-bc <bootclasspath>] [-compilelibs] [-target <target>]"

compilelibs=""

if [ $# -lt 1 ]
then
	echo >&2 "$usage"
	exit 1
fi

while [ $# -gt 0 ]
do
	case "$1" in
		-os) os="$2"; shift;;
		-ws) ws="$2"; shift;;		 
		-arch) arch="$2";shift;;
		-java5home) java5home="-Djava5.home=$2"; shift;;  
		-bc) bootclasspath="-Dbootclasspath=$2"; shift;;  
	    -compilelibs) compilelibs="-Dlibsconfig=true";;    
		-target) target="$2"; shift;;
		-*)
			echo >&2 $usage
			exit 1;;
		*) break;;	# terminate while loop
	esac
	shift
done

if [ "x$java5home" = "x" ]
then
	echo >&2 "$usage"
	exit 1
fi

if [ "x$os" = "x" ]
then
	echo >&2 "$usage"
	exit 1
fi

if [ "x$ws" = "x" ]
then
	echo >&2 "$usage"
	exit 1
fi

if [ "x$arch" = "x" ]
then
	echo >&2 "$usage"
	exit 1
fi

if [ "$os-$ws-$arch" = "linux-motif-x86" ] || [ "$os-$ws-$arch" = "linux-gtk-x86" ] || [ "$os-$ws-$arch" = "linux-gtk-x86_64" ] || [ "$os-$ws-$arch" = "linux-gtk-ia64" ] || [ "$os-$ws-$arch" = "solaris-motif-sparc" ] || [ "$os-$ws-$arch" = "solaris-gtk-x86" ] || [ "$os-$ws-$arch" = "solaris-gtk-sparc" ] || [ "$os-$ws-$arch" = "aix-motif-ppc" ] || [ "$os-$ws-$arch" = "hpux-motif-PA_RISC" ] || [ "$os-$ws-$arch" = "qnx-photon-x86" ] || [ "$os-$ws-$arch" = "win32-win32-x86" ] || [ "$os-$ws-$arch" = "linux-gtk-ppc" ] || [ "$os-$ws-$arch" = "linux-gtk-ppc64" ] || [ "$os-$ws-$arch" = "macosx-carbon-ppc" ] || [ "$os-$ws-$arch" = "hpux-motif-ia64" ] || [ "$os-$ws-$arch" = "hpux-motif-ia64_32" ]
then
		 ORIGCLASSPATH=$CLASSPATH;export ORIGCLASSPATH		 
		 ant -q -buildfile jdtcoresrc/compilejdtcorewithjavac.xml
         CLASSPATH=$PWD/jdtcoresrc/ecj.jar:$CLASSPATH;export CLASSPATH		
 		 ant -q -buildfile jdtcoresrc/compilejdtcore.xml
 		 CLASSPATH=$PWD/ecj.jar:$ORIGCLASSPATH;export CLASSPATH
 		 ant -q -buildfile build.xml $target -DinstallOs=$os -DinstallWs=$ws -DinstallArch=$arch $compilelibs $bootclasspath $java5home
		 else
		 		 echo "The os-ws-arch combination of $os-$ws-$arch is not valid."
 		 exit 1
 fi