SUMMARY="A port to Qt of the Scintilla editing component"
DESCRIPTION="As well as features found in standard text editing components, \
Scintilla includes features especially useful when editing and debugging \
source code:

* syntax styling with support for over 70 languages
* error indicators
* code completion
* call tips
* code folding
* margins can contain markers like those used in debuggers to indicate \
breakpoints and the current line
* recordable macros
* multiple views
* printing

QScintilla is a port or Scintilla to the Qt GUI toolkit from The Qt Company \
and runs on any operating system supported by Qt (eg. Windows, Linux, OS X, \
iOS and Android). QScintilla works with Qt v4 and v5.

QScintilla also includes language bindings for Python. These require that \
PyQt v4 or v5 is also installed.

This version of QScintilla is based on Scintilla v3.5.4."
HOMEPAGE="https://www.riverbankcomputing.com/software/qscintilla/"
COPYRIGHT="2015-2017 Riverbank Computing Limited"
LICENSE="GNU GPL v3"
REVISION="3"
SOURCE_URI="https://www.riverbankcomputing.com/static/Downloads/QScintilla/$portVersion/QScintilla-$portVersion.tar.gz"
CHECKSUM_SHA256="e7346057db47d2fb384467fafccfcb13aa0741373c5d593bc72b55b2f0dd20a7"
SOURCE_DIR="QScintilla-$portVersion"
PATCHES="qscintilla-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	qscintilla$secondaryArchSuffix = $portVersion
	lib:libqscintilla2_qt5$secondaryArchSuffix = 15.0.0 compat >= 15
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

PROVIDES_devel="
	qscintilla${secondaryArchSuffix}_devel = $portVersion
	devel:libqscintilla2_qt5$secondaryArchSuffix = 15.0.0 compat >= 15
	"
REQUIRES_devel="
	haiku${secondaryArchSuffix}_devel
	qscintilla$secondaryArchSuffix == $portVersion base
	"

PROVIDES_python38="
	qscintilla${secondaryArchSuffix}_python38 = $portVersion
	"
REQUIRES_python38="
	qscintilla$secondaryArchSuffix == $portVersion base
	pyqt5_python38
	"
if [ "$targetArchitecture" = "x86_gcc2" ]; then
	PROVIDES_python38+="
		qscintilla_python38 = $portVersion
		"
fi


BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	pyqt5_python38
	pyqt_builder_python38
	sip_python38
	"
BUILD_PREREQUIRES="
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:python3.8
	cmd:sed
	cmd:sip
	"

BUILD()
{
	export QMAKEFEATURES=$PWD/Qt4Qt5/features/
	cd Qt4Qt5
    qmake
    make $jobArgs

	cd ../designer-Qt4Qt5
	qmake INCLUDEPATH+=../Qt4Qt5 QMAKE_LIBDIR+=../Qt4Qt5
	make $jobArgs

	cd ..
	export LIBRARY_PATH=$LIBRARY_PATH:$PWD/Qt4Qt5/
	installLocation=$prefix/../pyqt5_python38/lib/python3.8/vendor-packages
	BINDINGS_DIR=$installLocation/PyQt5/bindings/
	sed -i -e "s|BINDINGS_DIR|$BINDINGS_DIR|g" pyproject.toml
	sip-build --no-make \
		--qsci-features-dir Qt4Qt5/features --qsci-include-dir Qt4Qt5 \
		--qsci-library-dir Qt4Qt5 \
		--api-dir $dataDir/Qt5/qsci/api/python \
		--verbose --tracing
	cd build
	make $jobArgs
}

INSTALL()
{
	cd Qt4Qt5
	sed -i -e 's|INSTALL_ROOT)/boot/system/|INSTALL_ROOT)/|g' Makefile
	make INSTALL_ROOT=$prefix install

	cd ../designer-Qt4Qt5
	sed -i -e 's|INSTALL_ROOT)/boot/system/|INSTALL_ROOT)/|g' Makefile
	make INSTALL_ROOT=$prefix install

	cd ../build
	sed -i -e 's|/packages/python.*/.self/lib/python3.8/site-packages|/lib/python3.8/vendor-packages|g' \
		Makefile Qsci/Makefile Qsci/Qsci.pro inventory.txt QScintilla.pro

	make INSTALL_ROOT=$prefix install

	cp -R $prefix/packages/*/.self/* $prefix/
	rm -rf $prefix/packages

	prepareInstalledDevelLibs \
		libqscintilla2_qt5
	packageEntries devel \
		$developDir \
		$dataDir/Qt5/mkspecs
	packageEntries python38 \
		$prefix/lib/python* \
		$dataDir/Qt5/qsci
}
