# Contributor: Carlo Bramini <carlo_bramini@users.sourceforge.net>

_realname=mxml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.1
pkgrel=4
pkgdesc="A tiny XML library for reading and writing XML files (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.msweet.org/mxml/"
msys2_repository_url="https://github.com/michaelrsweet/mxml"
msys2_references=(
  "cpe: cpe:/a:mini-xml_project:mini-xml"
  "cpe: cpe:/a:msweet:mini-xml"
)
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/michaelrsweet/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
         0001-autoconf-remove-options-for-clang.patch
         0002-makefile-install-dll.patch)
sha256sums=('59eba16ce43765f2e2a6cf4873a58d317be801f1e929647d85da9f171e41e9ac'
            'a05cd5621a1c5bc5f0977adf7e0282319c6c2408346913a6f5fe1b7e180eb5f9'
            '95f8947746e9ee5e7e7fb0b453bc0953e825c1ccf7559936f49b870a95f8c7f6')

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

  patch -p1 -i "${srcdir}"/0001-autoconf-remove-options-for-clang.patch
  patch -p1 -i "${srcdir}"/0002-makefile-install-dll.patch
}

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

  CFLAGS+=" -Wno-implicit-function-declaration" \
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --enable-shared

  make
}

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

  make DSTROOT="${pkgdir}" install

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