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

_realname=lal-refactor
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=26.0.0
pkgrel=1
pkgdesc="Source code refactoring tools for the Ada programming language, leveraging the power of Libadalang (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/AdaCore/lal-refactor"
msys2_references=(
  'aur: lal-refactor'
)
license=("spdx:Apache-2.0 WITH LLVM-exception")
depends=(
  "${MINGW_PACKAGE_PREFIX}-gcc-ada"
  "${MINGW_PACKAGE_PREFIX}-cc-libs"
  "${MINGW_PACKAGE_PREFIX}-gmp"
  "${MINGW_PACKAGE_PREFIX}-gnatcoll-core"
  "${MINGW_PACKAGE_PREFIX}-gnatcoll-gmp"
  "${MINGW_PACKAGE_PREFIX}-gpr"
  "${MINGW_PACKAGE_PREFIX}-langkit_support"
  "${MINGW_PACKAGE_PREFIX}-libadalang"
  "${MINGW_PACKAGE_PREFIX}-libadalang-tools"
  "${MINGW_PACKAGE_PREFIX}-libgpr"
  "${MINGW_PACKAGE_PREFIX}-vss-extra"
  "${MINGW_PACKAGE_PREFIX}-vss-text"
  "${MINGW_PACKAGE_PREFIX}-xmlada"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-gprbuild"
)
source=("https://github.com/AdaCore/lal-refactor/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "https://github.com/AdaCore/lal-refactor/commit/d8a78617.patch"
        "https://github.com/AdaCore/lal-refactor/commit/9bc2b4f3.patch")
sha256sums=('92e89339476fd69e275b34d98c0041a6efbeec2af06fa951bfa7552e6bbee381'
            'c8288b04154571c53c4228b8b9afe828e7dfa0ceaa76713dfd9e997dc0175925'
            'e8ed6b78a9e384f54602608a13e72c6022c48539d2bbac4852d996dff10874d5')

prepare() {
  cd ${_realname}-${pkgver}
  # backports for ada_language_server 2026.202510141
  patch -p1 -i "${srcdir}"/d8a78617.patch
  patch -p1 -i "${srcdir}"/9bc2b4f3.patch
}

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

  BUILD_MODE=prod \
  LIBRARY_TYPE=relocatable \
  make lib bin
}

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

  BUILD_MODE=prod \
  LIBRARY_TYPE=relocatable \
  make install PREFIX=${pkgdir}${MINGW_PREFIX}

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