# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           openssl 1.0

name                mupdf

# Keep synchronized with port:py-mupdf.
version             1.23.4

revision            2
categories          graphics
platforms           darwin
maintainers         {gmail.com:starkhalo @harciga} openmaintainer
license             AGPL-3+

description         lightweight PDF and XPS viewer and parser/rendering library

long_description    MuPDF is a lightweight PDF and XPS viewer and \
                    parser/rendering library. \
                    \
                    The renderer in MuPDF is tailored for high-quality \
                    anti-aliased graphics. It renders text with metrics and \
                    spacing accurate to within fractions of a pixel for the \
                    highest fidelity in reproducing the look of a printed \
                    page on screen. \
                    \
                    MuPDF is also small, fast, and yet complete. It supports \
                    PDF 1.7 with transparency, encryption, hyperlinks, \
                    annotations, search and many other bells and whistles. \
                    MuPDF can also read XPS documents (OpenXPS ECMA-388).

homepage            https://www.mupdf.com/

master_sites        ${homepage}downloads/archive/
distname            ${name}-${version}-source

checksums           rmd160  63d39c7cfc70ac08beed28d8da6e581bbf09ae6f \
                    sha256  deb0347a3f9ce0967611d479a8a07b57e2c730b0aaf09dce28ee41abb9ac4838 \
                    size    55146083

depends_build       port:pkgconfig

depends_lib         port:freetype \
                    port:gumbo-parser \
                    path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
                    port:leptonica \
                    port:jbig2dec \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:openjpeg \
                    port:tesseract \
                    port:zlib

patchfiles          patch-build.diff

use_configure       no
use_parallel_build  no

compiler.cxx_standard   2017

build.args          PREFIX=${prefix}
build.args-append   CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP=${configure.cpp} \
                    XCFLAGS="${configure.cflags} [get_canonical_archflags cc]" \
                    XLIBS="${configure.ldflags} [get_canonical_archflags ld]" \
                    HAVE_GLUT=yes \
                    HAVE_X11=no \
                    USE_SYSTEM_LIBS=yes \
                    USE_TESSERACT=yes \
                    build=release \
                    shared=yes \
                    verbose=yes \
                    shared-release

destroot.destdir    prefix=${destroot}${prefix}
destroot.args-append \
                    HAVE_GLUT=yes \
                    HAVE_X11=no \
                    USE_SYSTEM_LIBS=yes \
                    shared=yes

variant x11 {
    depends_lib-append \
                    port:mesa \
                    port:xorg-libXcursor \
                    port:xorg-libXext \
                    port:xorg-libXinerama \
                    port:xorg-libXrandr

    build.args-replace \
                    HAVE_X11=no HAVE_X11=yes
    destroot.args-replace \
                    HAVE_X11=no HAVE_X11=yes
}

variant universal   {}

post-extract {
# delete thirdparty software other than mujs
    delete ${worksrcpath}/thirdparty/curl
    delete ${worksrcpath}/thirdparty/freeglut
    delete ${worksrcpath}/thirdparty/freetype
    delete ${worksrcpath}/thirdparty/gumbo-parser
    delete ${worksrcpath}/thirdparty/harfbuzz
    delete ${worksrcpath}/thirdparty/jbig2dec
    delete ${worksrcpath}/thirdparty/jpeg
    delete ${worksrcpath}/thirdparty/libjpeg
    delete ${worksrcpath}/thirdparty/leptonica
    delete ${worksrcpath}/thirdparty/openjpeg
    delete ${worksrcpath}/thirdparty/tesseract
    delete ${worksrcpath}/thirdparty/zlib
}

# https://trac.macports.org/ticket/33240
# Mac OS X Tiger has an old version of `make`, needs to use GNU make
platform darwin 8 {
    depends_build-append port:gmake
    build.cmd ${prefix}/bin/gmake
}

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     ${name}-(\\d+(?:\\.\\d+)*\[a-z\]?)-source
