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

_realname=libmwaw
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.3.22
pkgrel=1
pkgdesc="A library for reading ClarisWorks/MacWrite/WriteNow/Writerperfect word processor documents. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://sourceforge.net/projects/libmwaw/'
msys2_references=(
  'archlinux: libmwaw'
)
license=('spdx:MPL-2.0 OR LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-librevenge"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://sourceforge.net/projects/${_realname}/files/${_realname}/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.xz"
        "001-fix-build-on-mingw.patch")
sha256sums=('a1a39ffcea3ff2a7a7aae0c23877ddf4918b554bf82b0de5d7ce8e7f61ea8e32'
            'a6a96fec6ea2654f3c822333106731dbb8e463d288bf50ec6c2a50ba6d2bc9ed')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001-fix-build-on-mingw.patch

  autoreconf -fiv
}

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

  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}"

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check
}

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

  make install DESTDIR="${pkgdir}"

  install -d "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -p -m644 "${srcdir}"/${_realname}-${pkgver}/COPYING* "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
