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

_realname=libe-book
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.1.3
pkgrel=8
pkgdesc="Library for import of reflowable e-book formats. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://sourceforge.net/projects/libebook'
msys2_references=(
  'archlinux: libe-book'
)
license=('spdx:MPL-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-icu"
         "${MINGW_PACKAGE_PREFIX}-liblangtag"
         "${MINGW_PACKAGE_PREFIX}-librevenge"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-gperf"
             "${MINGW_PACKAGE_PREFIX}-cppunit")
source=("https://sourceforge.net/projects/${_realname//-/}/files//${_realname}-${pkgver}/${_realname}-${pkgver}.tar.xz"
        "001-fix-build-with-icu-68.patch")
sha256sums=('7e8d8ff34f27831aca3bc6f9cc532c2f90d2057c778963b884ff3d1e34dfe1f9'
            '602da16758c2e43a45298d6c747673c5b7a5def3df939dce8d7a6d6f28f7ffda')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001-fix-build-with-icu-68.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 -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
