# 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.9
pkgrel=3
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=(
  '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=('85957c7c76975818ff759ec9243f9dc7091ef6f373ea37a2eb50c320fd9a86f3'
            '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"
}
