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