1# SPDX-License-Identifier: GPL-2.0-only 2 3ifeq ($(src-perf),) 4src-perf := $(srctree)/tools/perf 5endif 6 7ifeq ($(obj-perf),) 8obj-perf := $(OUTPUT) 9endif 10 11ifneq ($(obj-perf),) 12obj-perf := $(abspath $(obj-perf))/ 13endif 14 15$(shell printf "" > $(OUTPUT).config-detected) 16detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) 17detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) 18 19CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) 20HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) 21 22# This is required because the kernel is built with this and some of the code 23# borrowed from kernel headers depends on it, e.g. put_unaligned_*(). 24CFLAGS += -fno-strict-aliasing 25 26# Set target flag and options when using clang as compiler. 27ifeq ($(CC_NO_CLANG), 0) 28 CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi 29 CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu 30 CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu 31 CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu 32 CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu 33 CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu 34 CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu 35 CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu 36 CLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu 37 38 # Default to host architecture if ARCH is not explicitly given. 39 ifeq ($(ARCH), $(HOSTARCH)) 40 CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple) 41 else 42 CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) 43 endif 44 45 ifeq ($(CROSS_COMPILE),) 46 ifeq ($(CLANG_TARGET_FLAGS),) 47 $(error Specify CROSS_COMPILE or add CLANG_TARGET_FLAGS for $(ARCH)) 48 else 49 CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS) 50 endif # CLANG_TARGET_FLAGS 51 else 52 CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) 53 endif # CROSS_COMPILE 54 55 CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as 56 CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as 57 58 # Enabled Wthread-safety analysis for clang builds. 59 CFLAGS += -Wthread-safety 60endif 61 62include $(srctree)/tools/scripts/Makefile.arch 63 64$(call detected_var,SRCARCH) 65 66CFLAGS += -I$(OUTPUT)arch/$(SRCARCH)/include/generated 67CFLAGS += -I$(OUTPUT)libperf/arch/$(SRCARCH)/include/generated/uapi 68 69# Additional ARCH settings for ppc 70ifeq ($(SRCARCH),powerpc) 71 ifndef NO_LIBUNWIND 72 LIBUNWIND_LIBS := -lunwind -lunwind-ppc64 73 endif 74endif 75 76# Additional ARCH settings for x86 77ifeq ($(SRCARCH),x86) 78 $(call detected,CONFIG_X86) 79 ifeq (${IS_64_BIT}, 1) 80 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT 81 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S 82 ifndef NO_LIBUNWIND 83 LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma 84 endif 85 $(call detected,CONFIG_X86_64) 86 else 87 ifndef NO_LIBUNWIND 88 LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind 89 endif 90 endif 91endif 92 93ifeq ($(SRCARCH),arm) 94 ifndef NO_LIBUNWIND 95 LIBUNWIND_LIBS = -lunwind -lunwind-arm 96 endif 97endif 98 99ifeq ($(SRCARCH),arm64) 100 ifndef NO_LIBUNWIND 101 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64 102 endif 103endif 104 105ifeq ($(SRCARCH),loongarch) 106 ifndef NO_LIBUNWIND 107 LIBUNWIND_LIBS = -lunwind -lunwind-loongarch64 108 endif 109endif 110 111ifeq ($(ARCH),s390) 112 CFLAGS += -fPIC 113endif 114 115ifeq ($(ARCH),mips) 116 ifndef NO_LIBUNWIND 117 LIBUNWIND_LIBS = -lunwind -lunwind-mips 118 endif 119endif 120 121# So far there's only x86 and arm libdw unwind support merged in perf. 122# Disable it on all other architectures in case libdw unwind 123# support is detected in system. Add supported architectures 124# to the check. 125ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky riscv loongarch)) 126 NO_LIBDW_DWARF_UNWIND := 1 127endif 128 129ifneq ($(LIBUNWIND),1) 130 NO_LIBUNWIND := 1 131endif 132 133ifeq ($(LIBUNWIND_LIBS),) 134 NO_LIBUNWIND := 1 135endif 136# 137# For linking with debug library, run like: 138# 139# make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/ 140# 141 142libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code)) 143define libunwind_arch_set_flags_code 144 FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include 145 FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib 146endef 147 148ifdef LIBUNWIND_DIR 149 LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include 150 LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib 151 LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64 loongarch 152 $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch))) 153endif 154 155ifndef NO_LIBUNWIND 156 # Set per-feature check compilation flags 157 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS) 158 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) 159 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS) 160 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) 161 162 FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm 163 FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64 164 FEATURE_CHECK_LDFLAGS-libunwind-x86 += -lunwind -llzma -lunwind-x86 165 FEATURE_CHECK_LDFLAGS-libunwind-x86_64 += -lunwind -llzma -lunwind-x86_64 166endif 167 168ifdef CSINCLUDES 169 LIBOPENCSD_CFLAGS := -I$(CSINCLUDES) 170endif 171OPENCSDLIBS := -lopencsd_c_api -lopencsd 172ifeq ($(findstring -static,${LDFLAGS}),-static) 173 OPENCSDLIBS += -lstdc++ 174endif 175ifdef CSLIBS 176 LIBOPENCSD_LDFLAGS := -L$(CSLIBS) 177endif 178FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS) 179FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS) 180 181# for linking with debug library, run like: 182# make DEBUG=1 LIBDW_DIR=/opt/libdw/ 183ifdef LIBDW_DIR 184 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include 185 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib 186endif 187DWARFLIBS := -ldw 188ifeq ($(findstring -static,${LDFLAGS}),-static) 189 DWARFLIBS += -lelf -lz -llzma -lbz2 190 191 LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw).0.0 192 LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION))) 193 LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION))) 194 195 # Elfutils merged libebl.a into libdw.a starting from version 0.177, 196 # Link libebl.a only if libdw is older than this version. 197 ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0) 198 DWARFLIBS += -lebl 199 endif 200 201 # Must put -ldl after -lebl for dependency 202 DWARFLIBS += -ldl 203endif 204FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS) 205FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS) 206 207# for linking with debug library, run like: 208# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/ 209ifdef LIBBABELTRACE_DIR 210 LIBBABELTRACE_CFLAGS := -I$(LIBBABELTRACE_DIR)/include 211 LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib 212endif 213FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS) 214FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf 215 216# for linking with debug library, run like: 217# make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/ 218ifdef LIBCAPSTONE_DIR 219 LIBCAPSTONE_CFLAGS := -I$(LIBCAPSTONE_DIR)/include 220 LIBCAPSTONE_LDFLAGS := -L$(LIBCAPSTONE_DIR)/ 221endif 222FEATURE_CHECK_CFLAGS-libcapstone := $(LIBCAPSTONE_CFLAGS) 223FEATURE_CHECK_LDFLAGS-libcapstone := $(LIBCAPSTONE_LDFLAGS) -lcapstone 224 225ifdef LIBZSTD_DIR 226 LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib 227 LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib 228endif 229FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS) 230FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS) 231 232# for linking with debug library, run like: 233# make DEBUG=1 PKG_CONFIG_PATH=/opt/libtraceevent/(lib|lib64)/pkgconfig 234 235ifneq ($(NO_LIBTRACEEVENT),1) 236 ifeq ($(call get-executable,$(PKG_CONFIG)),) 237 $(error Error: $(PKG_CONFIG) needed by libtraceevent is missing on this system, please install it) 238 endif 239endif 240 241FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi 242# include ARCH specific config 243-include $(src-perf)/arch/$(SRCARCH)/Makefile 244 245include $(srctree)/tools/scripts/utilities.mak 246 247ifeq ($(call get-executable,$(FLEX)),) 248 $(error Error: $(FLEX) is missing on this system, please install it) 249endif 250 251ifeq ($(call get-executable,$(BISON)),) 252 $(error Error: $(BISON) is missing on this system, please install it) 253endif 254 255ifneq ($(OUTPUT),) 256 ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1) 257 BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)= 258 endif 259endif 260 261# Treat warnings as errors unless directed not to 262ifneq ($(WERROR),0) 263 CORE_CFLAGS += -Werror 264 CXXFLAGS += -Werror 265 HOSTCFLAGS += -Werror 266endif 267 268ifndef DEBUG 269 DEBUG := 0 270endif 271 272ifeq ($(DEBUG),0) 273CORE_CFLAGS += -DNDEBUG=1 274CORE_CFLAGS += -O3 275else 276 CORE_CFLAGS += -g 277 CXXFLAGS += -g 278endif 279 280ifdef PARSER_DEBUG 281 PARSER_DEBUG_BISON := -t 282 PARSER_DEBUG_FLEX := -d 283 CFLAGS += -DPARSER_DEBUG 284 $(call detected_var,PARSER_DEBUG_BISON) 285 $(call detected_var,PARSER_DEBUG_FLEX) 286endif 287 288ifdef LTO 289 CORE_CFLAGS += -flto 290 CXXFLAGS += -flto 291endif 292 293# Try different combinations to accommodate systems that only have 294# python[2][3]-config in weird combinations in the following order of 295# priority from lowest to highest: 296# * python2-config as per pep-0394. 297# * python-config 298# * python3-config 299# * $(PYTHON)-config (If PYTHON is user supplied but PYTHON_CONFIG isn't) 300# 301PYTHON_AUTO := python-config 302PYTHON_AUTO := $(if $(call get-executable,python2-config),python2-config,$(PYTHON_AUTO)) 303PYTHON_AUTO := $(if $(call get-executable,python-config),python-config,$(PYTHON_AUTO)) 304PYTHON_AUTO := $(if $(call get-executable,python3-config),python3-config,$(PYTHON_AUTO)) 305 306# If PYTHON is defined but PYTHON_CONFIG isn't, then take $(PYTHON)-config as if it was the user 307# supplied value for PYTHON_CONFIG. Because it's "user supplied", error out if it doesn't exist. 308ifdef PYTHON 309 ifndef PYTHON_CONFIG 310 PYTHON_CONFIG_AUTO := $(call get-executable,$(PYTHON)-config) 311 PYTHON_CONFIG := $(if $(PYTHON_CONFIG_AUTO),$(PYTHON_CONFIG_AUTO),\ 312 $(call $(error $(PYTHON)-config not found))) 313 endif 314endif 315 316# Select either auto detected python and python-config or use user supplied values if they are 317# defined. get-executable-or-default fails with an error if the first argument is supplied but 318# doesn't exist. 319override PYTHON_CONFIG := $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON_AUTO)) 320override PYTHON := $(call get-executable-or-default,PYTHON,$(subst -config,,$(PYTHON_CONFIG))) 321 322grep-libs = $(filter -l%,$(1)) 323strip-libs = $(filter-out -l%,$(1)) 324 325PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG)) 326 327# Python 3.8 changed the output of `python-config --ldflags` to not include the 328# '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for 329# libpython fails if that flag is not included in LDFLAGS 330ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0) 331 PYTHON_CONFIG_LDFLAGS := --ldflags --embed 332else 333 PYTHON_CONFIG_LDFLAGS := --ldflags 334endif 335 336ifdef PYTHON_CONFIG 337 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null) 338 # Update the python flags for cross compilation 339 ifdef CROSS_COMPILE 340 PYTHON_NATIVE := $(shell echo $(PYTHON_EMBED_LDOPTS) | sed 's/\(-L.*\/\)\(.*-linux-gnu\).*/\2/') 341 PYTHON_EMBED_LDOPTS := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EMBED_LDOPTS)) 342 endif 343 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS)) 344 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil 345 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null) 346 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) 347 ifeq ($(CC_NO_CLANG), 0) 348 PYTHON_EMBED_CCOPTS := $(filter-out -ffat-lto-objects, $(PYTHON_EMBED_CCOPTS)) 349 endif 350endif 351 352FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS) 353FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS) 354 355FEATURE_CHECK_LDFLAGS-libaio = -lrt 356 357CORE_CFLAGS += -fno-omit-frame-pointer 358CORE_CFLAGS += -Wall 359CORE_CFLAGS += -Wextra 360CORE_CFLAGS += -std=gnu11 361 362CXXFLAGS += -std=gnu++17 -fno-exceptions -fno-rtti 363CXXFLAGS += -Wall 364CXXFLAGS += -Wextra 365CXXFLAGS += -fno-omit-frame-pointer 366 367HOSTCFLAGS += -Wall 368HOSTCFLAGS += -Wextra 369 370# Enforce a non-executable stack, as we may regress (again) in the future by 371# adding assembler files missing the .GNU-stack linker note. 372LDFLAGS += -Wl,-z,noexecstack 373 374EXTLIBS = -lpthread -lrt -lm -ldl 375 376ifneq ($(TCMALLOC),) 377 CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free 378 EXTLIBS += -ltcmalloc 379endif 380 381ifeq ($(FEATURES_DUMP),) 382# We will display at the end of this Makefile.config, using $(call feature_display_entries) 383# As we may retry some feature detection here, see the disassembler-four-args case, for instance 384 FEATURE_DISPLAY_DEFERRED := 1 385include $(srctree)/tools/build/Makefile.feature 386else 387include $(FEATURES_DUMP) 388endif 389 390ifeq ($(feature-stackprotector-all), 1) 391 CORE_CFLAGS += -fstack-protector-all 392endif 393 394ifeq ($(DEBUG),0) 395 ifeq ($(feature-fortify-source), 1) 396 CORE_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 397 endif 398endif 399 400INC_FLAGS += -I$(src-perf)/util/include 401INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include 402INC_FLAGS += -I$(srctree)/tools/include/ 403INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi 404INC_FLAGS += -I$(srctree)/tools/include/uapi 405INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/ 406INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/ 407 408# $(obj-perf) for generated common-cmds.h 409# $(obj-perf)/util for generated bison/flex headers 410ifneq ($(OUTPUT),) 411INC_FLAGS += -I$(obj-perf)/util 412INC_FLAGS += -I$(obj-perf) 413endif 414 415INC_FLAGS += -I$(src-perf)/util 416INC_FLAGS += -I$(src-perf) 417 418CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE 419 420CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS) 421CXXFLAGS += $(INC_FLAGS) 422 423LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS) 424 425ifeq ($(feature-pthread-attr-setaffinity-np), 1) 426 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP 427endif 428 429ifeq ($(feature-pthread-barrier), 1) 430 CFLAGS += -DHAVE_PTHREAD_BARRIER 431endif 432 433ifndef NO_BIONIC 434 $(call feature_check,bionic) 435 ifeq ($(feature-bionic), 1) 436 BIONIC := 1 437 CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE 438 CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE 439 EXTLIBS := $(filter-out -lrt,$(EXTLIBS)) 440 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS)) 441 endif 442endif 443 444ifeq ($(feature-eventfd), 1) 445 CFLAGS += -DHAVE_EVENTFD_SUPPORT 446endif 447 448ifeq ($(feature-gettid), 1) 449 CFLAGS += -DHAVE_GETTID 450endif 451 452ifeq ($(feature-file-handle), 1) 453 CFLAGS += -DHAVE_FILE_HANDLE 454endif 455 456ifdef NO_LIBELF 457 NO_LIBDW := 1 458 NO_LIBUNWIND := 1 459 NO_LIBDW_DWARF_UNWIND := 1 460 NO_LIBBPF := 1 461 NO_JVMTI := 1 462else 463 ifeq ($(feature-libelf), 0) 464 ifeq ($(feature-glibc), 1) 465 LIBC_SUPPORT := 1 466 endif 467 ifeq ($(BIONIC),1) 468 LIBC_SUPPORT := 1 469 endif 470 ifeq ($(LIBC_SUPPORT),1) 471 $(error ERROR: No libelf found. Disables 'probe' tool, jvmti and BPF support. Please install libelf-dev, libelf-devel, elfutils-libelf-devel or build with NO_LIBELF=1.) 472 else 473 ifneq ($(filter s% -fsanitize=address%,$(EXTRA_CFLAGS),),) 474 ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0) 475 $(error No libasan found, please install libasan) 476 endif 477 endif 478 479 ifneq ($(filter s% -fsanitize=undefined%,$(EXTRA_CFLAGS),),) 480 ifneq ($(shell ldconfig -p | grep libubsan >/dev/null 2>&1; echo $$?), 0) 481 $(error No libubsan found, please install libubsan) 482 endif 483 endif 484 485 ifneq ($(filter s% -static%,$(LDFLAGS),),) 486 $(error No static glibc found, please install glibc-static) 487 else 488 $(error No gnu/libc-version.h found, please install glibc-dev[el]) 489 endif 490 endif 491 else 492 ifneq ($(feature-libdw), 1) 493 ifndef NO_LIBDW 494 $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.157, disables dwarf support. Please install new elfutils-devel/libdw-dev) 495 NO_LIBDW := 1 496 endif 497 endif # Dwarf support 498 endif # libelf support 499endif # NO_LIBELF 500 501ifeq ($(feature-libaio), 1) 502 ifndef NO_AIO 503 CFLAGS += -DHAVE_AIO_SUPPORT 504 endif 505endif 506 507ifdef NO_LIBDW 508 NO_LIBDW_DWARF_UNWIND := 1 509endif 510 511ifeq ($(feature-scandirat), 1) 512 # Ignore having scandirat with memory sanitizer that lacks an interceptor. 513 ifeq ($(filter s% -fsanitize=memory%,$(EXTRA_CFLAGS),),) 514 CFLAGS += -DHAVE_SCANDIRAT_SUPPORT 515 endif 516endif 517 518ifeq ($(feature-sched_getcpu), 1) 519 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT 520endif 521 522ifeq ($(feature-setns), 1) 523 CFLAGS += -DHAVE_SETNS_SUPPORT 524 $(call detected,CONFIG_SETNS) 525endif 526 527ifeq ($(feature-reallocarray), 0) 528 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY 529endif 530 531ifdef CORESIGHT 532 $(call feature_check,libopencsd) 533 ifeq ($(feature-libopencsd), 1) 534 CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS) 535 LDFLAGS += $(LIBOPENCSD_LDFLAGS) 536 EXTLIBS += $(OPENCSDLIBS) 537 $(call detected,CONFIG_LIBOPENCSD) 538 ifdef CSTRACE_RAW 539 CFLAGS += -DCS_DEBUG_RAW 540 ifeq (${CSTRACE_RAW}, packed) 541 CFLAGS += -DCS_RAW_PACKED 542 endif 543 endif 544 else 545 $(error Error: No libopencsd library found or the version is not up-to-date. Please install recent libopencsd to build with CORESIGHT=1) 546 endif 547endif 548 549ifndef NO_ZLIB 550 ifeq ($(feature-zlib), 1) 551 CFLAGS += -DHAVE_ZLIB_SUPPORT 552 EXTLIBS += -lz 553 $(call detected,CONFIG_ZLIB) 554 else 555 NO_ZLIB := 1 556 endif 557endif 558 559ifndef NO_LIBELF 560 CFLAGS += -DHAVE_LIBELF_SUPPORT 561 EXTLIBS += -lelf 562 $(call detected,CONFIG_LIBELF) 563 564 ifeq ($(feature-libelf-getphdrnum), 1) 565 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT 566 endif 567 568 ifeq ($(feature-libelf-gelf_getnote), 1) 569 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT 570 else 571 $(warning gelf_getnote() not found on libelf, SDT support disabled) 572 endif 573 574 ifeq ($(feature-libelf-getshdrstrndx), 1) 575 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT 576 endif 577 578 ifeq ($(feature-libelf-zstd), 1) 579 ifdef NO_LIBZSTD 580 $(error Error: libzstd is required by libelf, please do not set NO_LIBZSTD) 581 endif 582 endif 583 584 ifndef NO_LIBDEBUGINFOD 585 $(call feature_check,libdebuginfod) 586 ifeq ($(feature-libdebuginfod), 1) 587 CFLAGS += -DHAVE_DEBUGINFOD_SUPPORT 588 EXTLIBS += -ldebuginfod 589 else 590 $(warning No elfutils/debuginfod.h found, no debuginfo server support, please install libdebuginfod-dev/elfutils-debuginfod-client-devel or equivalent) 591 endif 592 endif 593 594 ifndef NO_LIBDW 595 CFLAGS += -DHAVE_LIBDW_SUPPORT $(LIBDW_CFLAGS) 596 LDFLAGS += $(LIBDW_LDFLAGS) 597 EXTLIBS += ${DWARFLIBS} 598 $(call detected,CONFIG_LIBDW) 599 endif # NO_LIBDW 600 601 ifndef NO_LIBBPF 602 ifeq ($(feature-bpf), 1) 603 # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status 604 $(call feature_check,libbpf) 605 606 ifdef LIBBPF_DYNAMIC 607 ifeq ($(feature-libbpf), 1) 608 EXTLIBS += -lbpf 609 CFLAGS += -DHAVE_LIBBPF_SUPPORT 610 $(call detected,CONFIG_LIBBPF) 611 $(call detected,CONFIG_LIBBPF_DYNAMIC) 612 else 613 $(error Error: No libbpf devel library found or older than v1.0, please install/update libbpf-devel) 614 endif 615 else 616 ifeq ($(NO_ZLIB), 1) 617 $(warning Warning: Statically building libbpf not possible as zlib is missing) 618 NO_LIBBPF := 1 619 else 620 # Libbpf will be built as a static library from tools/lib/bpf. 621 LIBBPF_STATIC := 1 622 $(call detected,CONFIG_LIBBPF) 623 CFLAGS += -DHAVE_LIBBPF_SUPPORT 624 LIBBPF_INCLUDE = $(LIBBPF_DIR)/.. 625 endif 626 endif 627 endif 628 endif # NO_LIBBPF 629endif # NO_LIBELF 630 631ifndef NO_SDT 632 ifneq ($(feature-sdt), 1) 633 $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev) 634 NO_SDT := 1; 635 else 636 CFLAGS += -DHAVE_SDT_EVENT 637 $(call detected,CONFIG_SDT_EVENT) 638 endif 639endif 640 641ifdef PERF_HAVE_JITDUMP 642 ifndef NO_LIBELF 643 $(call detected,CONFIG_JITDUMP) 644 CFLAGS += -DHAVE_JITDUMP 645 endif 646endif 647 648ifeq ($(SRCARCH),powerpc) 649 ifndef NO_LIBDW 650 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX 651 endif 652endif 653 654ifndef NO_LIBUNWIND 655 have_libunwind := 656 657 $(call feature_check,libunwind) 658 659 $(call feature_check,libunwind-x86) 660 ifeq ($(feature-libunwind-x86), 1) 661 $(call detected,CONFIG_LIBUNWIND_X86) 662 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT 663 LDFLAGS += -lunwind-x86 664 EXTLIBS_LIBUNWIND += -lunwind-x86 665 have_libunwind = 1 666 endif 667 668 $(call feature_check,libunwind-aarch64) 669 ifeq ($(feature-libunwind-aarch64), 1) 670 $(call detected,CONFIG_LIBUNWIND_AARCH64) 671 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT 672 LDFLAGS += -lunwind-aarch64 673 EXTLIBS_LIBUNWIND += -lunwind-aarch64 674 have_libunwind = 1 675 $(call feature_check,libunwind-debug-frame-aarch64) 676 ifneq ($(feature-libunwind-debug-frame-aarch64), 1) 677 $(warning No debug_frame support found in libunwind-aarch64) 678 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64 679 endif 680 endif 681 682 ifneq ($(feature-libunwind), 1) 683 $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR and set LIBUNWIND=1 in the make command line as it is opt-in now) 684 NO_LOCAL_LIBUNWIND := 1 685 else 686 have_libunwind := 1 687 $(call detected,CONFIG_LOCAL_LIBUNWIND) 688 endif 689 690 ifneq ($(have_libunwind), 1) 691 NO_LIBUNWIND := 1 692 endif 693else 694 NO_LOCAL_LIBUNWIND := 1 695endif 696 697ifndef NO_LIBBPF 698 ifneq ($(feature-bpf), 1) 699 $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.) 700 NO_LIBBPF := 1 701 endif 702endif 703 704ifndef BUILD_BPF_SKEL 705 # BPF skeletons control a large number of perf features, by default 706 # they are enabled. 707 BUILD_BPF_SKEL := 1 708endif 709 710ifeq ($(BUILD_BPF_SKEL),1) 711 ifeq ($(filter -DHAVE_LIBELF_SUPPORT, $(CFLAGS)),) 712 $(warning Warning: Disabled BPF skeletons as libelf is required by bpftool) 713 BUILD_BPF_SKEL := 0 714 else ifeq ($(filter -DHAVE_ZLIB_SUPPORT, $(CFLAGS)),) 715 $(warning Warning: Disabled BPF skeletons as zlib is required by bpftool) 716 BUILD_BPF_SKEL := 0 717 else ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),) 718 $(warning Warning: Disabled BPF skeletons as libbpf is required) 719 BUILD_BPF_SKEL := 0 720 else ifeq ($(call get-executable,$(CLANG)),) 721 $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) 722 BUILD_BPF_SKEL := 0 723 else 724 CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') 725 ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) 726 $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) 727 BUILD_BPF_SKEL := 0 728 endif 729 endif 730 ifeq ($(BUILD_BPF_SKEL),1) 731 $(call feature_check,clang-bpf-co-re) 732 ifeq ($(feature-clang-bpf-co-re), 0) 733 $(warning Warning: Disabled BPF skeletons as clang is too old) 734 BUILD_BPF_SKEL := 0 735 endif 736 endif 737 ifeq ($(BUILD_BPF_SKEL),1) 738 $(call detected,CONFIG_PERF_BPF_SKEL) 739 CFLAGS += -DHAVE_BPF_SKEL 740 endif 741endif 742 743ifndef GEN_VMLINUX_H 744 VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h 745endif 746 747dwarf-post-unwind := 1 748dwarf-post-unwind-text := BUG 749 750# setup DWARF post unwinder 751ifdef NO_LIBUNWIND 752 ifdef NO_LIBDW_DWARF_UNWIND 753 $(warning Disabling post unwind, no support found.) 754 dwarf-post-unwind := 0 755 else 756 dwarf-post-unwind-text := libdw 757 $(call detected,CONFIG_LIBDW_DWARF_UNWIND) 758 endif 759else 760 dwarf-post-unwind-text := libunwind 761 $(call detected,CONFIG_LIBUNWIND) 762 # Enable libunwind support by default. 763 ifndef NO_LIBDW_DWARF_UNWIND 764 NO_LIBDW_DWARF_UNWIND := 1 765 endif 766endif 767 768ifeq ($(dwarf-post-unwind),1) 769 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT 770 $(call detected,CONFIG_DWARF_UNWIND) 771endif 772 773ifndef NO_LIBUNWIND 774 ifndef NO_LOCAL_LIBUNWIND 775 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64)) 776 $(call feature_check,libunwind-debug-frame) 777 ifneq ($(feature-libunwind-debug-frame), 1) 778 $(warning No debug_frame support found in libunwind) 779 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 780 endif 781 else 782 # non-ARM has no dwarf_find_debug_frame() function: 783 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 784 endif 785 EXTLIBS += $(LIBUNWIND_LIBS) 786 LDFLAGS += $(LIBUNWIND_LIBS) 787 endif 788 ifeq ($(findstring -static,${LDFLAGS}),-static) 789 # gcc -static links libgcc_eh which contans piece of libunwind 790 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition 791 endif 792 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT 793 CFLAGS += $(LIBUNWIND_CFLAGS) 794 LDFLAGS += $(LIBUNWIND_LDFLAGS) 795 EXTLIBS += $(EXTLIBS_LIBUNWIND) 796endif 797 798ifneq ($(NO_LIBTRACEEVENT),1) 799 $(call detected,CONFIG_TRACE) 800endif 801 802ifndef NO_SLANG 803 ifneq ($(feature-libslang), 1) 804 $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev) 805 NO_SLANG := 1 806 endif 807 ifndef NO_SLANG 808 CFLAGS += -DHAVE_SLANG_SUPPORT 809 EXTLIBS += -lslang 810 $(call detected,CONFIG_SLANG) 811 endif 812endif 813 814ifdef GTK2 815 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 816 $(call feature_check,gtk2) 817 ifneq ($(feature-gtk2), 1) 818 $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev) 819 NO_GTK2 := 1 820 else 821 $(call feature_check,gtk2-infobar) 822 ifeq ($(feature-gtk2-infobar), 1) 823 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT 824 endif 825 CFLAGS += -DHAVE_GTK2_SUPPORT 826 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null) 827 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null) 828 EXTLIBS += -ldl 829 endif 830endif 831 832ifdef LIBPERL 833 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 834 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 835 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 836 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) 837 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) 838 PERL_EMBED_CCOPTS := $(filter-out -flto% -ffat-lto-objects, $(PERL_EMBED_CCOPTS)) 839 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) 840 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 841 842 $(call feature_check,libperl) 843 ifneq ($(feature-libperl), 1) 844 $(error Missing perl devel files. Please install perl-ExtUtils-Embed/libperl-dev) 845 else 846 LDFLAGS += $(PERL_EMBED_LDFLAGS) 847 EXTLIBS += $(PERL_EMBED_LIBADD) 848 CFLAGS += -DHAVE_LIBPERL_SUPPORT 849 $(call detected,CONFIG_LIBPERL) 850 endif 851endif 852 853ifeq ($(feature-timerfd), 1) 854 CFLAGS += -DHAVE_TIMERFD_SUPPORT 855else 856 $(warning No timerfd support. Disables 'perf kvm stat live') 857endif 858 859disable-python = $(eval $(disable-python_code)) 860define disable-python_code 861 CFLAGS += -DNO_LIBPYTHON 862 $(warning $1) 863 NO_LIBPYTHON := 1 864endef 865 866PYTHON_EXTENSION_SUFFIX := '.so' 867ifdef NO_LIBPYTHON 868 $(call disable-python,Python support disabled by user) 869else 870 871 ifndef PYTHON 872 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev) 873 else 874 PYTHON_WORD := $(call shell-wordify,$(PYTHON)) 875 876 ifndef PYTHON_CONFIG 877 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev) 878 else 879 880 ifneq ($(feature-libpython), 1) 881 $(call disable-python,No 'Python.h' was found: disables Python support - please install python-devel/python-dev) 882 else 883 LDFLAGS += $(PYTHON_EMBED_LDFLAGS) 884 EXTLIBS += $(PYTHON_EMBED_LIBADD) 885 PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no") 886 ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes) 887 PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])') 888 ifdef CROSS_COMPILE 889 PYTHON_EXTENSION_SUFFIX := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EXTENSION_SUFFIX)) 890 endif 891 LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX) 892 else 893 $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent) 894 endif 895 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT 896 $(call detected,CONFIG_LIBPYTHON) 897 ifeq ($(filter -fPIC,$(CFLAGS)),) 898 # Building a shared library requires position independent code. 899 CFLAGS += -fPIC 900 CXXFLAGS += -fPIC 901 endif 902 endif 903 endif 904 endif 905endif 906 907ifneq ($(NO_JEVENTS),1) 908 ifeq ($(wildcard pmu-events/arch/$(SRCARCH)/mapfile.csv),) 909 NO_JEVENTS := 1 910 endif 911endif 912ifneq ($(NO_JEVENTS),1) 913 NO_JEVENTS := 0 914 ifndef PYTHON 915 $(error ERROR: No python interpreter needed for jevents generation. Install python or build with NO_JEVENTS=1.) 916 else 917 # jevents.py uses f-strings present in Python 3.6 released in Dec. 2016. 918 JEVENTS_PYTHON_GOOD := $(shell $(PYTHON) -c 'import sys;print("1" if(sys.version_info.major >= 3 and sys.version_info.minor >= 6) else "0")' 2> /dev/null) 919 ifneq ($(JEVENTS_PYTHON_GOOD), 1) 920 $(error ERROR: Python interpreter needed for jevents generation too old (older than 3.6). Install a newer python or build with NO_JEVENTS=1.) 921 endif 922 endif 923endif 924 925ifdef BUILD_NONDISTRO 926 $(call feature_check,libbfd) 927 928 ifeq ($(feature-libbfd), 1) 929 EXTLIBS += -lbfd -lopcodes 930 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl 931 FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl 932 else 933 # we are on a system that requires -liberty and (maybe) -lz 934 # to link against -lbfd; test each case individually here 935 936 # call all detections now so we get correct 937 # status in VF output 938 $(call feature_check,libbfd-liberty) 939 $(call feature_check,libbfd-liberty-z) 940 941 ifeq ($(feature-libbfd-liberty), 1) 942 EXTLIBS += -lbfd -lopcodes -liberty 943 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl 944 FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl 945 else 946 ifeq ($(feature-libbfd-liberty-z), 1) 947 EXTLIBS += -lbfd -lopcodes -liberty -lz 948 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl 949 FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl 950 endif 951 endif 952 $(call feature_check,disassembler-four-args) 953 $(call feature_check,disassembler-init-styled) 954 endif 955 956 CFLAGS += -DHAVE_LIBBFD_SUPPORT 957 CXXFLAGS += -DHAVE_LIBBFD_SUPPORT 958 $(call detected,CONFIG_LIBBFD) 959 960 $(call feature_check,libbfd-buildid) 961 962 ifeq ($(feature-libbfd-buildid), 1) 963 CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT 964 else 965 $(warning Old version of libbfd/binutils things like PE executable profiling will not be available) 966 endif 967 968 ifeq ($(feature-disassembler-four-args), 1) 969 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 970 endif 971 972 ifeq ($(feature-disassembler-init-styled), 1) 973 CFLAGS += -DDISASM_INIT_STYLED 974 endif 975endif 976 977ifndef NO_LIBLLVM 978 $(call feature_check,llvm-perf) 979 ifeq ($(feature-llvm-perf), 1) 980 CFLAGS += -DHAVE_LIBLLVM_SUPPORT 981 CFLAGS += $(shell $(LLVM_CONFIG) --cflags) 982 CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT 983 CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags) 984 LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs) 985 EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM) 986 EXTLIBS += -lstdc++ 987 $(call detected,CONFIG_LIBLLVM) 988 else 989 $(warning No libllvm 13+ found, slower source file resolution, please install llvm-devel/llvm-dev) 990 NO_LIBLLVM := 1 991 endif 992endif 993 994ifndef NO_DEMANGLE 995 $(call feature_check,cxa-demangle) 996 ifeq ($(feature-cxa-demangle), 1) 997 EXTLIBS += -lstdc++ 998 CFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT 999 CXXFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT 1000 $(call detected,CONFIG_CXX_DEMANGLE) 1001 endif 1002 ifdef BUILD_NONDISTRO 1003 ifeq ($(filter -liberty,$(EXTLIBS)),) 1004 $(call feature_check,cplus-demangle) 1005 ifeq ($(feature-cplus-demangle), 1) 1006 EXTLIBS += -liberty 1007 endif 1008 endif 1009 ifneq ($(filter -liberty,$(EXTLIBS)),) 1010 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 1011 CXXFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 1012 endif 1013 endif 1014endif 1015 1016ifndef NO_LZMA 1017 ifeq ($(feature-lzma), 1) 1018 CFLAGS += -DHAVE_LZMA_SUPPORT 1019 EXTLIBS += -llzma 1020 $(call detected,CONFIG_LZMA) 1021 else 1022 $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev) 1023 NO_LZMA := 1 1024 endif 1025endif 1026 1027ifndef NO_LIBZSTD 1028 ifeq ($(feature-libzstd), 1) 1029 CFLAGS += -DHAVE_ZSTD_SUPPORT 1030 CFLAGS += $(LIBZSTD_CFLAGS) 1031 LDFLAGS += $(LIBZSTD_LDFLAGS) 1032 EXTLIBS += -lzstd 1033 $(call detected,CONFIG_ZSTD) 1034 else 1035 $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR) 1036 NO_LIBZSTD := 1 1037 endif 1038endif 1039 1040ifndef NO_BACKTRACE 1041 ifeq ($(feature-backtrace), 1) 1042 CFLAGS += -DHAVE_BACKTRACE_SUPPORT 1043 endif 1044endif 1045 1046ifndef NO_LIBNUMA 1047 ifeq ($(feature-libnuma), 0) 1048 $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev) 1049 NO_LIBNUMA := 1 1050 else 1051 ifeq ($(feature-numa_num_possible_cpus), 0) 1052 $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8) 1053 NO_LIBNUMA := 1 1054 else 1055 CFLAGS += -DHAVE_LIBNUMA_SUPPORT 1056 EXTLIBS += -lnuma 1057 $(call detected,CONFIG_NUMA) 1058 endif 1059 endif 1060endif 1061 1062ifdef HAVE_KVM_STAT_SUPPORT 1063 CFLAGS += -DHAVE_KVM_STAT_SUPPORT 1064endif 1065 1066ifeq (${IS_64_BIT}, 1) 1067 ifndef NO_PERF_READ_VDSO32 1068 $(call feature_check,compile-32) 1069 ifeq ($(feature-compile-32), 1) 1070 CFLAGS += -DHAVE_PERF_READ_VDSO32 1071 else 1072 NO_PERF_READ_VDSO32 := 1 1073 endif 1074 endif 1075 ifneq ($(SRCARCH), x86) 1076 NO_PERF_READ_VDSOX32 := 1 1077 endif 1078 ifndef NO_PERF_READ_VDSOX32 1079 $(call feature_check,compile-x32) 1080 ifeq ($(feature-compile-x32), 1) 1081 CFLAGS += -DHAVE_PERF_READ_VDSOX32 1082 else 1083 NO_PERF_READ_VDSOX32 := 1 1084 endif 1085 endif 1086else 1087 NO_PERF_READ_VDSO32 := 1 1088 NO_PERF_READ_VDSOX32 := 1 1089endif 1090 1091ifndef NO_LIBBABELTRACE 1092 $(call feature_check,libbabeltrace) 1093 ifeq ($(feature-libbabeltrace), 1) 1094 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS) 1095 LDFLAGS += $(LIBBABELTRACE_LDFLAGS) 1096 EXTLIBS += -lbabeltrace-ctf 1097 $(call detected,CONFIG_LIBBABELTRACE) 1098 else 1099 $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev) 1100 endif 1101endif 1102 1103ifndef NO_CAPSTONE 1104 $(call feature_check,libcapstone) 1105 ifeq ($(feature-libcapstone), 1) 1106 CFLAGS += -DHAVE_LIBCAPSTONE_SUPPORT $(LIBCAPSTONE_CFLAGS) 1107 LDFLAGS += $(LICAPSTONE_LDFLAGS) 1108 EXTLIBS += -lcapstone 1109 $(call detected,CONFIG_LIBCAPSTONE) 1110 else 1111 msg := $(warning No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel); 1112 endif 1113endif 1114 1115ifndef NO_AUXTRACE 1116 ifeq ($(SRCARCH),x86) 1117 ifeq ($(feature-get_cpuid), 0) 1118 $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc) 1119 NO_AUXTRACE := 1 1120 endif 1121 endif 1122 ifndef NO_AUXTRACE 1123 $(call detected,CONFIG_AUXTRACE) 1124 CFLAGS += -DHAVE_AUXTRACE_SUPPORT 1125 endif 1126endif 1127 1128ifdef EXTRA_TESTS 1129 $(call detected,CONFIG_EXTRA_TESTS) 1130 CFLAGS += -DHAVE_EXTRA_TESTS 1131endif 1132 1133ifndef NO_JVMTI 1134 ifneq (,$(wildcard /usr/sbin/update-java-alternatives)) 1135 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}') 1136 else 1137 ifneq (,$(wildcard /usr/sbin/alternatives)) 1138 JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' -f 5 | sed -e 's%/jre/bin/java.%%g' -e 's%/bin/java.%%g') 1139 endif 1140 endif 1141 ifndef JDIR 1142 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory) 1143 NO_JVMTI := 1 1144 endif 1145endif 1146 1147ifndef NO_JVMTI 1148 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux 1149 $(call feature_check,jvmti) 1150 ifeq ($(feature-jvmti), 1) 1151 $(call detected_var,JDIR) 1152 ifndef NO_JVMTI_CMLR 1153 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti) 1154 $(call feature_check,jvmti-cmlr) 1155 ifeq ($(feature-jvmti-cmlr), 1) 1156 CFLAGS += -DHAVE_JVMTI_CMLR 1157 endif 1158 endif # NO_JVMTI_CMLR 1159 else 1160 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-latest-openjdk-devel) 1161 NO_JVMTI := 1 1162 endif 1163endif 1164 1165ifndef NO_LIBPFM4 1166 $(call feature_check,libpfm4) 1167 ifeq ($(feature-libpfm4), 1) 1168 CFLAGS += -DHAVE_LIBPFM 1169 EXTLIBS += -lpfm 1170 ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1 1171 $(call detected,CONFIG_LIBPFM4) 1172 else 1173 $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev) 1174 endif 1175endif 1176 1177# libtraceevent is a recommended dependency picked up from the system. 1178ifneq ($(NO_LIBTRACEEVENT),1) 1179 ifeq ($(feature-libtraceevent), 1) 1180 CFLAGS += -DHAVE_LIBTRACEEVENT $(shell $(PKG_CONFIG) --cflags libtraceevent) 1181 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libtraceevent) 1182 EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libtraceevent) 1183 LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent).0.0 1184 LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION))) 1185 LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION))) 1186 LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION))) 1187 LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3)) 1188 CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP) 1189 $(call detected,CONFIG_LIBTRACEEVENT) 1190 else 1191 $(error ERROR: libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel and/or set LIBTRACEEVENT_DIR or build with NO_LIBTRACEEVENT=1) 1192 endif 1193endif 1194 1195# Among the variables below, these: 1196# perfexecdir 1197# libbpf_include_dir 1198# perf_examples_dir 1199# template_dir 1200# mandir 1201# infodir 1202# htmldir 1203# ETC_PERFCONFIG (but not sysconfdir) 1204# can be specified as a relative path some/where/else; 1205# this is interpreted as relative to $(prefix) and "perf" at 1206# runtime figures out where they are based on the path to the executable. 1207# This can help installing the suite in a relocatable way. 1208 1209# Make the path relative to DESTDIR, not to prefix 1210ifndef DESTDIR 1211prefix ?= $(HOME) 1212endif 1213bindir_relative = bin 1214bindir = $(abspath $(prefix)/$(bindir_relative)) 1215includedir_relative = include 1216includedir = $(abspath $(prefix)/$(includedir_relative)) 1217mandir = share/man 1218infodir = share/info 1219perfexecdir = libexec/perf-core 1220# FIXME: system's libbpf header directory, where we expect to find bpf/bpf_helpers.h, for instance 1221libbpf_include_dir = /usr/include 1222perf_examples_dir = lib/perf/examples 1223sharedir = $(prefix)/share 1224template_dir = share/perf-core/templates 1225STRACE_GROUPS_DIR = share/perf-core/strace/groups 1226htmldir = share/doc/perf-doc 1227tipdir = share/doc/perf-tip 1228srcdir = $(srctree)/tools/perf 1229ifeq ($(prefix),/usr) 1230sysconfdir = /etc 1231ETC_PERFCONFIG = $(sysconfdir)/perfconfig 1232else 1233sysconfdir = $(prefix)/etc 1234ETC_PERFCONFIG = etc/perfconfig 1235endif 1236ifndef lib 1237ifeq ($(SRCARCH)$(IS_64_BIT), x861) 1238lib = lib64 1239else 1240lib = lib 1241endif 1242endif # lib 1243libdir = $(prefix)/$(lib) 1244 1245# Shell quote (do not use $(call) to accommodate ancient setups); 1246ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG)) 1247STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR)) 1248DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) 1249bindir_SQ = $(subst ','\'',$(bindir)) 1250includedir_SQ = $(subst ','\'',$(includedir)) 1251mandir_SQ = $(subst ','\'',$(mandir)) 1252infodir_SQ = $(subst ','\'',$(infodir)) 1253perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) 1254libbpf_include_dir_SQ = $(subst ','\'',$(libbpf_include_dir)) 1255perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir)) 1256template_dir_SQ = $(subst ','\'',$(template_dir)) 1257htmldir_SQ = $(subst ','\'',$(htmldir)) 1258tipdir_SQ = $(subst ','\'',$(tipdir)) 1259prefix_SQ = $(subst ','\'',$(prefix)) 1260sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) 1261libdir_SQ = $(subst ','\'',$(libdir)) 1262srcdir_SQ = $(subst ','\'',$(srcdir)) 1263 1264ifneq ($(filter /%,$(firstword $(perfexecdir))),) 1265perfexec_instdir = $(perfexecdir) 1266perf_include_instdir = $(libbpf_include_dir) 1267perf_examples_instdir = $(perf_examples_dir) 1268STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) 1269tip_instdir = $(tipdir) 1270else 1271perfexec_instdir = $(prefix)/$(perfexecdir) 1272perf_include_instdir = $(prefix)/$(libbpf_include_dir) 1273perf_examples_instdir = $(prefix)/$(perf_examples_dir) 1274STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) 1275tip_instdir = $(prefix)/$(tipdir) 1276endif 1277perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) 1278perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir)) 1279perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir)) 1280STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) 1281tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) 1282 1283export perfexec_instdir_SQ 1284 1285print_var = $(eval $(print_var_code)) $(info $(MSG)) 1286define print_var_code 1287 MSG = $(shell printf '...%40s: %s' $(1) $($(1))) 1288endef 1289 1290ifeq ($(feature_display),1) 1291 $(call feature_display_entries) 1292endif 1293 1294ifeq ($(VF),1) 1295 # Display EXTRA features which are detected manualy 1296 # from here with feature_check call and thus cannot 1297 # be partof global state output. 1298 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),) $(info $(MSG))) 1299 $(call print_var,prefix) 1300 $(call print_var,bindir) 1301 $(call print_var,libdir) 1302 $(call print_var,sysconfdir) 1303 $(call print_var,LIBUNWIND_DIR) 1304 $(call print_var,LIBDW_DIR) 1305 $(call print_var,JDIR) 1306 1307 ifeq ($(dwarf-post-unwind),1) 1308 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) $(info $(MSG)) 1309 endif 1310endif 1311 1312$(info ) 1313 1314$(call detected_var,bindir_SQ) 1315$(call detected_var,PYTHON_WORD) 1316ifneq ($(OUTPUT),) 1317$(call detected_var,OUTPUT) 1318endif 1319$(call detected_var,htmldir_SQ) 1320$(call detected_var,infodir_SQ) 1321$(call detected_var,mandir_SQ) 1322$(call detected_var,ETC_PERFCONFIG_SQ) 1323$(call detected_var,STRACE_GROUPS_DIR_SQ) 1324$(call detected_var,prefix_SQ) 1325$(call detected_var,perfexecdir_SQ) 1326$(call detected_var,libbpf_include_dir_SQ) 1327$(call detected_var,perf_examples_dir_SQ) 1328$(call detected_var,tipdir_SQ) 1329$(call detected_var,srcdir_SQ) 1330$(call detected_var,LIBDIR) 1331$(call detected_var,GTK_CFLAGS) 1332$(call detected_var,PERL_EMBED_CCOPTS) 1333$(call detected_var,PYTHON_EMBED_CCOPTS) 1334ifneq ($(BISON_FILE_PREFIX_MAP),) 1335$(call detected_var,BISON_FILE_PREFIX_MAP) 1336endif 1337 1338# re-generate FEATURE-DUMP as we may have called feature_check, found out 1339# extra libraries to add to LDFLAGS of some other test and then redo those 1340# tests, see the block about libbfd, disassembler-four-args, for instance. 1341$(shell rm -f $(FEATURE_DUMP_FILENAME)) 1342$(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME))) 1343