SUMMARY="Open-source implementation of the Java Platform, SE"
DESCRIPTION="OpenJDK (Open Java Development Kit) is a free and open source \
implementation of the Java Platform, Standard Edition (Java SE). It is the \
result of an effort Sun Microsystems began in 2006. The implementation is \
licensed under the GNU General Public License (GNU GPL) with a linking \
exception. Were it not for the GPL linking exception, components that linked \
to the Java class library would be subject to the terms of the GPL license. \
OpenJDK is the official Java SE 7 reference implementation."
HOMEPAGE="http://openjdk.java.net/"
COPYRIGHT="2012 Oracle and/or its affiliates."
LICENSE="GNU GPL v2"

SOURCE_URI="https://dl.dropboxusercontent.com/u/61946213/j2sdk-image-140528.tar.xz"
CHECKSUM_SHA256="fe9ad5156baf62a14213667f18bf88035daf5f24d6370afc9af30d079d8609a3"
SOURCE_DIR="j2sdk-image"

SOURCE_URI_2="http://www.eu.apache.org/dist/ant/binaries/apache-ant-1.9.4-bin.zip"
CHECKSUM_SHA256_2="973d97d656e65561e2753823de6cf6db35570aaf93eeec6e7cb3d68e1ec4d0e8"
SOURCE_DIR_2="apache-ant-1.9.4"

SOURCE_URI_3="hg+http://hg.openjdk.java.net/jdk7u/jdk7u#jdk7u80-b02"
SOURCE_URI_4="hg+http://hg.openjdk.java.net/jdk7u/jdk7u/langtools#jdk7u80-b02"
SOURCE_URI_5="hg+http://bitbucket.org/hamishm/haiku-jdk7u-corba#44a6a68"
SOURCE_URI_6="hg+http://hg.openjdk.java.net/jdk7u/jdk7u/jaxp#jdk7u80-b02"
SOURCE_URI_7="hg+http://hg.openjdk.java.net/jdk7u/jdk7u/jaxws#jdk7u80-b02"
SOURCE_URI_8="hg+http://bitbucket.org/hamishm/haiku-jdk7u-hotspot#755ff2f"
SOURCE_URI_9="hg+http://bitbucket.org/hamishm/haiku-jdk7u-jdk#f39f6f6"

ADDITIONAL_FILES="
	hjava.cpp
	hjava.rdef
	"

REVISION="2"
ARCHITECTURES="!x86_gcc2 ?x86"
SECONDARY_ARCHITECTURES="?x86"

DISABLE_SOURCE_PACKAGE=yes
	# at least as long as Ant and a complete SDK image are part of the sources

PROVIDES="
	openjdk$secondaryArchSuffix = $portVersion compat >= 1
	cmd:appletviewer$secondaryArchSuffix = $portVersion compat >= 1
	cmd:apt$secondaryArchSuffix = $portVersion compat >= 1
	cmd:extcheck$secondaryArchSuffix = $portVersion compat >= 1
	cmd:idlj$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jar$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jarsigner$secondaryArchSuffix = $portVersion compat >= 1
	cmd:java$secondaryArchSuffix = $portVersion compat >= 1
	cmd:java_config$secondaryArchSuffix = $portVersion compat >= 1
	cmd:javac$secondaryArchSuffix = $portVersion compat >= 1
	cmd:javadoc$secondaryArchSuffix = $portVersion compat >= 1
	cmd:javah$secondaryArchSuffix = $portVersion compat >= 1
	cmd:javap$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jcmd$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jconsole$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jdb$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jhat$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jinfo$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jmap$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jps$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jrunscript$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jsadebugd$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jstack$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jstat$secondaryArchSuffix = $portVersion compat >= 1
	cmd:jstatd$secondaryArchSuffix = $portVersion compat >= 1
	cmd:hjava = $portVersion compat >= 1
	cmd:keytool$secondaryArchSuffix = $portVersion compat >= 1
	cmd:native2ascii$secondaryArchSuffix = $portVersion compat >= 1
	cmd:orbd$secondaryArchSuffix = $portVersion compat >= 1
	cmd:pack200$secondaryArchSuffix = $portVersion compat >= 1
	cmd:policytool$secondaryArchSuffix = $portVersion compat >= 1
	cmd:rmic$secondaryArchSuffix = $portVersion compat >= 1
	cmd:rmid$secondaryArchSuffix = $portVersion compat >= 1
	cmd:rmiregistry$secondaryArchSuffix = $portVersion compat >= 1
	cmd:schemagen$secondaryArchSuffix = $portVersion compat >= 1
	cmd:serialver$secondaryArchSuffix = $portVersion compat >= 1
	cmd:servertool$secondaryArchSuffix = $portVersion compat >= 1
	cmd:tnameserv$secondaryArchSuffix = $portVersion compat >= 1
	cmd:unpack200$secondaryArchSuffix = $portVersion compat >= 1
	cmd:wsgen$secondaryArchSuffix = $portVersion compat >= 1
	cmd:wsimport$secondaryArchSuffix = $portVersion compat >= 1
	cmd:xjc$secondaryArchSuffix = $portVersion compat >= 1
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfreetype$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cpio
	cmd:make
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:sed
	cmd:tar
	cmd:zip
	cmd:awk
	cmd:hostname
	cmd:find
	cmd:unzip
	cmd:unzipsfx
	cmd:head
	cmd:file
	"

BUILD()
{
	# Build "hjava" command.
	g++ $portDir/additional-files/hjava.cpp -DJAVA_BINARY=\"$binDir/java\" \
		-o hjava
	addResourcesToBinaries $portDir/additional-files/hjava.rdef hjava

	OPENJDK_DIR=$(dirname $sourceDir)

	# prepare the directory structure
	cd $OPENJDK_DIR
	ln -sfn $sourceDir3 jdk
	ln -sfn $sourceDir4 jdk/langtools
	ln -sfn $sourceDir5 jdk/corba
	ln -sfn $sourceDir6 jdk/jaxp
	ln -sfn $sourceDir7 jdk/jaxws
	ln -sfn $sourceDir8 jdk/hotspot
	ln -sfn $sourceDir9 jdk/jdk

	chmod u+x ${sourceDir2}/bin/ant

	# set up environment
	export ALT_BOOTDIR=${OPENJDK_DIR}/j2sdk-image
	export ALT_JDK_IMPORT_PATH=$ALT_BOOTDIR
	export ANT_HOME=${sourceDir2}
	export ALT_OUTPUTDIR=${OPENJDK_DIR}/output
	export ALT_UNIXCOMMAND_PATH=

	export LC_ALL=C

	# If ASLR is enabled, the JVM can fail to find a large enough area for
	# the heap.
	export DISABLE_ASLR=1

	if [ -n "$secondaryArchSuffix" ]; then
		export ALT_COMPILER_PATH=`finddir B_SYSTEM_BIN_DIRECTORY`$secondaryArchSubDir
		export ALT_FREETYPE_HEADERS_PATH=`finddir B_SYSTEM_HEADERS_DIRECTORY`$secondaryArchSubDir
	fi

	export USE_EXTERNAL_ZLIB=true

	# Build. (multijob make sometimes fails)
	cd jdk
	make
}

INSTALL()
{
	mkdir -p $binDir

	# install hjava
	cp hjava $prefix/bin/

	# install the generated SDK image dir
	cd ..
	jdkDir=$libDir/openjdk
	mkdir -p $(dirname $jdkDir)
	cp -a output/j2sdk-image $jdkDir

	# symlink the executables to binDir
	symlinkRelative -s $jdkDir/bin/* $binDir
		# TODO: We should probably link only a subset.

	# create a profile.d file that sets up JAVA_HOME
	jdkProfile=$dataDir/profile.d/openjdk.sh
	mkdir -p $(dirname $jdkProfile)
	echo "JAVA_HOME=$jdkDir" > $jdkProfile
	echo "export JAVA_HOME" >> $jdkProfile
}
