SUMMARY="Pure-Python implementation of ASN.1 types and codecs"
DESCRIPTION="Pure-Python implementation of ASN.1 types and DER/BER/CER codecs \
(X.208)"
HOMEPAGE="http://snmplabs.com/pyasn1/
	https://github.com/etingof/pyasn1
	https://pypi.org/project/pyasn1"
COPYRIGHT="2007-2018 Ilya Etingof"
LICENSE="BSD (2-clause)"
REVISION="1"
SOURCE_URI="https://files.pythonhosted.org/packages/source/p/pyasn1/pyasn1-$portVersion.tar.gz"
CHECKSUM_SHA256="aef77c9fb94a3ac588e87841208bdec464471d9871bd5050a287cc9a475cd0ba"

ARCHITECTURES="any"

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

BUILD_REQUIRES="
	haiku_devel
	"

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
		\""
	eval "REQUIRES_$pythonPackage=\"
		haiku
		cmd:python$pythonVersion\
		\""
BUILD_REQUIRES="$BUILD_REQUIRES
	setuptools_$pythonPackage"
BUILD_PREREQUIRES="$BUILD_PREREQUIRES
	cmd:python$pythonVersion"
done

BUILD()
{
	for i in "${!PYTHON_PACKAGES[@]}"; do
		pythonPackage=${PYTHON_PACKAGES[i]}
		pythonVersion=${PYTHON_VERSIONS[$i]}

		rm -rf "$sourceDir"-$pythonPackage
		cp -a "$sourceDir" "$sourceDir"-$pythonPackage
		cd "$sourceDir"-$pythonPackage

		python=python$pythonVersion
		installLocation=$prefix/lib/$python/vendor-packages/
		export PYTHONPATH=$installLocation
		mkdir -p "$installLocation"
		$python setup.py build
	done
}

INSTALL()
{
	for i in "${!PYTHON_PACKAGES[@]}"; do
		pythonPackage=${PYTHON_PACKAGES[i]}
		pythonVersion=${PYTHON_VERSIONS[$i]}

		cd "$sourceDir"-$pythonPackage

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

		install -m 755 -d "$dataDir"/licenses
		install -m 644 -T LICENSE.rst "$dataDir"/licenses/pyasn1.rst

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

	install -m 755 -d "$dataDir"/licenses "$docDir"
	install -m 644 -T LICENSE.rst "$dataDir"/licenses/pyasn1.rst
	install -m 644 -t "$docDir" README.md
}

TEST()
{
	for i in "${!PYTHON_PACKAGES[@]}"; do
		pythonPackage=${PYTHON_PACKAGES[i]}
		pythonVersion=${PYTHON_VERSIONS[$i]}

		cd "$sourceDir"-$pythonPackage

		python=python$pythonVersion
		$python setup.py tests
	done
}
