#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../java-dirtree/parse-config
# Copyright (C) 2004 - 2006 The T2 SDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

if [ -f $root/var/adm/packages/java-dirtree ]; then
	# We have to set JAVA_HOME environment variable. For this we
	# check every jdk we know and verify if it is installed.

	JAVA_EVERYJDK="sun-jdk-142 ibm-jdk-142 blackdown-jdk"

	# ooo doesn't build with java 1.5+
	[ "$pkg" != "ooo" ] &&
		JAVA_EVERYJDK="sun-jdk-150 ibm-jdk-150 $JAVA_EVERYJDK"

	# use kaffe only for marked packages
	if hasflag KAFFE; then
		JAVA_EVERYJDK="kaffe $JAVA_EVERYJDK"
	fi

	# clean the enviroment
	unset JAVA_HOME CLASSPATH

	for jdk in $JAVA_EVERYJDK; do
		if [ -f $root$( pkgprefix sysconfdir java-dirtree )/$jdk.in ]; then
			pkgprefix -t $jdk

			# Make java home available to java packages.
			JAVA_HOME=$root/$( pkgprefix $jdk )
			CLASSPATH="$root$( pkgprefix libdir java-dirtree ):$CLASSPATH"
			CLASSPATH="$root/$( pkgprefix $jdk )/jre/lib:$CLASSPATH"
			CLASSPATH="$root/$( pkgprefix $jdk )/lib:$CLASSPATH"
			PATH="$root/$( pkgprefix $jdk )/jre/bin:$PATH"
			PATH="$root/$( pkgprefix $jdk )/bin:$PATH"

			echo_status "JAVA_HOME set to $jdk"
			export JAVA_HOME CLASSPATH PATH

			# Determine the java version.
			# Todo: might be important to some packages.

			break
		fi
	done

	# and remove the junk i injected
	unset jdk JAVA_EVERYJDK
fi