SUMMARY="A tool to create Python bindings for C and C++ libraries"
DESCRIPTION="SIP comprises a code generator and a Python module. The code generator \
processes a set of specification files and generates C or C++ code which is \
then compiled to create the bindings extension module. The SIP Python \
module provides support functions to the automatically generated code."
HOMEPAGE="https://www.riverbankcomputing.com/software/sip/"
COPYRIGHT="2019 Riverbank Computing Limited"
LICENSE="GNU GPL v2
	GNU GPL v3
	SIP"
REVISION="1"
SOURCE_URI="https://pypi.python.org/packages/source/s/sip/sip-$portVersion.tar.gz"
CHECKSUM_SHA256="42ec368520b8da4a0987218510b1b520b4981e4405086c1be384733affc2bcb0"
SOURCE_DIR="sip-$portVersion"
PATCHES="sip-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2"
if [ "$targetArchitecture" = "x86_gcc2" ]; then
SECONDARY_ARCHITECTURES="x86"
fi

commandBinDir=$binDir
if [ "$targetArchitecture" = "x86_gcc2" ]; then
	commandBinDir=$prefix/bin
fi

PROVIDES="
	sip$secondaryArchSuffix = $portVersion
	cmd:sip = $portVersion
	cmd:sip_build
	cmd:sip_distinfo
	cmd:sip_install
	cmd:sip_module
	cmd:sip_sdist
	cmd:sip_wheel
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

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

	maybe_sipNoSuffix=
	if [ "$targetArchitecture" = "x86_gcc2" ]; then
		maybe_sipNoSuffix="sip_$pythonPackage = $portVersion"
	fi

	eval "
		PROVIDES_${pythonPackage}=\"
			sip${secondaryArchSuffix}_$pythonPackage = $portVersion
			$maybe_sipNoSuffix
			\"
		REQUIRES_$pythonPackage=\"
			haiku$secondaryArchSuffix
			cmd:python$pythonVersion
			packaging_$pythonPackage
			setuptools_$pythonPackage
			toml_$pythonPackage
			\"
		"

	BUILD_REQUIRES+="
		setuptools_$pythonPackage
		"
	BUILD_PREREQUIRES+="
		cmd:python$pythonVersion
		"
done

BUILD()
{
	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"

		$python setup.py build
	done
}

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

		python=python$pythonVersion
		installLocation="$prefix"/lib/$python/vendor-packages/

		$python setup.py install --skip-build --root=/ --prefix=$prefix \
			--optimize=1

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