# Template file for 'lightzone'
pkgname=lightzone
version=4.2.2
revision=2
_ivy_version=2.4.0
hostmakedepends="automake git openjdk11 apache-ant javahelp2 rsync pkg-config"
makedepends="libgomp-devel lcms2-devel libjpeg-turbo-devel tiff-devel libX11-devel lensfun-devel"
depends="openjdk11 javahelp2 liblzma tiff"
short_desc="Professional-level digital darkroom and photo editor"
maintainer="Orphaned <orphan@voidlinux.org>"
license="BSD-3-Clause"
homepage="http://www.lightzoneproject.org/"
distfiles="https://github.com/ktgw0316/LightZone/archive/${version}.tar.gz>${pkgname}-${version}.tar.gz
 https://repo1.maven.org/maven2/org/apache/ivy/ivy/${_ivy_version}/ivy-${_ivy_version}.jar"
checksum="9106bbafe4cad6e398c0d83555e51a0e8ed550f1f3a9989ffdc047aba1150e8c
 ce81cb234406b093b5b8de9f6f5b2a50ed0824d6a235891353e8d3e941a53970"
skip_extraction="ivy-${_ivy_version}.jar"
# JNI binaries are not PIE
nopie=yes
replaces="lightzone-bin>=0"

do_build() {
	mkdir -p lightcrafts/lib
	ln -sf $XBPS_SRCDISTDIR/${pkgname}-${version}/ivy-${_ivy_version}.jar \
		lightcrafts/lib/ivy.jar

	# Fix for cross building
	vsed -i lightcrafts/jnisrc/tiff/GNUmakefile \
		-e "s;\./configure;& --host=${XBPS_MACHINE%-musl};"

	. /etc/profile.d/openjdk.sh
	cd linux
	TARGET=${XBPS_TARGET_MACHINE%-musl} ant jar
}

do_install() {
	vbin linux/products/lightzone

	vmkdir usr/share
	cp -pHR linux/icons ${DESTDIR}/usr/share
	vinstall linux/products/lightzone.desktop 644 usr/share/applications

	# Install shared libraries
	for f in linux/products/*.so; do
		vinstall $f 755 usr/lib/lightzone
	done

	# Install helpers
	for f in LightZone-forkd dcraw_lz; do
		vinstall linux/products/$f 755 usr/lib/lightzone
	done

	# Install jars
	for f in linux/products/*.jar; do
		vinstall $f 644 usr/share/java/lightzone
	done

	vlicense COPYING
}
