SUMMARY="Programable shading language for advanced renderers"
DESCRIPTION="Open Shading Language (OSL) is a small but rich language for \
programmable shading in advanced renderers and other applications, ideal \
for describing materials, lights, displacement, and pattern generation."
HOMEPAGE="https://github.com/imageworks/OpenShadingLanguage"
COPYRIGHT="2009-2020 Sony Pictures Imageworks Inc."
LICENSE="BSD (3-clause)"
REVISION="4"
SOURCE_URI="$HOMEPAGE/archive/Release-$portVersion.tar.gz"
CHECKSUM_SHA256="2bd4c7b29993499d0d0f011f71d0eb8e204b67e766b35462fdec1e3858dce981"
SOURCE_DIR="OpenShadingLanguage-Release-$portVersion"
PATCHES="osl-$portVersion.patchset"

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

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

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

PROVIDES="
	osl$secondaryArchSuffix = $portVersion
	cmd:oslc$commandSuffix
	cmd:oslinfo$commandSuffix
#	cmd:testrender$commandSuffix
#	cmd:testshade$commandSuffix
#	cmd:testshade_dso$commandSuffix
	lib:liboslcomp$secondaryArchSuffix
	lib:liboslexec$secondaryArchSuffix
	lib:liboslnoise$secondaryArchSuffix
	lib:liboslquery$secondaryArchSuffix
#	lib:libtestshade$secondaryArchSuffix
	lib:osl.imageio$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_atomic$secondaryArchSuffix
	lib:libboost_chrono$secondaryArchSuffix
	lib:libboost_date_time$secondaryArchSuffix
	lib:libboost_filesystem$secondaryArchSuffix
	lib:libboost_serialization$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libboost_thread$secondaryArchSuffix
	lib:libboost_wave$secondaryArchSuffix
	lib:libIex_3_0$secondaryArchSuffix
	lib:libIlmThread_3_0$secondaryArchSuffix
	lib:libImath_3_0$secondaryArchSuffix
	lib:libLLVM_9$secondaryArchSuffix
	lib:libOpenEXR_3_0$secondaryArchSuffix
	lib:libOpenEXRUtil_3_0$secondaryArchSuffix
	lib:libOpenImageIO$secondaryArchSuffix
#	lib:libpartio$secondaryArchSuffix
	lib:libpugixml$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	osl${secondaryArchSuffix}_devel = $portVersion
	devel:liboslcomp$secondaryArchSuffix
	devel:liboslexec$secondaryArchSuffix
	devel:liboslnoise$secondaryArchSuffix
	devel:liboslquery$secondaryArchSuffix
#	devel:libtestshade$secondaryArchSuffix
	devel:osl.imageio$secondaryArchSuffix
	"
REQUIRES_devel="
	osl$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	gcc${secondaryArchSuffix}_syslibs_devel
	devel:libboost_atomic$secondaryArchSuffix >= 1.70.0
	devel:libboost_chrono$secondaryArchSuffix >= 1.70.0
	devel:libboost_date_time$secondaryArchSuffix >= 1.70.0
	devel:libboost_filesystem$secondaryArchSuffix >= 1.70.0
	devel:libboost_serialization$secondaryArchSuffix >= 1.70.0
	devel:libboost_system$secondaryArchSuffix >= 1.70.0
	devel:libboost_thread$secondaryArchSuffix >= 1.70.0
	devel:libboost_wave$secondaryArchSuffix >= 1.70.0
	devel:libIex_3_0$secondaryArchSuffix
	devel:libIlmThread_3_0$secondaryArchSuffix
	devel:libImath_3_0$secondaryArchSuffix
	devel:libLLVM_9$secondaryArchSuffix
	devel:libOpenEXR_3_0$secondaryArchSuffix
	devel:libOpenEXRUtil_3_0$secondaryArchSuffix
	devel:libOpenImageIO$secondaryArchSuffix >= 2.2
#	devel:libpartio$secondaryArchSuffix
	devel:libpugixml$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:bison
	cmd:clang_9
	cmd:cmake
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python
	"

defineDebugInfoPackage osl$secondaryArchSuffix \
	$libDir/liboslcomp.so.$libVersion \
	$libDir/liboslexec.so.$libVersion \
	$libDir/liboslnoise.so.$libVersion \
	$libDir/liboslquery.so.$libVersion \
	$libDir/osl.imageio.so \
	$commandBinDir/oslc$commandSuffix \
	$commandBinDir/oslinfo$commandSuffix

BUILD()
{
	export LDFLAGS=-lnetwork
	cmake -B build -S . \
		$cmakeDirArgs \
		-DCMAKE_CXX_FLAGS="-DBOOST_NO_CXX11_CONSTEXPR" \
		-DCMAKE_INSTALL_BINDIR=$commandBinDir \
		-DUSE_PYTHON=OFF \
		-DVERBOSE=ON \
		-DUSE_PARTIO=OFF \
		-DOSL_BUILD_TESTS=OFF \
		-DOSL_BUILD_SHADERS=OFF \
		-DINSTALL_DOCS=OFF -L

	make -C build $jobArgs
}

INSTALL()
{
	make -C build install

	prepareInstalledDevelLibs \
		liboslcomp \
		liboslexec \
		liboslnoise \
		liboslquery \
		osl.imageio

	fixPkgconfig

	packageEntries devel \
		$developDir \
		$libDir/cmake
}

TEST()
{
	make -C build test
}
