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="3"
SOURCE_URI="https://github.com/AcademySoftwareFoundation/openexr/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="63ebc7677d63ad59f1ec205d149dff1da31e7e3c8e78e944458b1d371c7e2f3c"

if [ $effectiveTargetArchitecture = "x86_gcc2" ]; then
	PATCHES="openexr-$portVersion.patchset"
fi

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

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

PROVIDES="
	openexr$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$secondaryArchSuffix = $libVersionCompat
	lib:libiex$secondaryArchSuffix = $libVersionCompat
	lib:libiex_2_2$secondaryArchSuffix = $libVersionCompat
	lib:libiexmath$secondaryArchSuffix = $libVersionCompat
	lib:libiexmath_2_2$secondaryArchSuffix = $libVersionCompat
	lib:libilmthread$secondaryArchSuffix = $libVersionCompat
	lib:libilmthread_2_2$secondaryArchSuffix = $libVersionCompat
	lib:libimath$secondaryArchSuffix = $libVersionCompat
	lib:libimath_2_2$secondaryArchSuffix = $libVersionCompat

	lib:libilmimf$secondaryArchSuffix = $libVersionCompat
	lib:libilmimf_2_2$secondaryArchSuffix = $libVersionCompat
	lib:libilmimfutil$secondaryArchSuffix = $libVersionCompat
	lib:libilmimfutil_2_2$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"
CONFLICTS="
	ilmbase$secondaryArchSuffix
	"

PROVIDES_devel="
	openexr${secondaryArchSuffix}_devel = $portVersion

	devel:libhalf$secondaryArchSuffix = $libVersionCompat
	devel:libiex$secondaryArchSuffix = $libVersionCompat
	devel:libiex_2_2$secondaryArchSuffix = $libVersionCompat
	devel:libiexmath$secondaryArchSuffix = $libVersionCompat
	devel:libiexmath_2_2$secondaryArchSuffix = $libVersionCompat
	devel:libilmthread$secondaryArchSuffix = $libVersionCompat
	devel:libilmthread_2_2$secondaryArchSuffix = $libVersionCompat
	devel:libimath$secondaryArchSuffix = $libVersionCompat
	devel:libimath_2_2$secondaryArchSuffix = $libVersionCompat

	devel:libilmimf$secondaryArchSuffix = $libVersionCompat
	devel:libilmimf_2_2$secondaryArchSuffix = $libVersionCompat
	devel:libilmimfutil$secondaryArchSuffix = $libVersionCompat
	devel:libilmimfutil_2_2$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	openexr$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	if [ $effectiveTargetArchitecture = "x86_gcc2" ]; then
		export CXXFLAGS="-Dios_base=ios -ftemplate-depth-30"
	fi

	cd IlmBase
	./bootstrap
	runConfigure ./configure
	make $jobArgs
	make install
	export PKG_CONFIG_PATH+=:$libDir/pkgconfig/

	cd ../OpenEXR
	./bootstrap
	runConfigure ./configure
	make $jobArgs
}

INSTALL()
{
	cd IlmBase
	make install

	cd ../OpenEXR
	make install

	# remove libtool library files
	rm $libDir/lib*.la

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

	# prepare autom4te script
	mkdir -p $developDir
	mv $dataDir/aclocal $developDir

	# clear empty directory
	rmdir $dataDir

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

	fixPkgconfig

	# devel package
	packageEntries devel $developDir
}

TEST()
{
	make check
}
