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

_realname=libpaper
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1.28
_suffix=
pkgrel=1
pkgdesc="library for handling paper characteristics (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://packages.debian.org/unstable/source/libpaper'
license=('GPL-2')
makedepends=('gettext')
#backup=("${MINGW_PREFIX:1}/etc/papersize")
source=("http://http.debian.net/debian/pool/main/libp/libpaper/${_realname}_${pkgver}${_suffix}.tar.gz"
        001-no-undefined.patch)
sha256sums=('c8bb946ec93d3c2c72bbb1d7257e90172a22a44a07a07fb6b802a5bb2c95fddc'
            'a77784a1a2dce1bf0155ee0cd889157fdbb67024e2967d3b0466a39849ac75f0')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}${_suffix}
  patch -p1 -i ${srcdir}/001-no-undefined.patch
  autoreconf -fiv
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}${_suffix}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}${_suffix}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --sbindir=${MINGW_PREFIX}/bin \
    --enable-static \
    --enable-shared

  make
}

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

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

  # add systemwide default papersize read by many office applications
  install -dm 755 ${pkgdir}${MINGW_PREFIX}/etc
  echo '# Simply write the paper name. See papersize(5) for possible values' > ${pkgdir}${MINGW_PREFIX}/etc/papersize

  # add libpaper.d directory other packages can use to store files
  install -dm 755 $pkgdir${MINGW_PREFIX}/etc/libpaper.d
  # add localisation
  pushd ${srcdir}/${_realname}-${pkgver}${_suffix}/debian/po
    for i in `ls *.po`; do
      install -dm 755 ${pkgdir}${MINGW_PREFIX}/share/locale/${i%.po}/LC_MESSAGES/;
      msgfmt $i -o ${pkgdir}${MINGW_PREFIX}/share/locale/${i%.po}/LC_MESSAGES/${pkgname}.mo;
    done
  popd
}
