1 # SPDX-License-Identifier: (GPL-2.0-only OR BS !! 1 # SPDX-License-Identifier: GPL-2.0-only 2 include ../../scripts/Makefile.include 2 include ../../scripts/Makefile.include >> 3 include ../../scripts/utilities.mak 3 4 4 ifeq ($(srctree),) 5 ifeq ($(srctree),) 5 srctree := $(patsubst %/,%,$(dir $(CURDIR))) 6 srctree := $(patsubst %/,%,$(dir $(CURDIR))) 6 srctree := $(patsubst %/,%,$(dir $(srctree))) 7 srctree := $(patsubst %/,%,$(dir $(srctree))) 7 srctree := $(patsubst %/,%,$(dir $(srctree))) 8 srctree := $(patsubst %/,%,$(dir $(srctree))) 8 endif 9 endif 9 10 10 ifeq ($(V),1) 11 ifeq ($(V),1) 11 Q = 12 Q = 12 else 13 else 13 Q = @ 14 Q = @ 14 endif 15 endif 15 16 16 BPF_DIR = $(srctree)/tools/lib/bpf !! 17 BPF_DIR = $(srctree)/tools/lib/bpf/ 17 18 18 ifneq ($(OUTPUT),) 19 ifneq ($(OUTPUT),) 19 _OUTPUT := $(OUTPUT) !! 20 LIBBPF_OUTPUT = $(OUTPUT)/libbpf/ >> 21 LIBBPF_PATH = $(LIBBPF_OUTPUT) 20 else 22 else 21 _OUTPUT := $(CURDIR)/ !! 23 LIBBPF_PATH = $(BPF_DIR) 22 endif 24 endif 23 BOOTSTRAP_OUTPUT := $(_OUTPUT)bootstrap/ << 24 25 25 LIBBPF_OUTPUT := $(_OUTPUT)libbpf/ !! 26 LIBBPF = $(LIBBPF_PATH)libbpf.a 26 LIBBPF_DESTDIR := $(LIBBPF_OUTPUT) << 27 LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)include << 28 LIBBPF_HDRS_DIR := $(LIBBPF_INCLUDE)/bpf << 29 LIBBPF := $(LIBBPF_OUTPUT)libbpf.a << 30 << 31 LIBBPF_BOOTSTRAP_OUTPUT := $(BOOTSTRAP_OUTPUT) << 32 LIBBPF_BOOTSTRAP_DESTDIR := $(LIBBPF_BOOTSTRAP << 33 LIBBPF_BOOTSTRAP_INCLUDE := $(LIBBPF_BOOTSTRAP << 34 LIBBPF_BOOTSTRAP_HDRS_DIR := $(LIBBPF_BOOTSTRA << 35 LIBBPF_BOOTSTRAP := $(LIBBPF_BOOTSTRAP_OUTPUT) << 36 << 37 # We need to copy hashmap.h, nlattr.h, relo_co << 38 # which are not otherwise exported by libbpf, << 39 LIBBPF_INTERNAL_HDRS := $(addprefix $(LIBBPF_H << 40 LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix << 41 << 42 $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_ << 43 $(QUIET_MKDIR)mkdir -p $@ << 44 << 45 $(LIBBPF): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_ << 46 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIB << 47 DESTDIR=$(LIBBPF_DESTDIR:/=) p << 48 << 49 $(LIBBPF_INTERNAL_HDRS): $(LIBBPF_HDRS_DIR)/%. << 50 $(call QUIET_INSTALL, $@) << 51 $(Q)install -m 644 -t $(LIBBPF_HDRS_DI << 52 << 53 $(LIBBPF_BOOTSTRAP): $(wildcard $(BPF_DIR)/*.[ << 54 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIB << 55 DESTDIR=$(LIBBPF_BOOTSTRAP_DES << 56 ARCH= CROSS_COMPILE= CC="$(HOS << 57 << 58 $(LIBBPF_BOOTSTRAP_INTERNAL_HDRS): $(LIBBPF_BO << 59 $(call QUIET_INSTALL, $@) << 60 $(Q)install -m 644 -t $(LIBBPF_BOOTSTR << 61 27 62 $(LIBBPF)-clean: FORCE | $(LIBBPF_OUTPUT) !! 28 BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion) >> 29 >> 30 $(LIBBPF): FORCE >> 31 $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT)) >> 32 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a >> 33 >> 34 $(LIBBPF)-clean: 63 $(call QUIET_CLEAN, libbpf) 35 $(call QUIET_CLEAN, libbpf) 64 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIB 36 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null 65 37 66 $(LIBBPF_BOOTSTRAP)-clean: FORCE | $(LIBBPF_BO << 67 $(call QUIET_CLEAN, libbpf-bootstrap) << 68 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIB << 69 << 70 prefix ?= /usr/local 38 prefix ?= /usr/local 71 bash_compdir ?= /usr/share/bash-completion/com 39 bash_compdir ?= /usr/share/bash-completion/completions 72 40 73 CFLAGS += -O2 41 CFLAGS += -O2 74 CFLAGS += -W -Wall -Wextra -Wno-unused-paramet 42 CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers 75 CFLAGS += $(filter-out -Wswitch-enum -Wnested- !! 43 CFLAGS += $(filter-out -Wswitch-enum,$(EXTRA_WARNINGS)) 76 CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_H 44 CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \ 77 -I$(or $(OUTPUT),.) \ << 78 -I$(LIBBPF_INCLUDE) \ << 79 -I$(srctree)/kernel/bpf/ \ 45 -I$(srctree)/kernel/bpf/ \ 80 -I$(srctree)/tools/include \ 46 -I$(srctree)/tools/include \ 81 -I$(srctree)/tools/include/uapi !! 47 -I$(srctree)/tools/include/uapi \ 82 ifneq ($(BPFTOOL_VERSION),) !! 48 -I$(srctree)/tools/lib \ >> 49 -I$(srctree)/tools/perf 83 CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSIO 50 CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' 84 endif << 85 ifneq ($(EXTRA_CFLAGS),) 51 ifneq ($(EXTRA_CFLAGS),) 86 CFLAGS += $(EXTRA_CFLAGS) 52 CFLAGS += $(EXTRA_CFLAGS) 87 endif 53 endif 88 ifneq ($(EXTRA_LDFLAGS),) 54 ifneq ($(EXTRA_LDFLAGS),) 89 LDFLAGS += $(EXTRA_LDFLAGS) 55 LDFLAGS += $(EXTRA_LDFLAGS) 90 endif 56 endif 91 57 92 HOST_CFLAGS := $(subst -I$(LIBBPF_INCLUDE),-I$ << 93 $(subst $(CLANG_CROSS_FLAGS),, << 94 HOST_LDFLAGS := $(LDFLAGS) << 95 << 96 INSTALL ?= install 58 INSTALL ?= install 97 RM ?= rm -f 59 RM ?= rm -f >> 60 CLANG ?= clang 98 61 99 FEATURE_USER = .bpftool 62 FEATURE_USER = .bpftool 100 !! 63 FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib libcap \ 101 FEATURE_TESTS := clang-bpf-co-re !! 64 clang-bpf-global-var 102 FEATURE_TESTS += llvm !! 65 FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \ 103 FEATURE_TESTS += libcap !! 66 clang-bpf-global-var 104 FEATURE_TESTS += libbfd << 105 FEATURE_TESTS += libbfd-liberty << 106 FEATURE_TESTS += libbfd-liberty-z << 107 FEATURE_TESTS += disassembler-four-args << 108 FEATURE_TESTS += disassembler-init-styled << 109 << 110 FEATURE_DISPLAY := clang-bpf-co-re << 111 FEATURE_DISPLAY += llvm << 112 FEATURE_DISPLAY += libcap << 113 FEATURE_DISPLAY += libbfd << 114 FEATURE_DISPLAY += libbfd-liberty << 115 FEATURE_DISPLAY += libbfd-liberty-z << 116 67 117 check_feat := 1 68 check_feat := 1 118 NON_CHECK_FEAT_TARGETS := clean uninstall doc 69 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall 119 ifdef MAKECMDGOALS 70 ifdef MAKECMDGOALS 120 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$ 71 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) 121 check_feat := 0 72 check_feat := 0 122 endif 73 endif 123 endif 74 endif 124 75 125 ifeq ($(check_feat),1) 76 ifeq ($(check_feat),1) 126 ifeq ($(FEATURES_DUMP),) 77 ifeq ($(FEATURES_DUMP),) 127 include $(srctree)/tools/build/Makefile.featur 78 include $(srctree)/tools/build/Makefile.feature 128 else 79 else 129 include $(FEATURES_DUMP) 80 include $(FEATURES_DUMP) 130 endif 81 endif 131 endif 82 endif 132 83 >> 84 ifeq ($(feature-disassembler-four-args), 1) >> 85 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE >> 86 endif >> 87 >> 88 ifeq ($(feature-reallocarray), 0) >> 89 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY >> 90 endif >> 91 133 LIBS = $(LIBBPF) -lelf -lz 92 LIBS = $(LIBBPF) -lelf -lz 134 LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz << 135 ifeq ($(feature-libcap), 1) 93 ifeq ($(feature-libcap), 1) 136 CFLAGS += -DUSE_LIBCAP 94 CFLAGS += -DUSE_LIBCAP 137 LIBS += -lcap 95 LIBS += -lcap 138 endif 96 endif 139 97 140 include $(wildcard $(OUTPUT)*.d) 98 include $(wildcard $(OUTPUT)*.d) 141 99 142 all: $(OUTPUT)bpftool 100 all: $(OUTPUT)bpftool 143 101 144 SRCS := $(wildcard *.c) !! 102 BFD_SRCS = jit_disasm.c 145 103 146 ifeq ($(feature-llvm),1) !! 104 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) 147 # If LLVM is available, use it for JIT disas << 148 CFLAGS += -DHAVE_LLVM_SUPPORT << 149 LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler << 150 CFLAGS += $(shell $(LLVM_CONFIG) --cflags) << 151 LIBS += $(shell $(LLVM_CONFIG) --libs $(L << 152 ifeq ($(shell $(LLVM_CONFIG) --shared-mode), << 153 LIBS += $(shell $(LLVM_CONFIG) --system-li << 154 LIBS += -lstdc++ << 155 endif << 156 LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags) << 157 else << 158 # Fall back on libbfd << 159 ifeq ($(feature-libbfd),1) << 160 LIBS += -lbfd -ldl -lopcodes << 161 else ifeq ($(feature-libbfd-liberty),1) << 162 LIBS += -lbfd -ldl -lopcodes -liberty << 163 else ifeq ($(feature-libbfd-liberty-z),1) << 164 LIBS += -lbfd -ldl -lopcodes -liberty -lz << 165 endif << 166 << 167 # If one of the above feature combinations i << 168 ifneq ($(filter -lbfd,$(LIBS)),) << 169 CFLAGS += -DHAVE_LIBBFD_SUPPORT << 170 << 171 # Libbfd interface changed over time, figu << 172 ifeq ($(feature-disassembler-four-args), 1 << 173 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE << 174 endif << 175 ifeq ($(feature-disassembler-init-styled), << 176 CFLAGS += -DDISASM_INIT_STYLED << 177 endif << 178 endif << 179 endif << 180 ifeq ($(filter -DHAVE_LLVM_SUPPORT -DHAVE_LIBB << 181 # No support for JIT disassembly << 182 SRCS := $(filter-out jit_disasm.c,$(SRCS)) << 183 endif << 184 105 185 BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT)bpftoo !! 106 ifeq ($(feature-libbfd),1) >> 107 LIBS += -lbfd -ldl -lopcodes >> 108 else ifeq ($(feature-libbfd-liberty),1) >> 109 LIBS += -lbfd -ldl -lopcodes -liberty >> 110 else ifeq ($(feature-libbfd-liberty-z),1) >> 111 LIBS += -lbfd -ldl -lopcodes -liberty -lz >> 112 endif 186 113 187 BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPU !! 114 ifneq ($(filter -lbfd,$(LIBS)),) 188 $(BOOTSTRAP_OBJS): $(LIBBPF_BOOTSTRAP) !! 115 CFLAGS += -DHAVE_LIBBFD_SUPPORT >> 116 SRCS += $(BFD_SRCS) >> 117 endif 189 118 190 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $( 119 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o 191 $(OBJS): $(LIBBPF) $(LIBBPF_INTERNAL_HDRS) !! 120 _OBJS = $(filter-out $(OUTPUT)prog.o,$(OBJS)) $(OUTPUT)_prog.o 192 << 193 VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) << 194 $(if $(KBUILD_OUTPUT),$(K << 195 ../../../vmlinux << 196 /sys/kernel/btf/vmlinux << 197 /boot/vmlinux-$(shell una << 198 VMLINUX_BTF ?= $(abspath $(firstword $(wildcar << 199 121 200 bootstrap: $(BPFTOOL_BOOTSTRAP) !! 122 ifeq ($(feature-clang-bpf-global-var),1) 201 !! 123 __OBJS = $(OBJS) 202 ifneq ($(VMLINUX_BTF)$(VMLINUX_H),) << 203 ifeq ($(feature-clang-bpf-co-re),1) << 204 << 205 BUILD_BPF_SKELS := 1 << 206 << 207 ifeq ($(VMLINUX_H),) << 208 $(OUTPUT)vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL_B << 209 $(QUIET_GEN)$(BPFTOOL_BOOTSTRAP) btf d << 210 else 124 else 211 $(OUTPUT)vmlinux.h: $(VMLINUX_H) !! 125 __OBJS = $(_OBJS) 212 $(Q)cp "$(VMLINUX_H)" $@ << 213 endif 126 endif 214 127 215 $(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vm !! 128 $(OUTPUT)_prog.o: prog.c >> 129 $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $< >> 130 >> 131 $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) >> 132 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS) >> 133 >> 134 skeleton/profiler.bpf.o: skeleton/profiler.bpf.c $(LIBBPF) 216 $(QUIET_CLANG)$(CLANG) \ 135 $(QUIET_CLANG)$(CLANG) \ 217 -I$(or $(OUTPUT),.) \ << 218 -I$(srctree)/tools/include/uap 136 -I$(srctree)/tools/include/uapi/ \ 219 -I$(LIBBPF_BOOTSTRAP_INCLUDE) !! 137 -I$(LIBBPF_PATH) -I$(srctree)/tools/lib \ 220 -g -O2 -Wall -fno-stack-protec !! 138 -g -O2 -target bpf -c $< -o $@ 221 --target=bpf -c $< -o $@ << 222 $(Q)$(LLVM_STRIP) -g $@ << 223 << 224 $(OUTPUT)%.skel.h: $(OUTPUT)%.bpf.o $(BPFTOOL_ << 225 $(QUIET_GEN)$(BPFTOOL_BOOTSTRAP) gen s << 226 139 227 $(OUTPUT)prog.o: $(OUTPUT)profiler.skel.h !! 140 profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o >> 141 $(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@ 228 142 229 $(OUTPUT)pids.o: $(OUTPUT)pid_iter.skel.h !! 143 $(OUTPUT)prog.o: prog.c profiler.skel.h 230 !! 144 $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $< 231 endif << 232 endif << 233 << 234 CFLAGS += $(if $(BUILD_BPF_SKELS),,-DBPFTOOL_W << 235 145 236 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disas 146 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c 237 $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD $< !! 147 $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $< 238 148 239 $(BPFTOOL_BOOTSTRAP): $(BOOTSTRAP_OBJS) $(LIBB !! 149 $(OUTPUT)feature.o: | zdep 240 $(QUIET_LINK)$(HOSTCC) $(HOST_CFLAGS) << 241 150 242 $(OUTPUT)bpftool: $(OBJS) $(LIBBPF) !! 151 $(OUTPUT)bpftool: $(__OBJS) $(LIBBPF) 243 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS !! 152 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(__OBJS) $(LIBS) 244 << 245 $(BOOTSTRAP_OUTPUT)%.o: %.c $(LIBBPF_BOOTSTRAP << 246 $(QUIET_CC)$(HOSTCC) $(HOST_CFLAGS) -c << 247 153 248 $(OUTPUT)%.o: %.c 154 $(OUTPUT)%.o: %.c 249 $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD $< !! 155 $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $< 250 << 251 feature-detect-clean: << 252 $(call QUIET_CLEAN, feature-detect) << 253 $(Q)$(MAKE) -C $(srctree)/tools/build/ << 254 156 255 clean: $(LIBBPF)-clean $(LIBBPF_BOOTSTRAP)-cle !! 157 clean: $(LIBBPF)-clean 256 $(call QUIET_CLEAN, bpftool) 158 $(call QUIET_CLEAN, bpftool) 257 $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT 159 $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d 258 $(Q)$(RM) -- $(OUTPUT)*.skel.h $(OUTPU !! 160 $(Q)$(RM) -- $(OUTPUT)_bpftool profiler.skel.h skeleton/profiler.bpf.o 259 $(Q)$(RM) -r -- $(LIBBPF_OUTPUT) $(BOO !! 161 $(Q)$(RM) -r -- $(OUTPUT)libbpf/ 260 $(call QUIET_CLEAN, core-gen) 162 $(call QUIET_CLEAN, core-gen) 261 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf 163 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool 262 $(Q)$(RM) -r -- $(OUTPUT)feature/ 164 $(Q)$(RM) -r -- $(OUTPUT)feature/ 263 165 264 install-bin: $(OUTPUT)bpftool !! 166 install: $(OUTPUT)bpftool 265 $(call QUIET_INSTALL, bpftool) 167 $(call QUIET_INSTALL, bpftool) 266 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$( 168 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin 267 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DEST 169 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool 268 << 269 install: install-bin << 270 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$( 170 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir) 271 $(Q)$(INSTALL) -m 0644 bash-completion 171 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir) 272 172 273 uninstall: 173 uninstall: 274 $(call QUIET_UNINST, bpftool) 174 $(call QUIET_UNINST, bpftool) 275 $(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/ 175 $(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/bpftool 276 $(Q)$(RM) -- $(DESTDIR)$(bash_compdir) 176 $(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool 277 177 278 doc: 178 doc: 279 $(call descend,Documentation) 179 $(call descend,Documentation) 280 180 281 doc-clean: 181 doc-clean: 282 $(call descend,Documentation,clean) 182 $(call descend,Documentation,clean) 283 183 284 doc-install: 184 doc-install: 285 $(call descend,Documentation,install) 185 $(call descend,Documentation,install) 286 186 287 doc-uninstall: 187 doc-uninstall: 288 $(call descend,Documentation,uninstall 188 $(call descend,Documentation,uninstall) 289 189 290 FORCE: 190 FORCE: 291 191 292 .SECONDARY: !! 192 zdep: 293 .PHONY: all FORCE bootstrap clean install-bin !! 193 @if [ "$(feature-zlib)" != "1" ]; then echo "No zlib found"; exit 1 ; fi >> 194 >> 195 .PHONY: all FORCE clean install uninstall zdep 294 .PHONY: doc doc-clean doc-install doc-uninstal 196 .PHONY: doc doc-clean doc-install doc-uninstall 295 .DEFAULT_GOAL := all 197 .DEFAULT_GOAL := all 296 << 297 # Delete partially updated (corrupted) files o << 298 .DELETE_ON_ERROR: <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.