# -*- 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       boost 1.0

boost.version   1.88

name            enblend
version         4.2
revision        9
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      graphics
maintainers     nomaintainer
license         GPL-2+

description     a tool to composite images
long_description Enblend is a tool to composite overlapping images \
                with invisible (or very difficult to see) seams. Enfuse is a \
                tool for automatic exposure and contrast blending.
homepage        http://enblend.sourceforge.net/
master_sites    sourceforge:project/enblend/enblend-enfuse/enblend-enfuse-${branch}
distname        enblend-enfuse-${version}

checksums       rmd160  997a849a39da3f367b666c6d0d344059d97738d7 \
                sha256  8703e324939ebd70d76afd350e56800f5ea2c053a040a5f5218b2a1a4300bd48 \
                size    777747

depends_build   port:pkgconfig \
                port:help2man

depends_lib     port:gsl \
                path:include/turbojpeg.h:libjpeg-turbo \
                port:lcms2 \
                port:libpng \
                port:openexr2 \
                port:tiff \
                port:vigra \
                port:zlib

configure.args  --with-openexr
configure.pkg_config_path-append \
                ${prefix}/libexec/openexr2/lib/pkgconfig

# vigra header file requires C++11
compiler.cxx_standard   2011
configure.cxxflags-append -std=c++11

# Avoid Xcode Clang 9 and earlier, due to crash
# See: https://trac.macports.org/ticket/65694
compiler.blacklist-append \
                {clang < 1000}

set perl_branch  5.34

# bold-extra sets OT1 bold small caps in cmbcsc10, which TeX Live ships as
# METAFONT sources only.  pdfTeX renders it as a bitmap font, and microtype's
# automatic font expansion fails outright on those.  Turn the expansion off.
set tex_preamble {\def\finishdynamicpreamble{\ifpdf\microtypesetup{expansion=false}\fi}}

post-patch {
    # avoid c++17 header collision
    move ${worksrcpath}/VERSION ${worksrcpath}/VERSION.txt

    # fix a boost path for the BOOST_FALLTHROUGH check
    reinplace "s|boost/config/suffix\\.hpp|boost/config.hpp|" \
        ${worksrcpath}/configure

    if {[variant_isset docs]} {
        reinplace -W ${worksrcpath}/doc \
            "s|^#! /usr/bin/env perl|#!${prefix}/bin/perl${perl_branch}|" \
            cleantex config2tex docstrings updated-on
    }
}

post-destroot {
    xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS COPYING NEWS README \
        ${destroot}${prefix}/share/doc/${name}
}

variant docs description {Build HTML and PDF docs} {
    depends_build-append \
                port:ghostscript \
                port:gnuplot \
                port:graphviz \
                port:hevea \
                port:ImageMagick \
                port:librsvg \
                port:m4 \
                port:p${perl_branch}-readonly \
                port:perl${perl_branch} \
                port:texlive-fonts-extra \
                port:texlive-fonts-recommended \
                port:texlive-fontutils \
                port:texlive-latex-extra

    configure.args-append \
                M4=${prefix}/bin/gm4

    build.args-append \
                DYNAMIC_TEX_PREAMBLE=[shellescape ${tex_preamble}]

    # pdf is not built in make all
    post-build {
        system -W ${worksrcpath} \
            "${build.cmd} pdf DYNAMIC_TEX_PREAMBLE=[shellescape ${tex_preamble}]"
    }

    destroot.target-append \
                install-html install-pdf
    destroot.args-append \
                htmldir=${destroot}${prefix}/share/doc/${name}/html \
                pdfdir=${destroot}${prefix}/share/doc/${name} \
                DYNAMIC_TEX_PREAMBLE=[shellescape ${tex_preamble}]
}

if {![variant_isset docs]} {
    # force configure to skip docs even if we happen
    # to have latex etc installed
    configure.args-append \
                ac_cv_prog_latex=false \
                ac_cv_path_CONVERT=false \
                ac_cv_path_DOT=false \
                ac_cv_path_DVIPS=false \
                ac_cv_path_GNUPLOT=false \
                ac_cv_path_MAKEINDEX=false \
                ac_cv_path_SVGCONVERT=false
}

variant openmp description {Use OpenMP} {
    compiler.openmp_version 2.5
    configure.args-append   --enable-openmp
}

default_variants +openmp

livecheck.regex   /enblend-enfuse-(\[0-9.\]+)${extract.suffix}
