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