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

_realname=pyqt5
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
           "${MINGW_PACKAGE_PREFIX}-${_realname}-common")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
          "${MINGW_PACKAGE_PREFIX}-${_realname}-common")
pkgver=5.15.4
pkgrel=2
pkgdesc="Qt5 bindings for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('GPL')
url="https://riverbankcomputing.com/software/pyqt"
depends=(#"${MINGW_PACKAGE_PREFIX}-python-dbus"
         "${MINGW_PACKAGE_PREFIX}-python-pyopengl"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-pyqt5-sip"
         "${MINGW_PACKAGE_PREFIX}-qt5"
         $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] ||
           echo "${MINGW_PACKAGE_PREFIX}-qtwebkit"))
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-sip"
             "${MINGW_PACKAGE_PREFIX}-pyqt-builder"
             "${MINGW_PACKAGE_PREFIX}-python-packaging")
options=('strip' 'staticlibs')
source=(https://pypi.python.org/packages/source/P/PyQt5/PyQt5-${pkgver}.tar.gz)
sha256sums=('2a69597e0dd11caabe75fae133feca66387819fc9bc050f547e5551bce97e5be')

prepare() {
 cd "${srcdir}"/PyQt5-${pkgver}

}

build() {
  [[ -d python-${MINGW_CHOST} ]] && rm -rf python-${MINGW_CHOST}
  cp -r PyQt5-${pkgver} python-${MINGW_CHOST} && cd python-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--api-dir=;" \
  ${MINGW_PREFIX}/bin/sip-build \
    --confirm-license \
    --no-make \
    --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-${MINGW_CHOST}/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 -d / "$pkgdir"${MINGW_PREFIX}/lib
  ${MINGW_PREFIX}/bin/python -O -m compileall -d / "$pkgdir"${MINGW_PREFIX}/lib
}
