
_realname=gpr
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=25.0.0
pkgrel=2
pkgdesc="The framework for analyzing the GNAT Project (GPR) files (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/AdaCore/gpr"
msys2_references=(
  'aur: gpr'
  'gentoo: dev-ada/gpr'
)
license=('spdx:(Apache-2.0 WITH LLVM-exception) AND GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-ada"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-core"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-iconv"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-gmp"
         "${MINGW_PACKAGE_PREFIX}-python-funcy"
         "${MINGW_PACKAGE_PREFIX}-python-mako"
         "${MINGW_PACKAGE_PREFIX}-python-docutils")
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild"
             "${MINGW_PACKAGE_PREFIX}-python-e3-core")
source=("https://github.com/AdaCore/gpr/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-fix-build-with-gcc-ada-14.patch)
sha256sums=('2a0cdbb42cdd5440cbb06cbe3a2075c9ca7ccb82225bb3491509f930593ab33e'
            'df61949e11734267e0ccf8072612cc33abf26b92f12e40041c9b18e7e228eefa')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-fix-build-with-gcc-ada-14.patch
}

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

  make setup prefix="${pkgdir}${MINGW_PREFIX}" GPR2KBDIR=${MINGW_PREFIX}/share/gprconfig

  make
}

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

  # Without -j1 concurrent gprinstall processes may crash:
  #
  #     raised ADA.IO_EXCEPTIONS.END_ERROR : a-tigeli.adb:96
  #     make: *** [Makefile:209: install-lib-static-pic] Error 1
  #
  # Inspired by: https://github.com/AdaCore/gprbuild/issues/41#issuecomment-396234433
  #
  make -j1 install prefix="${pkgdir}${MINGW_PREFIX}"

  # These conflict with the binaries from 'gprbuild'.
  #
  rm -fv "${pkgdir}${MINGW_PREFIX}"/bin/gprconfig.exe

  # Copy License Files
  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" \
    LICENSE-lib LICENSE-tool
}
