#!/bin/sh

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