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-dwarf_getcfi.bin \ 11 test-eventfd.bin \ 12 test-fortify-source.bin \ 13 test-get_current_dir_name.bin \ 14 test-glibc.bin \ 15 test-gtk2.bin \ 16 test-gtk2-infobar.bin \ 17 test-hello.bin \ 18 test-libaudit.bin \ 19 test-libbfd.bin \ 20 test-libbfd-buildid.bin \ 21 test-disassembler-four-args.bin \ 22 test-disassembler-init-styled.bin \ 23 test-reallocarray.bin \ 24 test-libbfd-liberty.bin \ 25 test-libbfd-liberty-z.bin \ 26 test-cplus-demangle.bin \ 27 test-cxa-demangle.bin \ 28 test-libcap.bin \ 29 test-libelf.bin \ 30 test-libelf-getphdrnum.bin \ 31 test-libelf-gelf_getnote.bin \ 32 test-libelf-getshdrstrndx.bin \ 33 test-libdebuginfod.bin \ 34 test-libnuma.bin \ 35 test-numa_num_possible_cpus.bin \ 36 test-libperl.bin \ 37 test-libpython.bin \ 38 test-libslang.bin \ 39 test-libslang-include-subdir.bin \ 40 test-libtraceevent.bin \ 41 test-libcpupower.bin \ 42 test-libtracefs.bin \ 43 test-libcrypto.bin \ 44 test-libunwind.bin \ 45 test-libunwind-debug-frame.bin \ 46 test-libunwind-x86.bin \ 47 test-libunwind-x86_64.bin \ 48 test-libunwind-arm.bin \ 49 test-libunwind-aarch64.bin \ 50 test-libunwind-debug-frame-arm.bin \ 51 test-libunwind-debug-frame-aarch64.bin \ 52 test-pthread-attr-setaffinity-np.bin \ 53 test-pthread-barrier.bin \ 54 test-stackprotector-all.bin \ 55 test-timerfd.bin \ 56 test-libdw-dwarf-unwind.bin \ 57 test-libbabeltrace.bin \ 58 test-libcapstone.bin \ 59 test-compile-32.bin \ 60 test-compile-x32.bin \ 61 test-zlib.bin \ 62 test-lzma.bin \ 63 test-bpf.bin \ 64 test-libbpf.bin \ 65 test-get_cpuid.bin \ 66 test-sdt.bin \ 67 test-cxx.bin \ 68 test-gettid.bin \ 69 test-jvmti.bin \ 70 test-jvmti-cmlr.bin \ 71 test-scandirat.bin \ 72 test-sched_getcpu.bin \ 73 test-setns.bin \ 74 test-libopencsd.bin \ 75 test-clang.bin \ 76 test-llvm.bin \ 77 test-llvm-perf.bin \ 78 test-libaio.bin \ 79 test-libzstd.bin \ 80 test-clang-bpf-co-re.bin \ 81 test-file-handle.bin \ 82 test-libpfm4.bin 83 84FILES := $(addprefix $(OUTPUT),$(FILES)) 85 86# Some distros provide the command $(CROSS_COMPILE)pkg-config for 87# searching packges installed with Multiarch. Use it for cross 88# compilation if it is existed. 89ifneq (, $(shell which $(CROSS_COMPILE)pkg-config)) 90 PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config 91else 92 PKG_CONFIG ?= pkg-config 93 94 # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR 95 # for modified system root, are required for the cross compilation. 96 # If these PKG_CONFIG environment variables are not set, Multiarch library 97 # paths are used instead. 98 ifdef CROSS_COMPILE 99 ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),) 100 CROSS_ARCH = $(shell $(CC) -dumpmachine) 101 PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/ 102 PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/ 103 PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/ 104 PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/ 105 PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/ 106 export PKG_CONFIG_LIBDIR 107 endif 108 endif 109endif 110 111all: $(FILES) 112 113__BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) 114 BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1 115 BUILD_BFD = $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl 116 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 117 118__BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) 119 BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 120 121############################### 122 123$(OUTPUT)test-all.bin: 124 $(BUILD_ALL) || $(BUILD_ALL) -lopcodes -liberty 125 126$(OUTPUT)test-hello.bin: 127 $(BUILD) 128 129$(OUTPUT)test-pthread-attr-setaffinity-np.bin: 130 $(BUILD) -D_GNU_SOURCE -lpthread 131 132$(OUTPUT)test-pthread-barrier.bin: 133 $(BUILD) -lpthread 134 135$(OUTPUT)test-stackprotector-all.bin: 136 $(BUILD) -fstack-protector-all 137 138$(OUTPUT)test-fortify-source.bin: 139 $(BUILD) -O2 -D_FORTIFY_SOURCE=2 140 141$(OUTPUT)test-bionic.bin: 142 $(BUILD) 143 144$(OUTPUT)test-libcap.bin: 145 $(BUILD) -lcap 146 147$(OUTPUT)test-libelf.bin: 148 $(BUILD) -lelf 149 150$(OUTPUT)test-eventfd.bin: 151 $(BUILD) 152 153$(OUTPUT)test-get_current_dir_name.bin: 154 $(BUILD) 155 156$(OUTPUT)test-glibc.bin: 157 $(BUILD) 158 159$(OUTPUT)test-scandirat.bin: 160 $(BUILD) 161 162$(OUTPUT)test-sched_getcpu.bin: 163 $(BUILD) 164 165$(OUTPUT)test-setns.bin: 166 $(BUILD) 167 168$(OUTPUT)test-libopencsd.bin: 169 $(BUILD) # -lopencsd_c_api -lopencsd provided by 170 # $(FEATURE_CHECK_LDFLAGS-libopencsd) 171 172DWARFLIBS := -ldw 173ifeq ($(findstring -static,${LDFLAGS}),-static) 174 DWARFLIBS += -lelf -lz -llzma -lbz2 -lzstd 175 176 LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw).0.0 177 LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION))) 178 LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION))) 179 180 # Elfutils merged libebl.a into libdw.a starting from version 0.177, 181 # Link libebl.a only if libdw is older than this version. 182 ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0) 183 DWARFLIBS += -lebl 184 endif 185 186 # Must put -ldl after -lebl for dependency 187 DWARFLIBS += -ldl 188endif 189 190$(OUTPUT)test-dwarf.bin: 191 $(BUILD) $(DWARFLIBS) 192 193$(OUTPUT)test-dwarf_getlocations.bin: 194 $(BUILD) $(DWARFLIBS) 195 196$(OUTPUT)test-dwarf_getcfi.bin: 197 $(BUILD) $(DWARFLIBS) 198 199$(OUTPUT)test-libelf-getphdrnum.bin: 200 $(BUILD) -lelf 201 202$(OUTPUT)test-libelf-gelf_getnote.bin: 203 $(BUILD) -lelf 204 205$(OUTPUT)test-libelf-getshdrstrndx.bin: 206 $(BUILD) -lelf 207 208$(OUTPUT)test-libdebuginfod.bin: 209 $(BUILD) -ldebuginfod 210 211$(OUTPUT)test-libnuma.bin: 212 $(BUILD) -lnuma 213 214$(OUTPUT)test-numa_num_possible_cpus.bin: 215 $(BUILD) -lnuma 216 217$(OUTPUT)test-libunwind.bin: 218 $(BUILD) -lelf -llzma 219 220$(OUTPUT)test-libunwind-debug-frame.bin: 221 $(BUILD) -lelf -llzma 222$(OUTPUT)test-libunwind-x86.bin: 223 $(BUILD) -lelf -llzma -lunwind-x86 224 225$(OUTPUT)test-libunwind-x86_64.bin: 226 $(BUILD) -lelf -llzma -lunwind-x86_64 227 228$(OUTPUT)test-libunwind-arm.bin: 229 $(BUILD) -lelf -llzma -lunwind-arm 230 231$(OUTPUT)test-libunwind-aarch64.bin: 232 $(BUILD) -lelf -llzma -lunwind-aarch64 233 234$(OUTPUT)test-libunwind-debug-frame-arm.bin: 235 $(BUILD) -lelf -llzma -lunwind-arm 236 237$(OUTPUT)test-libunwind-debug-frame-aarch64.bin: 238 $(BUILD) -lelf -llzma -lunwind-aarch64 239 240$(OUTPUT)test-libaudit.bin: 241 $(BUILD) -laudit 242 243$(OUTPUT)test-libslang.bin: 244 $(BUILD) -lslang 245 246$(OUTPUT)test-libslang-include-subdir.bin: 247 $(BUILD) -lslang 248 249$(OUTPUT)test-libtraceevent.bin: 250 $(BUILD) -ltraceevent 251 252$(OUTPUT)test-libcpupower.bin: 253 $(BUILD) -lcpupower 254 255$(OUTPUT)test-libtracefs.bin: 256 $(BUILD) $(shell $(PKG_CONFIG) --cflags libtracefs 2>/dev/null) -ltracefs 257 258$(OUTPUT)test-libcrypto.bin: 259 $(BUILD) -lcrypto 260 261$(OUTPUT)test-gtk2.bin: 262 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations 263 264$(OUTPUT)test-gtk2-infobar.bin: 265 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 266 267grep-libs = $(filter -l%,$(1)) 268strip-libs = $(filter-out -l%,$(1)) 269 270PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 271PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 272PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 273PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) 274FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 275 276ifeq ($(CC_NO_CLANG), 0) 277 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) 278 PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS)) 279 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) 280 FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro 281endif 282 283$(OUTPUT)test-libperl.bin: 284 $(BUILD) $(FLAGS_PERL_EMBED) 285 286$(OUTPUT)test-libpython.bin: 287 $(BUILD) $(FLAGS_PYTHON_EMBED) 288 289$(OUTPUT)test-libbfd.bin: 290 $(BUILD_BFD) 291 292$(OUTPUT)test-libbfd-buildid.bin: 293 $(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz 294 295$(OUTPUT)test-disassembler-four-args.bin: 296 $(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \ 297 $(BUILD_BFD) -lopcodes -liberty -lz 298 299$(OUTPUT)test-disassembler-init-styled.bin: 300 $(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \ 301 $(BUILD_BFD) -lopcodes -liberty -lz 302 303$(OUTPUT)test-reallocarray.bin: 304 $(BUILD) 305 306$(OUTPUT)test-libbfd-liberty.bin: 307 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty 308 309$(OUTPUT)test-libbfd-liberty-z.bin: 310 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz 311 312$(OUTPUT)test-cplus-demangle.bin: 313 $(BUILD) -liberty 314 315$(OUTPUT)test-cxa-demangle.bin: 316 $(BUILDXX) 317 318$(OUTPUT)test-backtrace.bin: 319 $(BUILD) 320 321$(OUTPUT)test-timerfd.bin: 322 $(BUILD) 323 324$(OUTPUT)test-libdw-dwarf-unwind.bin: 325 $(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind) 326 327$(OUTPUT)test-libbabeltrace.bin: 328 $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace) 329 330$(OUTPUT)test-libcapstone.bin: 331 $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone) 332 333$(OUTPUT)test-compile-32.bin: 334 $(CC) -m32 -o $@ test-compile.c 335 336$(OUTPUT)test-compile-x32.bin: 337 $(CC) -mx32 -o $@ test-compile.c 338 339$(OUTPUT)test-zlib.bin: 340 $(BUILD) -lz 341 342$(OUTPUT)test-lzma.bin: 343 $(BUILD) -llzma 344 345$(OUTPUT)test-get_cpuid.bin: 346 $(BUILD) 347 348$(OUTPUT)test-bpf.bin: 349 $(BUILD) 350 351$(OUTPUT)test-libbpf.bin: 352 $(BUILD) -lbpf 353 354$(OUTPUT)test-libbpf-btf__load_from_kernel_by_id.bin: 355 $(BUILD) -lbpf 356 357$(OUTPUT)test-libbpf-bpf_prog_load.bin: 358 $(BUILD) -lbpf 359 360$(OUTPUT)test-libbpf-bpf_map_create.bin: 361 $(BUILD) -lbpf 362 363$(OUTPUT)test-libbpf-bpf_object__next_program.bin: 364 $(BUILD) -lbpf 365 366$(OUTPUT)test-libbpf-bpf_object__next_map.bin: 367 $(BUILD) -lbpf 368 369$(OUTPUT)test-libbpf-bpf_program__set_insns.bin: 370 $(BUILD) -lbpf 371 372$(OUTPUT)test-libbpf-btf__raw_data.bin: 373 $(BUILD) -lbpf 374 375$(OUTPUT)test-sdt.bin: 376 $(BUILD) 377 378$(OUTPUT)test-cxx.bin: 379 $(BUILDXX) -std=gnu++11 380 381$(OUTPUT)test-gettid.bin: 382 $(BUILD) 383 384$(OUTPUT)test-jvmti.bin: 385 $(BUILD) 386 387$(OUTPUT)test-jvmti-cmlr.bin: 388 $(BUILD) 389 390$(OUTPUT)test-llvm.bin: 391 $(BUILDXX) -std=gnu++17 \ 392 -I$(shell $(LLVM_CONFIG) --includedir) \ 393 -L$(shell $(LLVM_CONFIG) --libdir) \ 394 $(shell $(LLVM_CONFIG) --libs Core BPF) \ 395 $(shell $(LLVM_CONFIG) --system-libs) \ 396 > $(@:.bin=.make.output) 2>&1 397 398$(OUTPUT)test-llvm-perf.bin: 399 $(BUILDXX) -std=gnu++17 \ 400 -I$(shell $(LLVM_CONFIG) --includedir) \ 401 -L$(shell $(LLVM_CONFIG) --libdir) \ 402 $(shell $(LLVM_CONFIG) --libs Core BPF) \ 403 $(shell $(LLVM_CONFIG) --system-libs) \ 404 > $(@:.bin=.make.output) 2>&1 405 406$(OUTPUT)test-clang.bin: 407 $(BUILDXX) -std=gnu++17 \ 408 -I$(shell $(LLVM_CONFIG) --includedir) \ 409 -L$(shell $(LLVM_CONFIG) --libdir) \ 410 -Wl,--start-group -lclang-cpp -Wl,--end-group \ 411 $(shell $(LLVM_CONFIG) --libs Core option) \ 412 $(shell $(LLVM_CONFIG) --system-libs) \ 413 > $(@:.bin=.make.output) 2>&1 414 415-include $(OUTPUT)*.d 416 417$(OUTPUT)test-libaio.bin: 418 $(BUILD) -lrt 419 420$(OUTPUT)test-libzstd.bin: 421 $(BUILD) -lzstd 422 423$(OUTPUT)test-clang-bpf-co-re.bin: 424 $(CLANG) -S -g --target=bpf -o - $(patsubst %.bin,%.c,$(@F)) | \ 425 grep BTF_KIND_VAR 426 427$(OUTPUT)test-file-handle.bin: 428 $(BUILD) 429 430$(OUTPUT)test-libpfm4.bin: 431 $(BUILD) -lpfm 432 433############################### 434 435clean: 436 rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output) 437