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