# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=wv
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.2.9
pkgrel=4
pkgdesc="Word Document Filter library and utilities. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/AbiWord/wv'
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libgsf"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/AbiWord/wv/archive/${_realname}-${pkgver//./-}.tar.gz")
sha256sums=('effe7a2b5b81a3707c60894e7799f7c086fdec76549eb80c1e8fb835b873d2c9')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd "wv-wv-${pkgver//./-}"

  mv CHANGELOG ChangeLog
  touch AUTHORS
  autoreconf -fiv
}

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

  CFLAGS+=" -Wno-int-conversion -Wno-incompatible-function-pointer-types" \
  ../wv-wv-${pkgver//./-}/configure \
    --prefix="${MINGW_PREFIX}"

  make
}

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

  make install DESTDIR="${pkgdir}"

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