Re: [PATCH] tools/libbpf: add WERROR option

From: Daniel Borkmann
Date: Mon Jul 07 2025 - 09:18:51 EST


On 7/5/25 12:43 PM, Sam James wrote:
Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.

This mirrors what tools/perf and other directories in tools do to handle
-Werror rather than adding it unconditionally.

Could you also add to the commit desc why you need it? Are there particular
warnings you specifically need to suppress when building under gentoo?

Signed-off-by: Sam James <sam@xxxxxxxxxx>
---
tools/lib/bpf/Makefile | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 168140f8e646..9563d37265da 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -77,10 +77,15 @@ else
CFLAGS := -g -O2
endif
+# Treat warnings as errors unless directed not to
+ifneq ($(WERROR),0)
+ CFLAGS += -Werror
+endif

Should we also add sth similar to tools/bpf/bpftool/Makefile and by default
enforce with -Werror with the option to disable?

# Append required CFLAGS
override CFLAGS += -std=gnu89
override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
-override CFLAGS += -Werror -Wall
+override CFLAGS += -Wall
override CFLAGS += $(INCLUDES)
override CFLAGS += -fvisibility=hidden
override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64