SUMMARY="An 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 8 reference implementation."
HOMEPAGE="https://openjdk.java.net/"
COPYRIGHT="2007-2015 Oracle and/or its affiliates."
LICENSE="GNU GPL v2"
REVISION="4"
jdkUpdate="242"
jdkBuild="b08"
jdkUpdateBuild="jdk8u$jdkUpdate-$jdkBuild"
srcGitRev="23005bb46a16c600ba6442b97aab96554498ad1e"
SOURCE_URI="https://github.com/korli/haiku-jdk8u/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="27876162989fa56679b4e9ff13a052a982ed6004071c3bae9197e5803ce1fda6"
SOURCE_DIR="haiku-jdk8u-$srcGitRev"
SOURCE_FILENAME="jdk8u-$jdkUpdateBuild-$srcGitRev.tar.gz"
srcGitRev2="7af4dc204131c384f5610493dd90cfdaca4ef2fc"
SOURCE_URI_2="https://github.com/korli/haiku-jdk8u-hotspot/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="8bd934ff73deb328cfeedc35d1f2c365dd382daef395da239a980a0d6aa660a1"
SOURCE_DIR_2="haiku-jdk8u-hotspot-$srcGitRev2"
SOURCE_FILENAME_2="hotspot-$jdkUpdateBuild-$srcGitRev2.tar.gz"
srcGitRev3="cef6ade4079c9b392ea6436c35a39cf4aab5d524"
SOURCE_URI_3="https://github.com/korli/haiku-jdk8u-jdk/archive/$srcGitRev3.tar.gz"
CHECKSUM_SHA256_3="57d48b74d395a629f8c04309c790f4f23c19eeb89f7bb2be0cb6abe91e9897c8"
SOURCE_DIR_3="haiku-jdk8u-jdk-$srcGitRev3"
SOURCE_FILENAME_3="jdk-$jdkUpdateBuild-$srcGitRev3.tar.gz"
SOURCE_URI_4="https://hg.openjdk.java.net/jdk8u/jdk8u/langtools/archive/$jdkUpdateBuild.tar.bz2"
CHECKSUM_SHA256_4="070ee6b054459b14e742af9920c473f18c037cb3f07825ec57f6385f49f8ab1d"
SOURCE_DIR_4="langtools-$jdkUpdateBuild"
SOURCE_FILENAME_4="langtools-$jdkUpdateBuild.tar.bz2"
SOURCE_URI_5="https://hg.openjdk.java.net/jdk8u/jdk8u/corba/archive/$jdkUpdateBuild.tar.bz2"
CHECKSUM_SHA256_5="488f9f49abe472198dc6da3fa84a0eea89533938333fe8030a0e5903f0f8c267"
SOURCE_DIR_5="corba-$jdkUpdateBuild"
SOURCE_FILENAME_5="corba-$jdkUpdateBuild.tar.bz2"
SOURCE_URI_6="https://hg.openjdk.java.net/jdk8u/jdk8u/jaxp/archive/$jdkUpdateBuild.tar.bz2"
CHECKSUM_SHA256_6="ca383597cf634838e23ad23d57e0778e3714bdc698225aced9b1c8b90f7cd10b"
SOURCE_DIR_6="jaxp-$jdkUpdateBuild"
SOURCE_FILENAME_6="jaxp-$jdkUpdateBuild.tar.bz2"
SOURCE_URI_7="https://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/archive/$jdkUpdateBuild.tar.bz2"
CHECKSUM_SHA256_7="c735c9c0af2422fec88fa67110d442170d25bdc6d83f3bfc8a936458057ea73b"
SOURCE_DIR_7="jaxws-$jdkUpdateBuild"
SOURCE_FILENAME_7="jaxws-$jdkUpdateBuild.tar.bz2"
SOURCE_URI_8="https://hg.openjdk.java.net/jdk8u/jdk8u/nashorn/archive/$jdkUpdateBuild.tar.bz2"
CHECKSUM_SHA256_8="a86741ee31f46b7c15230a4ce961bf1578e11c6a7a401c43a761b60e20531d98"
SOURCE_DIR_8="nashorn-$jdkUpdateBuild"
SOURCE_FILENAME_8="nashorn-$jdkUpdateBuild.tar.bz2"
SOURCE_URI_9="https://ftp.osuosl.org/pub/blfs/conglomeration/openjdk/jtreg-4.2-b13-433.tar.gz"
CHECKSUM_SHA256_9="ddf76660d4f519302b9c6310febcde3ff45313c435fff4e157854d1ff50785b1"
SOURCE_DIR_9="jtreg"
if [ "$secondaryArchSuffix" = _x86 ] ; then
	PATCHES_2="openjdk8_x86-$portVersion-source2.patchset"
fi
PATCHES_3="openjdk8-$portVersion-source3.patchset"
ADDITIONAL_FILES="
	elf.h
	"

ARCHITECTURES="all !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" package

PROVIDES="
	openjdk8$secondaryArchSuffix = $portVersion compat >= 1.8
	java:environment = 8
	"
REQUIRES="
	openjdk8${secondaryArchSuffix}_jre == $portVersion
	"

PROVIDES_default="
	openjdk8${secondaryArchSuffix}_default = $portVersion
	cmd:jar = $portVersion compat >= 1.8
	cmd:jarsigner = $portVersion compat >= 1.8
	cmd:java = $portVersion compat >= 1.8
	cmd:javac = $portVersion compat >= 1.8
	cmd:javadoc = $portVersion compat >= 1.8
	cmd:javah = $portVersion compat >= 1.8
	cmd:javap = $portVersion compat >= 1.8
	cmd:jcmd = $portVersion compat >= 1.8
	cmd:jconsole = $portVersion compat >= 1.8
	cmd:jdb = $portVersion compat >= 1.8
	cmd:jinfo = $portVersion compat >= 1.8
	cmd:jmap = $portVersion compat >= 1.8
	cmd:jps = $portVersion compat >= 1.8
	cmd:jstack = $portVersion compat >= 1.8
	cmd:jstat = $portVersion compat >= 1.8
	cmd:jstatd = $portVersion compat >= 1.8
	cmd:keytool = $portVersion compat >= 1.8
	cmd:orbd = $portVersion compat >= 1.8
	cmd:pack200 = $portVersion compat >= 1.8
	cmd:rmic = $portVersion compat >= 1.8
	cmd:rmid = $portVersion compat >= 1.8
	cmd:rmiregistry = $portVersion compat >= 1.8
	cmd:schemagen = $portVersion compat >= 1.8
	cmd:serialver = $portVersion compat >= 1.8
	cmd:servertool = $portVersion compat >= 1.8
	cmd:tnameserv = $portVersion compat >= 1.8
	cmd:unpack200 = $portVersion compat >= 1.8
	cmd:wsgen = $portVersion compat >= 1.8
	cmd:wsimport = $portVersion compat >= 1.8
	cmd:xjc = $portVersion compat >= 1.8
	"
REQUIRES_default="
	openjdk8${secondaryArchSuffix} == $portVersion
	"
REPLACES_default="
	openjdk${secondaryArchSuffix}
	"

PROVIDES_jre="
	openjdk8${secondaryArchSuffix}_jre = $portVersion compat >= 1.8
	java:runtime = 8
	"
REQUIRES_jre="
	haiku$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	ca_root_certificates_java
	dejavu
	"

SUMMARY_sources="JDK source files, demos and examples"
PROVIDES_sources="
	openjdk8${secondaryArchSuffix}_sources = $portVersion compat >= 1.8
	"
REQUIRES_sources="
	openjdk8$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	java:environment == 7
	ca_root_certificates
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cpio
	cmd:make
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:sed
	cmd:tar
	cmd:zip
	cmd:gawk
	cmd:hostname
	cmd:find
	cmd:unzip
	cmd:unzipsfx
	cmd:head
	cmd:file
	cmd:which
	cmd:autoconf
	"

TEST_REQUIRES="
	cmd:true
	"

BUILD()
{
	source /system/data/profile.d/openjdk7.sh
	export PATH=$JDK7_HOME/bin:$PATH

	# prepare the directory structure
	ln -sfn $sourceDir2 hotspot
	ln -sfn $sourceDir3 jdk
	ln -sfn $sourceDir4 langtools
	ln -sfn $sourceDir5 corba
	ln -sfn $sourceDir6 jaxp
	ln -sfn $sourceDir7 jaxws
	ln -sfn $sourceDir8 nashorn
	ln -sfn $sourceDir9 jtreg

	cp $portDir/additional-files/elf.h hotspot/src/share/vm/utilities

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

	# Verify that we can allocate a large enough heap before starting.
	maxHeapSize=960M
	java -XX:ThreadStackSize=1536 -XX:MaxPermSize=160m \
		-Xmx${maxHeapSize} -version

	freeTypeHeaders=$(finddir B_SYSTEM_HEADERS_DIRECTORY)$secondaryArchSubDir/freetype2
	freeTypeLib=$(finddir B_SYSTEM_DEVELOP_DIRECTORY)/lib$secondaryArchSubDir

	#OpenJDK has an internal limitation of 256 characters in a path. And with the default src dir we go past it.
	cd ..
	mv $sourceDir src
	cd src
	ln -s src $sourceDir

	bash ./common/autoconf/autogen.sh
	bash ./configure --with-boot-jdk-jvmargs="-Xmx${maxHeapSize}" \
					--with-freetype-include="${freeTypeHeaders}" \
					--with-freetype-lib="${freeTypeLib}" \
					--disable-freetype-bundling \
					--with-jtreg=./jtreg \
					--with-update-version="$jdkUpdate" \
					--with-build-number="$jdkBuild" \
					--with-milestone="fcs" \
					--with-jobs=1

	make DEBUG_BINARIES=true SCTP_WERROR= images
}

INSTALL()
{
	# install the generated SDK image dir
	jdkDir=$libDir/openjdk8

	mkdir -p $(dirname $jdkDir)
	cp -a build/haiku-*/images/j2sdk-image $jdkDir

	# set up the cacerts link
	ln -sf $dataDir/ssl/java/cacerts $jdkDir/jre/lib/security/

	# symlink the executables to binDir
	mkdir -p $prefix/bin
	bins="jar jarsigner javac javadoc javah javap jcmd jconsole jdb jinfo \
		jmap jps jstack jstat jstatd rmic schemagen serialver wsgen wsimport \
		xjc"
	bins_runtime="java keytool orbd pack200 rmid rmiregistry servertool \
		tnameserv unpack200"
	man_runtime=""
	for b in $bins $bins_runtime; do
		symlinkRelative -s $jdkDir/bin/$b $prefix/bin
	done
	for b in $bins_runtime; do
		man_runtime+=" $jdkDir/man/man1/$b.1 $jdkDir/man/ja_JP.UTF-8/man1/$b.1"
	done

	mkdir -p $dataDir/profile.d

	# create a profile.d file that sets up JAVA_HOME
	jdkProfile=$dataDir/profile.d/openjdk.sh
	echo "JAVA_HOME=$jdkDir" > $jdkProfile
	echo "export JAVA_HOME" >> $jdkProfile

	# create a profile.d file that sets up JDK8_HOME
	jdk8Profile=$dataDir/profile.d/openjdk8.sh
	echo "JDK8_HOME=$jdkDir" > $jdk8Profile
	echo "export JDK8_HOME" >> $jdk8Profile

	# create a profile.d file that sets up JRE8_HOME
	jre8Profile=$dataDir/profile.d/openjre8.sh
	echo "JRE8_HOME=$jdkDir" > $jre8Profile
	echo "export JRE8_HOME" >> $jre8Profile

	packageEntries jre \
		$jdkDir/jre \
		$man_runtime \
		$jdkDir/man/ja \
		$dataDir/profile.d/openjre8.sh

	packageEntries default \
		$prefix/bin \
		$dataDir/profile.d/openjdk.sh

	packageEntries sources \
		$jdkDir/src.zip \
		$jdkDir/sample \
		$jdkDir/demo
}

TEST()
{
	export DISABLE_ASLR=1
	cd ../src
	make test-only JOBS=1 TEST=langtools_jtreg
	make test-only JOBS=1 TEST=jdk_lang
	make test-only JOBS=1 TEST=jdk_util
	make test-only JOBS=1 TEST=jdk_math # OK
	make test-only JOBS=1 TEST=jdk_io
	make test-only JOBS=1 TEST=jdk_nio
	make test-only JOBS=1 TEST=jdk_net
	make test-only JOBS=1 TEST=jdk_time # OK
	make test-only JOBS=1 TEST=jdk_rmi
	make test-only JOBS=1 TEST=jdk_security
	make test-only JOBS=1 TEST=jdk_text # OK
	make test-only JOBS=1 TEST=jdk_management
	make test-only JOBS=1 TEST=jdk_instrument
	make test-only JOBS=1 TEST=jdk_jmx
	make test-only JOBS=1 TEST=jdk_jdi
}
