# Maintainer: Jürgen Pfeifer <juergen@familiepfeifer.de>
# Contributor: Tim S <stahta01@gmail.com>

# Pathnames in this project can get quite long, so at least on Windows
# I recommend to use a short BUILDDIR setting to avoid problems
#

_realname=xmlada
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=25.0.0
pkgrel=2
epoch=1
pkgdesc="A full XML suite for Ada (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-gpl")
url="https://github.com/AdaCore/xmlada/"
msys2_references=(
  'aur: xmlada'
)
license=('spdx:GPL-3.0-or-later with GCC-exception-3.1')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gcc-ada")
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild-bootstrap-git"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/AdaCore/xmlada/archive/v${pkgver}/xmlada-${pkgver}.tar.gz")
sha256sums=('dbb5984a0931311c7a787a679ef4cfaeeedd357474a585dc170140ef2251dcca')

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

  ./configure \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-shared

  make
}

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

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/include/xmlada
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib/xmlada/static
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib/xmlada/relocatable
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib/gnat/xmlada

  make -j1 prefix="${pkgdir}"${MINGW_PREFIX} INSTALL=cp install

  rm -rf "${pkgdir}"${MINGW_PREFIX}/share/examples
  rm -rf "${pkgdir}"${MINGW_PREFIX}/share/doc

  # Copy License Files
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/share/licenses/$_realname
  cp -pf "${srcdir}"/xmlada-${pkgver}/COPYING* \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
}
