# Maintainer: Philipp Smirnov https://github.com/sad-poet

_realname=gnatdoc
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=26.0.0
pkgrel=1
pkgdesc="GNAT documentation generation tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/AdaCore/gnatdoc"
msys2_references=(
  'aur: gnatdoc'
  'gentoo: dev-ada/gnatdoc'
)
license=('spdx:GPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (Apache-2.0 WITH LLVM-exception)')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-ada"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-core"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-gmp"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-iconv"
         "${MINGW_PACKAGE_PREFIX}-langkit_support"
         "${MINGW_PACKAGE_PREFIX}-libadalang"
         "${MINGW_PACKAGE_PREFIX}-libgpr"
         "${MINGW_PACKAGE_PREFIX}-markdown"
         "${MINGW_PACKAGE_PREFIX}-vss-text"
         "${MINGW_PACKAGE_PREFIX}-xmlada")
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild")
source=("https://github.com/AdaCore/gnatdoc/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "https://github.com/AdaCore/gnatdoc/commit/c83364d4.patch")
sha256sums=('88265a4a4c96d709431c899758c1ba9c896919c1cdca62383143d4fb39e7a850'
            '54accf9f1a8c52191c8bacc171f55d4d19e299e1e2d8fafb8f9c4e1600f89581')

prepare() {
  cd ${_realname}-${pkgver}
  # backport for ada_language_sever 202510141
  patch -p1 -i "${srcdir}"/c83364d4.patch
}

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

  gprbuild -p -P gnat/libgnatdoc.gpr \
    -j"$(nproc)" \
    -XBUILD_MODE=prod \
    -XLIBRARY_TYPE=relocatable

  gprbuild -p -P gnat/gnatdoc.gpr \
    -j"$(nproc)" \
    -XBUILD_MODE=prod \
    -XLIBRARY_TYPE=relocatable
}

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

  gprinstall -f -p -P gnat/libgnatdoc.gpr \
    --prefix="${pkgdir}${MINGW_PREFIX}" \
    -XBUILD_MODE=prod \
    -XLIBRARY_TYPE=relocatable \
    --build-var=LIBRARY_TYPE \
    --build-name=relocatable

  gprinstall -f -p -P gnat/gnatdoc.gpr \
    --prefix="${pkgdir}${MINGW_PREFIX}" \
    -XBUILD_MODE=prod \
    -XLIBRARY_TYPE=relocatable \
    --build-var=LIBRARY_TYPE \
    --build-name=relocatable

  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" \
    "${srcdir}/${_realname}-${pkgver}"/LICENSE*
}
