# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=adasat
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=25.0.0
pkgrel=2
pkgdesc="Implementation of a DPLL-based SAT solver in Ada (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
msys2_references=(
  'aur: adasat'
)
license=('spdx:Apache-2.0 WITH LLVM-exception')
url="https://github.com/AdaCore/AdaSAT"
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gcc-ada")
source=("https://github.com/AdaCore/AdaSAT/archive/v${pkgver}/adasat-${pkgver}.tar.gz")
sha256sums=('b823969345cdd3678bf3cb1eb55592a0f74c2d99fc67303e187b4fbc960188a2')

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

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

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

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

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

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