# Contributor: Fabien Chouteau <chouteau@adacore.com>

_realname=langkit
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=26.0.0
pkgrel=1
pkgdesc="A Python framework to generate language parsers (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/AdaCore/langkit"
msys2_references=(
  'aur: langkit'
  'gentoo: dev-ada/langkit'
)
license=('spdx:Apache-2.0 WITH LLVM-exception')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-docutils"
         "${MINGW_PACKAGE_PREFIX}-python-e3-core"
         "${MINGW_PACKAGE_PREFIX}-python-funcy"
         "${MINGW_PACKAGE_PREFIX}-python-mako"
         "${MINGW_PACKAGE_PREFIX}-python-yaml")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-ada"
             "${MINGW_PACKAGE_PREFIX}-gprbuild"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=("!strip")
source=("https://github.com/AdaCore/langkit/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('9cef59480c9d927433ab4a74fbdfe118192b65c869b66bd59539325d966f7cf9')

build() {
  [[ -d "${srcdir}"/python-build-${MSYSTEM} ]] && rm -rf "${srcdir}"/python-build-${MSYSTEM}
  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 -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
