#! /bin/sh

export ANT_OPTS=-Xmx1000M

bootclasspath=$JAVA_HOME/jre/lib/rt.jar
os=""
ws=""
arch=""
target=""

usage="usage: $0 -os <osType> -ws <windowingSystemType> -arch <architecture> [-bc <bootclasspath>] [-target <target>]"

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;;
		-bc) bootclasspath="$2"; shift;;
		-target) target="$2"; shift;;
 		-*)
			echo >&2 $usage
			exit 1;;
		*) break;;	# terminate while loop
	esac
	shift
done

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-amd64" ] || [ "$os-$ws-$arch" = "linux-gtk-ia64" ] ||[ "$os-$ws-$arch" = "solaris-motif-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" = "macosx-carbon-ppc" ]
then
	ant -buildfile build.xml $target -DinstallOs=$os -DinstallWs=$ws -DinstallArch=$arch -Dbootclasspath=$bootclasspath -DjavacTarget=1.2
else
	echo "The os-ws-arch combination of $os-$ws-$arch is not valid."
	exit 1
fi
