# -*- 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               conflicts_build 1.0
PortGroup               legacysupport 1.1

# https://trac.macports.org/ticket/65314
#   undefined vtable symbols, related to std::bad_variant_access
# https://trac.macports.org/ticket/66697
#   error: call to unavailable function 'get': introduced in macOS 10.14
legacysupport.newest_darwin_requires_legacy 17
legacysupport.use_mp_libcxx                 yes

name                    doxygen
conflicts               doxygen-devel
set my_name             doxygen

# please don't update doxygen without first checking the build status of doxygen-devel
version                 1.17.0
revision                2
epoch                   2

categories              textproc devel
license                 GPL-2
maintainers             nomaintainer
description             Documentation system for several programming languages
long_description        It can generate an on-line documentation browser \
                        (in HTML) and/or an off-line reference manual \
                        from a set of documented source files. There is \
                        also support for generating output in RTF \
                        (MS-Word), PostScript, hyperlinked PDF, \
                        compressed HTML, and Unix man pages. \
                        The documentation is extracted directly from \
                        the sources, which makes it much easier to keep \
                        the documentation consistent with the source code. \
                        You can configure doxygen to extract the code \
                        structure from undocumented source files. This \
                        is very useful to quickly find your way in large \
                        source distributions. You can also visualize \
                        the relations between the various elements by means \
                        of include dependency graphs, inheritance \
                        diagrams, and collaboration diagrams, which are \
                        all generated automatically.
homepage                https://www.doxygen.nl

master_sites            ${homepage}/files
distname                ${my_name}-${version}
dist_subdir             ${my_name}
distfiles               ${distname}.src${extract.suffix}

checksums               rmd160  e9546ecf9acb30d8bf905ce877e07ecd7f4a3f5d \
                        sha256  fa4c3dd78785abc11ccc992bc9c01e7a8c3120fe14b8a8dfd7cefa7014530814 \
                        size    9350308

set py_ver              3.14
set py_ver_nodot        [string map {. {}} ${py_ver}]
configure.python        ${prefix}/bin/python${py_ver}

installs_libs           no
license_noconflict      perl5 python${py_ver_nodot}
# 59037
conflicts_build         libmd

patchfiles-append       patch-src-portable_c.c.diff
patchfiles-append       patch-CMakeLists.txt.diff

depends_build-append    port:bison \
                        port:flex \
                        path:bin/perl:perl5 \
                        port:python${py_ver_nodot}

set libfmt_v            12
cmake.prefix_path-append \
                        ${prefix}/lib/libfmt${libfmt_v}/cmake

depends_lib-append      port:libfmt${libfmt_v} \
                        port:libiconv \
                        port:spdlog \
                        port:sqlite3

# DO NOT depend on graphviz by default, it creates dependency cycle for other ports.
# depends_run-append      path:bin/dot:graphviz

compiler.cxx_standard   2017
# error: no matching constructor for initialization of 'value_type'
# (aka 'pair<const std::__1::basic_string<char>, DotFilePatcher>')
# dotrunner.cpp: error: 'dirStr' in capture list does not name a variable
compiler.blacklist-append \
                        {clang < 1300}

compiler.thread_local_storage yes

# see #50342
configure.args-append   -DICONV_INCLUDE_DIR=${prefix}/include \
                        -DICONV_LIBRARY=${prefix}/lib/libiconv.dylib \
                        -DPython_ADDITIONAL_VERSIONS=${py_ver} \
                        -Duse_sys_fmt=ON \
                        -Duse_sys_spdlog=ON \
                        -Duse_sys_sqlite3=ON

# see #59552
if {${os.platform} eq "darwin" && ${os.major} < 13} {
    depends_build-append \
                        path:bin/git:git
    configure.args-append \
                        -DGIT_EXECUTABLE=${prefix}/bin/git
}

# cmake PortGroup sets arch flags
# duplicate archflags can cause problems
# see #50044
# see #48331
# see https://cmake.org/pipermail/cmake-developers/2015-September/thread.html#26586
configure.universal_cflags
configure.universal_cxxflags
configure.universal_objcflags
configure.universal_objcxxflags
configure.universal_ldflags
configure.cc_archflags
configure.cxx_archflags
configure.objc_archflags
configure.objcxx_archflags
configure.ld_archflags

post-extract {
    # Use our flex
    delete ${worksrcpath}/src/ce_lex.cpp
    delete ${worksrcpath}/src/code.cpp
    delete ${worksrcpath}/src/commentcnv.cpp
    delete ${worksrcpath}/src/commentscan.cpp
    delete ${worksrcpath}/src/config.cpp
    delete ${worksrcpath}/src/declinfo.cpp
    delete ${worksrcpath}/src/defargs.cpp
    delete ${worksrcpath}/src/doctokenizer.cpp
    delete ${worksrcpath}/src/fortrancode.cpp
    delete ${worksrcpath}/src/fortranscanner.cpp
    delete ${worksrcpath}/src/pre.cpp
    delete ${worksrcpath}/src/pycode.cpp
    delete ${worksrcpath}/src/pyscanner.cpp
    delete ${worksrcpath}/src/scanner.cpp
    delete ${worksrcpath}/src/tclscanner.cpp
    delete ${worksrcpath}/src/vhdlcode.cpp
    delete ${worksrcpath}/src/vhdlscanner.cpp

    # Use our bison
    delete ${worksrcpath}/src/ce_parse.cpp
    delete ${worksrcpath}/src/ce_parse.h
    delete ${worksrcpath}/src/vhdlparser.cpp
    delete ${worksrcpath}/src/vhdlparser.h
}

set cxx_stdlibflags {}
if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    set cxx_stdlibflags -stdlib=${configure.cxx_stdlib}
}

# build fails out of source :/
cmake.out_of_source     no

# https://trac.macports.org/ticket/65814 etc.
legacysupport.redirect_bins doxygen

test.run                yes

destroot.args           INSTALL=${prefix} \
                        DOCDIR=${prefix}/share/doc/doxygen \
                        MAN1DIR=share/man/man1

variant docs description "Include the doxygen HTML and PDF documentation" {
    depends_build-append \
                        path:bin/gs:ghostscript \
                        path:bin/dot:graphviz \
                        port:texlive \
                        port:texlive-latex-extra

    configure.args-append \
                        -Dbuild_doc=YES \
                        -DEPSTOPDF=${prefix}/bin/epstopdf

    build.target-append docs
    use_parallel_build  no
}

variant qt4 conflicts qt5 description "Include the GUI wizard based on Qt4" {
    # use the Qt4 PortGroup, which provides a bunch of variables
    # and defines for how Qt4 was installed
    PortGroup           qt4 1.0

    # tell configure to make the wizard app
    configure.args-append \
                        -Dbuild_wizard=YES \
                        -Dforce_qt4=YES
}

variant qt5 conflicts qt4 description "Include the GUI wizard based on Qt5" {
    # use the Qt5 PortGroup, which provides a bunch of variables
    # and defines for how Qt5 was installed
    PortGroup           qt5 1.0

    # tell configure to make the wizard app
    configure.args-append \
                        -Dbuild_wizard=ON \
                        -Dforce_qt=Qt5
}

# LLVM/Clang version to use for the clangparser variant.
set llvm_version 20

variant clangparser description "Use libclang for CLANG_ASSISTED_PARSING" {
    depends_lib-append port:clang-${llvm_version}
    # Tell doxygen to use libclang.
    # Tell its cmake where to find clang and llvm.
    # Tell cmake to embed the rpath for libclang.
    configure.args-append \
        -Duse_libclang=ON \
        -DCMAKE_PREFIX_PATH=${prefix}/libexec/llvm-${llvm_version} \
        -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON
}

livecheck.type          regex
livecheck.name          ${my_name}
livecheck.url           ${homepage}/download.html
livecheck.regex         {(\d+(?:\.\d+)*)\.src}
