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