# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/dev-java/sun-jre-bin/sun-jre-bin-1.6.0.22.ebuild,v 1.3 2010/10/13 11:24:06 hwoarang Exp $

inherit versionator pax-utils eutils java-vm-2

MY_PVR="$(replace_version_separator 3 _)"
MY_PV="$(replace_all_version_separators _ )"
MY_PVS="$(get_version_component_range 2)u$(get_version_component_range 4)"

BUILD="04"
BUILDDATE="19_jul_2012"
SUFFIX=".tar.gz"
ARMV5_AT="ejre-${MY_PV}-fcs-b${BUILD}-linux-arm-sflt-eabi-headless-${BUILDDATE}${SUFFIX}"
ARMV6_AT="ejre-${MY_PV}-fcs-b${BUILD}-linux-arm-vfp-eabi-headless-${BUILDDATE}${SUFFIX}"
ARMV7_AT="ejre-${MY_PV}-fcs-b${BUILD}-linux-arm-vfp-eabi-headful-${BUILDDATE}${SUFFIX}"

DESCRIPTION="Sun's Java SE Embedded Runtime Environment"
HOMEPAGE="http://www.oracle.com/technetwork/java/embedded/overview/index.html"
URL_BASE="http://download.oracle.com/otn-pub/java/ejre/${MY_PVS}-b${BUILD}/"
SRC_URI="arm? ( ${URL_BASE}/${ARMV5_AT} ${URL_BASE}/${ARMV6_AT} ${URL_BASE}/${ARMV7_AT} )"

SLOT="1.6"
LICENSE="ejre-6"
KEYWORDS="~arm"
RESTRICT="strip fetch"
IUSE="X jce odbc"

DEPEND="jce? ( =dev-java/sun-jce-bin-1.6.0* )"
RDEPEND="${DEPEND}
	sys-libs/glibc
	X? (
		x11-libs/libXext
		x11-libs/libX11
	)
	odbc? ( dev-db/unixODBC )"

JAVA_PROVIDE="jdbc-stdext jdbc-rowset"

QA_TEXTRELS_ARM="opt/${P}/lib/arm/client/libjvm.so
	opt/${P}/lib/arm/motif21/libmawt.so
	opt/${P}/lib/arm/libdeploy.so
	opt/${P}/lib/arm/server/libjvm.so"

S="${WORKDIR}/ejre${MY_PVR}"


src_unpack() {
	einfo "Unpacking for arch ${CHOST/-*/}"

	if [[ ${CHOST/-*/} = "armv5tel" ]]; then
		unpack ${ARMV5_AT}
	elif [[ ${CHOST/-*/} = "armv6j" ]]; then
		unpack ${ARMV6_AT}
	elif [[ ${CHOST/-*/} = "armv7a" ]]; then
		unpack ${ARMV7_AT}
	fi
}

src_compile() {
	# Set PaX markings on all JDK/JRE executables to allow code-generation on
	# the heap by the JIT compiler. This has to be done before CDS - #215225
	pax-mark m $(list-paxables "${S}"/bin/*)

	# see bug #207282
	if use arm; then
		einfo "Creating the Class Data Sharing archives"
		"${S}"/bin/java -client -Xshare:dump || die
	#	"${S}"/bin/java -server -Xshare:dump || die
	fi
}

src_install() {
	local dirs="bin lib"

	dodir /opt/${P}

	cp -pPR $dirs "${D}/opt/${P}/" || die "failed to copy"

	dodoc README COPYRIGHT THIRDPARTYLICENSEREADME.txt || die
	dodir /opt/${P}/share/

	if use jce; then
		cd "${D}/opt/${P}/lib/security"
		dodir /opt/${P}/lib/security/strong-jce
		mv "${D}"/opt/${P}/lib/security/US_export_policy.jar \
			"${D}"/opt/${P}/lib/security/strong-jce || die
		mv "${D}"/opt/${P}/lib/security/local_policy.jar \
			"${D}"/opt/${P}/lib/security/strong-jce || die
		dosym /opt/sun-jce-bin-1.6.0/jre/lib/security/unlimited-jce/US_export_policy.jar /opt/${P}/lib/security/
		dosym /opt/sun-jce-bin-1.6.0/jre/lib/security/unlimited-jce/local_policy.jar /opt/${P}/lib/security/
	fi

	# bug #56444
	insinto /opt/${P}/lib/
	newins "${FILESDIR}"/fontconfig.Gentoo.properties fontconfig.properties

	set_java_env
	java-vm_revdep-mask
}

pkg_postinst() {
	# Set as default VM if none exists
	java-vm-2_pkg_postinst
}

pkg_nofetch() {
	einfo "This files require you to register at ${HOMEPAGE} (free account)"
	einfo "Please download following file:"
	einfo " - ${ARMV5_AT} - ${ARMV6_AT} - ${ARMV7_AT}"
	einfo "from ${HOMEPAGE}"
	einfo "and place them into ${DISTDIR}"
}