# Maintainer: Saul Ibarra Corretge <saghul@gmail.com>

_realname=pyqt5
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=5.15.11
pkgrel=3
pkgdesc="Qt5 bindings for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://riverbankcomputing.com/software/pyqt"
msys2_references=(
  'archlinux: pyqt5'
  'purl: pkg:pypi/pyqt5'
)
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-pyqt5-sip"
         "${MINGW_PACKAGE_PREFIX}-qt5-base")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt5-declarative"
            "${MINGW_PACKAGE_PREFIX}-qt5-multimedia"
            "${MINGW_PACKAGE_PREFIX}-qt5-svg"
            "${MINGW_PACKAGE_PREFIX}-qt5-tools"
            "${MINGW_PACKAGE_PREFIX}-qtwebkit"
            "${MINGW_PACKAGE_PREFIX}-qt5-activeqt"
            "${MINGW_PACKAGE_PREFIX}-qt5-connectivity"
            "${MINGW_PACKAGE_PREFIX}-qt5-location"
            "${MINGW_PACKAGE_PREFIX}-qt5-quick3d"
            "${MINGW_PACKAGE_PREFIX}-qt5-remoteobjects"
            "${MINGW_PACKAGE_PREFIX}-qt5-sensors"
            "${MINGW_PACKAGE_PREFIX}-qt5-serialport"
            "${MINGW_PACKAGE_PREFIX}-qt5-speech"
            "${MINGW_PACKAGE_PREFIX}-qt5-webchannel"
            "${MINGW_PACKAGE_PREFIX}-qt5-websockets"
            "${MINGW_PACKAGE_PREFIX}-qt5-winextras"
            "${MINGW_PACKAGE_PREFIX}-qt5-xmlpatterns")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-sip"
             "${MINGW_PACKAGE_PREFIX}-pyqt-builder"
             "${MINGW_PACKAGE_PREFIX}-qt5-declarative"
             "${MINGW_PACKAGE_PREFIX}-qt5-multimedia"
             "${MINGW_PACKAGE_PREFIX}-qt5-svg"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools"
             "${MINGW_PACKAGE_PREFIX}-qt5-activeqt"
             "${MINGW_PACKAGE_PREFIX}-qt5-connectivity"
             "${MINGW_PACKAGE_PREFIX}-qt5-location"
             "${MINGW_PACKAGE_PREFIX}-qt5-quick3d"
             "${MINGW_PACKAGE_PREFIX}-qt5-remoteobjects"
             "${MINGW_PACKAGE_PREFIX}-qt5-sensors"
             "${MINGW_PACKAGE_PREFIX}-qt5-serialport"
             "${MINGW_PACKAGE_PREFIX}-qt5-speech"
             "${MINGW_PACKAGE_PREFIX}-qt5-webchannel"
             "${MINGW_PACKAGE_PREFIX}-qt5-websockets"
             "${MINGW_PACKAGE_PREFIX}-qt5-winextras"
             "${MINGW_PACKAGE_PREFIX}-qt5-xmlpatterns"
             $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-aarch64* ]] || echo "${MINGW_PACKAGE_PREFIX}-qtwebkit"))
source=(https://pypi.python.org/packages/source/P/PyQt5/PyQt5-${pkgver}.tar.gz)
sha256sums=('fda45743ebb4a27b4b1a51c6d8ef455c4c1b5d610c90d2934c7802b5c1557c52')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r PyQt5-${pkgver} python-build-${MSYSTEM}
}

build() {
  cd python-build-${MSYSTEM}

  CXXFLAGS+=" -Wno-deprecated-declarations" \
  MSYS2_ARG_CONV_EXCL="--api-dir=;" \
  ${MINGW_PREFIX}/bin/sip-build \
    --confirm-license \
    --link-full-dll \
    --no-make \
    --concatenate 2 \
    --api-dir=${MINGW_PREFIX}/share/qt5/qsci/api/python \
    --qmake=${MINGW_PREFIX}/bin/qmake.exe \
    --verbose

    cd build
    make V=1
}

package(){
  local _pysite=$(cygpath -u $(${MINGW_PREFIX}/bin/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"))
  cd python-build-${MSYSTEM}/build
  # INSTALL_ROOT is needed for the QtDesigner module, the other Makefiles use DESTDIR
  MSYS2_ARG_CONV_EXCL="${_pysite}" \
  make DESTDIR="${pkgdir}" INSTALL_ROOT="${pkgdir}" install

  # compile Python bytecode
  ${MINGW_PREFIX}/bin/python -m compileall -o 0 -o 1 -d / "$pkgdir"${MINGW_PREFIX}/lib

  install -Dm644 ../LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
