# Maintainer: Dirk Stolle

_realname=passagemath-glpk
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=10.6.38
pkgrel=1
pkgdesc="passagemath: Linear and mixed integer linear optimization backend using GLPK (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/passagemath/passagemath'
msys2_references=(
  'purl: pkg:pypi/passagemath-glpk'
)
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-glpk"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-cysignals"
         "${MINGW_PACKAGE_PREFIX}-python-memory-allocator"
         "${MINGW_PACKAGE_PREFIX}-python-passagemath-objects")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-gmp"
             "${MINGW_PACKAGE_PREFIX}-mpc"
             "${MINGW_PACKAGE_PREFIX}-mpfr"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-passagemath-categories"
             "${MINGW_PACKAGE_PREFIX}-python-passagemath-environment"
             "${MINGW_PACKAGE_PREFIX}-python-passagemath-setup"
             "${MINGW_PACKAGE_PREFIX}-python-pkgconfig"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz"
        "0001-allow-newer-cysignals.patch")
sha256sums=('43c3ad9de2dd1c8125c55f9f99c2133d7225ec36abb4a2bb73a432a1d5010086'
            'f4f296f2169cccb2f3a47fc3c132635ffb9e74485c213533ea06fb9ef5d983aa')

prepare() {
  cd "${_realname/-/_}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-allow-newer-cysignals.patch"
}

build() {
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  # fix to link zlib as -lz instead of -lzlib
  sed -i 's/ZLIB_LIBRARIES/z/g' sage/libs/glpk/env.pxd
  sed -i 's/ZLIB_LIBRARIES/z/g' sage/libs/glpk/graph.pxd
  sed -i 's/ZLIB_LIBRARIES/z/g' sage/libs/glpk/lp.pxd

  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
}
