# Maintainer: Antoine Martin <totaam@xpra.org>

_realname=xpra
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=6.2.0
pkgrel=2
pkgdesc='Remote access client/server software (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: xpra'
  'pypi: xpra'
)
url='https://github.com/Xpra-org/xpra'
license=('spdx:GPL-2.0-or-later')
depends=(
    ${MINGW_PACKAGE_PREFIX}-gtk3
    ${MINGW_PACKAGE_PREFIX}-libjpeg-turbo
    ${MINGW_PACKAGE_PREFIX}-libspng
    ${MINGW_PACKAGE_PREFIX}-libvpx
    ${MINGW_PACKAGE_PREFIX}-libwebp
    ${MINGW_PACKAGE_PREFIX}-libyuv
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-comtypes
    ${MINGW_PACKAGE_PREFIX}-python-gobject
    ${MINGW_PACKAGE_PREFIX}-lz4
    ${MINGW_PACKAGE_PREFIX}-python-pillow
    ${MINGW_PACKAGE_PREFIX}-python-pyopengl
    ${MINGW_PACKAGE_PREFIX}-python-setproctitle
    ${MINGW_PACKAGE_PREFIX}-xxhash
    ${MINGW_PACKAGE_PREFIX}-libx264)
optdepends=(
    "${MINGW_PACKAGE_PREFIX}-libnotify: notification support"
    "${MINGW_PACKAGE_PREFIX}-gstreamer: audio/video streaming support"
    "${MINGW_PACKAGE_PREFIX}-gst-plugins-bad: extra codecs"
    "${MINGW_PACKAGE_PREFIX}-gst-plugins-ugly: extra codecs"
    "${MINGW_PACKAGE_PREFIX}-gst-plugins-good: extra codecs"
    "${MINGW_PACKAGE_PREFIX}-gst-python: audio/video support"
    "${MINGW_PACKAGE_PREFIX}-python-paramiko: SSH client and server support"
    "${MINGW_PACKAGE_PREFIX}-python-dnspython: SSHFP support with paramiko"
    "${MINGW_PACKAGE_PREFIX}-python-netifaces: mDNS and network integration"
    "${MINGW_PACKAGE_PREFIX}-python-pyu2f: U2F authentication"
    "${MINGW_PACKAGE_PREFIX}-python-ldap: LDAP authentication via python-ldap"
    "${MINGW_PACKAGE_PREFIX}-python-ldap3: LDAP authentication via python-ldap3"
    "${MINGW_PACKAGE_PREFIX}-python-cryptography: AES packet encryption"
    "${MINGW_PACKAGE_PREFIX}-python-aioquic: QUIC transport"
    "${MINGW_PACKAGE_PREFIX}-python-zeroconf: mDNS support"
    "${MINGW_PACKAGE_PREFIX}-python-nvidia-ml: nvidia GPU support"
    "${MINGW_PACKAGE_PREFIX}-python-pyopengl-accelerate: OpenGL-accelerate support")
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-brotli
    ${MINGW_PACKAGE_PREFIX}-cython
    ${MINGW_PACKAGE_PREFIX}-cc
    ${MINGW_PACKAGE_PREFIX}-pkgconf
    ${MINGW_PACKAGE_PREFIX}-python-cairo
    ${MINGW_PACKAGE_PREFIX}-python-build
    ${MINGW_PACKAGE_PREFIX}-python-installer
    ${MINGW_PACKAGE_PREFIX}-python-setuptools
    ${MINGW_PACKAGE_PREFIX}-pygobject-devel)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-build.patch")
sha256sums=('7f5baf7daa0de5697829cff553e56197f186978f36be8bbe8fb1b72103857dd6'
            '71a752dbfe8f6b6252e03cca3251dbdb14a844bab669f575b7f26002f4efd31b')

prepare() {
  cd "${_realname}-${pkgver}"

  # https://github.com/Xpra-org/xpra/issues/4263
  patch -Np1 -i "${srcdir}/0001-fix-build.patch"
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
  cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation \
    -C--without-cuda_kernels -C--with-data -C--without-docs -C--with-modules -C-without-warn
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
  install -Dm644 README.md "${pkgdir}${MINGW_PREFIX}/share/${_realname}/README.md"
  install -Dm644 fs/share/xpra/bell.wav "${pkgdir}${MINGW_PREFIX}/share/${_realname}/bell.wav"
}
