SUMMARY="A Python interface to the cURL library"
DESCRIPTION="PycURL is a Python interface to libcurl, the multiprotocol file \
transfer library. Similarly to the urllib Python module, PycURL can be used to \
fetch objects identified by a URL from a Python program. Beyond simple fetches \
however PycURL exposes most of the functionality of libcurl."
HOMEPAGE="http://pycurl.io/
	https://github.com/pycurl/pycurl"
COPYRIGHT="2001-2008 Kjetil Jacobsen
	2001-2008 Markus F.X.J. Oberhumer
	2013-2018 Oleg Pudeyev"
LICENSE="GNU LGPL v2.1
	MIT"
REVISION="4"
SOURCE_URI="https://github.com/pycurl/pycurl/archive/REL_${portVersion//./_}.tar.gz"
CHECKSUM_SHA256="553047902a738cc2e6b1cd42783a9d0992e47086773be30027a71e1293493c39"
SOURCE_DIR="pycurl-REL_${portVersion//./_}"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

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

if [ -z "$secondaryArchSuffix" ]; then
ARCHITECTURES_doc="any"
SUMMARY_doc="A Python interface to the cURL library (documentation)"
PROVIDES_doc="
	pycurl_doc = $portVersion
	"
REQUIRES_doc="
	haiku
	"
fi

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libnghttp2$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

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+=("")
fi
# gcc2 does not support the flags passed by python3
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
	PYTHON_PACKAGES+=(python3)
	PYTHON_VERSIONS+=(3.7)
	PYTHON_LIBSUFFIXES+=(m)
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:libcrypto$secondaryArchSuffix
		lib:libcurl$secondaryArchSuffix
		lib:libnghttp2$secondaryArchSuffix
		lib:libpython$pythonVersion$pythonLibSuffix$secondaryArchSuffix
		lib:libssl$secondaryArchSuffix
		lib:libz$secondaryArchSuffix
		\""
BUILD_REQUIRES="$BUILD_REQUIRES
	setuptools_$pythonPackage"
BUILD_PREREQUIRES="$BUILD_PREREQUIRES
	cmd:python$pythonVersion"
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/
		export PYTHONPATH="$installLocation"
		rm -rf build
		make PYTHON=$python
		mkdir -p "$installLocation"
		$python setup.py build install --root=/ --prefix="$prefix"

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

	if [ -z "$secondaryArchSuffix" ]; then
		mkdir -p "$docDir"
		mv "$prefix"/share/doc/pycurl/* "$docDir"
		rmdir "$prefix"/share/doc/pycurl
		packageEntries doc \
			"$docDir"
		rmdir "$prefix"/documentation/packages "$prefix"/documentation
	else
		rm -rf "$prefix"/share/doc/pycurl
	fi
	rmdir "$prefix"/share/doc "$prefix"/share
}
