# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=olefile
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}")
pkgdesc="Python library to parse, read and write Microsoft OLE2 files (formerly OleFileIO_PL) (mingw-w64)"
pkgver=0.46
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('BSD')
url="https://www.decalage.info/olefile"
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/decalage2/olefile/archive/v${pkgver}.tar.gz)
sha256sums=('11d1a3810e50956c9360a4c76f1ecebf3e54f9d8406f75127bd0d296638488f4')

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

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package() {
  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})
  local _py3basever=$(${MINGW_PREFIX}/bin/python3 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")
  
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}/" --optimize=0 --skip-build

  install -Dm644 doc/LICENSE.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 README.md doc/* -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/README"
}
