# Maintainer: Andrew Chadwick <a.t.chadwick@gmail.com>

_realname=styrene
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=0.3.0
pkgrel=11
pkgdesc="Repacks MSYS2 packages into installer .exes and standalone .zips (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/achadwick/styrene"
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc"
         "${MINGW_PACKAGE_PREFIX}-binutils"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-nsis"
         "zip")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(https://github.com/achadwick/styrene/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('5b31beb1ee0fcb6518fe83eb1933b539a0583feae4b0eda942cb497101e3f6a4')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  # De-hardcode script paths
  local MINGW_PREFIX_W=$(cygpath -m "${MINGW_PREFIX}")
  sed -i -e "s,${MINGW_PREFIX_W},${MINGW_PREFIX},g" \
      "${pkgdir}${MINGW_PREFIX}/bin/styrene"

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/COPYING
}
