SUMMARY="Python Imaging Library (fork)"
DESCRIPTION="Pillow is the friendly PIL fork by Alex Clark and Contributors.
PIL is the Python Imaging Library by Fredrik Lundh and Contributors."
HOMEPAGE="https://github.com/python-imaging/Pillow
	https://pypi.python.org/pypi/Pillow"
COPYRIGHT="1997-2011 by Secret Labs AB
	1995-2011 by Fredrik Lundh"
LICENSE="HPND"
REVISION="4"
SOURCE_URI="https://github.com/python-pillow/Pillow/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="7bf2d6bdb68fa6ccec15c0fd9aa20fac9641cd20dc6079344f5a6534e13a70f9"
SOURCE_FILENAME="pillow-$portVersion.tar.gz"
SOURCE_DIR="Pillow-$portVersion"

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

PROVIDES="
	$portName = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:liblcms2$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libopenjp2$secondaryArchSuffix
	devel:libtiff$secondaryArchSuffix
	devel:libwebp$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:pkg_config$secondaryArchSuffix
	"

PYTHON_PACKAGES=(python python3 python38 python39)
PYTHON_VERSIONS=(2.7 3.7 3.8 3.9)
for i in "${!PYTHON_PACKAGES[@]}"; do
pythonPackage=${PYTHON_PACKAGES[i]}
pythonVersion=${PYTHON_VERSIONS[$i]}
eval "PROVIDES_${pythonPackage}=\"\
	${portName}_$pythonPackage = $portVersion\
	\"; \
REQUIRES_$pythonPackage=\"\
	haiku${secondaryArchSuffix}\n\
	cmd:python$pythonVersion\n\
	lib:liblcms2$secondaryArchSuffix\n\
	lib:libfreetype$secondaryArchSuffix\n\
	lib:libjpeg$secondaryArchSuffix\n\
	lib:libopenjp2$secondaryArchSuffix\n\
	lib:libtiff$secondaryArchSuffix\n\
	lib:libwebp$secondaryArchSuffix\n\
	lib:libz$secondaryArchSuffix\n\
	\""
BUILD_REQUIRES="$BUILD_REQUIRES
	setuptools_$pythonPackage"
BUILD_PREREQUIRES="$BUILD_PREREQUIRES
	cmd:python$pythonVersion"
done

INSTALL()
{
	export INCLUDE="$(findpaths -c: B_FIND_PATH_HEADERS_DIRECTORY)"
	export LIB="$(findpaths -c: B_FIND_PATH_DEVELOP_LIB_DIRECTORY)"
	for i in "${!PYTHON_PACKAGES[@]}"; do
		pythonPackage=${PYTHON_PACKAGES[i]}
		pythonVersion=${PYTHON_VERSIONS[$i]}

		python=python$pythonVersion
		installLocation=$prefix/lib/$python/vendor-packages/
		export PYTHONPATH=$installLocation:$PYTHONPATH
		mkdir -p $installLocation
		rm -rf build
		$python setup.py build install \
			--root=/ --prefix=$prefix

		packageEntries  $pythonPackage \
			$prefix/lib/python*
	done
}
