SUMMARY="A Pythonic binding for the libxml2 and libxslt libraries"
DESCRIPTION="The lxml XML toolkit is unique in that it combines the speed \
and XML feature completeness of the libxml2 and libxslt libraries with the \
simplicity of a native Python API, mostly compatible but superior to the \
well-known ElementTree API."
HOMEPAGE="https://lxml.de/
	https://github.com/lxml/lxml
	https://pypi.python.org/pypi/lxml/"
COPYRIGHT="2003-2010 Gustavo Niemeyer
	2003 Shuttleworth Foundation
	2004 Infrae"
LICENSE="BSD (3-clause)
	GNU GPL v2
	PSF-2"
REVISION="2"
SOURCE_URI="https://lxml.de/files/lxml-$portVersion.tgz"
CHECKSUM_SHA256="c81cb40bff373ab7a7446d6bbca0190bccc5be3448b47b51d729e37799bb5692"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libxml2$secondaryArchSuffix
	devel:libxslt$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	"

PYTHON_PACKAGES=()
PYTHON_VERSIONS=()
PYTHON_LIBSUFFIXES=()
# We don't have python2 for secondaryArch
if [ -z "$secondaryArchSuffix" ]; then
	PYTHON_PACKAGES+=(python)
	PYTHON_VERSIONS+=(2.7)
	PYTHON_LIBSUFFIXES+=("")
	BUILD_REQUIRES+="
		setuptools_python
		"
	BUILD_PREREQUIRES+="
		cmd:python2
		"
	REPLACES_python="
		python_lxml
		"
fi
# gcc2 does not support the flags passed by python3
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
	PYTHON_PACKAGES+=(python3 python38 python39)
	PYTHON_VERSIONS+=(3.7 3.8 3.9)
	PYTHON_LIBSUFFIXES+=(m '' '')
	BUILD_REQUIRES+="
		setuptools_python3
		setuptools_python38
		setuptools_python39
		"
	BUILD_PREREQUIRES+="
		cmd:python3
		cmd:python3.8
		cmd:python3.9
		"
fi
for i in "${!PYTHON_PACKAGES[@]}"; do
	pythonPackage=${PYTHON_PACKAGES[i]}
	pythonVersion=${PYTHON_VERSIONS[$i]}
	pythonLibSuffix=${PYTHON_LIBSUFFIXES[$i]}

	eval "PROVIDES_$pythonPackage=\"
		${portName}_$pythonPackage = $portVersion
		\""
	eval "REQUIRES_$pythonPackage=\"
		haiku$secondaryArchSuffix
		lib:libpython$pythonVersion$pythonLibSuffix$secondaryArchSuffix
		lib:libxml2$secondaryArchSuffix
		lib:libxslt$secondaryArchSuffix
		lib:libz$secondaryArchSuffix
		\""
done
if [ "$targetArchitecture" = x86_gcc2 -a -n "$secondaryArchSuffix" ]; then
	PROVIDES_python3+="
		lxml_python3 = $portVersion
		"
	PROVIDES_python38+="
		lxml_python38 = $portVersion
		"
	PROVIDES_python39+="
		lxml_python39 = $portVersion
		"
fi

INSTALL()
{
	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
		mkdir -p "$installLocation"
		rm -rf build
		$python setup.py build install \
			--root=/ --prefix="$prefix"

		packageEntries $pythonPackage \
			"$prefix"/lib/$python
	done

	if [ -z "$secondaryArchSuffix" ]; then
		install -m 755 -d "$docDir"
		install -m 644 -t "$docDir" CHANGES.txt CREDITS.txt README.rst
	fi
}
