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 LIBBPF_INCLUDE = $(LIBBPF_DIR)/.. 599 endif 600 endif 601 602 FEATURE_CHECK_CFLAGS-libbpf-strings="-I$(LIBBPF_INCLUDE)" 603 $(call feature_check,libbpf-strings) 604 ifeq ($(feature-libbpf-strings), 1) 605 $(call detected,CONFIG_LIBBPF_STRINGS) 606 CFLAGS += -DHAVE_LIBBPF_STRINGS_SUPPORT 607 endif 608 endif 609 endif # NO_LIBBPF 610endif # NO_LIBELF 611 612ifndef NO_SDT 613 ifneq ($(feature-sdt), 1) 614 $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev) 615 NO_SDT := 1; 616 else 617 CFLAGS += -DHAVE_SDT_EVENT 618 $(call detected,CONFIG_SDT_EVENT) 619 endif 620endif 621 622ifdef PERF_HAVE_JITDUMP 623 ifndef NO_LIBELF 624 $(call detected,CONFIG_JITDUMP) 625 CFLAGS += -DHAVE_JITDUMP 626 endif 627endif 628 629ifeq ($(SRCARCH),powerpc) 630 ifndef NO_LIBDW 631 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX 632 endif 633endif 634 635ifndef NO_LIBUNWIND 636 have_libunwind := 637 638 $(call feature_check,libunwind) 639 640 $(call feature_check,libunwind-x86) 641 ifeq ($(feature-libunwind-x86), 1) 642 $(call detected,CONFIG_LIBUNWIND_X86) 643 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT 644 LDFLAGS += -lunwind-x86 645 EXTLIBS_LIBUNWIND += -lunwind-x86 646 have_libunwind = 1 647 endif 648 649 $(call feature_check,libunwind-aarch64) 650 ifeq ($(feature-libunwind-aarch64), 1) 651 $(call detected,CONFIG_LIBUNWIND_AARCH64) 652 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT 653 LDFLAGS += -lunwind-aarch64 654 EXTLIBS_LIBUNWIND += -lunwind-aarch64 655 have_libunwind = 1 656 $(call feature_check,libunwind-debug-frame-aarch64) 657 ifneq ($(feature-libunwind-debug-frame-aarch64), 1) 658 $(warning No debug_frame support found in libunwind-aarch64) 659 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64 660 endif 661 endif 662 663 ifneq ($(feature-libunwind), 1) 664 $(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) 665 NO_LOCAL_LIBUNWIND := 1 666 else 667 have_libunwind := 1 668 $(call detected,CONFIG_LOCAL_LIBUNWIND) 669 endif 670 671 ifneq ($(have_libunwind), 1) 672 NO_LIBUNWIND := 1 673 endif 674else 675 NO_LOCAL_LIBUNWIND := 1 676endif 677 678ifndef NO_LIBBPF 679 ifneq ($(feature-bpf), 1) 680 $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.) 681 NO_LIBBPF := 1 682 endif 683endif 684 685ifndef BUILD_BPF_SKEL 686 # BPF skeletons control a large number of perf features, by default 687 # they are enabled. 688 BUILD_BPF_SKEL := 1 689endif 690 691ifeq ($(BUILD_BPF_SKEL),1) 692 ifeq ($(filter -DHAVE_LIBELF_SUPPORT, $(CFLAGS)),) 693 $(warning Warning: Disabled BPF skeletons as libelf is required by bpftool) 694 BUILD_BPF_SKEL := 0 695 else ifeq ($(filter -DHAVE_ZLIB_SUPPORT, $(CFLAGS)),) 696 $(warning Warning: Disabled BPF skeletons as zlib is required by bpftool) 697 BUILD_BPF_SKEL := 0 698 else ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),) 699 $(warning Warning: Disabled BPF skeletons as libbpf is required) 700 BUILD_BPF_SKEL := 0 701 else ifeq ($(call get-executable,$(CLANG)),) 702 $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) 703 BUILD_BPF_SKEL := 0 704 else 705 CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') 706 ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) 707 $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) 708 BUILD_BPF_SKEL := 0 709 endif 710 endif 711 ifeq ($(BUILD_BPF_SKEL),1) 712 $(call feature_check,clang-bpf-co-re) 713 ifeq ($(feature-clang-bpf-co-re), 0) 714 $(warning Warning: Disabled BPF skeletons as clang is too old) 715 BUILD_BPF_SKEL := 0 716 endif 717 endif 718 ifeq ($(BUILD_BPF_SKEL),1) 719 $(call detected,CONFIG_PERF_BPF_SKEL) 720 CFLAGS += -DHAVE_BPF_SKEL 721 endif 722endif 723 724ifndef GEN_VMLINUX_H 725 VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h 726endif 727 728dwarf-post-unwind := 1 729dwarf-post-unwind-text := BUG 730 731# setup DWARF post unwinder 732ifdef NO_LIBUNWIND 733 ifdef NO_LIBDW_DWARF_UNWIND 734 $(warning Disabling post unwind, no support found.) 735 dwarf-post-unwind := 0 736 else 737 dwarf-post-unwind-text := libdw 738 $(call detected,CONFIG_LIBDW_DWARF_UNWIND) 739 endif 740else 741 dwarf-post-unwind-text := libunwind 742 $(call detected,CONFIG_LIBUNWIND) 743 # Enable libunwind support by default. 744 ifndef NO_LIBDW_DWARF_UNWIND 745 NO_LIBDW_DWARF_UNWIND := 1 746 endif 747endif 748 749ifeq ($(dwarf-post-unwind),1) 750 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT 751 $(call detected,CONFIG_DWARF_UNWIND) 752endif 753 754ifndef NO_LIBUNWIND 755 ifndef NO_LOCAL_LIBUNWIND 756 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64)) 757 $(call feature_check,libunwind-debug-frame) 758 ifneq ($(feature-libunwind-debug-frame), 1) 759 $(warning No debug_frame support found in libunwind) 760 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 761 endif 762 else 763 # non-ARM has no dwarf_find_debug_frame() function: 764 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 765 endif 766 EXTLIBS += $(LIBUNWIND_LIBS) 767 LDFLAGS += $(LIBUNWIND_LIBS) 768 endif 769 ifeq ($(findstring -static,${LDFLAGS}),-static) 770 # gcc -static links libgcc_eh which contans piece of libunwind 771 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition 772 endif 773 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT 774 CFLAGS += $(LIBUNWIND_CFLAGS) 775 LDFLAGS += $(LIBUNWIND_LDFLAGS) 776 EXTLIBS += $(EXTLIBS_LIBUNWIND) 777endif 778 779ifneq ($(NO_LIBTRACEEVENT),1) 780 $(call detected,CONFIG_TRACE) 781endif 782 783ifndef NO_LIBCRYPTO 784 ifneq ($(feature-libcrypto), 1) 785 $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev) 786 NO_LIBCRYPTO := 1 787 else 788 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT 789 EXTLIBS += -lcrypto 790 $(call detected,CONFIG_CRYPTO) 791 endif 792endif 793 794ifndef NO_SLANG 795 ifneq ($(feature-libslang), 1) 796 ifneq ($(feature-libslang-include-subdir), 1) 797 $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev) 798 NO_SLANG := 1 799 else 800 CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR 801 endif 802 endif 803 ifndef NO_SLANG 804 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h 805 CFLAGS += -DHAVE_SLANG_SUPPORT 806 EXTLIBS += -lslang 807 $(call detected,CONFIG_SLANG) 808 endif 809endif 810 811ifdef GTK2 812 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 813 $(call feature_check,gtk2) 814 ifneq ($(feature-gtk2), 1) 815 $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev) 816 NO_GTK2 := 1 817 else 818 $(call feature_check,gtk2-infobar) 819 ifeq ($(feature-gtk2-infobar), 1) 820 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT 821 endif 822 CFLAGS += -DHAVE_GTK2_SUPPORT 823 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null) 824 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null) 825 EXTLIBS += -ldl 826 endif 827endif 828 829ifdef NO_LIBPERL 830 CFLAGS += -DNO_LIBPERL 831else 832 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 833 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 834 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 835 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) 836 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) 837 PERL_EMBED_CCOPTS := $(filter-out -flto% -ffat-lto-objects, $(PERL_EMBED_CCOPTS)) 838 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) 839 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 840 841 ifneq ($(feature-libperl), 1) 842 CFLAGS += -DNO_LIBPERL 843 NO_LIBPERL := 1 844 $(warning Missing perl devel files. Disabling perl scripting support, 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 ifeq ($(CC_NO_CLANG), 0) 850 CFLAGS += -Wno-compound-token-split-by-macro 851 endif 852 $(call detected,CONFIG_LIBPERL) 853 endif 854endif 855 856ifeq ($(feature-timerfd), 1) 857 CFLAGS += -DHAVE_TIMERFD_SUPPORT 858else 859 $(warning No timerfd support. Disables 'perf kvm stat live') 860endif 861 862disable-python = $(eval $(disable-python_code)) 863define disable-python_code 864 CFLAGS += -DNO_LIBPYTHON 865 $(warning $1) 866 NO_LIBPYTHON := 1 867endef 868 869PYTHON_EXTENSION_SUFFIX := '.so' 870ifdef NO_LIBPYTHON 871 $(call disable-python,Python support disabled by user) 872else 873 874 ifndef PYTHON 875 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev) 876 else 877 PYTHON_WORD := $(call shell-wordify,$(PYTHON)) 878 879 ifndef PYTHON_CONFIG 880 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev) 881 else 882 883 ifneq ($(feature-libpython), 1) 884 $(call disable-python,No 'Python.h' was found: disables Python support - please install python-devel/python-dev) 885 else 886 LDFLAGS += $(PYTHON_EMBED_LDFLAGS) 887 EXTLIBS += $(PYTHON_EMBED_LIBADD) 888 PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no") 889 ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes) 890 PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])') 891 ifdef CROSS_COMPILE 892 PYTHON_EXTENSION_SUFFIX := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EXTENSION_SUFFIX)) 893 endif 894 LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX) 895 else 896 $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent) 897 endif 898 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT 899 $(call detected,CONFIG_LIBPYTHON) 900 ifeq ($(filter -fPIC,$(CFLAGS)),) 901 # Building a shared library requires position independent code. 902 CFLAGS += -fPIC 903 CXXFLAGS += -fPIC 904 endif 905 endif 906 endif 907 endif 908endif 909 910ifneq ($(NO_JEVENTS),1) 911 ifeq ($(wildcard pmu-events/arch/$(SRCARCH)/mapfile.csv),) 912 NO_JEVENTS := 1 913 endif 914endif 915ifneq ($(NO_JEVENTS),1) 916 NO_JEVENTS := 0 917 ifndef PYTHON 918 $(error ERROR: No python interpreter needed for jevents generation. Install python or build with NO_JEVENTS=1.) 919 else 920 # jevents.py uses f-strings present in Python 3.6 released in Dec. 2016. 921 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) 922 ifneq ($(JEVENTS_PYTHON_GOOD), 1) 923 $(error ERROR: Python interpreter needed for jevents generation too old (older than 3.6). Install a newer python or build with NO_JEVENTS=1.) 924 endif 925 endif 926endif 927 928ifdef BUILD_NONDISTRO 929 $(call feature_check,libbfd) 930 931 ifeq ($(feature-libbfd), 1) 932 EXTLIBS += -lbfd -lopcodes 933 else 934 # we are on a system that requires -liberty and (maybe) -lz 935 # to link against -lbfd; test each case individually here 936 937 # call all detections now so we get correct 938 # status in VF output 939 $(call feature_check,libbfd-liberty) 940 $(call feature_check,libbfd-liberty-z) 941 942 ifeq ($(feature-libbfd-liberty), 1) 943 EXTLIBS += -lbfd -lopcodes -liberty 944 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl 945 FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl 946 else 947 ifeq ($(feature-libbfd-liberty-z), 1) 948 EXTLIBS += -lbfd -lopcodes -liberty -lz 949 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl 950 FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl 951 endif 952 endif 953 $(call feature_check,disassembler-four-args) 954 $(call feature_check,disassembler-init-styled) 955 endif 956 957 CFLAGS += -DHAVE_LIBBFD_SUPPORT 958 CXXFLAGS += -DHAVE_LIBBFD_SUPPORT 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 967endif 968 969ifndef NO_LIBLLVM 970 $(call feature_check,llvm-perf) 971 ifeq ($(feature-llvm-perf), 1) 972 CFLAGS += -DHAVE_LIBLLVM_SUPPORT 973 CFLAGS += $(shell $(LLVM_CONFIG) --cflags) 974 CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT 975 CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags) 976 LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs) 977 EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM) 978 EXTLIBS += -lstdc++ 979 $(call detected,CONFIG_LIBLLVM) 980 else 981 $(warning No libllvm 13+ found, slower source file resolution, please install llvm-devel/llvm-dev) 982 NO_LIBLLVM := 1 983 endif 984endif 985 986ifndef NO_DEMANGLE 987 $(call feature_check,cxa-demangle) 988 ifeq ($(feature-cxa-demangle), 1) 989 EXTLIBS += -lstdc++ 990 CFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT 991 CXXFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT 992 $(call detected,CONFIG_CXX_DEMANGLE) 993 endif 994 ifdef BUILD_NONDISTRO 995 ifeq ($(filter -liberty,$(EXTLIBS)),) 996 $(call feature_check,cplus-demangle) 997 ifeq ($(feature-cplus-demangle), 1) 998 EXTLIBS += -liberty 999 endif 1000 endif 1001 ifneq ($(filter -liberty,$(EXTLIBS)),) 1002 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 1003 CXXFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 1004 endif 1005 endif 1006endif 1007 1008ifndef NO_LZMA 1009 ifeq ($(feature-lzma), 1) 1010 CFLAGS += -DHAVE_LZMA_SUPPORT 1011 EXTLIBS += -llzma 1012 $(call detected,CONFIG_LZMA) 1013 else 1014 $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev) 1015 NO_LZMA := 1 1016 endif 1017endif 1018 1019ifndef NO_LIBZSTD 1020 ifeq ($(feature-libzstd), 1) 1021 CFLAGS += -DHAVE_ZSTD_SUPPORT 1022 CFLAGS += $(LIBZSTD_CFLAGS) 1023 LDFLAGS += $(LIBZSTD_LDFLAGS) 1024 EXTLIBS += -lzstd 1025 $(call detected,CONFIG_ZSTD) 1026 else 1027 $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR) 1028 NO_LIBZSTD := 1 1029 endif 1030endif 1031 1032ifndef NO_BACKTRACE 1033 ifeq ($(feature-backtrace), 1) 1034 CFLAGS += -DHAVE_BACKTRACE_SUPPORT 1035 endif 1036endif 1037 1038ifndef NO_LIBNUMA 1039 ifeq ($(feature-libnuma), 0) 1040 $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev) 1041 NO_LIBNUMA := 1 1042 else 1043 ifeq ($(feature-numa_num_possible_cpus), 0) 1044 $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8) 1045 NO_LIBNUMA := 1 1046 else 1047 CFLAGS += -DHAVE_LIBNUMA_SUPPORT 1048 EXTLIBS += -lnuma 1049 $(call detected,CONFIG_NUMA) 1050 endif 1051 endif 1052endif 1053 1054ifdef HAVE_KVM_STAT_SUPPORT 1055 CFLAGS += -DHAVE_KVM_STAT_SUPPORT 1056endif 1057 1058ifeq ($(feature-disassembler-four-args), 1) 1059 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 1060endif 1061 1062ifeq ($(feature-disassembler-init-styled), 1) 1063 CFLAGS += -DDISASM_INIT_STYLED 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 1193 1194 ifeq ($(feature-libtracefs), 1) 1195 CFLAGS += $(shell $(PKG_CONFIG) --cflags libtracefs) 1196 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libtracefs) 1197 EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libtracefs) 1198 LIBTRACEFS_VERSION := $(shell $(PKG_CONFIG) --modversion libtracefs).0.0 1199 LIBTRACEFS_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEFS_VERSION))) 1200 LIBTRACEFS_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEFS_VERSION))) 1201 LIBTRACEFS_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEFS_VERSION))) 1202 LIBTRACEFS_VERSION_CPP := $(shell expr $(LIBTRACEFS_VERSION_1) \* 255 \* 255 + $(LIBTRACEFS_VERSION_2) \* 255 + $(LIBTRACEFS_VERSION_3)) 1203 CFLAGS += -DLIBTRACEFS_VERSION=$(LIBTRACEFS_VERSION_CPP) 1204 else 1205 $(warning libtracefs is missing. Please install libtracefs-dev/libtracefs-devel) 1206 endif 1207endif 1208 1209# Among the variables below, these: 1210# perfexecdir 1211# libbpf_include_dir 1212# perf_examples_dir 1213# template_dir 1214# mandir 1215# infodir 1216# htmldir 1217# ETC_PERFCONFIG (but not sysconfdir) 1218# can be specified as a relative path some/where/else; 1219# this is interpreted as relative to $(prefix) and "perf" at 1220# runtime figures out where they are based on the path to the executable. 1221# This can help installing the suite in a relocatable way. 1222 1223# Make the path relative to DESTDIR, not to prefix 1224ifndef DESTDIR 1225prefix ?= $(HOME) 1226endif 1227bindir_relative = bin 1228bindir = $(abspath $(prefix)/$(bindir_relative)) 1229includedir_relative = include 1230includedir = $(abspath $(prefix)/$(includedir_relative)) 1231mandir = share/man 1232infodir = share/info 1233perfexecdir = libexec/perf-core 1234# FIXME: system's libbpf header directory, where we expect to find bpf/bpf_helpers.h, for instance 1235libbpf_include_dir = /usr/include 1236perf_examples_dir = lib/perf/examples 1237sharedir = $(prefix)/share 1238template_dir = share/perf-core/templates 1239STRACE_GROUPS_DIR = share/perf-core/strace/groups 1240htmldir = share/doc/perf-doc 1241tipdir = share/doc/perf-tip 1242srcdir = $(srctree)/tools/perf 1243ifeq ($(prefix),/usr) 1244sysconfdir = /etc 1245ETC_PERFCONFIG = $(sysconfdir)/perfconfig 1246else 1247sysconfdir = $(prefix)/etc 1248ETC_PERFCONFIG = etc/perfconfig 1249endif 1250ifndef lib 1251ifeq ($(SRCARCH)$(IS_64_BIT), x861) 1252lib = lib64 1253else 1254lib = lib 1255endif 1256endif # lib 1257libdir = $(prefix)/$(lib) 1258 1259# Shell quote (do not use $(call) to accommodate ancient setups); 1260ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG)) 1261STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR)) 1262DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) 1263bindir_SQ = $(subst ','\'',$(bindir)) 1264includedir_SQ = $(subst ','\'',$(includedir)) 1265mandir_SQ = $(subst ','\'',$(mandir)) 1266infodir_SQ = $(subst ','\'',$(infodir)) 1267perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) 1268libbpf_include_dir_SQ = $(subst ','\'',$(libbpf_include_dir)) 1269perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir)) 1270template_dir_SQ = $(subst ','\'',$(template_dir)) 1271htmldir_SQ = $(subst ','\'',$(htmldir)) 1272tipdir_SQ = $(subst ','\'',$(tipdir)) 1273prefix_SQ = $(subst ','\'',$(prefix)) 1274sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) 1275libdir_SQ = $(subst ','\'',$(libdir)) 1276srcdir_SQ = $(subst ','\'',$(srcdir)) 1277 1278ifneq ($(filter /%,$(firstword $(perfexecdir))),) 1279perfexec_instdir = $(perfexecdir) 1280perf_include_instdir = $(libbpf_include_dir) 1281perf_examples_instdir = $(perf_examples_dir) 1282STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) 1283tip_instdir = $(tipdir) 1284else 1285perfexec_instdir = $(prefix)/$(perfexecdir) 1286perf_include_instdir = $(prefix)/$(libbpf_include_dir) 1287perf_examples_instdir = $(prefix)/$(perf_examples_dir) 1288STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) 1289tip_instdir = $(prefix)/$(tipdir) 1290endif 1291perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) 1292perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir)) 1293perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir)) 1294STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) 1295tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) 1296 1297export perfexec_instdir_SQ 1298 1299print_var = $(eval $(print_var_code)) $(info $(MSG)) 1300define print_var_code 1301 MSG = $(shell printf '...%40s: %s' $(1) $($(1))) 1302endef 1303 1304ifeq ($(feature_display),1) 1305 $(call feature_display_entries) 1306endif 1307 1308ifeq ($(VF),1) 1309 # Display EXTRA features which are detected manualy 1310 # from here with feature_check call and thus cannot 1311 # be partof global state output. 1312 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),) $(info $(MSG))) 1313 $(call print_var,prefix) 1314 $(call print_var,bindir) 1315 $(call print_var,libdir) 1316 $(call print_var,sysconfdir) 1317 $(call print_var,LIBUNWIND_DIR) 1318 $(call print_var,LIBDW_DIR) 1319 $(call print_var,JDIR) 1320 1321 ifeq ($(dwarf-post-unwind),1) 1322 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) $(info $(MSG)) 1323 endif 1324endif 1325 1326$(info ) 1327 1328$(call detected_var,bindir_SQ) 1329$(call detected_var,PYTHON_WORD) 1330ifneq ($(OUTPUT),) 1331$(call detected_var,OUTPUT) 1332endif 1333$(call detected_var,htmldir_SQ) 1334$(call detected_var,infodir_SQ) 1335$(call detected_var,mandir_SQ) 1336$(call detected_var,ETC_PERFCONFIG_SQ) 1337$(call detected_var,STRACE_GROUPS_DIR_SQ) 1338$(call detected_var,prefix_SQ) 1339$(call detected_var,perfexecdir_SQ) 1340$(call detected_var,libbpf_include_dir_SQ) 1341$(call detected_var,perf_examples_dir_SQ) 1342$(call detected_var,tipdir_SQ) 1343$(call detected_var,srcdir_SQ) 1344$(call detected_var,LIBDIR) 1345$(call detected_var,GTK_CFLAGS) 1346$(call detected_var,PERL_EMBED_CCOPTS) 1347$(call detected_var,PYTHON_EMBED_CCOPTS) 1348ifneq ($(BISON_FILE_PREFIX_MAP),) 1349$(call detected_var,BISON_FILE_PREFIX_MAP) 1350endif 1351 1352# re-generate FEATURE-DUMP as we may have called feature_check, found out 1353# extra libraries to add to LDFLAGS of some other test and then redo those 1354# tests, see the block about libbfd, disassembler-four-args, for instance. 1355$(shell rm -f $(FEATURE_DUMP_FILENAME)) 1356$(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME))) 1357