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

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

pkgdesc="Library for parsing and semantic analysis of Ada code (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('GPL3 with GCC exception')
url="https://github.com/AdaCore/gprbuild/"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-ada"
             "${MINGW_PACKAGE_PREFIX}-gprbuild")
depends=("${MINGW_PACKAGE_PREFIX}-gnatcoll"
         "${MINGW_PACKAGE_PREFIX}-libgpr"
         "${MINGW_PACKAGE_PREFIX}-langkit_support"
         "${MINGW_PACKAGE_PREFIX}-iconv"
         "${MINGW_PACKAGE_PREFIX}-gmp")
source=("https://github.com/AdaCore/libadalang/releases/download/v${pkgver}/libadalang-${pkgver}.tar.gz")
sha256sums=('c92637d4c2e3405b47e7be5ac96a01ed507557be671d6c52590dabe47fa01a70')

_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 libadalang.gpr \
      -j"$(nproc)" \
      -XBUILD_MODE="${_build_mode}" \
      -XLIBRARY_TYPE="${_library_type}" \
      --relocate-build-tree="${_library_type}"
  done
}

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

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