# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Nulo <alpine@nulo.in>
# Contributor: Donoban <donoban@riseup.net>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=telegram-desktop
# NOTE: Keep in mind that seemingly normal releases may be pre-releases.
# Check GitHub to make sure:
# https://github.com/telegramdesktop/tdesktop/releases
pkgver=5.9.0
pkgrel=1
pkgdesc="Telegram Desktop messaging app"
options="!check" # no test suite
url="https://desktop.telegram.org/"
# armhf blocked by qt5-qtwayland
# ppc64le and s390x blocked by tg_owt
# x86, riscv64: textrels
# riscv64: libdispatch
arch="all !x86 !ppc64le !s390x !armhf !riscv64"
license="GPL-3.0-or-later WITH OpenSSL"

depends="qt6-qtimageformats font-opensans"

# Sorted according to
# https://github.com/telegramdesktop/tdesktop/wiki/The-Packaged-Building-Mode
# libtgvoip is bundled as suggested by upstream
# jemalloc is disabled
# rlottie is bundled as suggested by upstream
# We are forcing it to use packaged libvpx with a patch below
# kcoreaddons is bundled as it requires to be built with Qt6.
makedepends="
	ada-dev
	python3
	extra-cmake-modules
	qt6-qt5compat-dev
	qt6-qtsvg-dev
	qt6-qtwayland-dev

	tg_owt-dev<20230314
	opus-dev
	alsa-lib-dev
	pulseaudio-dev

	boost-dev
	fmt-dev

	abseil-cpp-dev
	ffmpeg-dev
	gobject-introspection-dev
	libdispatch-dev
	gsl-dev
	hunspell-dev
	lz4-dev
	minizip-dev
	msgsl
	openal-soft-dev
	openssl-dev>3
	range-v3-dev
	rnnoise-dev
	tl-expected
	wayland-dev
	libxcb-dev
	xcb-util-keysyms-dev
	xxhash-dev
	zlib-dev

	libvpx-dev
	protobuf-dev

	cmake
	samurai
	meson
	"

# small-sizes.patch is for postmarketOS. It makes UI elements fit in small
# screens.
# https://github.com/telegramdesktop/tdesktop/issues/8058#issuecomment-643461605
source="
	https://github.com/telegramdesktop/tdesktop/releases/download/v$pkgver/tdesktop-$pkgver-full.tar.gz
	small-sizes.patch
	"
builddir="$srcdir/tdesktop-$pkgver-full"

build() {
	LDFLAGS="$LDFLAGS -Wl,-z,stack-size=1024768" \
	cmake -B build -G Ninja . \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DDESKTOP_APP_DISABLE_CRASH_REPORTS=ON \
		-DTDESKTOP_API_ID=17349 \
		-DTDESKTOP_API_HASH=344583e45741c457fe1862106095a5eb \
		-DDESKTOP_APP_DISABLE_JEMALLOC=ON \
		-DDESKTOP_APP_USE_PACKAGED=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
378735399cfd3557d473723fcf35b52fccb17c96bc8ce8e3d54658e4d955c750743aa44e5b3fe905a01276030fe4df8618fe8647e71cd5100409b339482b73c2  tdesktop-5.9.0-full.tar.gz
396b5577bdeb852be3659fcbf09a1ebdc33432baea49296869e2f968d61343679187ed4b923c51c8f417b8d4679aedd7ac863abed255b5b6b1b589029fdc34f6  small-sizes.patch
"
