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