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

github.setup                danmar cppcheck 2.17.1
revision                    0

categories                  devel
license                     GPL-3
maintainers                 {khindenburg @kurthindenburg} openmaintainer

description                 Static analysis of C and C++ code.

long_description            Cppcheck is an analysis tool for C and C++ code. Unlike \
                            compilers and many other analysis tools, we do not detect \
                            syntax errors. Cppcheck only detects the types of bugs that \
                            the compilers normally fail to detect. The goal is no false \
                            positives.

github.tarball_from         archive

checksums                   rmd160  1b761190f2ceb30397f4330d03a6608c9150669e \
                            sha256  bfd681868248ec03855ca7c2aea7bcb1f39b8b18860d76aec805a92a967b966c \
                            size    3872633

set python_branch   3.12
set python_version  [string map {"." ""} ${python_branch}]
set python_bin      ${prefix}/bin/python${python_branch}

depends_build-append        port:docbook-xsl-nons \
                            port:docbook-xml-4.5 \
                            port:libxslt

depends_lib-append          port:pcre \
                            port:python${python_version} \
                            port:py${python_version}-pygments

# Jan 2023 - master base/github PG default to yes which errors
if {[exists extract.rename]} { extract.rename no }

post-patch {
    reinplace -W ${worksrcpath} "s|#!/usr/bin/env python3|#!${python_bin}|" htmlreport/cppcheck-htmlreport
}

compiler.cxx_standard       2011
compiler.thread_local_storage yes
# build/valueflow.cpp:10973:124: error: call
# to deleted function 'toString' on macOS <10.12
compiler.blacklist-append   {clang < 900}

use_configure               no

variant universal {}

set sharedir                ${prefix}/share/${name}

build.target                all man
build.args                  CXX="${configure.cxx} [get_canonical_archflags cxx] ${configure.cxxflags}" \
                            DB2MAN=${prefix}/share/xsl/docbook-xsl-nons/manpages/docbook.xsl \
                            FILESDIR=${sharedir} \
                            HAVE_RULES=yes \
                            MATCHCOMPILER=yes \
                            PREFIX=${prefix} \
                            PYTHON_INTERPRETER=${python_bin}

# https://trac.macports.org/ticket/66418
platform darwin 8 {
    depends_build-append    port:gmake-apple
    build.cmd               gmake-apple
}

test.run                    yes
test.target                 test
test.args                   {*}${build.args}

destroot.args               {*}${build.args}

post-destroot {
    xinstall -m 0644 ${worksrcpath}/cppcheck.1 ${destroot}${prefix}/share/man/man1
    xinstall -d ${destroot}${sharedir}

    foreach f [glob -tails -directory ${worksrcpath}/cfg *] {
        copy ${worksrcpath}/cfg/${f} ${destroot}${sharedir}/${f}.dist
    }
}

post-activate {
    foreach f [glob -directory ${sharedir} *.dist] {
        if {![file exists [file rootname ${f}]]} {
            copy ${f} [file rootname ${f}]
        }
    }
}

notes "
If you've updated cppcheck from a previous version,\
you may want to replace the included config files:

sudo find ${sharedir} -type f -name \"*.dist\" -exec bash -c 'f=\"\{\}\"; cp \"\$f\" \"\$\{f%.dist\}\"' \\;
"

github.livecheck.regex  {([0-9.]+)}