# -*- 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           cmake 1.1
PortGroup           compiler_blacklist_versions 1.0

name                xpdf
version             4.05
revision            0
description         Xpdf is a viewer for PDF files.
long_description    Xpdf is a viewer for Portable Document Format (PDF) files. \
                    These are also sometimes also called Acrobat files, from \
                    the name of Adobes PDF software.

maintainers         nomaintainer
categories          graphics print
license             {GPL-2 GPL-3}

homepage            https://www.xpdfreader.com

master_sites        https://dl.xpdfreader.com

checksums           rmd160  0c2d6533dd117aab8df935b89c3225531c5468c6 \
                    sha256  92707ed5acb6584fbd73f34091fda91365654ded1f31ba72f0970022cf2a5cea \
                    size    986596

compiler.cxx_standard   2011

patchfiles-append   patch-fix-qt4.diff

# PDFCore.h: error: atomic: No such file or directory
compiler.blacklist-append \
                    {clang < 601}

variant qt6 conflicts qt4 qt5 description {Use Qt 6} {
    PortGroup   qt6 1.0

    qt6.find_method module_path
}

variant qt5 conflicts qt4 qt6 description {Use Qt 5} {
    PortGroup   qt5 1.0

}

variant qt4 conflicts qt5 qt6 description {Use Qt 4} {
    PortGroup   qt4 1.0

}

if {${os.platform} eq "darwin" && ${os.major} < 12} {
    default_variants-append +qt4
} else {
    if {![variant_isset qt5]} {
        # https://doc.qt.io/qt-6/macos.html
        if {${os.major} >= 21 || ${os.platform} ne "darwin"} {
            # icons are missing when using Qt6
            # default_variants-append +qt6
        }
    }

    if {![variant_isset qt6]} {
        default_variants-append +qt5
    }
}

variant no_mangle_names description {do not mangle the CLI tool names, conflicts with poppler} {
    conflicts-append    poppler
}

post-destroot {
    if {![variant_isset no_mangle_names]} {
        # rename the CLI tools to xpdf-${TOOL_NAME} to avoid conflicts with poppler
        foreach binFile { pdfdetach pdffonts pdfimages pdfinfo pdftoppm pdftops pdftotext pdftohtml } {
            move ${destroot}${prefix}/bin/${binFile} ${destroot}${prefix}/bin/${name}-${binFile}
            move ${destroot}${prefix}/share/man/man1/${binFile}.1 ${destroot}${prefix}/share/man/man1/${name}-${binFile}.1
        }
    }
}
