SUMMARY="An open-source text processing system"
DESCRIPTION="Docutils is an open-source text processing system for processing \
plaintext documentation into useful formats, such as HTML, LaTeX, man-pages, \
open-document or XML. It includes reStructuredText, the easy to read, easy to \
use, what-you-see-is-what-you-get plaintext markup language."
HOMEPAGE="http://docutils.sourceforge.net/"
COPYRIGHT="Günter Milde
	John Gruber
	Alex Fernández"
LICENSE="Public Domain
	BSD (2-clause)
	GNU GPL v3
	Python"
REVISION="1"
SOURCE_URI="https://pypi.io/packages/source/${portName:0:1}/$portName/$portName-$portVersion.tar.gz"
CHECKSUM_SHA256="679987caf361a7539d76e584cbeddc311e3aee937877c87346f31debc63e9d06"

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

PROVIDES_python="$PROVIDES_python
	cmd:rst2html.py = $portVersion
	cmd:rst2html4.py = $portVersion
	cmd:rst2html5.py = $portVersion
	cmd:rst2latex.py = $portVersion
	cmd:rst2man.py = $portVersion
	cmd:rst2newlatex.py = $portVersion
	cmd:rst2odt_prepstyles.py = $portVersion
	cmd:rst2odt.py = $portVersion
	cmd:rst2pseudoxml.py = $portVersion
	cmd:rst2s5.py = $portVersion
	cmd:rst2xetex.py = $portVersion
	cmd:rst2xml.py = $portVersion
	cmd:rstpep2html.py = $portVersion
	"
PROVIDES_python3="$PROVIDES_python3
	cmd:rst2html3.py = $portVersion
	cmd:rst2html43.py = $portVersion
	cmd:rst2html53.py = $portVersion
	cmd:rst2latex3.py = $portVersion
	cmd:rst2man3.py = $portVersion
	cmd:rst2newlatex3.py = $portVersion
	cmd:rst2odt_prepstyles3.py = $portVersion
	cmd:rst2odt3.py = $portVersion
	cmd:rst2pseudoxml3.py = $portVersion
	cmd:rst2s53.py = $portVersion
	cmd:rst2xetex3.py = $portVersion
	cmd:rst2xml3.py = $portVersion
	cmd:rstpep2html3.py = $portVersion
	"
PROVIDES_python38="$PROVIDES_python38
	cmd:rst2html38.py = $portVersion
	cmd:rst2html438.py = $portVersion
	cmd:rst2html538.py = $portVersion
	cmd:rst2latex38.py = $portVersion
	cmd:rst2man38.py = $portVersion
	cmd:rst2newlatex38.py = $portVersion
	cmd:rst2odt_prepstyles38.py = $portVersion
	cmd:rst2odt38.py = $portVersion
	cmd:rst2pseudoxml38.py = $portVersion
	cmd:rst2s538.py = $portVersion
	cmd:rst2xetex38.py = $portVersion
	cmd:rst2xml38.py = $portVersion
	cmd:rstpep2html38.py = $portVersion
	"
PROVIDES_python39="$PROVIDES_python39
	cmd:rst2html39.py = $portVersion
	cmd:rst2html439.py = $portVersion
	cmd:rst2html539.py = $portVersion
	cmd:rst2latex39.py = $portVersion
	cmd:rst2man39.py = $portVersion
	cmd:rst2newlatex39.py = $portVersion
	cmd:rst2odt_prepstyles39.py = $portVersion
	cmd:rst2odt39.py = $portVersion
	cmd:rst2pseudoxml39.py = $portVersion
	cmd:rst2s539.py = $portVersion
	cmd:rst2xetex39.py = $portVersion
	cmd:rst2xml39.py = $portVersion
	cmd:rstpep2html39.py = $portVersion
	"

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:$PYTHONPATH
		mkdir -p $installLocation
		rm -rf build
		$python setup.py build install \
			--root=/ --prefix=$prefix

		if [ $pythonPackage == python3 ]; then
			for f in $binDir/*.py; do
				mv $f ${f%.py}3.py
			done
		fi
		if [ $pythonPackage == python38 ]; then
			for f in $binDir/*.py; do
				mv $f ${f%.py}38.py
			done
		fi
		if [ $pythonPackage == python39 ]; then
			for f in $binDir/*.py; do
				mv $f ${f%.py}39.py
			done
		fi
		packageEntries  $pythonPackage \
			$prefix/lib/python* \
			$binDir
	done
}
