# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=libpaper
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.2.7
pkgrel=1
pkgdesc="library for handling paper characteristics (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/rrthomas/libpaper'
license=('spdx:LGPL-2.1-or-later AND GPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "help2man")
source=("https://github.com/rrthomas/libpaper/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-relocation.patch")
sha256sums=('3925401edf1eda596277bc2485e050b704fd7f364f257c874b0c40ac5aa627c0'
            '591f90fbf97d1f848765ddf8a73908c3e4bf84eb0c2cda13bc00822180609bae')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -Np1 -i "${srcdir}/0001-fix-relocation.patch"

  autoreconf -fiv
}

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

  export MSYS2_ARG_CONV_EXCL="-DREAL_INSTALLPREFIX;-DINSTALLDIR"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --sbindir=${MINGW_PREFIX}/bin \
    --enable-relocatable \
    --enable-static \
    --enable-shared

  make
}

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

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