# Maintainer: Dominic Sisneros <dsisnero@gmail.com>

_realname=mtex2MML
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.1
pkgrel=3
pkgdesc="A Bison grammar to convert TeX math into MathML (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/gjtorikian/mtex2MML/"
license=('spdx:MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
            )
source=("https://github.com/gjtorikian/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-install-rules.patch)
sha256sums=('977be19419572da01c4c86789c28a6a0d8cd74cdab6e30f77d6ab7dbd38e7195'
            '32a4fbcf633d165c4fd36b2f4af8b902d0509dcca0fd3585e244e9cad65e7eee')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-install-rules.patch"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  CFLAGS+=" -Wno-strict-prototypes" \
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
    -DBUILD_STATIC_LIBS=ON \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_TESTING=OFF \
    "${_extra_config[@]}" \
    ../${_realname}-${pkgver}

  cmake --build .
}

# check() {
#     #make check
# }

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" cmake --install .
}
