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

_realname=markdown
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=25.0.0
pkgrel=2
pkgdesc="A Markdown parser for Ada (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/AdaCore/markdown"
msys2_references=(
  'aur: markdown'
  'gentoo: dev-ada/markdown'
)
license=('spdx:Apache-2.0 WITH LLVM-exception')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-ada"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libvss")
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild")
source=("https://github.com/AdaCore/markdown/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('95a043d527b44665e51da97c69cfa6b46447ef827822ec9ad74009184aaeed95')

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

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

  for _library_type in ${_library_types}; do
    echo "Building ${_library_type}:"
    gprbuild -p -P gnat/markdown.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 gnat/markdown.gpr \
      --prefix="${pkgdir}${MINGW_PREFIX}" \
      -XBUILD_MODE="${_build_mode}" \
      -XLIBRARY_TYPE="${_library_type}" \
      --build-var=LIBRARY_TYPE \
      --build-name=${_library_type}
  done

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