# Template file for 'mandrel'
pkgname=mandrel
version=21.1.0.0
revision=1
_java_ver=11
_mx_ver=5.304.3
archs="aarch64* x86_64*"  # upstream supported archs
wrksrc="mandrel-${version}"
create_wrksrc=yes
hostmakedepends="openjdk${_java_ver} openjdk${_java_ver}-src
 openjdk${_java_ver}-static-libs python3"
makedepends="zlib-devel"
short_desc="Downstream distribution of the GraalVM community edition"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="GPL-2.0-only, Classpath-exception-2.0"
homepage="https://github.com/graalvm/mandrel"
distfiles="https://github.com/graalvm/mandrel-packaging/archive/refs/tags/mandrel-${version}-Final.tar.gz>packaging-${version}.tar.gz
 https://github.com/graalvm/mandrel/archive/refs/tags/mandrel-${version}-Final.tar.gz
 https://github.com/graalvm/mx/archive/refs/tags/${_mx_ver}.tar.gz"
checksum="3f99ec20491cf79f8be19dfabb8fea6a82ea673bf450f2701f293db44fba4c95
 670dd01e196d51aac0e5e3a4aa9b92e6b3953e16efbc7b7f6bb9dc39f3d1f9a7
 b5d15a3ed5c4ab1a3d84055a84375acac67a344c91a3c8076c429ecff8062e9d"
shlib_provides="libawt.so libawt_xawt.so libjava.so libjli.so libjvm.so libjawt.so"
nocross=yes

post_patch() {
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		# XXX: only static builds with native-image work
		# (else TEXTREL issues)
		patch -d mandrel-mandrel-* -p0 < ${FILESDIR}/musl.patch
	fi
}

do_build() {
	cd mandrel-packaging-*
	export JAVA_HOME=/usr/lib/jvm/openjdk${_java_ver}
	$JAVA_HOME/bin/java -ea build.java \
		--mx-home $PWD/../mx-* \
		--mandrel-repo $PWD/../mandrel-mandrel-* \
		--verbose
}

do_install() {
	cd mandrel-packaging*/mandrel-java*

	vmkdir usr/lib/jvm/mandrel${_java_ver}
	vcopy . usr/lib/jvm/mandrel${_java_ver}

	vlicense LICENSE
	vlicense THIRD_PARTY_LICENSE.txt
}
