Makefile 9.2 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7
FILES=                                          \
         test-all.bin                           \
         test-backtrace.bin                     \
         test-bionic.bin                        \
         test-dwarf.bin                         \
         test-dwarf_getlocations.bin            \
8
         test-eventfd.bin                       \
9 10
         test-fortify-source.bin                \
         test-sync-compare-and-swap.bin         \
11
         test-get_current_dir_name.bin          \
12 13 14 15 16 17
         test-glibc.bin                         \
         test-gtk2.bin                          \
         test-gtk2-infobar.bin                  \
         test-hello.bin                         \
         test-libaudit.bin                      \
         test-libbfd.bin                        \
18
         test-disassembler-four-args.bin        \
19
         test-reallocarray.bin			\
20 21
         test-libbfd-liberty.bin                \
         test-libbfd-liberty-z.bin              \
22
         test-cplus-demangle.bin                \
23
         test-libcap.bin			\
24 25 26 27 28 29 30 31 32 33 34
         test-libelf.bin                        \
         test-libelf-getphdrnum.bin             \
         test-libelf-gelf_getnote.bin           \
         test-libelf-getshdrstrndx.bin          \
         test-libelf-mmap.bin                   \
         test-libnuma.bin                       \
         test-numa_num_possible_cpus.bin        \
         test-libperl.bin                       \
         test-libpython.bin                     \
         test-libpython-version.bin             \
         test-libslang.bin                      \
35
         test-libslang-include-subdir.bin       \
36 37 38 39 40 41 42 43 44 45
         test-libcrypto.bin                     \
         test-libunwind.bin                     \
         test-libunwind-debug-frame.bin         \
         test-libunwind-x86.bin                 \
         test-libunwind-x86_64.bin              \
         test-libunwind-arm.bin                 \
         test-libunwind-aarch64.bin             \
         test-libunwind-debug-frame-arm.bin     \
         test-libunwind-debug-frame-aarch64.bin \
         test-pthread-attr-setaffinity-np.bin   \
46
         test-pthread-barrier.bin		\
47 48 49 50 51 52 53 54 55
         test-stackprotector-all.bin            \
         test-timerfd.bin                       \
         test-libdw-dwarf-unwind.bin            \
         test-libbabeltrace.bin                 \
         test-compile-32.bin                    \
         test-compile-x32.bin                   \
         test-zlib.bin                          \
         test-lzma.bin                          \
         test-bpf.bin                           \
56
         test-libbpf.bin                        \
57 58 59
         test-get_cpuid.bin                     \
         test-sdt.bin                           \
         test-cxx.bin                           \
60
         test-gettid.bin			\
61
         test-jvmti.bin				\
J
Jiri Olsa 已提交
62
         test-jvmti-cmlr.bin			\
63
         test-sched_getcpu.bin			\
64
         test-setns.bin				\
65 66 67
         test-libopencsd.bin			\
         test-clang.bin				\
         test-llvm.bin				\
68
         test-llvm-version.bin			\
69
         test-libaio.bin			\
70 71
         test-libzstd.bin			\
         test-clang-bpf-global-var.bin
72

73 74
FILES := $(addprefix $(OUTPUT),$(FILES))

75 76 77
CC ?= $(CROSS_COMPILE)gcc
CXX ?= $(CROSS_COMPILE)g++
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
78
LLVM_CONFIG ?= llvm-config
79
CLANG ?= clang
80

81 82
all: $(FILES)

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 88
  BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1

89 90
###############################

91
$(OUTPUT)test-all.bin:
92
	$(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
93

94
$(OUTPUT)test-hello.bin:
95 96
	$(BUILD)

97
$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
98
	$(BUILD) -D_GNU_SOURCE -lpthread
99

100 101 102
$(OUTPUT)test-pthread-barrier.bin:
	$(BUILD) -lpthread

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 111
	$(BUILD)

112 113 114
$(OUTPUT)test-libcap.bin:
	$(BUILD) -lcap

115
$(OUTPUT)test-libelf.bin:
116 117
	$(BUILD) -lelf

118 119 120
$(OUTPUT)test-eventfd.bin:
	$(BUILD)

121 122 123
$(OUTPUT)test-get_current_dir_name.bin:
	$(BUILD)

124
$(OUTPUT)test-glibc.bin:
125 126
	$(BUILD)

127 128 129
$(OUTPUT)test-sched_getcpu.bin:
	$(BUILD)

130 131 132
$(OUTPUT)test-setns.bin:
	$(BUILD)

133 134 135 136
$(OUTPUT)test-libopencsd.bin:
	$(BUILD) # -lopencsd_c_api -lopencsd provided by
		 # $(FEATURE_CHECK_LDFLAGS-libopencsd)

137 138 139 140 141
DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
endif

142
$(OUTPUT)test-dwarf.bin:
143
	$(BUILD) $(DWARFLIBS)
144

145 146 147
$(OUTPUT)test-dwarf_getlocations.bin:
	$(BUILD) $(DWARFLIBS)

148
$(OUTPUT)test-libelf-mmap.bin:
149 150
	$(BUILD) -lelf

151
$(OUTPUT)test-libelf-getphdrnum.bin:
152 153
	$(BUILD) -lelf

154 155 156
$(OUTPUT)test-libelf-gelf_getnote.bin:
	$(BUILD) -lelf

157 158 159
$(OUTPUT)test-libelf-getshdrstrndx.bin:
	$(BUILD) -lelf

160
$(OUTPUT)test-libnuma.bin:
161 162
	$(BUILD) -lnuma

163
$(OUTPUT)test-numa_num_possible_cpus.bin:
164 165
	$(BUILD) -lnuma

166
$(OUTPUT)test-libunwind.bin:
167
	$(BUILD) -lelf
168

169
$(OUTPUT)test-libunwind-debug-frame.bin:
170
	$(BUILD) -lelf
171 172 173 174 175 176 177 178 179 180 181 182
$(OUTPUT)test-libunwind-x86.bin:
	$(BUILD) -lelf -lunwind-x86

$(OUTPUT)test-libunwind-x86_64.bin:
	$(BUILD) -lelf -lunwind-x86_64

$(OUTPUT)test-libunwind-arm.bin:
	$(BUILD) -lelf -lunwind-arm

$(OUTPUT)test-libunwind-aarch64.bin:
	$(BUILD) -lelf -lunwind-aarch64

183 184 185 186 187
$(OUTPUT)test-libunwind-debug-frame-arm.bin:
	$(BUILD) -lelf -lunwind-arm

$(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
	$(BUILD) -lelf -lunwind-aarch64
188

189
$(OUTPUT)test-libaudit.bin:
190 191
	$(BUILD) -laudit

192
$(OUTPUT)test-libslang.bin:
193
	$(BUILD) -lslang
194

195 196 197
$(OUTPUT)test-libslang-include-subdir.bin:
	$(BUILD) -lslang

198 199 200
$(OUTPUT)test-libcrypto.bin:
	$(BUILD) -lcrypto

201
$(OUTPUT)test-gtk2.bin:
J
Jiri Olsa 已提交
202
	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations
203

204
$(OUTPUT)test-gtk2-infobar.bin:
M
Mark Rutland 已提交
205
	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
206

207 208 209 210 211 212 213 214 215
grep-libs  = $(filter -l%,$(1))
strip-libs = $(filter-out -l%,$(1))

PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)

216
$(OUTPUT)test-libperl.bin:
217 218
	$(BUILD) $(FLAGS_PERL_EMBED)

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 232 233
$(OUTPUT)test-reallocarray.bin:
	$(BUILD)

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 242
	$(BUILD) -liberty

243
$(OUTPUT)test-backtrace.bin:
244 245
	$(BUILD)

246
$(OUTPUT)test-timerfd.bin:
247 248
	$(BUILD)

249
$(OUTPUT)test-libdw-dwarf-unwind.bin:
250 251
	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)

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 259
$(OUTPUT)test-compile-32.bin:
	$(CC) -m32 -o $@ test-compile.c
260

261 262
$(OUTPUT)test-compile-x32.bin:
	$(CC) -mx32 -o $@ test-compile.c
263

264
$(OUTPUT)test-zlib.bin:
265 266
	$(BUILD) -lz

267
$(OUTPUT)test-lzma.bin:
268 269
	$(BUILD) -llzma

270
$(OUTPUT)test-get_cpuid.bin:
271 272
	$(BUILD)

273
$(OUTPUT)test-bpf.bin:
274 275
	$(BUILD)

276 277 278
$(OUTPUT)test-libbpf.bin:
	$(BUILD) -lbpf

279 280 281
$(OUTPUT)test-sdt.bin:
	$(BUILD)

282 283 284
$(OUTPUT)test-cxx.bin:
	$(BUILDXX) -std=gnu++11

285 286 287
$(OUTPUT)test-gettid.bin:
	$(BUILD)

288 289 290
$(OUTPUT)test-jvmti.bin:
	$(BUILD)

J
Jiri Olsa 已提交
291 292 293
$(OUTPUT)test-jvmti-cmlr.bin:
	$(BUILD)

294
$(OUTPUT)test-llvm.bin:
295
	$(BUILDXX) -std=gnu++11 				\
296 297 298
		-I$(shell $(LLVM_CONFIG) --includedir) 		\
		-L$(shell $(LLVM_CONFIG) --libdir)		\
		$(shell $(LLVM_CONFIG) --libs Core BPF)		\
299 300
		$(shell $(LLVM_CONFIG) --system-libs)		\
		> $(@:.bin=.make.output) 2>&1
301

302 303
$(OUTPUT)test-llvm-version.bin:
	$(BUILDXX) -std=gnu++11 				\
304 305
		-I$(shell $(LLVM_CONFIG) --includedir)		\
		> $(@:.bin=.make.output) 2>&1
306

307
$(OUTPUT)test-clang.bin:
308
	$(BUILDXX) -std=gnu++11 				\
309 310 311 312 313 314
		-I$(shell $(LLVM_CONFIG) --includedir) 		\
		-L$(shell $(LLVM_CONFIG) --libdir)		\
		-Wl,--start-group -lclangBasic -lclangDriver	\
		  -lclangFrontend -lclangEdit -lclangLex	\
		  -lclangAST -Wl,--end-group 			\
		$(shell $(LLVM_CONFIG) --libs Core option)	\
315 316
		$(shell $(LLVM_CONFIG) --system-libs)		\
		> $(@:.bin=.make.output) 2>&1
317

318
-include $(OUTPUT)*.d
319

320 321 322
$(OUTPUT)test-libaio.bin:
	$(BUILD) -lrt

323 324 325
$(OUTPUT)test-libzstd.bin:
	$(BUILD) -lzstd

326 327 328 329 330
$(OUTPUT)test-clang-bpf-global-var.bin:
	$(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) |	\
		grep BTF_KIND_VAR


331 332 333
###############################

clean:
334
	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)