1 2ifeq ($(src-perf),) 3src-perf := $(srctree)/tools/perf 4endif 5 6ifeq ($(obj-perf),) 7obj-perf := $(OUTPUT) 8endif 9 10ifneq ($(obj-perf),) 11obj-perf := $(abspath $(obj-perf))/ 12endif 13 14$(shell printf "" > $(OUTPUT).config-detected) 15detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) 16detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) 17 18CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS) 19 20include $(srctree)/tools/scripts/Makefile.arch 21 22$(call detected_var,SRCARCH) 23 24NO_PERF_REGS := 1 25NO_SYSCALL_TABLE := 1 26 27# Additional ARCH settings for ppc 28ifeq ($(SRCARCH),powerpc) 29 NO_PERF_REGS := 0 30 NO_SYSCALL_TABLE := 0 31 CFLAGS += -I$(OUTPUT)arch/powerpc/include/generated 32 LIBUNWIND_LIBS := -lunwind -lunwind-ppc64 33endif 34 35# Additional ARCH settings for x86 36ifeq ($(SRCARCH),x86) 37 $(call detected,CONFIG_X86) 38 ifeq (${IS_64_BIT}, 1) 39 NO_SYSCALL_TABLE := 0 40 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT -I$(OUTPUT)arch/x86/include/generated 41 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S 42 LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma 43 $(call detected,CONFIG_X86_64) 44 else 45 LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind 46 endif 47 NO_PERF_REGS := 0 48endif 49 50ifeq ($(SRCARCH),arm) 51 NO_PERF_REGS := 0 52 LIBUNWIND_LIBS = -lunwind -lunwind-arm 53endif 54 55ifeq ($(SRCARCH),arm64) 56 NO_PERF_REGS := 0 57 NO_SYSCALL_TABLE := 0 58 CFLAGS += -I$(OUTPUT)arch/arm64/include/generated 59 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64 60endif 61 62ifeq ($(SRCARCH),csky) 63 NO_PERF_REGS := 0 64endif 65 66ifeq ($(ARCH),s390) 67 NO_PERF_REGS := 0 68 NO_SYSCALL_TABLE := 0 69 CFLAGS += -fPIC -I$(OUTPUT)arch/s390/include/generated 70endif 71 72ifeq ($(NO_PERF_REGS),0) 73 $(call detected,CONFIG_PERF_REGS) 74endif 75 76ifneq ($(NO_SYSCALL_TABLE),1) 77 CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT 78endif 79 80# So far there's only x86 and arm libdw unwind support merged in perf. 81# Disable it on all other architectures in case libdw unwind 82# support is detected in system. Add supported architectures 83# to the check. 84ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky)) 85 NO_LIBDW_DWARF_UNWIND := 1 86endif 87 88ifeq ($(LIBUNWIND_LIBS),) 89 NO_LIBUNWIND := 1 90endif 91# 92# For linking with debug library, run like: 93# 94# make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/ 95# 96 97libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code)) 98define libunwind_arch_set_flags_code 99 FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include 100 FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib 101endef 102 103ifdef LIBUNWIND_DIR 104 LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include 105 LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib 106 LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64 107 $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch))) 108endif 109 110# Set per-feature check compilation flags 111FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS) 112FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) 113FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS) 114FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) 115 116FEATURE_CHECK_LDFLAGS-libunwind-arm = -lunwind -lunwind-arm 117FEATURE_CHECK_LDFLAGS-libunwind-aarch64 = -lunwind -lunwind-aarch64 118FEATURE_CHECK_LDFLAGS-libunwind-x86 = -lunwind -llzma -lunwind-x86 119FEATURE_CHECK_LDFLAGS-libunwind-x86_64 = -lunwind -llzma -lunwind-x86_64 120 121FEATURE_CHECK_LDFLAGS-libcrypto = -lcrypto 122 123ifdef CSINCLUDES 124 LIBOPENCSD_CFLAGS := -I$(CSINCLUDES) 125endif 126OPENCSDLIBS := -lopencsd_c_api -lopencsd 127ifdef CSLIBS 128 LIBOPENCSD_LDFLAGS := -L$(CSLIBS) 129endif 130FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS) 131FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS) 132 133ifeq ($(NO_PERF_REGS),0) 134 CFLAGS += -DHAVE_PERF_REGS_SUPPORT 135endif 136 137# for linking with debug library, run like: 138# make DEBUG=1 LIBDW_DIR=/opt/libdw/ 139ifdef LIBDW_DIR 140 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include 141 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib 142endif 143DWARFLIBS := -ldw 144ifeq ($(findstring -static,${LDFLAGS}),-static) 145 DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2 146endif 147FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS) 148FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS) 149 150# for linking with debug library, run like: 151# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/ 152ifdef LIBBABELTRACE_DIR 153 LIBBABELTRACE_CFLAGS := -I$(LIBBABELTRACE_DIR)/include 154 LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib 155endif 156FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS) 157FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf 158 159ifdef LIBZSTD_DIR 160 LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib 161 LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib 162endif 163FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS) 164FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS) 165 166FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi 167# include ARCH specific config 168-include $(src-perf)/arch/$(SRCARCH)/Makefile 169 170ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET 171 CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET 172endif 173 174include $(srctree)/tools/scripts/utilities.mak 175 176ifeq ($(call get-executable,$(FLEX)),) 177 dummy := $(error Error: $(FLEX) is missing on this system, please install it) 178endif 179 180ifeq ($(call get-executable,$(BISON)),) 181 dummy := $(error Error: $(BISON) is missing on this system, please install it) 182endif 183 184# Treat warnings as errors unless directed not to 185ifneq ($(WERROR),0) 186 CFLAGS += -Werror 187 CXXFLAGS += -Werror 188endif 189 190ifndef DEBUG 191 DEBUG := 0 192endif 193 194ifeq ($(DEBUG),0) 195ifeq ($(CC_NO_CLANG), 0) 196 CFLAGS += -O3 197else 198 CFLAGS += -O6 199endif 200endif 201 202ifdef PARSER_DEBUG 203 PARSER_DEBUG_BISON := -t 204 PARSER_DEBUG_FLEX := -d 205 CFLAGS += -DPARSER_DEBUG 206 $(call detected_var,PARSER_DEBUG_BISON) 207 $(call detected_var,PARSER_DEBUG_FLEX) 208endif 209 210# Try different combinations to accommodate systems that only have 211# python[2][-config] in weird combinations but always preferring 212# python2 and python2-config as per pep-0394. If we catch a 213# python[-config] in version 3, the version check will kill it. 214PYTHON2 := $(if $(call get-executable,python2),python2,python) 215override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2)) 216PYTHON2_CONFIG := \ 217 $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config) 218override PYTHON_CONFIG := \ 219 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG)) 220 221grep-libs = $(filter -l%,$(1)) 222strip-libs = $(filter-out -l%,$(1)) 223 224PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG)) 225 226ifdef PYTHON_CONFIG 227 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null) 228 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS)) 229 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil 230 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null) 231 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) 232endif 233 234FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS) 235FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS) 236FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS) 237FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS) 238 239FEATURE_CHECK_LDFLAGS-libaio = -lrt 240 241FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl 242 243CFLAGS += -fno-omit-frame-pointer 244CFLAGS += -ggdb3 245CFLAGS += -funwind-tables 246CFLAGS += -Wall 247CFLAGS += -Wextra 248CFLAGS += -std=gnu99 249 250CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti 251CXXFLAGS += -Wall 252CXXFLAGS += -fno-omit-frame-pointer 253CXXFLAGS += -ggdb3 254CXXFLAGS += -funwind-tables 255CXXFLAGS += -Wno-strict-aliasing 256 257# Enforce a non-executable stack, as we may regress (again) in the future by 258# adding assembler files missing the .GNU-stack linker note. 259LDFLAGS += -Wl,-z,noexecstack 260 261EXTLIBS = -lpthread -lrt -lm -ldl 262 263ifeq ($(FEATURES_DUMP),) 264include $(srctree)/tools/build/Makefile.feature 265else 266include $(FEATURES_DUMP) 267endif 268 269ifeq ($(feature-stackprotector-all), 1) 270 CFLAGS += -fstack-protector-all 271endif 272 273ifeq ($(DEBUG),0) 274 ifeq ($(feature-fortify-source), 1) 275 CFLAGS += -D_FORTIFY_SOURCE=2 276 endif 277endif 278 279INC_FLAGS += -I$(src-perf)/util/include 280INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include 281INC_FLAGS += -I$(srctree)/tools/include/uapi 282INC_FLAGS += -I$(srctree)/tools/include/ 283INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi 284INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/ 285INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/ 286 287# $(obj-perf) for generated common-cmds.h 288# $(obj-perf)/util for generated bison/flex headers 289ifneq ($(OUTPUT),) 290INC_FLAGS += -I$(obj-perf)/util 291INC_FLAGS += -I$(obj-perf) 292endif 293 294INC_FLAGS += -I$(src-perf)/util 295INC_FLAGS += -I$(src-perf) 296INC_FLAGS += -I$(srctree)/tools/lib/ 297 298CFLAGS += $(INC_FLAGS) 299CXXFLAGS += $(INC_FLAGS) 300 301CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE 302 303ifeq ($(feature-sync-compare-and-swap), 1) 304 CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT 305endif 306 307ifeq ($(feature-pthread-attr-setaffinity-np), 1) 308 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP 309endif 310 311ifeq ($(feature-pthread-barrier), 1) 312 CFLAGS += -DHAVE_PTHREAD_BARRIER 313endif 314 315ifndef NO_BIONIC 316 $(call feature_check,bionic) 317 ifeq ($(feature-bionic), 1) 318 BIONIC := 1 319 CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE 320 CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE 321 EXTLIBS := $(filter-out -lrt,$(EXTLIBS)) 322 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS)) 323 endif 324endif 325 326ifeq ($(feature-eventfd), 1) 327 CFLAGS += -DHAVE_EVENTFD 328endif 329 330ifeq ($(feature-get_current_dir_name), 1) 331 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME 332endif 333 334ifdef NO_LIBELF 335 NO_DWARF := 1 336 NO_DEMANGLE := 1 337 NO_LIBUNWIND := 1 338 NO_LIBDW_DWARF_UNWIND := 1 339 NO_LIBBPF := 1 340 NO_JVMTI := 1 341else 342 ifeq ($(feature-libelf), 0) 343 ifeq ($(feature-glibc), 1) 344 LIBC_SUPPORT := 1 345 endif 346 ifeq ($(BIONIC),1) 347 LIBC_SUPPORT := 1 348 endif 349 ifeq ($(LIBC_SUPPORT),1) 350 msg := $(warning No libelf found. Disables 'probe' tool, jvmti and BPF support in 'perf record'. Please install libelf-dev, libelf-devel or elfutils-libelf-devel); 351 352 NO_LIBELF := 1 353 NO_DWARF := 1 354 NO_DEMANGLE := 1 355 NO_LIBUNWIND := 1 356 NO_LIBDW_DWARF_UNWIND := 1 357 NO_LIBBPF := 1 358 NO_JVMTI := 1 359 else 360 ifneq ($(filter s% -static%,$(LDFLAGS),),) 361 msg := $(error No static glibc found, please install glibc-static); 362 else 363 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]); 364 endif 365 endif 366 else 367 ifndef NO_LIBDW_DWARF_UNWIND 368 ifneq ($(feature-libdw-dwarf-unwind),1) 369 NO_LIBDW_DWARF_UNWIND := 1 370 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR); 371 endif 372 endif 373 ifneq ($(feature-dwarf), 1) 374 ifndef NO_DWARF 375 msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev); 376 NO_DWARF := 1 377 endif 378 else 379 ifneq ($(feature-dwarf_getlocations), 1) 380 msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157); 381 else 382 CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT 383 endif # dwarf_getlocations 384 endif # Dwarf support 385 endif # libelf support 386endif # NO_LIBELF 387 388ifeq ($(feature-glibc), 1) 389 CFLAGS += -DHAVE_GLIBC_SUPPORT 390endif 391 392ifeq ($(feature-libaio), 1) 393 ifndef NO_AIO 394 CFLAGS += -DHAVE_AIO_SUPPORT 395 endif 396endif 397 398ifdef NO_DWARF 399 NO_LIBDW_DWARF_UNWIND := 1 400endif 401 402ifeq ($(feature-sched_getcpu), 1) 403 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT 404endif 405 406ifeq ($(feature-setns), 1) 407 CFLAGS += -DHAVE_SETNS_SUPPORT 408 $(call detected,CONFIG_SETNS) 409endif 410 411ifdef CORESIGHT 412 $(call feature_check,libopencsd) 413 ifeq ($(feature-libopencsd), 1) 414 CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS) 415 LDFLAGS += $(LIBOPENCSD_LDFLAGS) 416 EXTLIBS += $(OPENCSDLIBS) 417 $(call detected,CONFIG_LIBOPENCSD) 418 ifdef CSTRACE_RAW 419 CFLAGS += -DCS_DEBUG_RAW 420 ifeq (${CSTRACE_RAW}, packed) 421 CFLAGS += -DCS_RAW_PACKED 422 endif 423 endif 424 endif 425endif 426 427ifndef NO_LIBELF 428 CFLAGS += -DHAVE_LIBELF_SUPPORT 429 EXTLIBS += -lelf 430 $(call detected,CONFIG_LIBELF) 431 432 ifeq ($(feature-libelf-mmap), 1) 433 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT 434 endif 435 436 ifeq ($(feature-libelf-getphdrnum), 1) 437 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT 438 endif 439 440 ifeq ($(feature-libelf-gelf_getnote), 1) 441 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT 442 else 443 msg := $(warning gelf_getnote() not found on libelf, SDT support disabled); 444 endif 445 446 ifeq ($(feature-libelf-getshdrstrndx), 1) 447 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT 448 endif 449 450 ifndef NO_DWARF 451 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined) 452 msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled); 453 NO_DWARF := 1 454 else 455 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS) 456 LDFLAGS += $(LIBDW_LDFLAGS) 457 EXTLIBS += ${DWARFLIBS} 458 $(call detected,CONFIG_DWARF) 459 endif # PERF_HAVE_DWARF_REGS 460 endif # NO_DWARF 461 462 ifndef NO_LIBBPF 463 ifeq ($(feature-bpf), 1) 464 CFLAGS += -DHAVE_LIBBPF_SUPPORT 465 $(call detected,CONFIG_LIBBPF) 466 endif 467 468 ifndef NO_DWARF 469 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET 470 CFLAGS += -DHAVE_BPF_PROLOGUE 471 $(call detected,CONFIG_BPF_PROLOGUE) 472 else 473 msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset()); 474 endif 475 else 476 msg := $(warning DWARF support is off, BPF prologue is disabled); 477 endif 478 479 endif # NO_LIBBPF 480endif # NO_LIBELF 481 482ifndef NO_SDT 483 ifneq ($(feature-sdt), 1) 484 msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev); 485 NO_SDT := 1; 486 else 487 CFLAGS += -DHAVE_SDT_EVENT 488 $(call detected,CONFIG_SDT_EVENT) 489 endif 490endif 491 492ifdef PERF_HAVE_JITDUMP 493 ifndef NO_LIBELF 494 $(call detected,CONFIG_JITDUMP) 495 CFLAGS += -DHAVE_JITDUMP 496 endif 497endif 498 499ifeq ($(SRCARCH),powerpc) 500 ifndef NO_DWARF 501 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX 502 endif 503endif 504 505ifndef NO_LIBUNWIND 506 have_libunwind := 507 508 $(call feature_check,libunwind-x86) 509 ifeq ($(feature-libunwind-x86), 1) 510 $(call detected,CONFIG_LIBUNWIND_X86) 511 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT 512 LDFLAGS += -lunwind-x86 513 EXTLIBS_LIBUNWIND += -lunwind-x86 514 have_libunwind = 1 515 endif 516 517 $(call feature_check,libunwind-aarch64) 518 ifeq ($(feature-libunwind-aarch64), 1) 519 $(call detected,CONFIG_LIBUNWIND_AARCH64) 520 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT 521 LDFLAGS += -lunwind-aarch64 522 EXTLIBS_LIBUNWIND += -lunwind-aarch64 523 have_libunwind = 1 524 $(call feature_check,libunwind-debug-frame-aarch64) 525 ifneq ($(feature-libunwind-debug-frame-aarch64), 1) 526 msg := $(warning No debug_frame support found in libunwind-aarch64); 527 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64 528 endif 529 endif 530 531 ifneq ($(feature-libunwind), 1) 532 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR); 533 NO_LOCAL_LIBUNWIND := 1 534 else 535 have_libunwind := 1 536 $(call detected,CONFIG_LOCAL_LIBUNWIND) 537 endif 538 539 ifneq ($(have_libunwind), 1) 540 NO_LIBUNWIND := 1 541 endif 542else 543 NO_LOCAL_LIBUNWIND := 1 544endif 545 546ifndef NO_LIBBPF 547 ifneq ($(feature-bpf), 1) 548 msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.) 549 NO_LIBBPF := 1 550 endif 551endif 552 553dwarf-post-unwind := 1 554dwarf-post-unwind-text := BUG 555 556# setup DWARF post unwinder 557ifdef NO_LIBUNWIND 558 ifdef NO_LIBDW_DWARF_UNWIND 559 msg := $(warning Disabling post unwind, no support found.); 560 dwarf-post-unwind := 0 561 else 562 dwarf-post-unwind-text := libdw 563 $(call detected,CONFIG_LIBDW_DWARF_UNWIND) 564 endif 565else 566 dwarf-post-unwind-text := libunwind 567 $(call detected,CONFIG_LIBUNWIND) 568 # Enable libunwind support by default. 569 ifndef NO_LIBDW_DWARF_UNWIND 570 NO_LIBDW_DWARF_UNWIND := 1 571 endif 572endif 573 574ifeq ($(dwarf-post-unwind),1) 575 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT 576 $(call detected,CONFIG_DWARF_UNWIND) 577else 578 NO_DWARF_UNWIND := 1 579endif 580 581ifndef NO_LOCAL_LIBUNWIND 582 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64)) 583 $(call feature_check,libunwind-debug-frame) 584 ifneq ($(feature-libunwind-debug-frame), 1) 585 msg := $(warning No debug_frame support found in libunwind); 586 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 587 endif 588 else 589 # non-ARM has no dwarf_find_debug_frame() function: 590 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 591 endif 592 EXTLIBS += $(LIBUNWIND_LIBS) 593 LDFLAGS += $(LIBUNWIND_LIBS) 594endif 595ifeq ($(findstring -static,${LDFLAGS}),-static) 596 # gcc -static links libgcc_eh which contans piece of libunwind 597 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition 598endif 599 600ifndef NO_LIBUNWIND 601 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT 602 CFLAGS += $(LIBUNWIND_CFLAGS) 603 LDFLAGS += $(LIBUNWIND_LDFLAGS) 604 EXTLIBS += $(EXTLIBS_LIBUNWIND) 605endif 606 607ifeq ($(NO_SYSCALL_TABLE),0) 608 $(call detected,CONFIG_TRACE) 609else 610 ifndef NO_LIBAUDIT 611 ifneq ($(feature-libaudit), 1) 612 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev); 613 NO_LIBAUDIT := 1 614 else 615 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT 616 EXTLIBS += -laudit 617 $(call detected,CONFIG_TRACE) 618 endif 619 endif 620endif 621 622ifndef NO_LIBCRYPTO 623 ifneq ($(feature-libcrypto), 1) 624 msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev); 625 NO_LIBCRYPTO := 1 626 else 627 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT 628 EXTLIBS += -lcrypto 629 $(call detected,CONFIG_CRYPTO) 630 endif 631endif 632 633ifdef NO_NEWT 634 NO_SLANG=1 635endif 636 637ifndef NO_SLANG 638 ifneq ($(feature-libslang), 1) 639 msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev); 640 NO_SLANG := 1 641 else 642 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h 643 CFLAGS += -I/usr/include/slang 644 CFLAGS += -DHAVE_SLANG_SUPPORT 645 EXTLIBS += -lslang 646 $(call detected,CONFIG_SLANG) 647 endif 648endif 649 650ifndef NO_GTK2 651 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 652 ifneq ($(feature-gtk2), 1) 653 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev); 654 NO_GTK2 := 1 655 else 656 ifeq ($(feature-gtk2-infobar), 1) 657 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT 658 endif 659 CFLAGS += -DHAVE_GTK2_SUPPORT 660 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null) 661 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null) 662 EXTLIBS += -ldl 663 endif 664endif 665 666ifdef NO_LIBPERL 667 CFLAGS += -DNO_LIBPERL 668else 669 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 670 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 671 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 672 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) 673 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) 674 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) 675 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 676 677 ifneq ($(feature-libperl), 1) 678 CFLAGS += -DNO_LIBPERL 679 NO_LIBPERL := 1 680 msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev); 681 else 682 LDFLAGS += $(PERL_EMBED_LDFLAGS) 683 EXTLIBS += $(PERL_EMBED_LIBADD) 684 CFLAGS += -DHAVE_LIBPERL_SUPPORT 685 $(call detected,CONFIG_LIBPERL) 686 endif 687endif 688 689ifeq ($(feature-timerfd), 1) 690 CFLAGS += -DHAVE_TIMERFD_SUPPORT 691else 692 msg := $(warning No timerfd support. Disables 'perf kvm stat live'); 693endif 694 695disable-python = $(eval $(disable-python_code)) 696define disable-python_code 697 CFLAGS += -DNO_LIBPYTHON 698 $(warning $1) 699 NO_LIBPYTHON := 1 700endef 701 702ifdef NO_LIBPYTHON 703 $(call disable-python,Python support disabled by user) 704else 705 706 ifndef PYTHON 707 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev) 708 else 709 PYTHON_WORD := $(call shell-wordify,$(PYTHON)) 710 711 ifndef PYTHON_CONFIG 712 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev) 713 else 714 715 ifneq ($(feature-libpython), 1) 716 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev) 717 else 718 LDFLAGS += $(PYTHON_EMBED_LDFLAGS) 719 EXTLIBS += $(PYTHON_EMBED_LIBADD) 720 LANG_BINDINGS += $(obj-perf)python/perf.so 721 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT 722 $(call detected,CONFIG_LIBPYTHON) 723 endif 724 endif 725 endif 726endif 727 728ifeq ($(feature-libbfd), 1) 729 EXTLIBS += -lbfd -lopcodes 730else 731 # we are on a system that requires -liberty and (maybe) -lz 732 # to link against -lbfd; test each case individually here 733 734 # call all detections now so we get correct 735 # status in VF output 736 $(call feature_check,libbfd-liberty) 737 $(call feature_check,libbfd-liberty-z) 738 739 ifeq ($(feature-libbfd-liberty), 1) 740 EXTLIBS += -lbfd -lopcodes -liberty 741 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl 742 else 743 ifeq ($(feature-libbfd-liberty-z), 1) 744 EXTLIBS += -lbfd -lopcodes -liberty -lz 745 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl 746 endif 747 endif 748 $(call feature_check,disassembler-four-args) 749endif 750 751ifdef NO_DEMANGLE 752 CFLAGS += -DNO_DEMANGLE 753else 754 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT 755 EXTLIBS += -liberty 756 else 757 ifeq ($(filter -liberty,$(EXTLIBS)),) 758 $(call feature_check,cplus-demangle) 759 760 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT 761 # or any of 'bfd iberty z' trinity 762 ifeq ($(feature-cplus-demangle), 1) 763 EXTLIBS += -liberty 764 else 765 msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling) 766 CFLAGS += -DNO_DEMANGLE 767 endif 768 endif 769 endif 770 771 ifneq ($(filter -liberty,$(EXTLIBS)),) 772 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 773 endif 774endif 775 776ifneq ($(filter -lbfd,$(EXTLIBS)),) 777 CFLAGS += -DHAVE_LIBBFD_SUPPORT 778endif 779 780ifndef NO_ZLIB 781 ifeq ($(feature-zlib), 1) 782 CFLAGS += -DHAVE_ZLIB_SUPPORT 783 EXTLIBS += -lz 784 $(call detected,CONFIG_ZLIB) 785 else 786 NO_ZLIB := 1 787 endif 788endif 789 790ifndef NO_LZMA 791 ifeq ($(feature-lzma), 1) 792 CFLAGS += -DHAVE_LZMA_SUPPORT 793 EXTLIBS += -llzma 794 $(call detected,CONFIG_LZMA) 795 else 796 msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev); 797 NO_LZMA := 1 798 endif 799endif 800 801ifndef NO_LIBZSTD 802 ifeq ($(feature-libzstd), 1) 803 CFLAGS += -DHAVE_ZSTD_SUPPORT 804 CFLAGS += $(LIBZSTD_CFLAGS) 805 LDFLAGS += $(LIBZSTD_LDFLAGS) 806 EXTLIBS += -lzstd 807 $(call detected,CONFIG_ZSTD) 808 else 809 msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR); 810 NO_LIBZSTD := 1 811 endif 812endif 813 814ifndef NO_BACKTRACE 815 ifeq ($(feature-backtrace), 1) 816 CFLAGS += -DHAVE_BACKTRACE_SUPPORT 817 endif 818endif 819 820ifndef NO_LIBNUMA 821 ifeq ($(feature-libnuma), 0) 822 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev); 823 NO_LIBNUMA := 1 824 else 825 ifeq ($(feature-numa_num_possible_cpus), 0) 826 msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8); 827 NO_LIBNUMA := 1 828 else 829 CFLAGS += -DHAVE_LIBNUMA_SUPPORT 830 EXTLIBS += -lnuma 831 $(call detected,CONFIG_NUMA) 832 endif 833 endif 834endif 835 836ifdef HAVE_KVM_STAT_SUPPORT 837 CFLAGS += -DHAVE_KVM_STAT_SUPPORT 838endif 839 840ifeq ($(feature-disassembler-four-args), 1) 841 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 842endif 843 844ifeq (${IS_64_BIT}, 1) 845 ifndef NO_PERF_READ_VDSO32 846 $(call feature_check,compile-32) 847 ifeq ($(feature-compile-32), 1) 848 CFLAGS += -DHAVE_PERF_READ_VDSO32 849 else 850 NO_PERF_READ_VDSO32 := 1 851 endif 852 endif 853 ifneq ($(SRCARCH), x86) 854 NO_PERF_READ_VDSOX32 := 1 855 endif 856 ifndef NO_PERF_READ_VDSOX32 857 $(call feature_check,compile-x32) 858 ifeq ($(feature-compile-x32), 1) 859 CFLAGS += -DHAVE_PERF_READ_VDSOX32 860 else 861 NO_PERF_READ_VDSOX32 := 1 862 endif 863 endif 864else 865 NO_PERF_READ_VDSO32 := 1 866 NO_PERF_READ_VDSOX32 := 1 867endif 868 869ifndef NO_LIBBABELTRACE 870 $(call feature_check,libbabeltrace) 871 ifeq ($(feature-libbabeltrace), 1) 872 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS) 873 LDFLAGS += $(LIBBABELTRACE_LDFLAGS) 874 EXTLIBS += -lbabeltrace-ctf 875 $(call detected,CONFIG_LIBBABELTRACE) 876 else 877 msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev); 878 endif 879endif 880 881ifndef NO_AUXTRACE 882 ifeq ($(SRCARCH),x86) 883 ifeq ($(feature-get_cpuid), 0) 884 msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc); 885 NO_AUXTRACE := 1 886 endif 887 endif 888 ifndef NO_AUXTRACE 889 $(call detected,CONFIG_AUXTRACE) 890 CFLAGS += -DHAVE_AUXTRACE_SUPPORT 891 endif 892endif 893 894ifndef NO_JVMTI 895 ifneq (,$(wildcard /usr/sbin/update-java-alternatives)) 896 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}') 897 else 898 ifneq (,$(wildcard /usr/sbin/alternatives)) 899 JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' -f 5 | sed 's%/jre/bin/java.%%g') 900 endif 901 endif 902 ifndef JDIR 903 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory) 904 NO_JVMTI := 1 905 endif 906endif 907 908ifndef NO_JVMTI 909 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux 910 $(call feature_check,jvmti) 911 ifeq ($(feature-jvmti), 1) 912 $(call detected_var,JDIR) 913 ifndef NO_JVMTI_CMLR 914 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti) 915 $(call feature_check,jvmti-cmlr) 916 ifeq ($(feature-jvmti-cmlr), 1) 917 CFLAGS += -DHAVE_JVMTI_CMLR 918 endif 919 endif # NO_JVMTI_CMLR 920 else 921 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel) 922 NO_JVMTI := 1 923 endif 924endif 925 926USE_CXX = 0 927USE_CLANGLLVM = 0 928ifdef LIBCLANGLLVM 929 $(call feature_check,cxx) 930 ifneq ($(feature-cxx), 1) 931 msg := $(warning No g++ found, disable clang and llvm support. Please install g++) 932 else 933 $(call feature_check,llvm) 934 $(call feature_check,llvm-version) 935 ifneq ($(feature-llvm), 1) 936 msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0)) 937 else 938 $(call feature_check,clang) 939 ifneq ($(feature-clang), 1) 940 msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0)) 941 else 942 CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT 943 CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir) 944 $(call detected,CONFIG_CXX) 945 $(call detected,CONFIG_CLANGLLVM) 946 USE_CXX = 1 947 USE_LLVM = 1 948 USE_CLANG = 1 949 ifneq ($(feature-llvm-version),1) 950 msg := $(warning This version of LLVM is not tested. May cause build errors) 951 endif 952 endif 953 endif 954 endif 955endif 956 957# Among the variables below, these: 958# perfexecdir 959# perf_include_dir 960# perf_examples_dir 961# template_dir 962# mandir 963# infodir 964# htmldir 965# ETC_PERFCONFIG (but not sysconfdir) 966# can be specified as a relative path some/where/else; 967# this is interpreted as relative to $(prefix) and "perf" at 968# runtime figures out where they are based on the path to the executable. 969# This can help installing the suite in a relocatable way. 970 971# Make the path relative to DESTDIR, not to prefix 972ifndef DESTDIR 973prefix ?= $(HOME) 974endif 975bindir_relative = bin 976bindir = $(abspath $(prefix)/$(bindir_relative)) 977mandir = share/man 978infodir = share/info 979perfexecdir = libexec/perf-core 980perf_include_dir = lib/perf/include 981perf_examples_dir = lib/perf/examples 982sharedir = $(prefix)/share 983template_dir = share/perf-core/templates 984STRACE_GROUPS_DIR = share/perf-core/strace/groups 985htmldir = share/doc/perf-doc 986tipdir = share/doc/perf-tip 987srcdir = $(srctree)/tools/perf 988ifeq ($(prefix),/usr) 989sysconfdir = /etc 990ETC_PERFCONFIG = $(sysconfdir)/perfconfig 991else 992sysconfdir = $(prefix)/etc 993ETC_PERFCONFIG = etc/perfconfig 994endif 995ifndef lib 996ifeq ($(SRCARCH)$(IS_64_BIT), x861) 997lib = lib64 998else 999lib = lib 1000endif 1001endif # lib 1002libdir = $(prefix)/$(lib) 1003 1004# Shell quote (do not use $(call) to accommodate ancient setups); 1005ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG)) 1006STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR)) 1007DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) 1008bindir_SQ = $(subst ','\'',$(bindir)) 1009mandir_SQ = $(subst ','\'',$(mandir)) 1010infodir_SQ = $(subst ','\'',$(infodir)) 1011perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) 1012perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir)) 1013perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir)) 1014template_dir_SQ = $(subst ','\'',$(template_dir)) 1015htmldir_SQ = $(subst ','\'',$(htmldir)) 1016tipdir_SQ = $(subst ','\'',$(tipdir)) 1017prefix_SQ = $(subst ','\'',$(prefix)) 1018sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) 1019libdir_SQ = $(subst ','\'',$(libdir)) 1020srcdir_SQ = $(subst ','\'',$(srcdir)) 1021 1022ifneq ($(filter /%,$(firstword $(perfexecdir))),) 1023perfexec_instdir = $(perfexecdir) 1024perf_include_instdir = $(perf_include_dir) 1025perf_examples_instdir = $(perf_examples_dir) 1026STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) 1027tip_instdir = $(tipdir) 1028else 1029perfexec_instdir = $(prefix)/$(perfexecdir) 1030perf_include_instdir = $(prefix)/$(perf_include_dir) 1031perf_examples_instdir = $(prefix)/$(perf_examples_dir) 1032STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) 1033tip_instdir = $(prefix)/$(tipdir) 1034endif 1035perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) 1036perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir)) 1037perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir)) 1038STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) 1039tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) 1040 1041# If we install to $(HOME) we keep the traceevent default: 1042# $(HOME)/.traceevent/plugins 1043# Otherwise we install plugins into the global $(libdir). 1044ifdef DESTDIR 1045plugindir=$(libdir)/traceevent/plugins 1046plugindir_SQ= $(subst ','\'',$(plugindir)) 1047endif 1048 1049print_var = $(eval $(print_var_code)) $(info $(MSG)) 1050define print_var_code 1051 MSG = $(shell printf '...%30s: %s' $(1) $($(1))) 1052endef 1053 1054ifeq ($(VF),1) 1055 # Display EXTRA features which are detected manualy 1056 # from here with feature_check call and thus cannot 1057 # be partof global state output. 1058 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),)) 1059 $(call print_var,prefix) 1060 $(call print_var,bindir) 1061 $(call print_var,libdir) 1062 $(call print_var,sysconfdir) 1063 $(call print_var,LIBUNWIND_DIR) 1064 $(call print_var,LIBDW_DIR) 1065 $(call print_var,JDIR) 1066 1067 ifeq ($(dwarf-post-unwind),1) 1068 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) 1069 endif 1070 $(info ) 1071endif 1072 1073$(call detected_var,bindir_SQ) 1074$(call detected_var,PYTHON_WORD) 1075ifneq ($(OUTPUT),) 1076$(call detected_var,OUTPUT) 1077endif 1078$(call detected_var,htmldir_SQ) 1079$(call detected_var,infodir_SQ) 1080$(call detected_var,mandir_SQ) 1081$(call detected_var,ETC_PERFCONFIG_SQ) 1082$(call detected_var,STRACE_GROUPS_DIR_SQ) 1083$(call detected_var,prefix_SQ) 1084$(call detected_var,perfexecdir_SQ) 1085$(call detected_var,perf_include_dir_SQ) 1086$(call detected_var,perf_examples_dir_SQ) 1087$(call detected_var,tipdir_SQ) 1088$(call detected_var,srcdir_SQ) 1089$(call detected_var,LIBDIR) 1090$(call detected_var,GTK_CFLAGS) 1091$(call detected_var,PERL_EMBED_CCOPTS) 1092$(call detected_var,PYTHON_EMBED_CCOPTS) 1093