Debian Codegraph @

libbpf-tools/Makefile

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 OUTPUT := $(abspath .output)
3 CLANG ?= clang
4 LLVM_STRIP ?= llvm-strip
5 BPFTOOL_SRC := $(abspath ./bpftool/src)
6 BPFTOOL_OUTPUT ?= $(abspath $(OUTPUT)/bpftool)
7 BPFTOOL ?= $(BPFTOOL_OUTPUT)/bootstrap/bpftool
8 LIBBPF_SRC := $(abspath ../src/cc/libbpf/src)
9 LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a)
10 LIBBLAZESYM_SRC := $(abspath blazesym/target/release/libblazesym.a)
11 INCLUDES := -I$(OUTPUT) -I../src/cc/libbpf/include/uapi
12 CFLAGS := -g -O2 -Wall -Wmissing-field-initializers -Werror -Werror=undef
13 BPFCFLAGS := -g -O2 -Wall -Werror=undef
14 BPFCFLAGS_softirqs := $(BPFCFLAGS) -mcpu=v3
15 INSTALL ?= install
16 prefix ?= /usr/local
17 bindir := $(prefix)/bin
18 ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/' \
19 | sed 's/ppc64le/powerpc/' | sed 's/mips.*/mips/' \
20 | sed 's/riscv64/riscv/' | sed 's/loongarch.*/loongarch/' \
21 | sed 's/s390x/s390/')
22 BTFHUB_ARCHIVE ?= $(abspath btfhub-archive)
23 ifeq ($(ARCH),x86)
24 CARGO ?= $(shell which cargo)
25 ifeq ($(strip $(CARGO)),)
26 USE_BLAZESYM ?= 0
27 else
28 USE_BLAZESYM ?= 1
29 endif
30 endif
31
32 ifeq ($(wildcard $(ARCH)/),)
33 $(error Architecture $(ARCH) is not supported yet. Please open an issue)
34 endif
35
36 BZ_APPS = \
37 futexctn \
38 memleak \
39 opensnoop \
40 #
41
42 APPS = \
43 bashreadline \
44 bindsnoop \
45 biolatency \
46 biopattern \
47 biosnoop \
48 biostacks \
49 biotop \
50 bitesize \
51 cachestat \
52 capable \
53 cpudist \
54 cpufreq \
55 drsnoop \
56 execsnoop \
57 exitsnoop \
58 filelife \
59 filetop \
60 fsdist \
61 fsslower \
62 funclatency \
63 gethostlatency \
64 hardirqs \
65 javagc \
66 klockstat \
67 ksnoop \
68 llcstat \
69 mdflush \
70 mountsnoop \
71 numamove \
72 offcputime \
73 oomkill \
74 profile \
75 readahead \
76 runqlat \
77 runqlen \
78 runqslower \
79 sigsnoop \
80 slabratetop \
81 softirqs \
82 solisten \
83 statsnoop \
84 syncsnoop \
85 syscount \
86 tcptracer \
87 tcpconnect \
88 tcpconnlat \
89 tcplife \
90 tcppktlat \
91 tcprtt \
92 tcpstates \
93 tcpsynbl \
94 tcptop \
95 vfsstat \
96 wakeuptime \
97 $(BZ_APPS) \
98 #
99
100 # export variables that are used in Makefile.btfgen as well.
101 export OUTPUT BPFTOOL ARCH BTFHUB_ARCHIVE APPS
102
103 FSDIST_ALIASES = btrfsdist ext4dist nfsdist xfsdist f2fsdist bcachefsdist zfsdist
104 FSSLOWER_ALIASES = btrfsslower ext4slower nfsslower xfsslower f2fsslower bcachefsslower zfsslower
105 SIGSNOOP_ALIAS = killsnoop
106 APP_ALIASES = $(FSDIST_ALIASES) $(FSSLOWER_ALIASES) ${SIGSNOOP_ALIAS}
107
108 COMMON_OBJ = \
109 $(OUTPUT)/trace_helpers.o \
110 $(OUTPUT)/syscall_helpers.o \
111 $(OUTPUT)/errno_helpers.o \
112 $(OUTPUT)/map_helpers.o \
113 $(OUTPUT)/uprobe_helpers.o \
114 $(OUTPUT)/btf_helpers.o \
115 $(OUTPUT)/compat.o \
116 $(if $(ENABLE_MIN_CORE_BTFS),$(OUTPUT)/min_core_btf_tar.o) \
117 #
118
119 ifeq ($(USE_BLAZESYM),1)
120 COMMON_OBJ += \
121 $(OUTPUT)/libblazesym.a \
122 $(OUTPUT)/blazesym.h \
123 #
124 endif
125
126 define allow-override
127 $(if $(or $(findstring environment,$(origin $(1))),\
128 $(findstring command line,$(origin $(1)))),,\
129 $(eval $(1) = $(2)))
130 endef
131
132 $(call allow-override,CC,$(CROSS_COMPILE)cc)
133 $(call allow-override,LD,$(CROSS_COMPILE)ld)
134
135 .PHONY: all
136 all: $(APPS) $(APP_ALIASES)
137
138 ifeq ($(V),1)
139 Q =
140 msg =
141 else
142 Q = @
143 msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
144 MAKEFLAGS += --no-print-directory
145 endif
146
147 ifneq ($(EXTRA_CFLAGS),)
148 CFLAGS += $(EXTRA_CFLAGS)
149 endif
150 ifneq ($(EXTRA_LDFLAGS),)
151 LDFLAGS += $(EXTRA_LDFLAGS)
152 endif
153 ifeq ($(USE_BLAZESYM),1)
154 CFLAGS += -DUSE_BLAZESYM=1
155 endif
156
157 ifeq ($(USE_BLAZESYM),1)
158 LDFLAGS += $(OUTPUT)/libblazesym.a -lrt -lpthread -ldl
159 endif
160
161 .PHONY: clean
162 clean:
163 $(call msg,CLEAN)
164 $(Q)rm -rf $(OUTPUT) $(APPS) $(APP_ALIASES)
165
166 $(LIBBLAZESYM_SRC)::
167 $(Q)cd blazesym && cargo build --release --features=cheader
168
169 $(OUTPUT)/libblazesym.a: $(LIBBLAZESYM_SRC) | $(OUTPUT)
170 $(call msg,LIB,$@)
171 $(Q)cp $(LIBBLAZESYM_SRC) $@
172
173 $(OUTPUT)/blazesym.h: $(LIBBLAZESYM_SRC) | $(OUTPUT)
174 $(call msg,INC,$@)
175 $(Q)cp blazesym/target/release/blazesym.h $@
176
177 $(OUTPUT) $(OUTPUT)/libbpf $(BPFTOOL_OUTPUT):
178 $(call msg,MKDIR,$@)
179 $(Q)mkdir -p $@
180
181 $(BPFTOOL): | $(BPFTOOL_OUTPUT)
182 $(call msg,BPFTOOL,$@)
183 $(Q)$(MAKE) ARCH= CROSS_COMPILE= OUTPUT=$(BPFTOOL_OUTPUT)/ -C $(BPFTOOL_SRC) bootstrap
184
185 $(APPS): %: $(OUTPUT)/%.o $(COMMON_OBJ) $(LIBBPF_OBJ) | $(OUTPUT)
186 $(call msg,BINARY,$@)
187 $(Q)$(CC) $(CFLAGS) $^ $(LDFLAGS) -lelf -lz -o $@
188
189 ifeq ($(USE_BLAZESYM),1)
190 $(patsubst %,$(OUTPUT)/%.o,$(BZ_APPS)): $(OUTPUT)/blazesym.h
191 endif
192
193 $(patsubst %,$(OUTPUT)/%.o,$(APPS)): %.o: %.skel.h
194
195 $(OUTPUT)/%.o: %.c $(wildcard %.h) $(LIBBPF_OBJ) | $(OUTPUT)
196 $(call msg,CC,$@)
197 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
198
199 $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL)
200 $(call msg,GEN-SKEL,$@)
201 $(Q)$(BPFTOOL) gen skeleton $< > $@
202
203 $(OUTPUT)/softirqs.bpf.o: BPFCFLAGS = $(BPFCFLAGS_softirqs)
204
205 $(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(ARCH)/vmlinux.h | $(OUTPUT)
206 $(call msg,BPF,$@)
207 $(Q)$(CLANG) $(BPFCFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) \
208 -I$(ARCH)/ $(INCLUDES) -c $(filter %.c,$^) -o $@ && \
209 $(LLVM_STRIP) -g $@
210
211 btfhub-archive: force
212 $(call msg,GIT,$@)
213 $(Q)[ -d "$(BTFHUB_ARCHIVE)" ] || git clone -q https://github.com/aquasecurity/btfhub-archive/ $(BTFHUB_ARCHIVE)
214 $(Q)cd $(BTFHUB_ARCHIVE) && git pull
215
216 ifdef ENABLE_MIN_CORE_BTFS
217 $(OUTPUT)/min_core_btf_tar.o: $(patsubst %,$(OUTPUT)/%.bpf.o,$(APPS)) btfhub-archive | bpftool
218 $(Q)$(MAKE) -f Makefile.btfgen
219 endif
220
221 # Build libbpf.a
222 $(LIBBPF_OBJ): $(wildcard $(LIBBPF_SRC)/*.[ch]) | $(OUTPUT)/libbpf
223 $(call msg,LIB,$@)
224 $(Q)$(MAKE) -C $(LIBBPF_SRC) BUILD_STATIC_ONLY=1 \
225 OBJDIR=$(dir $@)libbpf DESTDIR=$(dir $@) \
226 INCLUDEDIR= LIBDIR= UAPIDIR= \
227 install
228
229 $(FSSLOWER_ALIASES): fsslower
230 $(call msg,SYMLINK,$@)
231 $(Q)ln -f -s $(APP_PREFIX)$^ $@
232
233 $(FSDIST_ALIASES): fsdist
234 $(call msg,SYMLINK,$@)
235 $(Q)ln -f -s $(APP_PREFIX)$^ $@
236
237 $(SIGSNOOP_ALIAS): sigsnoop
238 $(call msg,SYMLINK,$@)
239 $(Q)ln -f -s $(APP_PREFIX)$^ $@
240
241 install: $(APPS) $(APP_ALIASES)
242 $(call msg, INSTALL libbpf-tools)
243 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bindir)
244 $(Q)$(foreach app,$(APPS),$(INSTALL) $(app) $(DESTDIR)$(bindir)/$(APP_PREFIX)$(app);)
245 $(Q)$(foreach alias,$(APP_ALIASES),cp -a $(alias) $(DESTDIR)$(bindir)/$(APP_PREFIX)$(alias);)
246
247 .PHONY: force
248 force:
249
250 # delete failed targets
251 .DELETE_ON_ERROR:
252 # keep intermediate (.skel.h, .bpf.o, etc) targets
253 .SECONDARY: