summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/Makefile
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki@daynix.com>2023-11-25 11:42:52 +0300
committerAndrii Nakryiko <andrii@kernel.org>2023-11-29 09:15:29 +0300
commit8998a479fd96b0b209dcb2feb468eba7eddb4ddb (patch)
tree0ce3896096bf17db577b084f544e8aa5b69335f1 /tools/testing/selftests/bpf/Makefile
parent18f6f9de98d1d0f7040e6e6c39fce8939f55520f (diff)
downloadlinux-8998a479fd96b0b209dcb2feb468eba7eddb4ddb.tar.xz
selftests/bpf: Use pkg-config for libelf
When linking statically, libraries may require other dependencies to be included to ld flags. In particular, libelf may require libzstd. Use pkg-config to determine such dependencies. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20231125084253.85025-4-akihiko.odaki@daynix.com
Diffstat (limited to 'tools/testing/selftests/bpf/Makefile')
-rw-r--r--tools/testing/selftests/bpf/Makefile8
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 94825ef813d5..617ae55c3bb5 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -29,13 +29,17 @@ SAN_CFLAGS ?=
SAN_LDFLAGS ?= $(SAN_CFLAGS)
RELEASE ?=
OPT_FLAGS ?= $(if $(RELEASE),-O2,-O0)
+
+LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libelf --cflags 2>/dev/null)
+LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
+
CFLAGS += -g $(OPT_FLAGS) -rdynamic \
-Wall -Werror \
- $(GENFLAGS) $(SAN_CFLAGS) \
+ $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \
-I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
-I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT)
LDFLAGS += $(SAN_LDFLAGS)
-LDLIBS += -lelf -lz -lrt -lpthread
+LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread
ifneq ($(LLVM),)
# Silence some warnings when compiled with clang