#!/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-gtk-x86" ] || [ "$os-$ws-$arch" = "linux-gtk-x86_64" ] || [ "$os-$ws-$arch" = "solaris-gtk-sparc" ] || [ "$os-$ws-$arch" = "aix-gtk-ppc" ] || [ "$os-$ws-$arch" = "aix-gtk-ppc64" ] || [ "$os-$ws-$arch" = "hpux-gtk-ia64_32"] || [ "$os-$ws-$arch" = "win32-win32-x86" ] || [ "$os-$ws-$arch" = "win32-win32-x86_64" ] || [ "$os-$ws-$arch" = "linux-gtk-ppc64" ] || [ "$os-$ws-$arch" = "macosx-carbon-ppc" ] || [ "$os-$ws-$arch" = "macosx-cocoa-x86" ] || [ "$os-$ws-$arch" = "macosx-cocoa-x86_64" ] || [ "$os-$ws-$arch" = "hpux-gtk-ia64_32" ] 
then
			          
                 if [ ! -r eclipse ]
                    then
 	                    tar -xzf eclipse-SDK-*.tar.gz
                    fi  
                 if [ ! -r eclipse ]
                    then 	         
                        echo "Please place an Eclipse SDK that matches the archictecture machine you are building on in the same directory that where you have extracted the source build zip."
                        exit 1
                    fi  
                 cd org.eclipse.releng.eclipsebuilder
                 cp -r eclipse/buildConfigs/sdk/srcBuild/* .
                 launcher=`ls ../eclipse/plugins/org.eclipse.equinox.launcher_*.jar`
                 java -jar $launcher -Dosgi.os=$os -Dosgi.ws=$ws -Dosgi.arch=$arch -application org.eclipse.ant.core.antRunner -buildfile buildFromSource.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
 
