# Maintainer: Renato Silva <br.renatosilva@gmail.com>
# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=xmlstarlet
pkgbase=mingw-w64-${_realname}
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname})
pkgdesc="Command-line XML toolkit"
pkgver=1.6.1
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('MIT')
url="https://xmlstar.sourceforge.io/"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
depends=("${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libxslt")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-libiconv")
source=("https://downloads.sourceforge.net/xmlstar/${_realname}-${pkgver}.tar.gz")
sha256sums=('15d838c4f3375332fd95554619179b69e4ec91418a3a5296e7c631b7ed19e7ca')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  autoreconf -sif
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-libxml-prefix=${MINGW_PREFIX} \
    --with-libxslt-prefix=${MINGW_PREFIX} \
    --with-libiconv-prefix=${MINGW_PREFIX}
    # --enable-static-libs  # To link with libxml/libxslt statically

  make
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
  local license_dir="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${license_dir}"
  cp -v Copyright "${license_dir}/Copyright"
  mv -v "${pkgdir}${MINGW_PREFIX}/bin/xml.exe" "${pkgdir}${MINGW_PREFIX}/bin/xmlstarlet.exe"
}
