#!/bin/sh

#
# To provide jdk path for compilation and testing (developer's environment)
#
set_jdk_home() {
if [ "$NO_PATH" ] ; then
  jdk_home=jdk/$star_arch/$@
else 
  jdk_home=$jdk_dir/$star_arch/$@
fi
JDKVERSION="$@"
}

# default settings
STAR_BIN_DIR=`dirname "$0"`
dev_dir=`cd $STAR_BIN_DIR/../.. && pwd`
jdk_dir=$dev_dir/jdk

while [ $# -gt 0 ]; do

    case "$1" in

    -installhome )
        jdk_dir=$2/jdk
        shift
    ;;

    -version )
	getjdkversion=true
    ;;

    -maparch )
	maparch=true
    ;;

    -nopath )
	NO_PATH=true
    ;;
    
    -arch )
        star_arch=$2
        shift
    ;;

    esac
    shift
done

if [ -z "$star_arch" ] ; then
    if [ $maparch ] ; then
    #
    # To map exact arch with version
    # e.g. linux-x86_64-2.2.5
	star_arch=`$dev_dir/star/bin/maparch`
    else 
    #
    # To map arch with no version
    # e.g. linux-x86_64
	star_arch=`$dev_dir/star/bin/getarch -noversion`
    fi
fi

#
# default option e.g. jdk/linux-x86/j2sdk1.4.2_10
#
case "$star_arch" in

	linux-x86_64*)
	  star_arch=linux-x86_64
          set_jdk_home jdk1.6.0_29
	;;

	linux-x86*)
	  star_arch=linux-x86
          set_jdk_home jdk1.6.0_29
	;;

	linux-ia64*)
	  star_arch=linux-ia64
          set_jdk_home jdk1.6.0_29
	;;

	sunos-sparc*)
	  star_arch=sunos-sparc
          set_jdk_home jdk1.6.0_24
	;;

	sunos-x86_64*)
	  star_arch=sunos-x86_64
          set_jdk_home jdk1.6.0_11
	;;

	hpux-hppa*)
	   star_arch=hpux-hppa
	   set_jdk_home jdk1.6.0_02
	;;

	hpux-ia64*)
	   star_arch=hpux-ia64
	   set_jdk_home jdk1.6.0_05
	;;

	aix-powerpc*)
	    star_arch=aix-powerpc
	    set_jdk_home jdk1.6.0
	;;

	win32*)
	   star_arch=win32
	   set_jdk_home jdk1.6.0_29
	;;

	win64*)
	   star_arch=win64
	   set_jdk_home jdk1.6.0_29
	;;

	*)                  
	    jdk_home=""
	;;

esac

[ $getjdkversion ] && echo $JDKVERSION && exit

echo $jdk_home
