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

github.setup                danmar cppcheck 2.21.0
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  506773381a0aa578c92fc90e5011b9ff43b1d6e4 \
                            sha256  f028ff75ca5372738f3737c8b3e8611426a6526b6aea2ef01301ab0f5902f044 \
                            size    4029561

set python_branch   3.14
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
# settings.cpp:84:11: error: exception specification of explicitly defaulted
# move constructor does not match the calculated one on macOS <10.15
compiler.blacklist-append   {clang < 1200}

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}

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.]+)}
