SUMMARY="A VIM-like web browser"
DESCRIPTION="QuteBrowser is a keyboard-focused browser with a minimal GUI. \
It’s based on Python and PyQt5 and free software, licensed under the GPL. \
It was inspired by other browsers/addons like dwb and Vimperator/Pentadactyl."
HOMEPAGE="https://qutebrowser.org/"
COPYRIGHT="2014-2020 Florian Bruhin (The Compiler)"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/qutebrowser/qutebrowser/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="71d7826042a5c63076c85a5a001a4a4f7bea6f6c0f25308e6e0d46b0b31e93ca"
PATCHES="qutebrowser-$portVersion.patchset"
PYTHON_VERSION="3.8"
ADDITIONAL_FILES="qutebrowser.rdef.in"

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

PROVIDES="
	qutebrowser$secondaryArchSuffix = $portVersion
	app:QuteBrowser$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	importlib_resources_python38
	jinja_python38
	pyqt5_python38
	pyyaml_python38
	setuptools_python38
	cmd:python$PYTHON_VERSION
	lib:libQt5Core$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	importlib_resources_python38
	jinja_python38
	pyyaml_python38
	setuptools_python38
	"
BUILD_PREREQUIRES="
	cmd:python$PYTHON_VERSION
	cmd:a2x
	cmd:make
	"

BUILD()
{
	python=$portPackageLinksDir/cmd~python$PYTHON_VERSION/bin/python$PYTHON_VERSION
	make -f misc/Makefile PYTHON=$python all
}

INSTALL()
{
	# GENERIC: all python_setuptools-based installs need this
	python=$portPackageLinksDir/cmd~python$PYTHON_VERSION/bin/python$PYTHON_VERSION
	pythonVersion=$($python --version 2>&1 | sed 's/Python //' | head -c3)
	installLocation=$prefix/lib/python$pythonVersion/vendor-packages/
	export PYTHONPATH=$installLocation:$PYTHONPATH
	mkdir -p $installLocation $appsDir

	make -f misc/Makefile PREFIX=$prefix PYTHON=$python DATAROOTDIR=$dataDir install

	# Add Haiku resources
	local APP_SIGNATURE="application/x-vnd.qutebrowser"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/qutebrowser.rdef.in \
			> qutebrowser.rdef

	mv $prefix/bin/qutebrowser $appsDir/QuteBrowser
	rm -rf $prefix/bin

	settype -t application/x-vnd.Be-elfexecutable \
		$appsDir/QuteBrowser

	# Installing extra-attribs
	rc qutebrowser.rdef
	resattr -o $appsDir/QuteBrowser \
		qutebrowser.rsrc

	addAppDeskbarSymlink $appsDir/QuteBrowser
}
