SUMMARY="A high dynamic-range (HDR) image file format"
DESCRIPTION="OpenEXR is a high dynamic-range (HDR) image file format developed \
by Industrial Light & Magic for use in computer imaging applications. OpenEXR \
is used by ILM on all motion pictures currently in production. The first \
movies to employ OpenEXR were Harry Potter and the Sorcerers Stone, Men in \
Black II, Gangs of New York, and Signs. Since then, OpenEXR has become ILM's \
main image file format."
HOMEPAGE="https://www.openexr.com/"
COPYRIGHT="2002-2017 Industrial Light & Magic"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://github.com/AcademySoftwareFoundation/openexr/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="3ebbe9a8e67edb4a25890b98c598e9fe23b10f96d1416d6a3ff0732e99d001c1"
SOURCE_FILENAME="openexr-$portVersion.tar.gz"
SOURCE_DIR="openexr-$portVersion"
PATCHES="openexr-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

libVersion="24.0.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	openexr$secondaryArchSuffix = $portVersion
	cmd:exr2aces$secondaryArchSuffix = $portVersion
	cmd:exrenvmap$secondaryArchSuffix = $portVersion
	cmd:exrheader$secondaryArchSuffix = $portVersion
	cmd:exrmakepreview$secondaryArchSuffix = $portVersion
	cmd:exrmaketiled$secondaryArchSuffix = $portVersion
	cmd:exrmultipart$secondaryArchSuffix = $portVersion
	cmd:exrmultiview$secondaryArchSuffix = $portVersion
	cmd:exrstdattr$secondaryArchSuffix = $portVersion
	lib:libhalf_2_4$secondaryArchSuffix = $libVersionCompat
	lib:libiex_2_4$secondaryArchSuffix = $libVersionCompat
	lib:libiexmath_2_4$secondaryArchSuffix = $libVersionCompat
	lib:libilmimf_2_4$secondaryArchSuffix = $libVersionCompat
	lib:libilmimfutil_2_4$secondaryArchSuffix = $libVersionCompat
	lib:libilmthread_2_4$secondaryArchSuffix = $libVersionCompat
	lib:libimath_2_4$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"
CONFLICTS="
	ilmbase$secondaryArchSuffix
	"

PROVIDES_devel="
	openexr${secondaryArchSuffix}_devel = $portVersion
	devel:libhalf_2_4$secondaryArchSuffix = $libVersionCompat
	devel:libiex_2_4$secondaryArchSuffix = $libVersionCompat
	devel:libiexmath_2_4$secondaryArchSuffix = $libVersionCompat
	devel:libilmimf_2_4$secondaryArchSuffix = $libVersionCompat
	devel:libilmimfutil_2_4$secondaryArchSuffix = $libVersionCompat
	devel:libilmthread_2_4$secondaryArchSuffix = $libVersionCompat
	devel:libimath_2_4$secondaryArchSuffix = $libVersionCompat
	devel:libhalf$secondaryArchSuffix = $libVersionCompat
	devel:libiex$secondaryArchSuffix = $libVersionCompat
	devel:libiexmath$secondaryArchSuffix = $libVersionCompat
	devel:libilmimf$secondaryArchSuffix = $libVersionCompat
	devel:libilmimfutil$secondaryArchSuffix = $libVersionCompat
	devel:libilmthread$secondaryArchSuffix = $libVersionCompat
	devel:libimath$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	openexr$secondaryArchSuffix == $portVersion base
	"
CONFLICTS_devel="
	openexr${secondaryArchSuffix}_devel
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake >= 3.10
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	mkdir -p build && cd build
	cmake .. -DCMAKE_INSTALL_PREFIX:PATH=$prefix
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	# prepare development documentation
	mkdir -p $developDocDir
	mv $prefix/share/doc $developDocDir

	#clear empty directory
	rmdir $prefix/share

	mkdir -p $(dirname $includeDir)
	mv $prefix/include $includeDir
	if [ -n "$secondaryArchSuffix" ]; then
		mv $prefix/lib $prefix/lib2
		mv $prefix/bin $prefix/bin2
		mkdir -p $(dirname $libDir) $(dirname $binDir)
		mv $prefix/lib2 $libDir
		mv $prefix/bin2 $binDir
	fi

	# prepare development lib links
	prepareInstalledDevelLibs \
		libHalf-2_4 libIlmImf-2_4 \
		libImath-2_4 libIex-2_4 libIexMath-2_4 \
		libIlmImfUtil-2_4 libIlmThread-2_4
	fixPkgconfig

	mv $libDir/lib{Half,Iex,Imath,IexMath,IlmImf,IlmImfUtil,IlmThread}.* \
		$developLibDir

	# devel package
	packageEntries devel $developDir $libDir/cmake
}

TEST()
{
	cd build
	make check
}
