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

_realname=langkit_support
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=21.0.0
pkgrel=1

pkgdesc="Language creation framework (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('GPL3 with GCC exception')
url="https://github.com/AdaCore/langkit"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-ada"
             "${MINGW_PACKAGE_PREFIX}-gprbuild")
depends=("${MINGW_PACKAGE_PREFIX}-gnatcoll"
         "${MINGW_PACKAGE_PREFIX}-iconv")
source=("https://github.com/AdaCore/langkit/releases/download/v${pkgver}/langkit_support-${pkgver}.tar.gz")
sha256sums=('79609dac4788810b6e5e9be30778476684d8ca08b8bb78f60bab7b3e32f69d27')

_library_types="static static-pic relocatable"
_build_mode="prod"

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  
  for _library_type in ${_library_types}; do
    echo "Building ${_library_type}:"
    gprbuild -p -P langkit_support.gpr \
      -j"$(nproc)" \
      -XBUILD_MODE="${_build_mode}" \
      -XLIBRARY_TYPE="${_library_type}"
    rm -rf obj/
  done
}

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

  for _library_type in ${_library_types}; do
    echo "Installing ${_library_type}:"
    gprinstall -f -p -P langkit_support.gpr \
      --prefix="${pkgdir}${MINGW_PREFIX}" \
      -XBUILD_MODE="${_build_mode}" \
      -XLIBRARY_TYPE="${_library_type}" \
      --build-var=LIBRARY_TYPE \
      --build-name=${_library_type}
  done
}
