# Maintainer: gym603 <gui_yuan_miao@163.com>

_realname=xlrd
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.0.1
pkgrel=1
pkgdesc="Library for developers to extract data from Microsoft Excel (tm) spreadsheet files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('custom')
url="https://github.com/python-excel/xlrd"
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/python-excel/xlrd/archive/${pkgver}.tar.gz)
sha256sums=('eb56c9d63059e18784cc172c0f2a2af738117e3397cc4f70aea60d6677832935')

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

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

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

  install -Dm644 docs/licenses.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/licenses.rst"

  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})
  for filename in runxlrd; do
    sed -e "s|${_mingw_prefix}/bin/|/usr/bin/env |g" -i "${pkgdir}${MINGW_PREFIX}"/bin/${filename}.py
  done
}
