Introduce the BPFTOOL_STATIC make variable, to let users build bpftool with static libraries (when set to 1). This increases the portability of the binary, especially for testing. Signed-off-by: Roberto Sassu <roberto.sassu@xxxxxxxxxx> --- tools/bpf/bpftool/Makefile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index 4b09a5c3b9f1..4628df456245 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile @@ -98,6 +98,13 @@ FEATURE_TESTS = libbfd libbfd-liberty libbfd-liberty-z \ FEATURE_DISPLAY = libbfd libbfd-liberty libbfd-liberty-z \ disassembler-four-args libcap clang-bpf-co-re +ifeq ($(BPFTOOL_STATIC),1) +FEATURE_CHECK_LDFLAGS-libbfd = -static +FEATURE_CHECK_LDFLAGS-libbfd-liberty = -static +FEATURE_CHECK_LDFLAGS-libbfd-liberty-z = -static +FEATURE_CHECK_LDFLAGS-libcap = -static +endif + check_feat := 1 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall ifdef MAKECMDGOALS @@ -122,8 +129,12 @@ LIBS = $(LIBBPF) -lelf -lz LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz ifeq ($(feature-libcap), 1) CFLAGS += -DUSE_LIBCAP +ifeq ($(BPFTOOL_STATIC),1) +LIBS += -l:libcap.a +else LIBS += -lcap endif +endif include $(wildcard $(OUTPUT)*.d) @@ -133,6 +144,16 @@ BFD_SRCS = jit_disasm.c SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) +ifeq ($(BPFTOOL_STATIC),1) +ifeq ($(feature-libbfd),1) + LIBS += -l:libbfd.a -ldl -l:libopcodes.a +else ifeq ($(feature-libbfd-liberty),1) + LIBS += -l:libbfd.a -ldl -l:libopcodes.a -l:libiberty.a +else ifeq ($(feature-libbfd-liberty-z),1) + LIBS += -l:libbfd.a -ldl -l:libopcodes.a -l:libiberty.a -l:libz.a + LIBS := $(filter-out -lz, $(LIBS)) +endif +else ifeq ($(feature-libbfd),1) LIBS += -lbfd -ldl -lopcodes else ifeq ($(feature-libbfd-liberty),1) @@ -140,6 +161,7 @@ else ifeq ($(feature-libbfd-liberty),1) else ifeq ($(feature-libbfd-liberty-z),1) LIBS += -lbfd -ldl -lopcodes -liberty -lz endif +endif ifneq ($(filter -lbfd,$(LIBS)),) CFLAGS += -DHAVE_LIBBFD_SUPPORT -- 2.25.1