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

_realname=python_ics
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=4.6
pkgrel=1
pkgdesc="Python C Code module for interfacing to the icsneo40 dynamic library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/intrepidcs/python_ics/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/intrepidcs/python_ics/archive/v${pkgver}.tar.gz"
        mingw-build.patch
        fix-cpp11-error.patch)
sha512sums=('e87ea3412b68f0f3df5bc5bb548ec72c13d98e8571a1d8f98bfb5a91f853d0d25d5de3be8b1d66777dc59a4b09c7f70e51b3620ca9ab550c3565d9ae785e7baf'
            '3c8622868fc017ca8d7f4ceb7ab7bfd4e2bfb6cc9be437f0a923b02d525fa23e3349990b5dc055e04a47be79a01ecdcd6358b7169d6e4f23cbaa7e47425b3bd5'
            '2515ed236346bd320d476bc030ecafc7952c68120a095cc079d7e36a512dd83d4a29765f2372ad0e9b0dde591e1e02ce25ed169118ec8341529ce9b67dab1cec')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/mingw-build.patch
  patch -p1 -i ${srcdir}/fix-cpp11-error.patch

  cd "${srcdir}"
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${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 --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

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