# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_pyname=SCons
_realname=scons
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.10.0
pkgrel=1
pkgdesc="Extensible Python-based build utility (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64' 'mingw32')
url="https://scons.org"
msys2_repository_url="https://github.com/SCons/scons"
msys2_references=(
  'archlinux: scons'
  'gentoo: dev-build/scons'
  'purl: pkg:pypi/scons'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=(!strip)
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-mingw-path.patch"
        "0002-fix-missing-man-pages.patch")
sha256sums=('61e2fc42e0e2c750105d61f26cc1dfebcae9f4103d3dc0e9aeb373016b0d208c'
            '4416b87da2d7e2879d6f2fd13796887b0a0de3dfffb9be3ec2f565f794a72048'
            'd6c7e88bd810bb32309cded3ddb3ee913b3b06872238e60bfd0f1cd615eaf936')

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

  patch -Np1 -i "${srcdir}/0001-fix-mingw-path.patch"
  patch -Np1 -i "${srcdir}/0002-fix-missing-man-pages.patch"
}

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

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
