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