# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=soundfile
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.13.1
pkgrel=3
pkgdesc='An audio library based on libsndfile, CFFI and NumPy (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://python-soundfile.readthedocs.io/'
msys2_repository_url='https://github.com/bastibe/python-soundfile'
msys2_references=(
  'purl: pkg:pypi/soundfile'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-cffi"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-libsndfile")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-fix-libsndfile-dll.patch
        0002-remove-wheel-tag-override.patch)
sha256sums=('b2c68dab1e30297317080a5b43df57e302584c49e2942defdde0acccc53f0e5b'
            'd8236f80c1c105f29ea55d160bfb4958311dfa24847f55133cbc00ab0f4320e7'
            'fb30ff97563a643628f1a06747d4b1c6f3ec617343affe925a0702073cb7ec01')

prepare() {  
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-fix-libsndfile-dll.patch"
  patch -p1 -i "${srcdir}/0002-remove-wheel-tag-override.patch"
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
