# Template file for 'openexr'
pkgname=openexr
version=2.4.1
revision=2
build_style=cmake
build_helper="qemu"
hostmakedepends="pkg-config"
makedepends="ilmbase-devel zlib-devel"
short_desc="High dynamic-range (HDR) image file format"
maintainer="Orphaned <orphan@voidlinux.org>"
license="BSD-3-Clause"
homepage="https://www.openexr.com/"
distfiles="https://github.com/openexr/openexr/archive/v${version}.tar.gz>${pkgname}-${version}.tar.gz"
checksum=3ebbe9a8e67edb4a25890b98c598e9fe23b10f96d1416d6a3ff0732e99d001c1

pre_patch() {
	# remove documentation with embedded non-free fonts
	find . -name *.pdf -exec rm -v '{}' \;
}

pre_configure() {
	if [ "$CROSS_BUILD" ]; then
		vsed -i IlmBase/Half/CMakeLists.txt \
			IlmBase/ImathTest/CMakeLists.txt \
			OpenEXR/IlmImf/CMakeLists.txt \
			-e "s; COMMAND ; COMMAND qemu-${XBPS_TARGET_QEMU_MACHINE}-static ;g"
	fi
}

post_install() {
	local d f

	vlicense LICENSE.md

	# Remove files which are already in ilmbase{,-devel}
	for pkg in ilmbase ilmbase-devel; do
		for f in $(xbps-query -Rf $pkg|awk '{print $1}'); do
			rm -f "${DESTDIR}/$f"
		done
	done
}

libopenexr_package() {
	short_desc+=" - runtime libraries"
	pkg_install() {
		vmove "usr/lib/*.so.*"
	}
}
libopenexr-devel_package() {
	short_desc+=" - development files"
	depends="${makedepends} libopenexr>=${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/cmake
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.so"
		vmove usr/share
	}
}
