# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=pyopengl-accelerate
_pyname=PyOpenGL-accelerate
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.1.10
pkgrel=1
pkgdesc="Acceleration code for PyOpenGL (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://mcfletch.github.io/pyopengl/'
msys2_repository_url="https://github.com/mcfletch/pyopengl"
msys2_references=(
  'gentoo: dev-python/pyopengl-accelerate'
  'purl: pkg:pypi/pyopengl-accelerate'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-pyopengl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=(!strip)
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_realname/-/_}-${pkgver}.tar.gz"
        "0001-cython-31-fix.patch")
sha256sums=('82751c83f0a6f732b8b5923990edc2441d38176a98756b1718e8d6c4379f5a71'
            'a610686055dc75d1893a4528621fe4cc6d906e0daf3b0574c3e2752bc6a8bafb')

prepare() {
  cd "${_realname/-/_}-${pkgver}"
  # https://github.com/mcfletch/pyopengl/issues/147
  patch -p1 < "${srcdir}/0001-cython-31-fix.patch"
}

build() {
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}" && 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.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
