# Contributor: Mark Riedesel <mark@klowner.com>
# Maintainer: Mark Riedesel <mark@klowner.com>
pkgname=opencolorio
pkgver=1.0.9
pkgrel=4
pkgdesc="A color management framework for visual effects and animation"
url="http://opencolorio.org"
arch="all"
license="BSD"
depends=""
makedepends="boost-dev cmake freeglut-dev glew-dev lcms2-dev python2-dev
	python3-dev tinyxml-dev yaml-cpp-dev"
subpackages="py2-$pkgname:py2 py3-$pkgname:py3 $pkgname-dev $pkgname-tools"
source="$pkgname-$pkgver.tar.gz::http://github.com/imageworks/OpenColorIO/archive/v$pkgver.tar.gz
	yaml-cpp-0.5-support.patch
	temp-deref-with-yaml-0.5.0.patch"
builddir="$srcdir/OpenColorIO-$pkgver"

build() {
	local pyver use_sse2
	cd "$builddir"

	# Just to be sure we're using Alpine packages.
	rm -f ext/lcms* ext/tinyxml* ext/yaml*

	case "$CARCH" in
		x86_64) use_sse2=TRUE ;;
		*) use_sse2=FALSE ;;
	esac

	local pyver
	for pyver in python3 python2; do
		mkdir build-$pyver && cd build-$pyver

		cmake .. \
			-DCMAKE_INSTALL_PREFIX=/usr \
			-DOCIO_BUILD_TRUELIGHT=OFF \
			-DOCIO_BUILD_NUKE=OFF \
			-DOCIO_BUILD_SHARED=ON \
			-DOCIO_BUILD_STATIC=OFF \
			-DOCIO_USE_SSE="$use_sse2" \
			-DPYTHON=/usr/bin/$pyver \
			-DUSE_EXTERNAL_YAML=TRUE \
			-DUSE_EXTERNAL_TINYXML=TRUE \
			-DUSE_EXTERNAL_LCMS=TRUE \
			|| return 1
		make || return 1
		cd ..
	done
}

package() {
	local pyver
	for pyver in python3 python2; do
		cd "$builddir"/build-$pyver
		make DESTDIR="$pkgdir" install || return 1
	done
}

tools() {
	pkgdesc="OpenColorIO color management framework tools"

	mkdir -p "$subpkgdir"/usr/
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr
}

_python() {
	pkgdesc="Python $1 bindings for OpenColorIO color management framework"
	depends="python$1"

	mv "$pkgdir"$2 "$subpkgdir"
}

py2() {
	_python 2 "$(python2 -c 'import site; print(site.getsitepackages()[0])')"
}

py3() {
	_python 3 "$(python3 -c 'import site; print(site.getsitepackages()[0])')"
}

md5sums="06d0efe9cc1b32d7b14134779c9d1251  opencolorio-1.0.9.tar.gz
11bb6b587b2e5242f75aca281bab158c  yaml-cpp-0.5-support.patch
5f13bef26e14b2dd908e69a2bc8fb7a4  temp-deref-with-yaml-0.5.0.patch"
sha256sums="27c81e691c15753cd2b560c2ca4bd5679a60c2350eedd43c99d44ca25d65ea7f  opencolorio-1.0.9.tar.gz
b381912a81342e242d1a6ef39cf1556f7b383407af9c1aefbde06e38186777ad  yaml-cpp-0.5-support.patch
6df29f0d3de06ab0fbc2fa06f6fc7537d0628c4185d7a9f6228b2d0be07917d7  temp-deref-with-yaml-0.5.0.patch"
sha512sums="ac953ba9904aff44de37cc2ee60dbf524bd86d25f699c1eacaa61ca30fed8f077194d47d34a72c05b706da7e1a3974a988d67d60031d424d91b9240f8ab86ed3  opencolorio-1.0.9.tar.gz
8b909e1aa688ca38ce7938a4855611cf19781a3c2dc9cc9bca3df3b8d21a2a7772e35917ba9f636c89ea2da8eec2aa7b7118bfa77e0787614110e7441b038de5  yaml-cpp-0.5-support.patch
3793e39d74f3c585d7fc2fbcc7f131fba9f0fea130de80c31461101355954c3d3fa158028652f074fb129e7c0a7ee1e506dbfc187ca5fbfdce09303b371bf266  temp-deref-with-yaml-0.5.0.patch"
