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

_realname=xpra
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
           "${MINGW_PACKAGE_PREFIX}-${_realname}-common")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
          "${MINGW_PACKAGE_PREFIX}-${_realname}-common")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=4.0.6
pkgrel=3
pkgdesc="Remote access client / server software"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://xpra.org'
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-ffmpeg"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libyuv"
         "${MINGW_PACKAGE_PREFIX}-libvpx"
         "${MINGW_PACKAGE_PREFIX}-x264"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-lz4"
         "${MINGW_PACKAGE_PREFIX}-python-rencode"
         "${MINGW_PACKAGE_PREFIX}-python-pillow"
         "${MINGW_PACKAGE_PREFIX}-python-pyopengl"
         "${MINGW_PACKAGE_PREFIX}-python-comtypes"
         "${MINGW_PACKAGE_PREFIX}-python-setproctitle")
optdepends=("${MINGW_PACKAGE_PREFIX}-libnotify: notification support"
            "${MINGW_PACKAGE_PREFIX}-gst-plugins-bad: extra audio codecs"
            "${MINGW_PACKAGE_PREFIX}-gst-plugins-ugly: extra audio codecs"
            "${MINGW_PACKAGE_PREFIX}-gst-plugins-good: extra audio codecs"
            "${MINGW_PACKAGE_PREFIX}-gst-python: audio 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-zeroconf: mDNS support"
            "${MINGW_PACKAGE_PREFIX}-python-nvidia-ml: nvidia GPU support")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-brotli"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python-cairo"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-pygobject-devel")
source=("https://xpra.org/src/xpra-${pkgver}.tar.xz")
sha512sums=('e3dc66040898ed40ef12b8cdb89e5f42c2f36edc071afb435334389e727f376ddc116dbee47018468bff24f2cdd7be35750b58bc108ba73c5558bd9eccbd04ea')

prepare() {
  cd "${srcdir}"
  rm -rf python3-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build \
    --without-cuda_kernels --with-data --without-html5 --with-modules
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --without-cuda_kernels --with-data  --without-html5 --skip-build \
    --root="${pkgdir}${MINW_PREFIX}" --share-xpra="./share/xpra"

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

  #python version agnostic launch scripts in /bin:
  for script in xpra xpra_launcher; do
    install -Dm755 scripts/${script} "${pkgdir}${MINGW_PREFIX}/bin/${script}"
    #patch path to the python interpreter:
    sed -i -e "s+/usr/bin/python+$MINGW_PREFIX/bin/python+g" "${pkgdir}${MINGW_PREFIX}/bin/${script}"
  done

  #html5 client:
  ${MINGW_PREFIX}/bin/python3 ./setup_html5.py "${pkgdir}${MINGW_PREFIX}/share/${_realname}/www/" ""
}
