SUMMARY="An encrypted, P2P, messaging, audio/video calling platform"
DESCRIPTION="Tox is a fully encrypted, censor resistant, private, distributed \
network library with a focus on personal communications.

It's a VERY secure Instant Messenger that supports Text, Audio/Video calls, \
group chats, audio group chats, and file transfers."
HOMEPAGE="https://tox.chat/"
COPYRIGHT="2013-2017 Tox Project"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/TokTok/c-toxcore/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="30ae3263c9b68d3bef06f799ba9d7a67e3fad447030625f0ffa4bb22684228b0"
SOURCE_DIR="c-toxcore-$portVersion"

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

if [ "$targetArchitecture" != x86_gcc2 ]; then
	commandSuffix=$secondaryArchSuffix
	commandBinDir=$binDir
else
	commandSuffix=
	commandBinDir=$prefix/bin
fi

libVersion="2.12.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	tox$secondaryArchSuffix = $portVersion
	cmd:DHT_bootstrap$commandSuffix = $portVersion
	cmd:tox_bootstrapd$commandSuffix = $portVersion
	lib:libtoxcore$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libconfig$secondaryArchSuffix
	lib:libgtest$secondaryArchSuffix
	lib:libopus$secondaryArchSuffix
	lib:libsodium$secondaryArchSuffix
	lib:libvpx$secondaryArchSuffix
	"

PROVIDES_devel="
	tox${secondaryArchSuffix}_devel = $portVersion
	devel:libtoxcore$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	tox$secondaryArchSuffix == $portVersion base
	devel:libopus$secondaryArchSuffix
	devel:libsodium$secondaryArchSuffix
	devel:libvpx$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libconfig$secondaryArchSuffix
	devel:libgtest$secondaryArchSuffix
	devel:libopus$secondaryArchSuffix
	devel:libsodium$secondaryArchSuffix
	devel:libvpx$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:git
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build && cd build
	cmake .. $cmakeDirArgs \
		-DCMAKE_BUILD_TYPE="Release" \
		-DCMAKE_INSTALL_BINDIR=$commandBinDir \
		-DCMAKE_EXE_LINKER_FLAGS:STRING=-lnetwork \
		-DSOCKET_LIBRARIES=-lnetwork \
		-DUSE_IPV6=OFF
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	prepareInstalledDevelLib \
		libtoxcore
	fixPkgconfig

	packageEntries devel \
		$developDir
}

TEST()
{
	cd build
	make test
}
