# 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}
_gh_release=21.0.0
pkgver=20${_gh_release}
pkgrel=2

pkgdesc="A full XML suite for Ada (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-gpl")
url="https://github.com/AdaCore/xmlada/"
license=('GPL3')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-ada"
             "${MINGW_PACKAGE_PREFIX}-gprbuild-bootstrap-git")
depends=()
source=("xmlada-${_gh_release}.tar.gz::https://github.com/AdaCore/xmlada/archive/v${_gh_release}.tar.gz")
sha256sums=('923024931f0c57451aa52cb9a3333874646102cb75957f27e3689670f90edc1e')
options=('strip')

build() {

  if [ "${CARCH}" = "x86_64" ]; then
    local _target='x86_64-windows'
  else
    local _target='x86-windows'
  fi

  cd ${srcdir}/xmlada-${_gh_release}/
  ./configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --target=${_target}

  make
}

package() {
  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

  cd ${srcdir}/xmlada-${_gh_release}/
  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-${_gh_release}/COPYING* \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
}
