# Maintainer: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: earnestly

pkgname=llpp
pkgver=31
# Often breaks with mupdf, which means I'll occasionally need to pin a specific commit.
_commit=77dd95ff11449f57f2ea002223bb282256270fa8  # tags/v31
pkgrel=2
pkgdesc='opengl accelerated pdf viewer based on mupdf'
arch=('x86_64')
url="https://github.com/moosotc/${pkgname}"
license=('GPL3')
depends=('glu' 'openjpeg2' 'jbig2dec' 'libjpeg-turbo' 'freetype2' 'desktop-file-utils')
optdepends=('djvulibre: llppac djvu conversion'
            'ghostscript: llppac ps, dvi, and djvu conversion'
            'unoconv: llppac office conversion'
            'librsvg: llppac svg conversion'
            'imagemagick: llppac image conversion'
            'inotify-tools: for the llpp.inotify autoreload wrapper')
makedepends=('git' 'asciidoc' 'ocaml' 'ocaml-lablgl' 'libmupdf' 'camlp4')

# llpp seems to go through build systems like fasion, holomorph has provided a
# very nice Makefile for building this software which has served well for
# months.  It was contributed, or offered, to the author malc, but he concluded
# that make was bad and needed constant effort to prevent "bitrot" as
# justification for using a terrible shell script that downloaded arbitrary
# commits of bundled libraries.  Now he's on to shake, a haskell NIH
# implementation of make requiring that you now also have ghc and the shake
# library to build this software.  Before this he used ninja.

# For obvious reasons I'm sticking with the custom makefile which greatly
# reduces maintainence burden and unecessary dependency bloat.
source=("git+${url}#commit=${_commit}"
        'no-quit-on-escape.patch'
        "${url}/pull/85/commits/6e40f7315cb620fef1d96bbe56cfe24dd91e182a.patch"
        'GNUmakefile')
sha256sums=('SKIP'
            '5814846ad19d9ddd8e1412bf36d4c2dc1a32186261126ec63cdf19f308396458'
            'e6fa1df1e9451d4ffecc416676ad4697da21fc8809e20c78502b97805e4f4321'
            'b764e6cc084ee472704faad2591f086beaf79c3c04dbf6f12711e050d9167028')

pkgver() {
    cd "${srcdir}"/${pkgname}

    git describe --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
    cd "${srcdir}"/${pkgname}

    # Don't use CPPFLAGS to insert '#include <inttypes.h>'
    patch -Np1 -i "${srcdir}"/6e40f7315cb620fef1d96bbe56cfe24dd91e182a.patch

    patch -Np1 -i "${srcdir}"/no-quit-on-escape.patch
    # apparently the desktop file went "stale"
    git revert --no-commit aad4b1e65e581ff7a096a3c3901b222a9c127a1c

    # This symlink ruins all the fun
    rm wsi/x11/wsi.mli

    ln -sf ../GNUmakefile GNUmakefile
}

build() {
    cd "${srcdir}"/${pkgname}

    make
}

package() {
    cd "${srcdir}"/${pkgname}

    make PREFIX=/usr DESTDIR="${pkgdir}" install
}
