# Maintainer: Hu Butui <hot123tea123@gmail.com>
# Contributor: Chris Severance aur.severach aATt spamgourmet dott com
# Contributor: oliver < a t >  first . in-berlin . de
# Contributor: 2ion <dev@2ion.de>

_pkgname=cpdf-source
pkgname=cpdf
pkgver=2.9.1
pkgrel=1
pkgdesc='Powerful, free tools to manipulate PDF files including merge, encrypt, decrypt, scale, crop, rotate, bookmarks, stamp, logos, page numbers'
arch=('x86_64')
url='http://community.coherentpdf.com'
license=('LicenseRef-cpdf')
depends=(
  glibc
  zstd
)
makedepends=(
  camlpdf
  ocaml-findlib
)
options=('!makeflags')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/johnwhitington/cpdf-source/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('8f96f92b2b19b42a6ee3aeb5986e7223a9fcfc8c65e534b6b45cb9525251ca80')

_setvars() {
  OCAMLFIND_DESTDIR="${pkgdir}/$(ocamlfind printconf destdir)"
  OCAMLFIND_LDCONF="${pkgdir}/$(ocamlfind printconf ldconf)"
}

build() { 
  cd "${_pkgname}-${pkgver}"
  local OCAMLFIND_DESTDIR OCAMLFIND_LDCONF; _setvars
  make OCAMLFIND_DESTDIR="${OCAMLFIND_DESTDIR}"
  # make twice to fix the broken build
  make OCAMLFIND_DESTDIR="${OCAMLFIND_DESTDIR}"
}

package() {
  cd "${_pkgname}-${pkgver}"
  local OCAMLFIND_DESTDIR OCAMLFIND_LDCONF; _setvars
  install -dm755 "${OCAMLFIND_DESTDIR}"
  make install -d OCAMLFIND_DESTDIR="${OCAMLFIND_DESTDIR}" OCAMLFIND_LDCONF="${OCAMLFIND_LDCONF}"
  install -Dm755 'cpdf' -t "${pkgdir}/usr/bin/"
  install -Dm644 'cpdf.1' -t "${pkgdir}/usr/share/man/man1/"
  install -Dpm644 'cpdfmanual.pdf' -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm644 LICENSE.md -t "${pkgdir}/usr/share/licenses/${pkgname}"
}
# vim:set ts=2 sw=2 et:
