# Contributor: Mark Riedesel <mark@klowner.com>
# Maintainer: Mark Riedesel <mark@klowner.com>
pkgname=opencolorio
pkgver=1.1.0
pkgrel=0
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
	OpenColorIO-gcc.patch
	ocio-1.1.0-yamlcpp060.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])')"
}

sha512sums="909874a9f91a8d229622810fc70233680c6e75203bd8555179322de2873da00bf302432e19f189b787ffcda3157ddec1e4601c97f75a36e16f644fe7d42f6998  opencolorio-1.1.0.tar.gz
befed734f240d26c7cbeb020b540ea91d84c9422fa61dcb0ab16f56389f7c5c90d10e015c6cdbed2033047b7e31ceb4fd1b2707c2bef1a8e0f33959601471d5f  OpenColorIO-gcc.patch
ef4b0e880c587fcd004865fd938e7f1fb1bbb933abf1ccf352260ebe3a50145664e27b9f1119b72ced99afe4d19b49b0b6c249dd95faaec9c1332ffc44bc9811  ocio-1.1.0-yamlcpp060.patch"
