SUMMARY="A chat, voice, video, and file transfer IM client"
DESCRIPTION="qTox is a powerful Tox client that follows the Tox design \
guidelines while running on all major platforms."
HOMEPAGE="https://github.com/qTox/qTox"
COPYRIGHT="2015-2021 qTox maintainers"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/qTox/qTox/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="3d2fe2a344c83c50e6603d2a4070f2cc0c6ccd13fa5e77457eff96f57ee6f8c2"
SOURCE_FILENAME="qtox-v$portVersion.tar.gz"
SOURCE_DIR="qTox-$portVersion"
PATCHES="qtox-$portVersion.patchset"
ADDITIONAL_FILES="qtox.rdef.in"

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

PROVIDES="
	qtox$secondaryArchSuffix = $portVersion
	app:qTox = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavdevice$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libexif$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libopus$secondaryArchSuffix
	lib:libqrencode$secondaryArchSuffix
	lib:libQt5Concurrent$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5OpenGL$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Test$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	lib:libsodium$secondaryArchSuffix
	lib:libsqlcipher$secondaryArchSuffix
	lib:libssp$secondaryArchSuffix
	lib:libswscale$secondaryArchSuffix
	lib:libtoxcore$secondaryArchSuffix
	lib:libvpx$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libavcodec$secondaryArchSuffix
	devel:libavdevice$secondaryArchSuffix
	devel:libavformat$secondaryArchSuffix
	devel:libavutil$secondaryArchSuffix
	devel:libexif$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libopus$secondaryArchSuffix
	devel:libqrencode$secondaryArchSuffix
	devel:libQt5Concurrent$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5OpenGL$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Test$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libQt5Xml$secondaryArchSuffix
	devel:libsodium$secondaryArchSuffix
	devel:libsqlcipher$secondaryArchSuffix
	devel:libssp$secondaryArchSuffix
	devel:libswscale$secondaryArchSuffix
	devel:libtoxcore$secondaryArchSuffix
	devel:libvpx$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build && cd build
	cmake -DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$appsDir \
		-DCMAKE_INSTALL_BINDIR=$appsDir \
		-DCMAKE_EXE_LINKER_FLAGS=-lnetwork ..
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir
	cp build/qtox $appsDir/qTox

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

	addResourcesToBinaries build/qtox.rdef $appsDir/qTox
	addAppDeskbarSymlink $appsDir/qTox
}

TEST()
{
	cd build
	make test
}
