[PATCH 3/8] bpftool: Conditionally add -Wformat-signedness flag

From: Leo Yan
Date: Thu Sep 25 2025 - 06:28:07 EST


clang-18.1.3 on Ubuntu 24.04.2 reports warning:

warning: unknown warning option '-Wformat-signedness' [-Wunknown-warning-option]

Conditionally add the option only when it is supported by compiler.

Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
---
tools/bpf/bpftool/Makefile | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 9e9a5f006cd2aabe1e89bd83e394455c0d4473e0..948a0cc98b39d3f9afa0de73643eab04e8798ff5 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -64,11 +64,21 @@ $(LIBBPF_BOOTSTRAP)-clean: FORCE | $(LIBBPF_BOOTSTRAP_OUTPUT)
prefix ?= /usr/local
bash_compdir ?= /usr/share/bash-completion/completions

+try-run = $(shell set -e; \
+ if ($(1)) >/dev/null 2>&1; \
+ then echo "$(2)"; \
+ else echo "$(3)"; \
+ fi)
+
+__cc-option = $(call try-run,\
+ $(1) -Werror $(2) -c -x c /dev/null -o /dev/null,$(2),)
+cc-option = $(call __cc-option, $(CC),$(1))
+
CFLAGS += -O2
CFLAGS += -W
CFLAGS += -Wall
CFLAGS += -Wextra
-CFLAGS += -Wformat-signedness
+CFLAGS += $(call cc-option,-Wformat-signedness)
CFLAGS += -Wno-unused-parameter
CFLAGS += -Wno-missing-field-initializers
CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS))

--
2.34.1