SUMMARY="A simple offline documentation browser inspired by Dash"
DESCRIPTION="Zeal is a cross-platform, open source, offline \
documentation browser for software developers, inspired by Dash Docs \
for macOS and iOS. Zeal has over 195+ docsets and are all compatible \
with Dash docsets."
HOMEPAGE="https://zealdocs.org/"
COPYRIGHT="2013-2018 Oleg Shparber"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/zealdocs/zeal/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="095c08f9903071849d5c79878abd48237ce1615f16d324afff1873ab6b5f0026"
SOURCE_FILENAME="zeal-$portVersion.tar.gz"
PATCHES="zeal-$portVersion.patchset"
ADDITIONAL_FILES="zeal.rdef.in"

ARCHITECTURES="all !x86_gcc2 ?x86"
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
fi

PROVIDES="
	zeal$secondaryArchSuffix = $portVersion
	app:Zeal = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libarchive$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5WebKit$secondaryArchSuffix
	lib:libQt5WebKitWidgets$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	extra_cmake_modules$secondaryArchSuffix
	devel:libarchive$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5WebKit$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake .. $cmakeDirArgs \
		-DECM_DIR=/system/data/cmake/Modules/ECM/cmake
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir
	cp build/bin/zeal $appsDir/Zeal

	local APP_SIGNATURE="application/x-vnd.zeal"
	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/zeal.rdef.in > zeal.rdef

	addResourcesToBinaries zeal.rdef $appsDir/Zeal
	mimeset -f $appsDir/Zeal
	addAppDeskbarSymlink $appsDir/Zeal
}

TEST()
{
	make test
}
