SUMMARY="WebRTC build for Telegram"
DESCRIPTION="Telegram Desktop's fork of Google's WebRTC."
HOMEPAGE="https://github.com/desktop-app/tg_owt"
COPYRIGHT="2013-2022 Telegram"
LICENSE="BSD (3-clause)"
REVISION="1"
srcGitRev="25c8637f5975db830cc5d74477641a8b609e248d"
SOURCE_URI="https://github.com/desktop-app/tg_owt/archive/$srcGitRev.tar.gz"
SOURCE_DIR="tg_owt-$srcGitRev"
CHECKSUM_SHA256="beb9965fc26df034e29d171ac9f6ed936066330692e935f9e662d57e689c6a04"
SOURCE_FILENAME="tg_owt-$srcGitRev.tar.gz"
srcGitRev_2="5b3351bd07e83f9f9a4cb6629561331ecdb7c546"
SOURCE_URI_2="https://github.com/lemenkov/libyuv/archive/$srcGitRev_2.tar.gz"
CHECKSUM_SHA256_2="242e3c42d2c6ff7770d62d78cfb45642541e92dea6afe2ebe07a9a04db3a98cb"
SOURCE_FILENAME_2="libyuv-$srcGitRev_2.tar.gz"

PATCHES="tg_owt-$portVersion.patchset"

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

PROVIDES="
	tg_owt$secondaryArchSuffix = $portVersion
	devel:libtg_owt$secondaryArchSuffix = 0.0.0 compat >= 0
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libabsl_strings$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libopus$secondaryArchSuffix
	lib:libprotobuf$secondaryArchSuffix
	lib:libswresample$secondaryArchSuffix
	lib:libswscale$secondaryArchSuffix
	lib:libvpx$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libabsl_strings$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libavcodec$secondaryArchSuffix
	devel:libavformat$secondaryArchSuffix
	devel:libavutil$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libopus$secondaryArchSuffix
	devel:libprotobuf$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libswresample$secondaryArchSuffix
	devel:libswscale$secondaryArchSuffix
	devel:libvpx$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python
	cmd:sed
	cmd:yasm
	"

BUILD()
{
	export DISABLE_ASLR=1

	rm -rf $sourceDir/src/third_party/libyuv
	cp -r $sourceDir2/libyuv-$srcGitRev_2 $sourceDir/src/third_party/libyuv

	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_LIBDIR=$developLibDir \
		-DCMAKE_INSTALL_INCLUDEDIR=$includeDir \
		-DBUILD_SHARED_LIBS=FALSE \
		-DTG_OWT_PACKAGED_BUILD=TRUE \
		-DTG_OWT_BUILD_AUDIO_BACKENDS=OFF \
		-DTG_OWT_USE_PROTOBUF=FALSE \
		-DTG_OWT_USE_PIPEWIRE=FALSE
	make $jobArgs
}

INSTALL()
{
	cd build
	make install
	mkdir -p $libDir
	mv $developLibDir/cmake $libDir
}
