Debian Codegraph @

tools/build/feature/Makefile

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