# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=h5py
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.10.0
pkgrel=1
pkgdesc="General-purpose Python bindings for the HDF5 library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.h5py.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-hdf5")
makedepends=("${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python-pkgconfig"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=(https://github.com/h5py/h5py/releases/download/${pkgver}/h5py-${pkgver}.tar.gz
        001-mingw-python.patch
        lzf_c.c.patch)
sha256sums=('84412798925dc870ffd7107f045d7659e60f5d46d1c70c700375248bf6bf512d'
            'cd8dff9d11117521cc7948400fa92cbc115d432c93aac181a20017d27e3f197e'
            '6d0126b881b5dcd637146d151341b72aa68eef760092272279072ec0bc4ceca9')

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

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

build() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --skip-build \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 licenses/license.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
