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