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