1 include ../../scripts/Makefile.include
2 include ../../scripts/utilities.mak
5 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
6 srctree := $(patsubst %/,%,$(dir $(srctree)))
7 srctree := $(patsubst %/,%,$(dir $(srctree)))
16 BPF_DIR = $(srctree)/tools/lib/bpf/
24 LIBBPF = $(BPF_PATH)libbpf.a
26 BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
29 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
32 $(call QUIET_CLEAN, libbpf)
33 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
36 bash_compdir ?= /usr/share/bash-completion/completions
39 CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
40 CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
41 -I$(srctree)/kernel/bpf/ \
42 -I$(srctree)/tools/include \
43 -I$(srctree)/tools/include/uapi \
44 -I$(srctree)/tools/lib/bpf \
45 -I$(srctree)/tools/perf
46 CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
47 ifneq ($(EXTRA_CFLAGS),)
48 CFLAGS += $(EXTRA_CFLAGS)
50 ifneq ($(EXTRA_LDFLAGS),)
51 LDFLAGS += $(EXTRA_LDFLAGS)
54 LIBS = -lelf $(LIBBPF)
59 FEATURE_USER = .bpftool
60 FEATURE_TESTS = libbfd disassembler-four-args reallocarray
61 FEATURE_DISPLAY = libbfd disassembler-four-args
64 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
66 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
71 ifeq ($(check_feat),1)
72 ifeq ($(FEATURES_DUMP),)
73 include $(srctree)/tools/build/Makefile.feature
75 include $(FEATURES_DUMP)
79 ifeq ($(feature-disassembler-four-args), 1)
80 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
83 ifeq ($(feature-reallocarray), 0)
84 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
87 include $(wildcard $(OUTPUT)*.d)
91 BFD_SRCS = jit_disasm.c
93 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
95 ifeq ($(feature-libbfd),1)
96 LIBS += -lbfd -ldl -lopcodes
97 else ifeq ($(feature-libbfd-liberty),1)
98 LIBS += -lbfd -ldl -lopcodes -liberty
99 else ifeq ($(feature-libbfd-liberty-z),1)
100 LIBS += -lbfd -ldl -lopcodes -liberty -lz
103 ifneq ($(filter -lbfd,$(LIBS)),)
104 CFLAGS += -DHAVE_LIBBFD_SUPPORT
108 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
110 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
111 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
113 $(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
114 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
117 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
119 clean: $(LIBBPF)-clean
120 $(call QUIET_CLEAN, bpftool)
121 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
122 $(call QUIET_CLEAN, core-gen)
123 $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
125 install: $(OUTPUT)bpftool
126 $(call QUIET_INSTALL, bpftool)
127 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
128 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
129 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
130 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
133 $(call QUIET_UNINST, bpftool)
134 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
135 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
138 $(call descend,Documentation)
141 $(call descend,Documentation,clean)
144 $(call descend,Documentation,install)
147 $(call descend,Documentation,uninstall)
151 .PHONY: all FORCE clean install uninstall
152 .PHONY: doc doc-clean doc-install doc-uninstall