PKGNAME=telegram-desktop
PKGSEC=web
PKGDEP="ffmpeg hicolor-icon-theme libnotify minizip abseil-cpp \
    openal-soft openssl lz4 qt-6 xxhash hunspell crc32c glibmm-2.68 fmt \
    libjpeg-turbo opus pulseaudio rnnoise pipewire kcoreaddons ada"
PKGDEP__MAINLINE_TIER2="${PKGDEP} libdispatch"
BUILDDEP="cmake range-v3 python-3 tl-expected microsoft-gsl yasm gperf \
          extra-cmake-modules wayland-protocols plasma-wayland-protocols"
PKGSUG="webkit2gtk"
PKGRECOM="kimageformats"
PKGDES="The official Telegram desktop application"

PKGPROV="telegram tdesktop"

CMAKE_AFTER=(
    '-DCMAKE_INSTALL_PREFIX=/usr'
    '-DDESKTOP_APP_SPECIAL_TARGET='
    '-DTDESKTOP_LAUNCHER_BASENAME=telegramdesktop;'
    '-DDESKTOP_APP_USE_PACKAGED=ON'
    '-DDESKTOP_APP_USE_PACKAGED_FONTS=OFF'
    '-DDESKTOP_APP_DISABLE_AUTOUPDATE=ON'
    '-DQT_VERSION_MAJOR=6'
)

# FIXME: relocation truncated to fit: R_MIPS_GOT_PAGE against `.text'
# CMake overrides our optimization flags, so pick a size-optimized build type
# for loongson3.
CMAKE_AFTER__LOONGSON3=(
    ${CMAKE_AFTER[@]}
    '-DCMAKE_BUILD_TYPE=MinSizeRel'
)

ABTYPE=cmakeninja

# FIXME: LTO fails on riscv64
# lto1: fatal error: LTO_symtab_tags out of range: Range is 0 to 5, value is 237
NOLTO__RISCV64=1

# FIXME: LTO requires enormous amount of RAM
NOLTO__LOONGSON3=1

# FIXME: relocation truncated to fit: R_MIPS_GOT_PAGE against `.text'
AB_FLAGS_OS__LOONGSON3=1
