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

_realname=libwpg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.3
pkgrel=1
pkgdesc="Library to read and parse graphics in WordPerfect Graphics format (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://libwpg.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}-libwpd")
options=(staticlibs strip)
source=("https://downloads.sourceforge.net/project/${_realname}/${_realname}/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.xz"
        fix-condition.patch
        fix-var-size.patch)
sha256sums=('99b3f7f8832385748582ab8130fbb9e5607bd5179bebf9751ac1d51a53099d1c'
            '0f7087a464623ee5680dbf54dc7a33a2214fb1c3edc0320e740c687c23d28045'
            'f9a6c853f8243005871a9ea3b5c235a672c966cc2f1f10d301ac62219faf2220')

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

build() {
  [[ -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

  make
}

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