# Template file for 'oracle-jre'
pkgname=jre
_extraversion=1.7.0_51
version=7u51
revision=3
wrksrc="jdk${_extraversion}"
if [ "$XBPS_TARGET_MACHINE" = "x86_64" ]; then
	distfiles="http://ghaffarian.net/downloads/Java/JDK/jdk-${version}-linux-x64.tar.gz"
	checksum=77367c3ef36e0930bf3089fb41824f4b8cf55dcc8f43cce0868f7687a474f55c
elif [ "$XBPS_TARGET_MACHINE" = "i686" ]; then
	distfiles="http://ghaffarian.net/downloads/Java/JDK/jdk-${version}-linux-i586.tar.gz"
	checksum=b3a2965e44446e476f4e27f7ea13a503a91403ac80bcd71693ad2f84baff42cf
fi
short_desc="Oracle's Java Runtime Environment (JRE) - Version 7"
maintainer="davehome <davehome@redthumb.info.tm>"
homepage="http://www.oracle.com/technetwork/java/javase/downloads/index.html"
license="oracle"

lib32disabled=yes
nonfree=yes
only_for_archs="i686 x86_64"
depends="hicolor-icon-theme desktop-file-utils xdg-utils shared-mime-info"
provides="java-runtime-${version}_1"
replaces="java-runtime>=0"

do_install() {
	# Install desktop related items
	vmkdir		usr/share
	vcopy		jre/lib/desktop/icons usr/share
	vcopy		jre/lib/desktop/applications usr/share
	vcopy		jre/lib/desktop/mime usr/share
	vcopy		jre/lib/locale usr/share
	vcopy		man usr/share
	rm -rf		${DESTDIR}/usr/share/man/ja

	# Install license(s)
	vmkdir		usr/share/licenses/java
	vcopy		COPYRIGHT usr/share/licenses/java
	vcopy		LICENSE usr/share/licenses/java
	vcopy		THIRDPARTYLICENSEREADME.txt usr/share/licenses/java
	vcopy           THIRDPARTYLICENSEREADME-JAVAFX.txt usr/share/licenses/java

	# For system environment vars and desktop extra shortcut
	vinstall	${FILESDIR}/java.sh 644 etc/profile.d
	vinstall 	${FILESDIR}/java-policy-settings.desktop 644 usr/share/applications

	vmkdir		usr/share/java
	vmkdir		usr/share/java/bin
	vmkdir		usr/share/java/lib

	# Install JDK
	vcopy		"bin/*" "usr/share/java/bin"
	vcopy		"lib/*" "usr/share/java/lib"
	vcopy           README.html usr/share/java

	# Install JRE
	vcopy		"jre/bin/*" "usr/share/java/bin"
	vcopy		"jre/lib/*" "usr/share/java/lib"
	vcopy		jre/Welcome.html usr/share/java
	vcopy		release usr/share/java
	
	rm -rf		${DESTDIR}/usr/share/java/lib/desktop
	rm -rf		${DESTDIR}/usr/share/java/lib/locale

	# Install mozilla compatible plugin.
	vmkdir		usr/lib/mozilla/plugins

	if [ "${XBPS_MACHINE}" = "x86_64" ]; then
		_arch=amd64
	else
		_arch=i386
	fi

	# Remove shlib linking to old ffmpeg libraries.
	rm -f		${DESTDIR}/usr/share/java/lib/${_arch}/fxavcodecplugin-52.so


	cd ${DESTDIR}/usr/lib/mozilla/plugins
	ln -sf	../../../share/java/lib/${_arch}/libnpjp2.so .

	# linker's config
        vmkdir etc/ld.so.conf.d
        echo "/usr/share/java/lib/${_arch}" > \
                ${DESTDIR}/etc/ld.so.conf.d/${pkgname}.conf
}

jdk_package() {
	short_desc="Oracle's Java Development Kit (JDK) - Version 7"
	depends="jre>=${version}_${revision}"
	nonfree=yes
	pkg_install() {
	       	vmove "usr/share/java/README.html"
		vmove "usr/share/licenses/java/THIRDPARTYLICENSEREADME-JAVAFX.txt"

		vmove "usr/share/java/lib/ant-javafx.jar"
		vmove "usr/share/java/lib/ct.sym"
		vmove "usr/share/java/lib/dt.jar"
		vmove "usr/share/java/lib/ir.idl"
		vmove "usr/share/java/lib/javafx-doclet.jar"
		vmove "usr/share/java/lib/javafx-mx.jar"
		vmove "usr/share/java/lib/jconsole.jar"
		vmove "usr/share/java/lib/missioncontrol"
		vmove "usr/share/java/lib/orb.idl"
		vmove "usr/share/java/lib/sa-jdi.jar"
		vmove "usr/share/java/lib/tools.jar"
		vmove "usr/share/java/lib/visualvm"

		vmove "usr/share/java/bin/appletviewer"
		vmove "usr/share/java/bin/apt"
		vmove "usr/share/java/bin/extcheck"
		vmove "usr/share/java/bin/idlj"
		vmove "usr/share/java/bin/jar"
		vmove "usr/share/java/bin/jarsigner"
		vmove "usr/share/java/bin/java-rmi.cgi"
		vmove "usr/share/java/bin/javac"
		vmove "usr/share/java/bin/javadoc"
		vmove "usr/share/java/bin/javafxpackager"
		vmove "usr/share/java/bin/javah"
		vmove "usr/share/java/bin/javap"
		vmove "usr/share/java/bin/jcmd"
		vmove "usr/share/java/bin/jconsole"
		vmove "usr/share/java/bin/jdb"
		vmove "usr/share/java/bin/jhat"
		vmove "usr/share/java/bin/jinfo"
		vmove "usr/share/java/bin/jmap"
		vmove "usr/share/java/bin/jmc"
		vmove "usr/share/java/bin/jmc.ini"
		vmove "usr/share/java/bin/jps"
		vmove "usr/share/java/bin/jrunscript"
		vmove "usr/share/java/bin/jsadebugd"
		vmove "usr/share/java/bin/jstack"
		vmove "usr/share/java/bin/jstat"
		vmove "usr/share/java/bin/jstatd"
		vmove "usr/share/java/bin/jvisualvm"
		vmove "usr/share/java/bin/native2ascii"
		vmove "usr/share/java/bin/rmic"
		vmove "usr/share/java/bin/schemagen"
		vmove "usr/share/java/bin/serialver"
		vmove "usr/share/java/bin/wsgen"
		vmove "usr/share/java/bin/wsimport"
		vmove "usr/share/java/bin/xjc"
	}
}
