xref: /linux/tools/build/feature/Makefile (revision 07f0148aafe8c95a3a76cd59e9e75b4d78d1d31d)
1# SPDX-License-Identifier: GPL-2.0
2include ../../scripts/Makefile.include
3
4FILES=                                          \
5         test-all.bin                           \
6         test-backtrace.bin                     \
7         test-bionic.bin                        \
8         test-dwarf.bin                         \
9         test-dwarf_getlocations.bin            \
10         test-eventfd.bin                       \
11         test-fortify-source.bin                \
12         test-get_current_dir_name.bin          \
13         test-glibc.bin                         \
14         test-gtk2.bin                          \
15         test-gtk2-infobar.bin                  \
16         test-hello.bin                         \
17         test-libaudit.bin                      \
18         test-libbfd.bin                        \
19         test-libbfd-buildid.bin		\
20         test-disassembler-four-args.bin        \
21         test-disassembler-init-styled.bin	\
22         test-reallocarray.bin			\
23         test-libbfd-liberty.bin                \
24         test-libbfd-liberty-z.bin              \
25         test-cplus-demangle.bin                \
26         test-libcap.bin			\
27         test-libelf.bin                        \
28         test-libelf-getphdrnum.bin             \
29         test-libelf-gelf_getnote.bin           \
30         test-libelf-getshdrstrndx.bin          \
31         test-libdebuginfod.bin                 \
32         test-libnuma.bin                       \
33         test-numa_num_possible_cpus.bin        \
34         test-libperl.bin                       \
35         test-libpython.bin                     \
36         test-libslang.bin                      \
37         test-libslang-include-subdir.bin       \
38         test-libtraceevent.bin                 \
39         test-libtracefs.bin                    \
40         test-libcrypto.bin                     \
41         test-libunwind.bin                     \
42         test-libunwind-debug-frame.bin         \
43         test-libunwind-x86.bin                 \
44         test-libunwind-x86_64.bin              \
45         test-libunwind-arm.bin                 \
46         test-libunwind-aarch64.bin             \
47         test-libunwind-debug-frame-arm.bin     \
48         test-libunwind-debug-frame-aarch64.bin \
49         test-pthread-attr-setaffinity-np.bin   \
50         test-pthread-barrier.bin		\
51         test-stackprotector-all.bin            \
52         test-timerfd.bin                       \
53         test-libdw-dwarf-unwind.bin            \
54         test-libbabeltrace.bin                 \
55         test-compile-32.bin                    \
56         test-compile-x32.bin                   \
57         test-zlib.bin                          \
58         test-lzma.bin                          \
59         test-bpf.bin                           \
60         test-libbpf.bin                        \
61         test-libbpf-btf__load_from_kernel_by_id.bin	\
62         test-libbpf-bpf_prog_load.bin          \
63         test-libbpf-bpf_map_create.bin		\
64         test-libbpf-bpf_object__next_program.bin \
65         test-libbpf-bpf_object__next_map.bin   \
66         test-libbpf-bpf_program__set_insns.bin	\
67         test-libbpf-btf__raw_data.bin          \
68         test-get_cpuid.bin                     \
69         test-sdt.bin                           \
70         test-cxx.bin                           \
71         test-gettid.bin			\
72         test-jvmti.bin				\
73         test-jvmti-cmlr.bin			\
74         test-sched_getcpu.bin			\
75         test-setns.bin				\
76         test-libopencsd.bin			\
77         test-clang.bin				\
78         test-llvm.bin				\
79         test-llvm-version.bin			\
80         test-libaio.bin			\
81         test-libzstd.bin			\
82         test-clang-bpf-co-re.bin		\
83         test-file-handle.bin			\
84         test-libpfm4.bin
85
86FILES := $(addprefix $(OUTPUT),$(FILES))
87
88PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
89
90all: $(FILES)
91
92__BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
93  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
94  BUILD_BFD = $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl
95  BUILD_ALL = $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma -lzstd -lcap
96
97__BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS)
98  BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1
99
100###############################
101
102$(OUTPUT)test-all.bin:
103	$(BUILD_ALL) || $(BUILD_ALL) -lopcodes -liberty
104
105$(OUTPUT)test-hello.bin:
106	$(BUILD)
107
108$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
109	$(BUILD) -D_GNU_SOURCE -lpthread
110
111$(OUTPUT)test-pthread-barrier.bin:
112	$(BUILD) -lpthread
113
114$(OUTPUT)test-stackprotector-all.bin:
115	$(BUILD) -fstack-protector-all
116
117$(OUTPUT)test-fortify-source.bin:
118	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
119
120$(OUTPUT)test-bionic.bin:
121	$(BUILD)
122
123$(OUTPUT)test-libcap.bin:
124	$(BUILD) -lcap
125
126$(OUTPUT)test-libelf.bin:
127	$(BUILD) -lelf
128
129$(OUTPUT)test-eventfd.bin:
130	$(BUILD)
131
132$(OUTPUT)test-get_current_dir_name.bin:
133	$(BUILD)
134
135$(OUTPUT)test-glibc.bin:
136	$(BUILD)
137
138$(OUTPUT)test-sched_getcpu.bin:
139	$(BUILD)
140
141$(OUTPUT)test-setns.bin:
142	$(BUILD)
143
144$(OUTPUT)test-libopencsd.bin:
145	$(BUILD) # -lopencsd_c_api -lopencsd provided by
146		 # $(FEATURE_CHECK_LDFLAGS-libopencsd)
147
148DWARFLIBS := -ldw
149ifeq ($(findstring -static,${LDFLAGS}),-static)
150DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
151endif
152
153$(OUTPUT)test-dwarf.bin:
154	$(BUILD) $(DWARFLIBS)
155
156$(OUTPUT)test-dwarf_getlocations.bin:
157	$(BUILD) $(DWARFLIBS)
158
159$(OUTPUT)test-libelf-getphdrnum.bin:
160	$(BUILD) -lelf
161
162$(OUTPUT)test-libelf-gelf_getnote.bin:
163	$(BUILD) -lelf
164
165$(OUTPUT)test-libelf-getshdrstrndx.bin:
166	$(BUILD) -lelf
167
168$(OUTPUT)test-libdebuginfod.bin:
169	$(BUILD) -ldebuginfod
170
171$(OUTPUT)test-libnuma.bin:
172	$(BUILD) -lnuma
173
174$(OUTPUT)test-numa_num_possible_cpus.bin:
175	$(BUILD) -lnuma
176
177$(OUTPUT)test-libunwind.bin:
178	$(BUILD) -lelf
179
180$(OUTPUT)test-libunwind-debug-frame.bin:
181	$(BUILD) -lelf
182$(OUTPUT)test-libunwind-x86.bin:
183	$(BUILD) -lelf -lunwind-x86
184
185$(OUTPUT)test-libunwind-x86_64.bin:
186	$(BUILD) -lelf -lunwind-x86_64
187
188$(OUTPUT)test-libunwind-arm.bin:
189	$(BUILD) -lelf -lunwind-arm
190
191$(OUTPUT)test-libunwind-aarch64.bin:
192	$(BUILD) -lelf -lunwind-aarch64
193
194$(OUTPUT)test-libunwind-debug-frame-arm.bin:
195	$(BUILD) -lelf -lunwind-arm
196
197$(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
198	$(BUILD) -lelf -lunwind-aarch64
199
200$(OUTPUT)test-libaudit.bin:
201	$(BUILD) -laudit
202
203$(OUTPUT)test-libslang.bin:
204	$(BUILD) -lslang
205
206$(OUTPUT)test-libslang-include-subdir.bin:
207	$(BUILD) -lslang
208
209$(OUTPUT)test-libtraceevent.bin:
210	$(BUILD) -ltraceevent
211
212$(OUTPUT)test-libtracefs.bin:
213	$(BUILD) -ltracefs
214
215$(OUTPUT)test-libcrypto.bin:
216	$(BUILD) -lcrypto
217
218$(OUTPUT)test-gtk2.bin:
219	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations
220
221$(OUTPUT)test-gtk2-infobar.bin:
222	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
223
224grep-libs  = $(filter -l%,$(1))
225strip-libs = $(filter-out -l%,$(1))
226
227PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
228PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
229PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
230PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
231FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
232
233ifeq ($(CC_NO_CLANG), 0)
234  PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
235  PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
236  PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
237  FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro
238endif
239
240$(OUTPUT)test-libperl.bin:
241	$(BUILD) $(FLAGS_PERL_EMBED)
242
243$(OUTPUT)test-libpython.bin:
244	$(BUILD) $(FLAGS_PYTHON_EMBED)
245
246$(OUTPUT)test-libbfd.bin:
247	$(BUILD_BFD)
248
249$(OUTPUT)test-libbfd-buildid.bin:
250	$(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz
251
252$(OUTPUT)test-disassembler-four-args.bin:
253	$(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
254	$(BUILD_BFD) -lopcodes -liberty -lz
255
256$(OUTPUT)test-disassembler-init-styled.bin:
257	$(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
258	$(BUILD_BFD) -lopcodes -liberty -lz
259
260$(OUTPUT)test-reallocarray.bin:
261	$(BUILD)
262
263$(OUTPUT)test-libbfd-liberty.bin:
264	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
265
266$(OUTPUT)test-libbfd-liberty-z.bin:
267	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
268
269$(OUTPUT)test-cplus-demangle.bin:
270	$(BUILD) -liberty
271
272$(OUTPUT)test-backtrace.bin:
273	$(BUILD)
274
275$(OUTPUT)test-timerfd.bin:
276	$(BUILD)
277
278$(OUTPUT)test-libdw-dwarf-unwind.bin:
279	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)
280
281$(OUTPUT)test-libbabeltrace.bin:
282	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
283
284$(OUTPUT)test-compile-32.bin:
285	$(CC) -m32 -o $@ test-compile.c
286
287$(OUTPUT)test-compile-x32.bin:
288	$(CC) -mx32 -o $@ test-compile.c
289
290$(OUTPUT)test-zlib.bin:
291	$(BUILD) -lz
292
293$(OUTPUT)test-lzma.bin:
294	$(BUILD) -llzma
295
296$(OUTPUT)test-get_cpuid.bin:
297	$(BUILD)
298
299$(OUTPUT)test-bpf.bin:
300	$(BUILD)
301
302$(OUTPUT)test-libbpf.bin:
303	$(BUILD) -lbpf
304
305$(OUTPUT)test-libbpf-btf__load_from_kernel_by_id.bin:
306	$(BUILD) -lbpf
307
308$(OUTPUT)test-libbpf-bpf_prog_load.bin:
309	$(BUILD) -lbpf
310
311$(OUTPUT)test-libbpf-bpf_map_create.bin:
312	$(BUILD) -lbpf
313
314$(OUTPUT)test-libbpf-bpf_object__next_program.bin:
315	$(BUILD) -lbpf
316
317$(OUTPUT)test-libbpf-bpf_object__next_map.bin:
318	$(BUILD) -lbpf
319
320$(OUTPUT)test-libbpf-bpf_program__set_insns.bin:
321	$(BUILD) -lbpf
322
323$(OUTPUT)test-libbpf-btf__raw_data.bin:
324	$(BUILD) -lbpf
325
326$(OUTPUT)test-sdt.bin:
327	$(BUILD)
328
329$(OUTPUT)test-cxx.bin:
330	$(BUILDXX) -std=gnu++11
331
332$(OUTPUT)test-gettid.bin:
333	$(BUILD)
334
335$(OUTPUT)test-jvmti.bin:
336	$(BUILD)
337
338$(OUTPUT)test-jvmti-cmlr.bin:
339	$(BUILD)
340
341$(OUTPUT)test-llvm.bin:
342	$(BUILDXX) -std=gnu++14 				\
343		-I$(shell $(LLVM_CONFIG) --includedir) 		\
344		-L$(shell $(LLVM_CONFIG) --libdir)		\
345		$(shell $(LLVM_CONFIG) --libs Core BPF)		\
346		$(shell $(LLVM_CONFIG) --system-libs)		\
347		> $(@:.bin=.make.output) 2>&1
348
349$(OUTPUT)test-llvm-version.bin:
350	$(BUILDXX) -std=gnu++14					\
351		-I$(shell $(LLVM_CONFIG) --includedir)		\
352		> $(@:.bin=.make.output) 2>&1
353
354$(OUTPUT)test-clang.bin:
355	$(BUILDXX) -std=gnu++14					\
356		-I$(shell $(LLVM_CONFIG) --includedir) 		\
357		-L$(shell $(LLVM_CONFIG) --libdir)		\
358		-Wl,--start-group -lclangBasic -lclangDriver	\
359		  -lclangFrontend -lclangEdit -lclangLex	\
360		  -lclangAST -Wl,--end-group 			\
361		$(shell $(LLVM_CONFIG) --libs Core option)	\
362		$(shell $(LLVM_CONFIG) --system-libs)		\
363		> $(@:.bin=.make.output) 2>&1
364
365-include $(OUTPUT)*.d
366
367$(OUTPUT)test-libaio.bin:
368	$(BUILD) -lrt
369
370$(OUTPUT)test-libzstd.bin:
371	$(BUILD) -lzstd
372
373$(OUTPUT)test-clang-bpf-co-re.bin:
374	$(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) |	\
375		grep BTF_KIND_VAR
376
377$(OUTPUT)test-file-handle.bin:
378	$(BUILD)
379
380$(OUTPUT)test-libpfm4.bin:
381	$(BUILD) -lpfm
382
383###############################
384
385clean:
386	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)
387