# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libwpd
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.10.3
pkgrel=1
pkgdesc="Library for Importing WordPerfect (tm) Documents (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://libwpd.sourceforge.io/"
license=("LGPL-2.1+" "MPL-2.0+")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-librevenge"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=(staticlibs strip !buildflags)
source=("https://downloads.sourceforge.net/project/${_realname}/${_realname}/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.xz"
        fix-condition.patch
        fix-var-sizes.patch)
sha256sums=('2465b0b662fdc5d4e3bebcdc9a79027713fb629ca2bff04a3c9251fdec42dd09'
            'bc596c1982365d5ee5eb659521e9343fcb7caee103bd5673f181df9a42aa9970'
            '125e7ea0b17b42bb41dbdc35c3072e40fa6a03e24f11f871620b261199d7cd4f')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/fix-condition.patch
  patch -p1 -i ${srcdir}/fix-var-sizes.patch
  autoreconf -fiv
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}

  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --without-docs \
    --disable-werror \
    --enable-silent-rules

  make
}

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