# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=libnumbertext
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.0.6
pkgrel=1
pkgdesc="Number to number name and money text conversion library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/Numbertext/libnumbertext'
license=('LGPL3' 'custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/Numbertext/libnumbertext/archive/${pkgver}.tar.gz"
        "libnumbertext-updateautotools.patch")
sha256sums=('d03860c98ec01bc52a2a65f04b1fc4c7e7823c76d54dec800ca32ab2196023bc'
            '4c1be70cbb6c7b5e2f9d3842ad83ea95971d99663768e5df2ac74956fc4555bd')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/libnumbertext-updateautotools.patch"
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make -k check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
