SUMMARY="An IM client for Matrix"
DESCRIPTION="The motivation behind the nheko is to provide a native desktop \
app for Matrix that feels more like a mainstream chat app (Element, Telegram \
etc.) and less like an IRC client. It was developed using the Qt5 framework."
HOMEPAGE="https://nheko.im/nheko-reborn/nheko"
COPYRIGHT="2017-2021 Nheko Authors"
LICENSE="GNU GPL v3"
REVISION="5"
SOURCE_URI="https://github.com/Nheko-Reborn/nheko/archive/v${portVersion}.tar.gz"
CHECKSUM_SHA256="df4575c47daab47d418637a4637b599e3848dd749132ca1e92f981d9212eabb2"
SOURCE_FILENAME="nheko-${portVersion}.tar.gz"
SOURCE_DIR="nheko-${portVersion}"
PATCHES="nheko-${portVersion}.patchset"
ADDITIONAL_FILES="nheko.rdef.in"

boostMinimumVersion="1.70.0"

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

PROVIDES="
	nheko$secondaryArchSuffix = $portVersion
	app:Nheko$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcmark$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libfmt$secondaryArchSuffix
	lib:liblmdb$secondaryArchSuffix
	lib:libmatrix_client$secondaryArchSuffix
	lib:libolm$secondaryArchSuffix
	lib:libQt5Concurrent$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQT5Gui$secondaryArchSuffix
	lib:libqt5keychain$secondaryArchSuffix
	lib:libQt5Multimedia$secondaryArchSuffix
	lib:libQt5Qml$secondaryArchSuffix
	lib:libQt5Quick$secondaryArchSuffix
	lib:libQt5QuickControls2$secondaryArchSuffix
	lib:libQt5QuickWidgets$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libspdlog$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	lmdbxx
	devel:libboost_iostreams$secondaryArchSuffix >= $boostMinimumVersion
	devel:libboost_system$secondaryArchSuffix >= $boostMinimumVersion
	devel:libboost_thread$secondaryArchSuffix >= $boostMinimumVersion
	devel:libcmark$secondaryArchSuffix
	devel:libfmt$secondaryArchSuffix
	devel:liblmdb$secondaryArchSuffix
	devel:libmatrix_client$secondaryArchSuffix  >= 0.5.1
	devel:libolm$secondaryArchSuffix
	devel:libQt5Concurrent$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Dbus$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libqt5keychain$secondaryArchSuffix
	devel:libQt5Multimedia$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Qml$secondaryArchSuffix
	devel:libQt5Quick$secondaryArchSuffix
	devel:libQt5QuickControls2$secondaryArchSuffix
	devel:libQt5QuickWidgets$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libspdlog$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:nlohmann_json
	devel:tweeny
	"
BUILD_PREREQUIRES="
	cmd:g++$secondaryArchSuffix
	cmd:cmake
	cmd:linguist$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	unset -f cmake
	cmake -S. -Bbuild $cmakeDirArgs \
		-DCMAKE_INSTALL_BINDIR=$appsDir \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_EXE_LINKER_FLAGS="-lnetwork -lz" \
		-Wno-dev
	make -C build $jobArgs
}

INSTALL()
{
	make -C build install

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

	mv $appsDir/nheko $appsDir/Nheko
	rm -rf $dataDir

	addResourcesToBinaries nheko.rdef $appsDir/Nheko
	addAppDeskbarSymlink $appsDir/Nheko
}
