# Maintainer: Saul Ibarra Corretge <saghul@gmail.com>
# Contributor: Alexey Pavlov <alexpux@gmail.com>

_realname=pyqt-builder
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.19.0
pkgrel=1
pkgdesc="The PEP 517 compliant PyQt build system (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/Python-PyQt/PyQt-builder"
msys2_documentation_url="https://pyqt-builder.readthedocs.io"
msys2_references=(
  'purl: pkg:pypi/pyqt-builder'
)
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-sip")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
options=(!strip)
source=("https://pypi.io/packages/source/P/PyQt-builder/pyqt_builder-${pkgver}.tar.gz"
        001-mingw-python.patch)
sha256sums=('79540e001c476bc050180db00fffcb1e9fa74544d95c148e48ad6117e49d6ea2'
            'f373ea9e84c0340a425ba795b2a3eacabf1e5ec289c13661ba6d34ff373dffb8')

prepare() {
  cd ${_realname/-/_}-${pkgver}
  patch -p1 -i "${srcdir}/001-mingw-python.patch"

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}"
}

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

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

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 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  # Delete bundled MSVC DLLs
  rm -rf "${pkgdir}"/${MINGW_PREFIX}/lib/python*/site-packages/pyqtbuild/bundle/dlls
}
