1# SPDX-License-Identifier: GPL-2.0 2include ../../scripts/Makefile.include 3 4FILES= \ 5 test-all.bin \ 6 test-backtrace.bin \ 7 test-bionic.bin \ 8 test-dwarf.bin \ 9 test-dwarf_getlocations.bin \ 10 test-eventfd.bin \ 11 test-fortify-source.bin \ 12 test-get_current_dir_name.bin \ 13 test-glibc.bin \ 14 test-gtk2.bin \ 15 test-gtk2-infobar.bin \ 16 test-hello.bin \ 17 test-libaudit.bin \ 18 test-libbfd.bin \ 19 test-libbfd-buildid.bin \ 20 test-disassembler-four-args.bin \ 21 test-disassembler-init-styled.bin \ 22 test-reallocarray.bin \ 23 test-libbfd-liberty.bin \ 24 test-libbfd-liberty-z.bin \ 25 test-cplus-demangle.bin \ 26 test-libcap.bin \ 27 test-libelf.bin \ 28 test-libelf-getphdrnum.bin \ 29 test-libelf-gelf_getnote.bin \ 30 test-libelf-getshdrstrndx.bin \ 31 test-libdebuginfod.bin \ 32 test-libnuma.bin \ 33 test-numa_num_possible_cpus.bin \ 34 test-libperl.bin \ 35 test-libpython.bin \ 36 test-libslang.bin \ 37 test-libslang-include-subdir.bin \ 38 test-libtraceevent.bin \ 39 test-libtracefs.bin \ 40 test-libcrypto.bin \ 41 test-libunwind.bin \ 42 test-libunwind-debug-frame.bin \ 43 test-libunwind-x86.bin \ 44 test-libunwind-x86_64.bin \ 45 test-libunwind-arm.bin \ 46 test-libunwind-aarch64.bin \ 47 test-libunwind-debug-frame-arm.bin \ 48 test-libunwind-debug-frame-aarch64.bin \ 49 test-pthread-attr-setaffinity-np.bin \ 50 test-pthread-barrier.bin \ 51 test-stackprotector-all.bin \ 52 test-timerfd.bin \ 53 test-libdw-dwarf-unwind.bin \ 54 test-libbabeltrace.bin \ 55 test-compile-32.bin \ 56 test-compile-x32.bin \ 57 test-zlib.bin \ 58 test-lzma.bin \ 59 test-bpf.bin \ 60 test-libbpf.bin \ 61 test-libbpf-btf__load_from_kernel_by_id.bin \ 62 test-libbpf-bpf_prog_load.bin \ 63 test-libbpf-bpf_map_create.bin \ 64 test-libbpf-bpf_object__next_program.bin \ 65 test-libbpf-bpf_object__next_map.bin \ 66 test-libbpf-btf__raw_data.bin \ 67 test-get_cpuid.bin \ 68 test-sdt.bin \ 69 test-cxx.bin \ 70 test-gettid.bin \ 71 test-jvmti.bin \ 72 test-jvmti-cmlr.bin \ 73 test-sched_getcpu.bin \ 74 test-setns.bin \ 75 test-libopencsd.bin \ 76 test-clang.bin \ 77 test-llvm.bin \ 78 test-llvm-version.bin \ 79 test-libaio.bin \ 80 test-libzstd.bin \ 81 test-clang-bpf-co-re.bin \ 82 test-file-handle.bin \ 83 test-libpfm4.bin 84 85FILES := $(addprefix $(OUTPUT),$(FILES)) 86 87PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config 88 89all: $(FILES) 90 91__BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) 92 BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1 93 BUILD_BFD = $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl 94 BUILD_ALL = $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma -lzstd -lcap 95 96__BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) 97 BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 98 99############################### 100 101$(OUTPUT)test-all.bin: 102 $(BUILD_ALL) || $(BUILD_ALL) -lopcodes -liberty 103 104$(OUTPUT)test-hello.bin: 105 $(BUILD) 106 107$(OUTPUT)test-pthread-attr-setaffinity-np.bin: 108 $(BUILD) -D_GNU_SOURCE -lpthread 109 110$(OUTPUT)test-pthread-barrier.bin: 111 $(BUILD) -lpthread 112 113$(OUTPUT)test-stackprotector-all.bin: 114 $(BUILD) -fstack-protector-all 115 116$(OUTPUT)test-fortify-source.bin: 117 $(BUILD) -O2 -D_FORTIFY_SOURCE=2 118 119$(OUTPUT)test-bionic.bin: 120 $(BUILD) 121 122$(OUTPUT)test-libcap.bin: 123 $(BUILD) -lcap 124 125$(OUTPUT)test-libelf.bin: 126 $(BUILD) -lelf 127 128$(OUTPUT)test-eventfd.bin: 129 $(BUILD) 130 131$(OUTPUT)test-get_current_dir_name.bin: 132 $(BUILD) 133 134$(OUTPUT)test-glibc.bin: 135 $(BUILD) 136 137$(OUTPUT)test-sched_getcpu.bin: 138 $(BUILD) 139 140$(OUTPUT)test-setns.bin: 141 $(BUILD) 142 143$(OUTPUT)test-libopencsd.bin: 144 $(BUILD) # -lopencsd_c_api -lopencsd provided by 145 # $(FEATURE_CHECK_LDFLAGS-libopencsd) 146 147DWARFLIBS := -ldw 148ifeq ($(findstring -static,${LDFLAGS}),-static) 149DWARFLIBS += -lelf -lebl -lz -llzma -lbz2 150endif 151 152$(OUTPUT)test-dwarf.bin: 153 $(BUILD) $(DWARFLIBS) 154 155$(OUTPUT)test-dwarf_getlocations.bin: 156 $(BUILD) $(DWARFLIBS) 157 158$(OUTPUT)test-libelf-getphdrnum.bin: 159 $(BUILD) -lelf 160 161$(OUTPUT)test-libelf-gelf_getnote.bin: 162 $(BUILD) -lelf 163 164$(OUTPUT)test-libelf-getshdrstrndx.bin: 165 $(BUILD) -lelf 166 167$(OUTPUT)test-libdebuginfod.bin: 168 $(BUILD) -ldebuginfod 169 170$(OUTPUT)test-libnuma.bin: 171 $(BUILD) -lnuma 172 173$(OUTPUT)test-numa_num_possible_cpus.bin: 174 $(BUILD) -lnuma 175 176$(OUTPUT)test-libunwind.bin: 177 $(BUILD) -lelf 178 179$(OUTPUT)test-libunwind-debug-frame.bin: 180 $(BUILD) -lelf 181$(OUTPUT)test-libunwind-x86.bin: 182 $(BUILD) -lelf -lunwind-x86 183 184$(OUTPUT)test-libunwind-x86_64.bin: 185 $(BUILD) -lelf -lunwind-x86_64 186 187$(OUTPUT)test-libunwind-arm.bin: 188 $(BUILD) -lelf -lunwind-arm 189 190$(OUTPUT)test-libunwind-aarch64.bin: 191 $(BUILD) -lelf -lunwind-aarch64 192 193$(OUTPUT)test-libunwind-debug-frame-arm.bin: 194 $(BUILD) -lelf -lunwind-arm 195 196$(OUTPUT)test-libunwind-debug-frame-aarch64.bin: 197 $(BUILD) -lelf -lunwind-aarch64 198 199$(OUTPUT)test-libaudit.bin: 200 $(BUILD) -laudit 201 202$(OUTPUT)test-libslang.bin: 203 $(BUILD) -lslang 204 205$(OUTPUT)test-libslang-include-subdir.bin: 206 $(BUILD) -lslang 207 208$(OUTPUT)test-libtraceevent.bin: 209 $(BUILD) -ltraceevent 210 211$(OUTPUT)test-libtracefs.bin: 212 $(BUILD) -ltracefs 213 214$(OUTPUT)test-libcrypto.bin: 215 $(BUILD) -lcrypto 216 217$(OUTPUT)test-gtk2.bin: 218 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations 219 220$(OUTPUT)test-gtk2-infobar.bin: 221 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 222 223grep-libs = $(filter -l%,$(1)) 224strip-libs = $(filter-out -l%,$(1)) 225 226PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 227PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 228PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 229PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) 230FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 231 232ifeq ($(CC_NO_CLANG), 0) 233 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) 234 PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS)) 235 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) 236 FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro 237endif 238 239$(OUTPUT)test-libperl.bin: 240 $(BUILD) $(FLAGS_PERL_EMBED) 241 242$(OUTPUT)test-libpython.bin: 243 $(BUILD) $(FLAGS_PYTHON_EMBED) 244 245$(OUTPUT)test-libbfd.bin: 246 $(BUILD_BFD) 247 248$(OUTPUT)test-libbfd-buildid.bin: 249 $(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz 250 251$(OUTPUT)test-disassembler-four-args.bin: 252 $(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \ 253 $(BUILD_BFD) -lopcodes -liberty -lz 254 255$(OUTPUT)test-disassembler-init-styled.bin: 256 $(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \ 257 $(BUILD_BFD) -lopcodes -liberty -lz 258 259$(OUTPUT)test-reallocarray.bin: 260 $(BUILD) 261 262$(OUTPUT)test-libbfd-liberty.bin: 263 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty 264 265$(OUTPUT)test-libbfd-liberty-z.bin: 266 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz 267 268$(OUTPUT)test-cplus-demangle.bin: 269 $(BUILD) -liberty 270 271$(OUTPUT)test-backtrace.bin: 272 $(BUILD) 273 274$(OUTPUT)test-timerfd.bin: 275 $(BUILD) 276 277$(OUTPUT)test-libdw-dwarf-unwind.bin: 278 $(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind) 279 280$(OUTPUT)test-libbabeltrace.bin: 281 $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace) 282 283$(OUTPUT)test-compile-32.bin: 284 $(CC) -m32 -o $@ test-compile.c 285 286$(OUTPUT)test-compile-x32.bin: 287 $(CC) -mx32 -o $@ test-compile.c 288 289$(OUTPUT)test-zlib.bin: 290 $(BUILD) -lz 291 292$(OUTPUT)test-lzma.bin: 293 $(BUILD) -llzma 294 295$(OUTPUT)test-get_cpuid.bin: 296 $(BUILD) 297 298$(OUTPUT)test-bpf.bin: 299 $(BUILD) 300 301$(OUTPUT)test-libbpf.bin: 302 $(BUILD) -lbpf 303 304$(OUTPUT)test-libbpf-btf__load_from_kernel_by_id.bin: 305 $(BUILD) -lbpf 306 307$(OUTPUT)test-libbpf-bpf_prog_load.bin: 308 $(BUILD) -lbpf 309 310$(OUTPUT)test-libbpf-bpf_map_create.bin: 311 $(BUILD) -lbpf 312 313$(OUTPUT)test-libbpf-bpf_object__next_program.bin: 314 $(BUILD) -lbpf 315 316$(OUTPUT)test-libbpf-bpf_object__next_map.bin: 317 $(BUILD) -lbpf 318 319$(OUTPUT)test-libbpf-btf__raw_data.bin: 320 $(BUILD) -lbpf 321 322$(OUTPUT)test-sdt.bin: 323 $(BUILD) 324 325$(OUTPUT)test-cxx.bin: 326 $(BUILDXX) -std=gnu++11 327 328$(OUTPUT)test-gettid.bin: 329 $(BUILD) 330 331$(OUTPUT)test-jvmti.bin: 332 $(BUILD) 333 334$(OUTPUT)test-jvmti-cmlr.bin: 335 $(BUILD) 336 337$(OUTPUT)test-llvm.bin: 338 $(BUILDXX) -std=gnu++14 \ 339 -I$(shell $(LLVM_CONFIG) --includedir) \ 340 -L$(shell $(LLVM_CONFIG) --libdir) \ 341 $(shell $(LLVM_CONFIG) --libs Core BPF) \ 342 $(shell $(LLVM_CONFIG) --system-libs) \ 343 > $(@:.bin=.make.output) 2>&1 344 345$(OUTPUT)test-llvm-version.bin: 346 $(BUILDXX) -std=gnu++14 \ 347 -I$(shell $(LLVM_CONFIG) --includedir) \ 348 > $(@:.bin=.make.output) 2>&1 349 350$(OUTPUT)test-clang.bin: 351 $(BUILDXX) -std=gnu++14 \ 352 -I$(shell $(LLVM_CONFIG) --includedir) \ 353 -L$(shell $(LLVM_CONFIG) --libdir) \ 354 -Wl,--start-group -lclangBasic -lclangDriver \ 355 -lclangFrontend -lclangEdit -lclangLex \ 356 -lclangAST -Wl,--end-group \ 357 $(shell $(LLVM_CONFIG) --libs Core option) \ 358 $(shell $(LLVM_CONFIG) --system-libs) \ 359 > $(@:.bin=.make.output) 2>&1 360 361-include $(OUTPUT)*.d 362 363$(OUTPUT)test-libaio.bin: 364 $(BUILD) -lrt 365 366$(OUTPUT)test-libzstd.bin: 367 $(BUILD) -lzstd 368 369$(OUTPUT)test-clang-bpf-co-re.bin: 370 $(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) | \ 371 grep BTF_KIND_VAR 372 373$(OUTPUT)test-file-handle.bin: 374 $(BUILD) 375 376$(OUTPUT)test-libpfm4.bin: 377 $(BUILD) -lpfm 378 379############################### 380 381clean: 382 rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output) 383