]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tools/checkconfig: strip C comments before macro extraction
authorKarel Zak <kzak@redhat.com>
Thu, 26 Feb 2026 10:27:48 +0000 (11:27 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 26 Feb 2026 10:51:38 +0000 (11:51 +0100)
Strip C/C++ comments (// line comments, single-line /* */ and
multi-line /* */ blocks) before extracting HAVE_ and ENABLE_ macros.
This avoids false positives from macros mentioned in comments, e.g.
"when HAVE_PIDFD_* ..." in include/pidfd-utils.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
tools/checkconfig.sh

index 7a17cd69e94a4c1bc35a8d9e3bdb0057ca2bd194..94c159ac9f79849cb4e5150e583a2c25d6616308 100755 (executable)
@@ -47,9 +47,15 @@ while [ "$#" -ne 0 ]; do
        # ENABLE_ and HAVE_ macros shouldn't be used for any other purpose than
        # for config/build options.
        #
-       DEFINES=$(sed -n -e 's/.*[ \t(]\+\(HAVE_[[:alnum:]]\+[^ \t);]*\).*/\1/p' \
-                        -e 's/.*[ \t(]\+\(ENABLE_[[:alnum:]]\+[^ \t);]*\).*/\1/p' \
-                         $srcfile | sort -u)
+       # Strip C/C++ comments to avoid false positives from
+       # macros mentioned in comments (e.g. "when HAVE_FOO is ...")
+       DEFINES=$(sed -e 's://.*::' \
+                     -e 's:/\*.*\*/::g' \
+                     $srcfile | \
+                 sed -e '/\/\*/,/\*\//d' | \
+                 sed -n -e 's/.*[ \t(]\+\(HAVE_[[:alnum:]]\+[^ \t);]*\).*/\1/p' \
+                        -e 's/.*[ \t(]\+\(ENABLE_[[:alnum:]]\+[^ \t);]*\).*/\1/p' | \
+                 sort -u)
        [ -z "$DEFINES" ] && continue
 
        for d in $DEFINES; do