1 # SPDX-License-Identifier: GPL-2.0-only
2 include ../../scripts/Makefile.include
3 include ../../scripts/utilities.mak
6 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7 srctree := $(patsubst %/,%,$(dir $(srctree)))
8 srctree := $(patsubst %/,%,$(dir $(srctree)))
17 BPF_DIR = $(srctree)/tools/lib/bpf/
25 LIBBPF = $(BPF_PATH)libbpf.a
27 BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
30 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
33 $(call QUIET_CLEAN, libbpf)
34 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
37 bash_compdir ?= /usr/share/bash-completion/completions
40 CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
41 CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
42 -I$(srctree)/kernel/bpf/ \
43 -I$(srctree)/tools/include \
44 -I$(srctree)/tools/include/uapi \
45 -I$(srctree)/tools/lib/bpf \
46 -I$(srctree)/tools/perf
47 CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
48 ifneq ($(EXTRA_CFLAGS),)
49 CFLAGS += $(EXTRA_CFLAGS)
51 ifneq ($(EXTRA_LDFLAGS),)
52 LDFLAGS += $(EXTRA_LDFLAGS)
55 LIBS = -lelf $(LIBBPF)
60 FEATURE_USER = .bpftool
61 FEATURE_TESTS = libbfd disassembler-four-args reallocarray
62 FEATURE_DISPLAY = libbfd disassembler-four-args
65 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
67 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
72 ifeq ($(check_feat),1)
73 ifeq ($(FEATURES_DUMP),)
74 include $(srctree)/tools/build/Makefile.feature
76 include $(FEATURES_DUMP)
80 ifeq ($(feature-disassembler-four-args), 1)
81 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
84 ifeq ($(feature-reallocarray), 0)
85 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
88 include $(wildcard $(OUTPUT)*.d)
92 BFD_SRCS = jit_disasm.c
94 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
96 ifeq ($(feature-libbfd),1)
97 LIBS += -lbfd -ldl -lopcodes
98 else ifeq ($(feature-libbfd-liberty),1)
99 LIBS += -lbfd -ldl -lopcodes -liberty
100 else ifeq ($(feature-libbfd-liberty-z),1)
101 LIBS += -lbfd -ldl -lopcodes -liberty -lz
104 ifneq ($(filter -lbfd,$(LIBS)),)
105 CFLAGS += -DHAVE_LIBBFD_SUPPORT
109 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
111 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
112 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
114 $(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
115 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
118 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
120 clean: $(LIBBPF)-clean
121 $(call QUIET_CLEAN, bpftool)
122 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
123 $(call QUIET_CLEAN, core-gen)
124 $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
126 install: $(OUTPUT)bpftool
127 $(call QUIET_INSTALL, bpftool)
128 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
129 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
130 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
131 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
134 $(call QUIET_UNINST, bpftool)
135 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
136 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
139 $(call descend,Documentation)
142 $(call descend,Documentation,clean)
145 $(call descend,Documentation,install)
148 $(call descend,Documentation,uninstall)
152 .PHONY: all FORCE clean install uninstall
153 .PHONY: doc doc-clean doc-install doc-uninstall