SUMMARY="A development branch of Psi IM XMPP/Jabber client"
DESCRIPTION="Psi is a cross-platform powerful XMPP client designed for experienced users."
HOMEPAGE="https://psi-plus.com/"
COPYRIGHT="2005-2020, Psi+ Project"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/psi-plus/psi-plus-snapshots/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="24f214de8e7ea2ab5feb4e08974281d698d726e13e22a34b493fbb4cd4cc882b"
SOURCE_DIR="psi-plus-snapshots-$portVersion"
SOURCE_URI_2="https://github.com/psi-plus/psi-plus-l10n/archive/$portVersion.tar.gz"
CHECKSUM_SHA256_2="b17f75e5eca476af29de97cc4dc5eab8f623e1834436e7a7e001b65c53687b34"
SOURCE_FILENAME_2="psi-plus-l10n-$portVersion.tar.gz"
SOURCE_DIR_2="psi-plus-l10n-$portVersion"
spcVersion="2.3.3"
SOURCE_URI_3="https://github.com/signalapp/libsignal-protocol-c/archive/v$spcVersion.tar.gz"
CHECKSUM_SHA256_3="c22e7690546e24d46210ca92dd808f17c3102e1344cd2f9a370136a96d22319d"
SOURCE_FILENAME_3="libsignal-protocol-c-$spcVersion.tar.gz"
SOURCE_DIR_3="libsignal-protocol-c-$spcVersion"
ADDITIONAL_FILES="psi-plus.rdef.in"

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

PROVIDES="
	psi_plus$secondaryArchSuffix = $portVersion
	app:Psi$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libgcrypt$secondaryArchSuffix
	lib:libhunspell_1.7$secondaryArchSuffix
	lib:libotr$secondaryArchSuffix
	lib:libqca_qt5$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5WebKit$secondaryArchSuffix
	lib:libQt5WebKitWidgets$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libtidy$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libgcrypt$secondaryArchSuffix
	devel:libhunspell_1.7$secondaryArchSuffix
	devel:libotr$secondaryArchSuffix
	devel:libqca$secondaryArchSuffix >= 2.1.3
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5WebKit$secondaryArchSuffix
	devel:libQt5WebKitWidgets$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libtidys$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:patch
	cmd:pkg_config$secondaryArchSuffix
	cmd:which
	"

BUILD()
{
	cd $sourceDir3
	mkdir -p build
	cd build
	cmake .. -DCMAKE_INSTALL_PREFIX=$sourceDir/libsignal-protocol-c
	make $jobArgs
	make install
	cd $sourceDir

	ln -sf ../../sources-2/psi-plus-l10n-$portVersion/translations .

	mkdir -p build && cd build

	cmake .. \
		-DCMAKE_INSTALL_PREFIX:PATH=$appsDir/Psi-plus \
		-DCMAKE_INSTALL_BINDIR:PATH=$appsDir/Psi-plus \
		-DCMAKE_INSTALL_LIBDIR:PATH=$appsDir/Psi-plus/lib \
		-DCMAKE_INSTALL_DATAROOTDIR:PATH=$appsDir/Psi-plus \
		-DSIGNAL_PROTOCOL_C_ROOT:PATH=$sourceDir/libsignal-protocol-c \
		-DCMAKE_BUILD_TYPE=RELEASE \
		-DCHAT_TYPE=WEBKIT \
		-DENABLE_PLUGINS=ON \
		-DPLUGINS_PATH=plugins \
		-DUSE_HUNSPELL=ON

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	mv -f $appsDir/Psi-plus/data/psi-plus/* $appsDir/Psi-plus
	mv $appsDir/Psi-plus/psi-plus $appsDir/Psi-plus/Psi-plus

	rm -rf $appsDir/Psi-plus/data

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

	addResourcesToBinaries psi-plus.rdef $appsDir/Psi-plus/Psi-plus
	addAppDeskbarSymlink $appsDir/Psi-plus/Psi-plus
}
