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