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

pkgname=llpp
pkgver=33
# Often breaks with mupdf, which means I'll occasionally need to pin a specific commit.
_commit=3fb41e63167a01638c1bf808e876e2380fe7a1f6
pkgrel=2
pkgdesc='opengl accelerated pdf viewer based on mupdf'
arch=('x86_64')
url="https://github.com/moosotc/${pkgname}"
license=('GPL3')
depends=('libgl' 'openjpeg2' 'jbig2dec' 'libjpeg' 'freetype2' 'gumbo-parser')
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' 'asciidoctor' 'ocaml' 'ocaml-lablgl' 'libmupdf')

# 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.  Then he used ninja.  Then he moved on to
# shake, a haskell NIH implementation of make requiring that you now also have
# ghc and the shake library to build this software.  Now he is back to a (new)
# shell script.

# 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'
        'GNUmakefile')
sha256sums=('SKIP'
            '5814846ad19d9ddd8e1412bf36d4c2dc1a32186261126ec63cdf19f308396458'
            '5771cc554407ff32ddd8c8982e8260687f31af37a4cb5e32875897ff5426a91f')

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

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

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

    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
}
