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