#!/bin/sh

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

usage="usage: $0 -os <osType> -ws <windowingSystemType> -arch <architecture> [-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;;
		-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$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-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
 		 if  [ -f /etc/debian_version ] || [ -f /etc/gentoo-release ] ;  then 
        		 		  LOCALCLASSPATH=$PWD/jdtcoresrc/ecj.jar:$CLASSPATH;export LOCALCLASSPATH
 		 elif [ -f /etc/redhat-release ] ; then
 		          CLASSPATH=$PWD/jdtcoresrc/ecj.jar:$CLASSPATH;export CLASSPATH
		 else 
 		          echo "Assuming RHEL CLASSPATH compatible."
 		          CLASSPATH=$PWD/jdtcoresrc/ecj.jar:$CLASSPATH; export CLASSPATH
 		 fi		 
 		 ant -q -buildfile jdtcoresrc/compilejdtcore.xml
 		 if  [ -f /etc/debian_version ] || [ -f /etc/gentoo-release ] ;  then
		  		  LOCALCLASSPATH=$PWD/ecj.jar:$ORIGCLASSPATH;export LOCALCLASSPATH
         elif [ -f /etc/redhat-release ] ; then
		   		  CLASSPATH=$PWD/ecj.jar:$ORIGCLASSPATH;export CLASSPATH
         else 
 		          echo "Assuming RHEL CLASSPATH compatible."
 		          CLASSPATH=$PWD/ecj.jar:$CLASSPATH;export CLASSPATH
         fi
 		 ant -q -buildfile build.xml $target -DinstallOs=$os -DinstallWs=$ws -DinstallArch=$arch $compilelibs $bootclasspath 
		 else
		 		 echo "The os-ws-arch combination of $os-$ws-$arch is not valid."
 		 exit 1
 fi