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

_realname=langkit_support
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=25.0.0
pkgrel=2
pkgdesc="Common code needed by parsers generated by Langkit, a language creation framework (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
msys2_references=(
  'aur: langkit'
)
license=('spdx:Apache-2.0 WITH LLVM-exception')
url="https://github.com/AdaCore/langkit"
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-core"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-gmp"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-iconv"
         "${MINGW_PACKAGE_PREFIX}-gcc-ada"
         "${MINGW_PACKAGE_PREFIX}-adasat"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-libvss"
         "${MINGW_PACKAGE_PREFIX}-prettier-ada")
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild"
             "${MINGW_PACKAGE_PREFIX}-langkit"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("https://github.com/AdaCore/langkit/archive/v${pkgver}/langkit-${pkgver}.tar.gz")
sha256sums=('de7976a815b810da98c841c475a0d0d83ed45dc1016c71327902ba63aa0d651c')

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -r "${srcdir}"/langkit-${pkgver} "${srcdir}"/build-${MSYSTEM}
  cd "${srcdir}"/build-${MSYSTEM}

  ${MINGW_PREFIX}/bin/python manage.py \
    build-langkit-support \
    --build-mode prod \
    --library-types=static,static-pic,relocatable
}

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

  ${MINGW_PREFIX}/bin/python manage.py \
    install-langkit-support \
    "${pkgdir}"${MINGW_PREFIX} \
    --build-mode prod \
    --library-types=static,static-pic,relocatable

  install -Dm644 "${srcdir}"/langkit-${pkgver}/LICENSE.txt \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
