SUMMARY="A Qt5-based IM client for Matrix"
DESCRIPTION="Quaternion is a cross-platform Qt5-based desktop IM client for Matrix, \
a reference desktop application using libQMatrixClient."
HOMEPAGE="https://matrix.org/docs/projects/client/quaternion/"
COPYRIGHT="Quotient contributors"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/QMatrixClient/Quaternion/archive/${portVersion}.tar.gz"
CHECKSUM_SHA256="69f034241dddc8d9436a895bb76b022e492e61e2f49d9a80ed8d79ab12b63a0e"
SOURCE_FILENAME="Quaternion-${portVersion}.tar.gz"
SOURCE_DIR="Quaternion-${portVersion}"
ADDITIONAL_FILES="quaternion.rdef.in"
PATCHES="quaternion-0.0.95.1.patchset"

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

PROVIDES="
	quaternion$secondaryArchSuffix = $portVersion
	app:Quaternion$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libqt5keychain$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libquotient$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libqt5keychain$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libQt5Xml$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libquotient$secondaryArchSuffix >= 0.6.6
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:linguist$secondaryArchSuffix >= 5
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	"

BUILD()
{
	cmake -B build \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_BINDIR=$appsDir \
		-DCMAKE_INSTALL_DATADIR=$dataDir
	cmake --build build
}

INSTALL()
{
	cmake --install build

	# we are not linux
	rm -rf $dataDir/{applications,metainfo,icons}

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

	mv $appsDir/quaternion $appsDir/Quaternion

	addResourcesToBinaries quaternion.rdef $appsDir/Quaternion
	addAppDeskbarSymlink $appsDir/Quaternion
}
