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