Skip to content

Commit 8998a47

Browse files
akihikodakianakryiko
authored andcommitted
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 18f6f9d commit 8998a47

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ SAN_CFLAGS ?=
2929
SAN_LDFLAGS ?= $(SAN_CFLAGS)
3030
RELEASE ?=
3131
OPT_FLAGS ?= $(if $(RELEASE),-O2,-O0)
32+
33+
LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libelf --cflags 2>/dev/null)
34+
LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
35+
3236
CFLAGS += -g $(OPT_FLAGS) -rdynamic \
3337
-Wall -Werror \
34-
$(GENFLAGS) $(SAN_CFLAGS) \
38+
$(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \
3539
-I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
3640
-I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT)
3741
LDFLAGS += $(SAN_LDFLAGS)
38-
LDLIBS += -lelf -lz -lrt -lpthread
42+
LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread
3943

4044
ifneq ($(LLVM),)
4145
# Silence some warnings when compiled with clang

0 commit comments

Comments
 (0)