SUMMARY="Grib reader and weather visualization software"
DESCRIPTION="XyGrib with OpenGribs - 'open-source meets open-data'
Serious about your weather? The combination of the best in free and open \
software with the best in free and open data can be found here.
XyGrib is a leading opensource weather visualization package that now \
interacts with OpenGribs's Grib server providing a choice of global and \
large area atmospheric and wave models.

XyGrib also uses free and open pre-cut Gribs of high resolution regional \
models found on sister site OpenSkiron.org"
HOMEPAGE="https://opengribs.org/"
COPYRIGHT="2008-2012 - Jacques Zaninetti"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/opengribs/XyGrib/archive/v$portVersion.tar.gz"
SOURCE_URI_2="https://github.com/opengribs/XyGrib/releases/download/v1.1.1/XyGrib___High_Resolution_Maps.tar.gz"
SOURCE_URI_3="https://github.com/opengribs/XyGrib/releases/download/v1.2.6.1/XyGrib__Languages_v1.2.6.tgz"
SOURCE_URI_4="https://github.com/opengribs/XyGrib/releases/download/v1.1.1/XyGrib___cities_files.tar.gz"
CHECKSUM_SHA256="2dc6099293ae6f7a4bfbfc0cab590cf7ad48241d608e6d7a76e35961b9fc2157"
CHECKSUM_SHA256_2="164d0bca0ab118f242d6d10dfb6e6b2f3eacdcf2781b532336e02a2d223a0d0d"
CHECKSUM_SHA256_3="e8a1835af31ad334974ccf3aa9a0b68ff6499d20f812895bd8215152859f3472"
CHECKSUM_SHA256_4="7122fe14c43e49c69c46af0c23e9c34224767feecb2e919da34dc0a6d16c2134"
SOURCE_DIR="XyGrib-$portVersion"
PATCHES="xygrib-$portVersion.patchset"
ADDITIONAL_FILES="xygrib.rdef.in"

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

PROVIDES="
	xygrib$secondaryArchSuffix = $portVersion
	cmd:xygrib$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libnova$secondaryArchSuffix
	lib:libopenjp2$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libproj$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libnova$secondaryArchSuffix
	devel:libopenjp2$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libproj$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libQt5Xml$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	"

BUILD()
{
	# HQ-maps
	cp -r $sourceDir2/data/data/maps/* $sourceDir/data/maps

	# Languages, currently every language included by default
	# cp -r $sourceDir3/* $sourceDir/data/tr

	# Cities
	cp -r $sourceDir4/* $sourceDir/data/gis

	cmake -B build -S . \
		$cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$appsDir
	make -C build $jobArgs
}

INSTALL()
{
	make -C build install

	local APP_SIGNATURE="application/x-vnd.xygrib"
	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/xygrib.rdef.in > $sourceDir/xygrib.rdef
	addResourcesToBinaries $sourceDir/xygrib.rdef $appsDir/XyGrib/XyGrib
	addAppDeskbarSymlink $appsDir/XyGrib/XyGrib
}
