# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=pivy
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.6.10
pkgrel=1
pkgdesc='Python bindings to Coin3D (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/coin3d/pivy'
msys2_references=(
  'archlinux: python-pivy'
)
license=('spdx:ISC')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-soqt-qt6")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-swig"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("${url}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-pivy-0.6.5-setup-py-msystem-env.patch"
        "003-find-qt6.patch"
        "004-fix-compile-flags.patch"
        "005-fix-install-destination.patch")
sha256sums=('7b409816c9fad84cf94f93659281f9dd2501d285eb2fc609e9401a3d004ce723'
            '0a37cf9f25ed3b0aca4547b484f448c840cf6a4d1f604ceed7094f8970a9c5b5'
            'ec2b3b7bed55ded8d451580766e78ca51a79cdd69e12fc5b11c4f3cd20d293e0'
            'b56addd46827bf817ba1e637ac7ee6f1d36752d92c0966a53145cb306b2f1770'
            '615797b71c50ca2ef9e3c74eb72f5423675472ace3b162ca7ead945fb5a6e7a9')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

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

  apply_patch_with_msg \
    001-pivy-0.6.5-setup-py-msystem-env.patch \
    003-find-qt6.patch \
    004-fix-compile-flags.patch \
    005-fix-install-destination.patch
}

build() {
  rm -rf "python-build-${MSYSTEM}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  GENERATOR="Ninja" \
  CMAKE_POLICY_VERSION_MINIMUM="3.5" \
  ${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/python-${_realname}/LICENSE"
}

# vim: ts=2 sw=2 et:
