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