Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to
the compiler.

urandom_read is built with clang.  Introduce URANDOM_READ_CFLAGS to copy
the compiler flags without appending EXTRA_CFLAGS, which may contain
incompatible options with clang.

Since lib.mk appends options to CFLAGS, ensure that CFLAGS is inherited
after including lib.mk.

Signed-off-by: Leo Yan <[email protected]>
---
 tools/testing/selftests/bpf/Makefile | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile 
b/tools/testing/selftests/bpf/Makefile
index 
f75c4f52c02842541f385bc8cbaeab32d8195ed3..50bcf4c386ba52e6cceef4c15f999d9eec6efd6e
 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -158,6 +158,12 @@ endef
 
 include ../lib.mk
 
+# urandom_read is built with clang. Copy $(CFLAGS) before EXTRA_CFLAGS are
+# appended so that it does not inherit potentially incompatible options.
+URANDOM_READ_CFLAGS := $(CFLAGS)
+
+CFLAGS += $(EXTRA_CFLAGS)
+
 NON_CHECK_FEAT_TARGETS := clean docs-clean
 CHECK_FEAT := $(filter-out $(NON_CHECK_FEAT_TARGETS),$(or $(MAKECMDGOALS), 
"none"))
 ifneq ($(CHECK_FEAT),)
@@ -255,7 +261,7 @@ endif
 $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c 
liburandom_read.map
        $(call msg,LIB,,$@)
        $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \
-                    $(filter-out -static,$(CFLAGS) $(LDFLAGS)) \
+                    $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) \
                     $(filter %.c,$^) $(filter-out -static,$(LDLIBS)) \
                     -Wno-unused-command-line-argument \
                     -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \
@@ -265,7 +271,7 @@ $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c 
urandom_read_lib2.c liburandom
 $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c 
$(OUTPUT)/liburandom_read.so
        $(call msg,BINARY,,$@)
        $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \
-                    $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter 
%.c,$^) \
+                    $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) 
$(filter %.c,$^) \
                     -Wno-unused-command-line-argument \
                     -lurandom_read $(filter-out -static,$(LDLIBS)) -L$(OUTPUT) 
\
                     -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \

-- 
2.34.1


Reply via email to