Skip to content

Commit

Permalink
selftests/bpf: Use pkg-config for libelf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Akihiko Odaki authored and Andrii Nakryiko committed Nov 29, 2023
1 parent 18f6f9d commit 8998a47
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tools/testing/selftests/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8998a47

Please sign in to comment.