# -*- 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           github 1.0
PortGroup           compiler_blacklist_versions 1.0
PortGroup           openssl 1.0

github.setup        mgieseki dvisvgm 3.4.4
name                dvisvgm
conflicts           dvisvgm-devel
set my_name         dvisvgm
revision            0

checksums           rmd160  acb4846c81e7b9baae21826499040e59537813c0 \
                    sha256  c9cea7bed1eef559cd3eacb4e764f3e33179b25515722face12e46d4fb93c7b5 \
                    size    2534180
github.tarball_from archive

categories          graphics textproc
license             GPL-3+
maintainers         {michaelld @michaelld} {mascguy @mascguy} openmaintainer

description         DVI to SVG converter
long_description    DVI to SVG converter. The command-line utility dvisvgm is a tool \
                    for TeX/LaTeX users. It converts DVI files to the XML-based scalable \
                    vector graphics format SVG.

dist_subdir         ${my_name}

compiler.cxx_standard 2011
# see https://trac.macports.org/ticket/63553
compiler.blacklist-append {clang < 900}

use_autoconf        yes
autoconf.cmd        ${worksrcpath}/autogen.sh

post-extract {
    copy ${filespath}/autogen.sh ${worksrcpath}
    system -W ${worksrcpath} "chmod +x autogen.sh"
}

# Setting autoconf.cmd to a non-default value after setting
# 'use_autoconf yes' removes the automatic dependencies, so re-add them.
depends_build-append \
    port:autoconf \
    port:autoconf-archive \
    port:automake \
    port:libtool

depends_build-append \
    port:asciidoc \
    path:bin/pkg-config:pkgconfig \
    port:xmlto

depends_lib-append \
    port:brotli \
    port:freetype \
    port:ghostscript \
    port:potrace \
    port:texlive-bin \
    port:woff2 \
    port:xxhashlib \
    port:zlib

# prevent opportunistic dependencies
configure.env-append \
    AWK=/usr/bin/awk

configure.args-append \
    --disable-silent-rules

test.run    yes
test.target check

pre-activate {
    if {![catch {set vers [lindex [registry_active texlive-bin-extra] 0]}]
        && ([vercmp [lindex $vers 1] 47446] < 0 ||
            [vercmp [lindex $vers 1] 47446] == 0
            && [vercmp [lindex $vers 2] 1] < 1)} {
        registry_deactivate_composite texlive-bin-extra "" [list ports_nodepcheck 1]
    }
}

variant mupdf description {Enable pdf support, via mupdf} {
    # Note: Project doesn't provide any configure/build args to enable mupdf
    # support. Instead, if it's available at runtime, it's used. Otherwise,
    # support for PDF is disabled.
    depends_run-append \
        port:mupdf
}

default_variants-append +mupdf