# Packager = Developer <dev@tuxcore.org> 
_name=FreeRDP
pkgname=freerdp2
pkgver=2.11.5
pkgrel=3
pkgdesc="Free implementation of the Remote Desktop Protocol (RDP)"
arch=(x86_64)
url="https://www.freerdp.com/"
license=(Apache-2.0)
depends=(
  glibc
  libcups
  libx11
  libxcursor
  libxext
  libxdamage
  libxfixes
  libxkbcommon
  libxi
  libxinerama
  libxkbfile
  libxrandr
  libxrender
  libxtst
  pcsclite
  wayland
)
makedepends=(
  alsa-lib
  cmake
  docbook-xsl
  ffmpeg
  icu
  krb5
  libjpeg-turbo
  libpulse
  libusb
  openssl
  pam
  systemd
  xmlto
  xorgproto
)
provides=(
  libfreerdp2.so
  libfreerdp-client2.so
  libfreerdp-server2
  libfreerdp-shadow2.so
  libfreerdp-shadow-subsystem2.so
  libwinpr2.so
  libwinpr-tools2.so
  libuwac0.so
)
source=(
  https://github.com/${_name,,}/${_name,,}/archive/$pkgver/${_name,,}-$pkgver.tar.gz
  d0c5b1ae.patch
  1ef7b9e3.patch
)
sha512sums=('7b89981a4d2773fdcf41f32d58ec7925765b3cedb7ebc77d54ded8c39f38d294f3adfdf5ab79ad23c5edd2cba456465ac9eafec437c004b5de7a9d76a6a94536'
            'f7d231fa8aaf08a20b4bbdb153219e94ba6518eee3238f6c26f2c928cd33ad6c975d2c62acb706ad5b0352889b5a9849cffb6e03b2a2e760accd31c492f6a0a9'
            'f5843f8daaa8225534b05dca3d6c1d26a25174d773c81495c73924298312d0c4aee39165a4fe0b4ba38676d40a6779b33443a761f094dd4e16c1303dec026841')
b2sums=('0b7365eccc625878c9543d8b6a92787b11e1c5463122e14536b2fb8ebc46d80b9e8b4274e6d5be8da0fe7a5a3578b907ff47267501b0fdc15dea64534a22f4a2'
        '99f60d738ebb594b3f48895bac567c5a4ba8f1e6ceb2a21d421c842d08f267b49f870c70ca7862fea3340ab247bf232dffd7f4b83ebb9bded2bdec9207cc1d1b'
        'a0157137a52f3f4817908d86b0a3ec575a7307ec05d3f2388a49fe40e9c40ea23aec4fdc6f926ac5b5c443d6d4063e2b35ad1e386577dcf5d5b208fc791a2605')

prepare() {
  cd $_name-$pkgver
# Fix build with ffmpeg 7
  patch -p1 -i ../d0c5b1ae.patch
  patch -p1 -i ../1ef7b9e3.patch
}

build() {
  # gcc14 buildfix
  export CFLAGS+=" -Wno-incompatible-pointer-types -Wno-int-conversion"
  export CXXFLAGS+=" -Wno-incompatible-pointer-types -Wno-int-conversion"

  local cmake_options=(
    -B build
    -D CHANNEL_URBDRC_CLIENT=ON
    -D CMAKE_INSTALL_PREFIX=/usr
    -D CMAKE_INSTALL_LIBDIR=lib
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_SKIP_INSTALL_RPATH=ON
    -D PROXY_PLUGINDIR=/usr/lib/freerdp2/server/proxy/plugins
    -D WITH_CHANNELS=ON
    -D WITH_CLIENT_CHANNELS=ON
    -D WITH_CUPS=ON
    -D WITH_DSP_FFMPEG=ON
    -D WITH_FFMPEG=ON
    -D WITH_ICU=ON
    -D WITH_JPEG=ON
    -D WITH_PCSC=ON
    -D WITH_PULSE=ON
    -D WITH_SERVER=ON
    -D WITH_SERVER_CHANNELS=ON
    -D WITH_SWSCALE=ON
    -S $_name-$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
}

check() {
  ctest --test-dir build --output-on-failure
}

package() {
  depends+=(
    alsa-lib libasound.so
    ffmpeg libavcodec.so libavutil.so libswresample.so libswscale.so
    icu libicuuc.so
    libjpeg-turbo libjpeg.so
    libpulse libpulse.so
    libusb libusb-1.0.so
    openssl libcrypto.so libssl.so
    pam libpam.so
    systemd-libs libsystemd.so
  )

  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 $_name-$pkgver/{ChangeLog,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}
