SUMMARY="A tabbed document viewer"
DESCRIPTION="qPDFView is a tabbed document viewer using Poppler, libspectre, \
DjVuLibre, CUPS and Qt, licensed under GPL version 2 or later."
HOMEPAGE="https://launchpad.net/qpdfview/"
COPYRIGHT="Adam Reichold et al."
LICENSE="GNU GPL v2"
REVISION="6"
SOURCE_URI="$HOMEPAGE/trunk/$portVersion/+download/qpdfview-$portVersion.tar.gz"
CHECKSUM_SHA256="cc642e7fa74029373ca9b9fbc29adc4883f8b455130a78ad54746d6844a0396c"
SOURCE_DIR="qpdfview-$portVersion"
PATCHES="qpdfview-$portVersion.patchset"
ADDITIONAL_FILES="qpdfview.rdef.in"

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

PROVIDES="
	qpdfview$secondaryArchSuffix = $portVersion
	app:qPDFView$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libdjvulibre$secondaryArchSuffix
	lib:libGl$secondaryArchSuffix
	lib:libmagic$secondaryArchSuffix
	lib:libpoppler$secondaryArchSuffix
	lib:libpoppler_qt5$secondaryArchSuffix
	lib:libQt5Concurrent$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Sql$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libdjvulibre$secondaryArchSuffix
	devel:libGl$secondaryArchSuffix
	devel:libmagic$secondaryArchSuffix
	devel:libpoppler$secondaryArchSuffix >= 117
	devel:libpoppler_qt5$secondaryArchSuffix
	devel:libQt5Concurrent$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Sql$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:qmake$secondaryArchSuffix >= 5
	"

BUILD()
{
	lrelease qpdfview.pro

	mkdir -p haiku_build && cd haiku_build
	qmake ../qpdfview.pro \
		CONFIG+="without_ps without_cups without_synctex without_dbus without_signals" \
		TARGET_INSTALL_PATH=$appsDir/qPDFView \
		PLUGIN_INSTALL_PATH=$appsDir/qPDFView/lib \
		DATA_INSTALL_PATH=$appsDir/qPDFView/data \
		MANUAL_INSTALL_PATH=$manDir

	make $jobArgs
}

INSTALL()
{
	cd haiku_build
	make install

	#To translate the help file, modify "translations/qpdfview_??.ts".
	#Replace the written "<translation>help.html</translation>"
	# with "<translation>help_??.html</translation>".
	
	mv $appsDir/qPDFView/qpdfview $appsDir/qPDFView/qPDFView
	# Icon
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/qpdfview.rdef.in > qpdfview.rdef

	addResourcesToBinaries qpdfview.rdef \
		$appsDir/qPDFView/qPDFView

	addAppDeskbarSymlink $appsDir/qPDFView/qPDFView
}
