Debian Codegraph @

libbpf-tools/Makefile

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