Debian Codegraph @

tools/build/feature/Makefile

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
2 include ../../scripts/Makefile.include
3
4 FILES= \
5 test-all.bin \
6 test-backtrace.bin \
7 test-bionic.bin \
8 test-libdw.bin \
9 test-eventfd.bin \
10 test-fortify-source.bin \
11 test-glibc.bin \
12 test-gtk2.bin \
13 test-gtk2-infobar.bin \
14 test-hello.bin \
15 test-libbfd.bin \
16 test-libbfd-threadsafe.bin \
17 test-disassembler-four-args.bin \
18 test-disassembler-init-styled.bin \
19 test-reallocarray.bin \
20 test-libbfd-liberty.bin \
21 test-libbfd-liberty-z.bin \
22 test-cplus-demangle.bin \
23 test-cxa-demangle.bin \
24 test-libcap.bin \
25 test-libelf.bin \
26 test-libelf-getphdrnum.bin \
27 test-libelf-gelf_getnote.bin \
28 test-libelf-getshdrstrndx.bin \
29 test-libelf-zstd.bin \
30 test-libdebuginfod.bin \
31 test-libnuma.bin \
32 test-numa_num_possible_cpus.bin \
33 test-libperl.bin \
34 test-libpython.bin \
35 test-libslang.bin \
36 test-libtraceevent.bin \
37 test-libcpupower.bin \
38 test-libtracefs.bin \
39 test-libunwind.bin \
40 test-libunwind-debug-frame.bin \
41 test-libunwind-x86.bin \
42 test-libunwind-x86_64.bin \
43 test-libunwind-arm.bin \
44 test-libunwind-aarch64.bin \
45 test-libunwind-debug-frame-arm.bin \
46 test-libunwind-debug-frame-aarch64.bin \
47 test-pthread-attr-setaffinity-np.bin \
48 test-pthread-barrier.bin \
49 test-stackprotector-all.bin \
50 test-timerfd.bin \
51 test-libbabeltrace.bin \
52 test-libcapstone.bin \
53 test-libcheck.bin \
54 test-compile-32.bin \
55 test-compile-x32.bin \
56 test-zlib.bin \
57 test-lzma.bin \
58 test-bpf.bin \
59 test-libbpf.bin \
60 test-sdt.bin \
61 test-cxx.bin \
62 test-gettid.bin \
63 test-jvmti.bin \
64 test-jvmti-cmlr.bin \
65 test-scandirat.bin \
66 test-sched_getcpu.bin \
67 test-setns.bin \
68 test-libopencsd.bin \
69 test-clang.bin \
70 test-llvm.bin \
71 test-llvm-perf.bin \
72 test-libaio.bin \
73 test-libzstd.bin \
74 test-clang-bpf-co-re.bin \
75 test-file-handle.bin \
76 test-libpfm4.bin \
77 test-rust.bin \
78 test-libopenssl.bin
79
80 FILES := $(addprefix $(OUTPUT),$(FILES))
81
82 # Some distros provide the command $(CROSS_COMPILE)pkg-config for
83 # searching packges installed with Multiarch. Use it for cross
84 # compilation if it is existed.
85 ifneq (, $(shell which $(CROSS_COMPILE)pkg-config))
86 PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
87 else
88 PKG_CONFIG ?= pkg-config
89
90 # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR
91 # for modified system root, are required for the cross compilation.
92 # If these PKG_CONFIG environment variables are not set, Multiarch library
93 # paths are used instead.
94 ifdef CROSS_COMPILE
95 ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),)
96 CROSS_ARCH = $(notdir $(CROSS_COMPILE:%-=%))
97 PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
98 PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
99 PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
100 PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
101 PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
102 export PKG_CONFIG_LIBDIR
103 endif
104 endif
105 endif
106
107 ifeq ($(findstring -static,${LDFLAGS}),-static)
108 PKG_CONFIG += --static
109 endif
110
111 all: $(FILES)
112
113 __BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
114 BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
115 BUILD_BFD = $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl
116 BUILD_ALL = $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang \
117 $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -ldl -lz -llzma -lzstd \
118 $(shell $(PKG_CONFIG) --libs --cflags openssl 2>/dev/null)
119
120 __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS)
121 BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1
122
123 ###############################
124
125 $(OUTPUT)test-all.bin:
126 $(BUILD_ALL)
127
128 $(OUTPUT)test-hello.bin:
129 $(BUILD)
130
131 $(OUTPUT)test-pthread-attr-setaffinity-np.bin:
132 $(BUILD) -D_GNU_SOURCE -lpthread
133
134 $(OUTPUT)test-pthread-barrier.bin:
135 $(BUILD) -lpthread
136
137 $(OUTPUT)test-stackprotector-all.bin:
138 $(BUILD) -fstack-protector-all
139
140 $(OUTPUT)test-fortify-source.bin:
141 $(BUILD) -O2 -D_FORTIFY_SOURCE=2
142
143 $(OUTPUT)test-bionic.bin:
144 $(BUILD)
145
146 $(OUTPUT)test-libcap.bin:
147 $(BUILD) -lcap
148
149 $(OUTPUT)test-libelf.bin:
150 $(BUILD) -lelf
151
152 $(OUTPUT)test-eventfd.bin:
153 $(BUILD)
154
155 $(OUTPUT)test-glibc.bin:
156 $(BUILD)
157
158 $(OUTPUT)test-scandirat.bin:
159 $(BUILD)
160
161 $(OUTPUT)test-sched_getcpu.bin:
162 $(BUILD)
163
164 $(OUTPUT)test-setns.bin:
165 $(BUILD)
166
167 $(OUTPUT)test-libopencsd.bin:
168 $(BUILD) # -lopencsd_c_api -lopencsd provided by
169 # $(FEATURE_CHECK_LDFLAGS-libopencsd)
170
171 DWLIBS := -ldw
172 ifeq ($(findstring -static,${LDFLAGS}),-static)
173 DWLIBS += -lelf -lz -llzma -lbz2 -lzstd
174
175 LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw).0.0
176 LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
177 LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
178
179 # Elfutils merged libebl.a into libdw.a starting from version 0.177,
180 # Link libebl.a only if libdw is older than this version.
181 ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
182 DWLIBS += -lebl
183 endif
184
185 # Must put -ldl after -lebl for dependency
186 DWARFLIBS += -ldl
187 endif
188
189 $(OUTPUT)test-libdw.bin:
190 $(BUILD) $(DWLIBS)
191
192 $(OUTPUT)test-libelf-getphdrnum.bin:
193 $(BUILD) -lelf
194
195 $(OUTPUT)test-libelf-gelf_getnote.bin:
196 $(BUILD) -lelf
197
198 $(OUTPUT)test-libelf-getshdrstrndx.bin:
199 $(BUILD) -lelf
200
201 $(OUTPUT)test-libelf-zstd.bin:
202 $(BUILD) -lelf -lz -lzstd
203
204 $(OUTPUT)test-libdebuginfod.bin:
205 $(BUILD) -ldebuginfod
206
207 $(OUTPUT)test-libnuma.bin:
208 $(BUILD) -lnuma
209
210 $(OUTPUT)test-numa_num_possible_cpus.bin:
211 $(BUILD) -lnuma
212
213 $(OUTPUT)test-libunwind.bin:
214 $(BUILD) -lelf -llzma
215
216 $(OUTPUT)test-libunwind-debug-frame.bin:
217 $(BUILD) -lelf -llzma
218 $(OUTPUT)test-libunwind-x86.bin:
219 $(BUILD) -lelf -llzma -lunwind-x86
220
221 $(OUTPUT)test-libunwind-x86_64.bin:
222 $(BUILD) -lelf -llzma -lunwind-x86_64
223
224 $(OUTPUT)test-libunwind-arm.bin:
225 $(BUILD) -lelf -llzma -lunwind-arm
226
227 $(OUTPUT)test-libunwind-aarch64.bin:
228 $(BUILD) -lelf -llzma -lunwind-aarch64
229
230 $(OUTPUT)test-libunwind-debug-frame-arm.bin:
231 $(BUILD) -lelf -llzma -lunwind-arm
232
233 $(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
234 $(BUILD) -lelf -llzma -lunwind-aarch64
235
236 $(OUTPUT)test-libslang.bin:
237 $(BUILD) -lslang
238
239 $(OUTPUT)test-libtraceevent.bin:
240 $(BUILD) -ltraceevent
241
242 $(OUTPUT)test-libcpupower.bin:
243 $(BUILD) -lcpupower
244
245 $(OUTPUT)test-libtracefs.bin:
246 $(BUILD) $(shell $(PKG_CONFIG) --cflags libtracefs 2>/dev/null) -ltracefs
247
248 $(OUTPUT)test-gtk2.bin:
249 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations
250
251 $(OUTPUT)test-gtk2-infobar.bin:
252 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
253
254 grep-libs = $(filter -l%,$(1))
255 strip-libs = $(filter-out -l%,$(1))
256
257 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
258 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
259 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
260 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
261 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
262
263 ifeq ($(CC_NO_CLANG), 0)
264 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
265 PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
266 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
267 FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro
268 endif
269
270 $(OUTPUT)test-libperl.bin:
271 $(BUILD) $(FLAGS_PERL_EMBED)
272
273 $(OUTPUT)test-libpython.bin:
274 $(BUILD) $(FLAGS_PYTHON_EMBED)
275
276 $(OUTPUT)test-libbfd.bin:
277 $(BUILD_BFD)
278
279 $(OUTPUT)test-libbfd-threadsafe.bin:
280 $(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz
281
282 $(OUTPUT)test-disassembler-four-args.bin:
283 $(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
284 $(BUILD_BFD) -lopcodes -liberty -lz
285
286 $(OUTPUT)test-disassembler-init-styled.bin:
287 $(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
288 $(BUILD_BFD) -lopcodes -liberty -lz
289
290 $(OUTPUT)test-reallocarray.bin:
291 $(BUILD)
292
293 $(OUTPUT)test-libbfd-liberty.bin:
294 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
295
296 $(OUTPUT)test-libbfd-liberty-z.bin:
297 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
298
299 $(OUTPUT)test-cplus-demangle.bin:
300 $(BUILD) -liberty
301
302 $(OUTPUT)test-cxa-demangle.bin:
303 $(BUILDXX)
304
305 $(OUTPUT)test-backtrace.bin:
306 $(BUILD)
307
308 $(OUTPUT)test-timerfd.bin:
309 $(BUILD)
310
311 $(OUTPUT)test-libbabeltrace.bin:
312 $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
313
314 $(OUTPUT)test-libcapstone.bin:
315 $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
316
317 $(OUTPUT)test-libcheck.bin:
318 $(BUILD) # -lcheck is provided by $(FEATURE_CHECK_LDFLAGS-libcheck)
319
320 $(OUTPUT)test-compile-32.bin:
321 $(CC) -m32 -Wall -Werror -o $@ test-compile.c
322
323 $(OUTPUT)test-compile-x32.bin:
324 $(CC) -mx32 -Wall -Werror -o $@ test-compile.c
325
326 $(OUTPUT)test-zlib.bin:
327 $(BUILD) -lz
328
329 $(OUTPUT)test-lzma.bin:
330 $(BUILD) -llzma
331
332 $(OUTPUT)test-bpf.bin:
333 $(BUILD)
334
335 $(OUTPUT)test-libbpf.bin:
336 $(BUILD) -lbpf
337
338 $(OUTPUT)test-sdt.bin:
339 $(BUILD)
340
341 $(OUTPUT)test-cxx.bin:
342 $(BUILDXX) -std=gnu++11
343
344 $(OUTPUT)test-gettid.bin:
345 $(BUILD)
346
347 $(OUTPUT)test-jvmti.bin:
348 $(BUILD)
349
350 $(OUTPUT)test-jvmti-cmlr.bin:
351 $(BUILD)
352
353 $(OUTPUT)test-llvm.bin:
354 $(BUILDXX) -std=gnu++17 \
355 -I$(shell $(LLVM_CONFIG) --includedir) \
356 -L$(shell $(LLVM_CONFIG) --libdir) \
357 $(shell $(LLVM_CONFIG) --libs Core BPF) \
358 $(shell $(LLVM_CONFIG) --system-libs) \
359 > $(@:.bin=.make.output) 2>&1
360
361 $(OUTPUT)test-llvm-perf.bin:
362 $(BUILDXX) -std=gnu++17 \
363 -I$(shell $(LLVM_CONFIG) --includedir) \
364 -L$(shell $(LLVM_CONFIG) --libdir) \
365 $(shell $(LLVM_CONFIG) --libs Core BPF) \
366 $(shell $(LLVM_CONFIG) --system-libs) \
367 > $(@:.bin=.make.output) 2>&1
368
369 $(OUTPUT)test-clang.bin:
370 $(BUILDXX) -std=gnu++17 \
371 -I$(shell $(LLVM_CONFIG) --includedir) \
372 -L$(shell $(LLVM_CONFIG) --libdir) \
373 -Wl,--start-group -lclang-cpp -Wl,--end-group \
374 $(shell $(LLVM_CONFIG) --libs Core option) \
375 $(shell $(LLVM_CONFIG) --system-libs) \
376 > $(@:.bin=.make.output) 2>&1
377
378 -include $(OUTPUT)*.d
379
380 $(OUTPUT)test-libaio.bin:
381 $(BUILD) -lrt
382
383 $(OUTPUT)test-libzstd.bin:
384 $(BUILD) -lzstd
385
386 $(OUTPUT)test-clang-bpf-co-re.bin:
387 $(CLANG) -S -g --target=bpf -o - $(patsubst %.bin,%.c,$(@F)) | \
388 grep BTF_KIND_VAR
389
390 $(OUTPUT)test-file-handle.bin:
391 $(BUILD)
392
393 $(OUTPUT)test-libpfm4.bin:
394 $(BUILD) -lpfm
395
396 $(OUTPUT)test-libopenssl.bin:
397 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags openssl 2>/dev/null)
398
399 $(OUTPUT)test-bpftool-skeletons.bin:
400 $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons' \
401 > $(@:.bin=.make.output) 2>&1
402
403 # Testing Rust is special: we don't compile anything, it's enough to check the
404 # compiler presence. Compiling a test code for this purposes is problematic,
405 # because Rust will emit a dependency file without any external references,
406 # meaning that if rustc will be removed the build process will still think it's
407 # there.
408 $(OUTPUT)test-rust.bin:
409 $(RUSTC) --version > /dev/null 2>&1
410
411 ###############################
412
413 clean:
414 rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)