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 endif 564 endif 565 566 ifndef NO_LIBDW 567 CFLAGS += -DHAVE_LIBDW_SUPPORT $(LIBDW_CFLAGS) 568 LDFLAGS += $(LIBDW_LDFLAGS) 569 EXTLIBS += ${DWARFLIBS} 570 $(call detected,CONFIG_LIBDW) 571 endif # NO_LIBDW 572 573 ifndef NO_LIBBPF 574 ifeq ($(feature-bpf), 1) 575 # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status 576 $(call feature_check,libbpf) 577 578 ifdef LIBBPF_DYNAMIC 579 ifeq ($(feature-libbpf), 1) 580 EXTLIBS += -lbpf 581 CFLAGS += -DHAVE_LIBBPF_SUPPORT 582 $(call detected,CONFIG_LIBBPF) 583 $(call detected,CONFIG_LIBBPF_DYNAMIC) 584 else 585 $(error Error: No libbpf devel library found or older than v1.0, please install/update libbpf-devel) 586 endif 587 else 588 ifeq ($(NO_ZLIB), 1) 589 $(warning Warning: Statically building libbpf not possible as zlib is missing) 590 NO_LIBBPF := 1 591 else 592 # Libbpf will be built as a static library from tools/lib/bpf. 593 LIBBPF_STATIC := 1 594 $(call detected,CONFIG_LIBBPF) 595 CFLAGS += -DHAVE_LIBBPF_SUPPORT 596 endif 597 endif 598 endif 599 endif # NO_LIBBPF 600endif # NO_LIBELF 601 602ifndef NO_SDT 603 ifneq ($(feature-sdt), 1) 604 $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev) 605 NO_SDT := 1; 606 else 607 CFLAGS += -DHAVE_SDT_EVENT 608 $(call detected,CONFIG_SDT_EVENT) 609 endif 610endif 611 612ifdef PERF_HAVE_JITDUMP 613 ifndef NO_LIBELF 614 $(call detected,CONFIG_JITDUMP) 615 CFLAGS += -DHAVE_JITDUMP 616 endif 617endif 618 619ifeq ($(SRCARCH),powerpc) 620 ifndef NO_LIBDW 621 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX 622 endif 623endif 624 625ifndef NO_LIBUNWIND 626 have_libunwind := 627 628 $(call feature_check,libunwind-x86) 629 ifeq ($(feature-libunwind-x86), 1) 630 $(call detected,CONFIG_LIBUNWIND_X86) 631 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT 632 LDFLAGS += -lunwind-x86 633 EXTLIBS_LIBUNWIND += -lunwind-x86 634 have_libunwind = 1 635 endif 636 637 $(call feature_check,libunwind-aarch64) 638 ifeq ($(feature-libunwind-aarch64), 1) 639 $(call detected,CONFIG_LIBUNWIND_AARCH64) 640 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT 641 LDFLAGS += -lunwind-aarch64 642 EXTLIBS_LIBUNWIND += -lunwind-aarch64 643 have_libunwind = 1 644 $(call feature_check,libunwind-debug-frame-aarch64) 645 ifneq ($(feature-libunwind-debug-frame-aarch64), 1) 646 $(warning No debug_frame support found in libunwind-aarch64) 647 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64 648 endif 649 endif 650 651 ifneq ($(feature-libunwind), 1) 652 $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR) 653 NO_LOCAL_LIBUNWIND := 1 654 else 655 have_libunwind := 1 656 $(call detected,CONFIG_LOCAL_LIBUNWIND) 657 endif 658 659 ifneq ($(have_libunwind), 1) 660 NO_LIBUNWIND := 1 661 endif 662else 663 NO_LOCAL_LIBUNWIND := 1 664endif 665 666ifndef NO_LIBBPF 667 ifneq ($(feature-bpf), 1) 668 $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.) 669 NO_LIBBPF := 1 670 endif 671endif 672 673ifndef BUILD_BPF_SKEL 674 # BPF skeletons control a large number of perf features, by default 675 # they are enabled. 676 BUILD_BPF_SKEL := 1 677endif 678 679ifeq ($(BUILD_BPF_SKEL),1) 680 ifeq ($(filter -DHAVE_LIBELF_SUPPORT, $(CFLAGS)),) 681 $(warning Warning: Disabled BPF skeletons as libelf is required by bpftool) 682 BUILD_BPF_SKEL := 0 683 else ifeq ($(filter -DHAVE_ZLIB_SUPPORT, $(CFLAGS)),) 684 $(warning Warning: Disabled BPF skeletons as zlib is required by bpftool) 685 BUILD_BPF_SKEL := 0 686 else ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),) 687 $(warning Warning: Disabled BPF skeletons as libbpf is required) 688 BUILD_BPF_SKEL := 0 689 else ifeq ($(call get-executable,$(CLANG)),) 690 $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) 691 BUILD_BPF_SKEL := 0 692 else 693 CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') 694 ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) 695 $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) 696 BUILD_BPF_SKEL := 0 697 endif 698 endif 699 ifeq ($(BUILD_BPF_SKEL),1) 700 $(call feature_check,clang-bpf-co-re) 701 ifeq ($(feature-clang-bpf-co-re), 0) 702 $(warning Warning: Disabled BPF skeletons as clang is too old) 703 BUILD_BPF_SKEL := 0 704 endif 705 endif 706 ifeq ($(BUILD_BPF_SKEL),1) 707 $(call detected,CONFIG_PERF_BPF_SKEL) 708 CFLAGS += -DHAVE_BPF_SKEL 709 endif 710endif 711 712ifndef GEN_VMLINUX_H 713 VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h 714endif 715 716dwarf-post-unwind := 1 717dwarf-post-unwind-text := BUG 718 719# setup DWARF post unwinder 720ifdef NO_LIBUNWIND 721 ifdef NO_LIBDW_DWARF_UNWIND 722 $(warning Disabling post unwind, no support found.) 723 dwarf-post-unwind := 0 724 else 725 dwarf-post-unwind-text := libdw 726 $(call detected,CONFIG_LIBDW_DWARF_UNWIND) 727 endif 728else 729 dwarf-post-unwind-text := libunwind 730 $(call detected,CONFIG_LIBUNWIND) 731 # Enable libunwind support by default. 732 ifndef NO_LIBDW_DWARF_UNWIND 733 NO_LIBDW_DWARF_UNWIND := 1 734 endif 735endif 736 737ifeq ($(dwarf-post-unwind),1) 738 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT 739 $(call detected,CONFIG_DWARF_UNWIND) 740endif 741 742ifndef NO_LIBUNWIND 743 ifndef NO_LOCAL_LIBUNWIND 744 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64)) 745 $(call feature_check,libunwind-debug-frame) 746 ifneq ($(feature-libunwind-debug-frame), 1) 747 $(warning No debug_frame support found in libunwind) 748 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 749 endif 750 else 751 # non-ARM has no dwarf_find_debug_frame() function: 752 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME 753 endif 754 EXTLIBS += $(LIBUNWIND_LIBS) 755 LDFLAGS += $(LIBUNWIND_LIBS) 756 endif 757 ifeq ($(findstring -static,${LDFLAGS}),-static) 758 # gcc -static links libgcc_eh which contans piece of libunwind 759 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition 760 endif 761 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT 762 CFLAGS += $(LIBUNWIND_CFLAGS) 763 LDFLAGS += $(LIBUNWIND_LDFLAGS) 764 EXTLIBS += $(EXTLIBS_LIBUNWIND) 765endif 766 767ifneq ($(NO_LIBTRACEEVENT),1) 768 $(call detected,CONFIG_TRACE) 769endif 770 771ifndef NO_LIBCRYPTO 772 ifneq ($(feature-libcrypto), 1) 773 $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev) 774 NO_LIBCRYPTO := 1 775 else 776 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT 777 EXTLIBS += -lcrypto 778 $(call detected,CONFIG_CRYPTO) 779 endif 780endif 781 782ifndef NO_SLANG 783 ifneq ($(feature-libslang), 1) 784 ifneq ($(feature-libslang-include-subdir), 1) 785 $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev) 786 NO_SLANG := 1 787 else 788 CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR 789 endif 790 endif 791 ifndef NO_SLANG 792 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h 793 CFLAGS += -DHAVE_SLANG_SUPPORT 794 EXTLIBS += -lslang 795 $(call detected,CONFIG_SLANG) 796 endif 797endif 798 799ifdef GTK2 800 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 801 $(call feature_check,gtk2) 802 ifneq ($(feature-gtk2), 1) 803 $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev) 804 NO_GTK2 := 1 805 else 806 $(call feature_check,gtk2-infobar) 807 ifeq ($(feature-gtk2-infobar), 1) 808 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT 809 endif 810 CFLAGS += -DHAVE_GTK2_SUPPORT 811 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null) 812 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null) 813 EXTLIBS += -ldl 814 endif 815endif 816 817ifdef NO_LIBPERL 818 CFLAGS += -DNO_LIBPERL 819else 820 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 821 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 822 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 823 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) 824 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) 825 PERL_EMBED_CCOPTS := $(filter-out -flto% -ffat-lto-objects, $(PERL_EMBED_CCOPTS)) 826 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) 827 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 828 829 ifneq ($(feature-libperl), 1) 830 CFLAGS += -DNO_LIBPERL 831 NO_LIBPERL := 1 832 $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev) 833 else 834 LDFLAGS += $(PERL_EMBED_LDFLAGS) 835 EXTLIBS += $(PERL_EMBED_LIBADD) 836 CFLAGS += -DHAVE_LIBPERL_SUPPORT 837 ifeq ($(CC_NO_CLANG), 0) 838 CFLAGS += -Wno-compound-token-split-by-macro 839 endif 840 $(call detected,CONFIG_LIBPERL) 841 endif 842endif 843 844ifeq ($(feature-timerfd), 1) 845 CFLAGS += -DHAVE_TIMERFD_SUPPORT 846else 847 $(warning No timerfd support. Disables 'perf kvm stat live') 848endif 849 850disable-python = $(eval $(disable-python_code)) 851define disable-python_code 852 CFLAGS += -DNO_LIBPYTHON 853 $(warning $1) 854 NO_LIBPYTHON := 1 855endef 856 857PYTHON_EXTENSION_SUFFIX := '.so' 858ifdef NO_LIBPYTHON 859 $(call disable-python,Python support disabled by user) 860else 861 862 ifndef PYTHON 863 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev) 864 else 865 PYTHON_WORD := $(call shell-wordify,$(PYTHON)) 866 867 ifndef PYTHON_CONFIG 868 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev) 869 else 870 871 ifneq ($(feature-libpython), 1) 872 $(call disable-python,No 'Python.h' was found: disables Python support - please install python-devel/python-dev) 873 else 874 LDFLAGS += $(PYTHON_EMBED_LDFLAGS) 875 EXTLIBS += $(PYTHON_EMBED_LIBADD) 876 PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no") 877 ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes) 878 PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])') 879 ifdef CROSS_COMPILE 880 PYTHON_EXTENSION_SUFFIX := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EXTENSION_SUFFIX)) 881 endif 882 LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX) 883 else 884 $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent) 885 endif 886 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT 887 $(call detected,CONFIG_LIBPYTHON) 888 ifeq ($(filter -fPIC,$(CFLAGS)),) 889 # Building a shared library requires position independent code. 890 CFLAGS += -fPIC 891 CXXFLAGS += -fPIC 892 endif 893 endif 894 endif 895 endif 896endif 897 898ifneq ($(NO_JEVENTS),1) 899 ifeq ($(wildcard pmu-events/arch/$(SRCARCH)/mapfile.csv),) 900 NO_JEVENTS := 1 901 endif 902endif 903ifneq ($(NO_JEVENTS),1) 904 NO_JEVENTS := 0 905 ifndef PYTHON 906 $(error ERROR: No python interpreter needed for jevents generation. Install python or build with NO_JEVENTS=1.) 907 else 908 # jevents.py uses f-strings present in Python 3.6 released in Dec. 2016. 909 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) 910 ifneq ($(JEVENTS_PYTHON_GOOD), 1) 911 $(error ERROR: Python interpreter needed for jevents generation too old (older than 3.6). Install a newer python or build with NO_JEVENTS=1.) 912 endif 913 endif 914endif 915 916ifdef BUILD_NONDISTRO 917 ifeq ($(feature-libbfd), 1) 918 EXTLIBS += -lbfd -lopcodes 919 else 920 # we are on a system that requires -liberty and (maybe) -lz 921 # to link against -lbfd; test each case individually here 922 923 # call all detections now so we get correct 924 # status in VF output 925 $(call feature_check,libbfd-liberty) 926 $(call feature_check,libbfd-liberty-z) 927 928 ifeq ($(feature-libbfd-liberty), 1) 929 EXTLIBS += -lbfd -lopcodes -liberty 930 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl 931 FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl 932 else 933 ifeq ($(feature-libbfd-liberty-z), 1) 934 EXTLIBS += -lbfd -lopcodes -liberty -lz 935 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl 936 FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl 937 endif 938 endif 939 $(call feature_check,disassembler-four-args) 940 $(call feature_check,disassembler-init-styled) 941 endif 942 943 CFLAGS += -DHAVE_LIBBFD_SUPPORT 944 CXXFLAGS += -DHAVE_LIBBFD_SUPPORT 945 ifeq ($(feature-libbfd-buildid), 1) 946 CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT 947 else 948 $(warning Old version of libbfd/binutils things like PE executable profiling will not be available) 949 endif 950endif 951 952ifndef NO_LIBLLVM 953 $(call feature_check,llvm-perf) 954 ifeq ($(feature-llvm-perf), 1) 955 CFLAGS += -DHAVE_LIBLLVM_SUPPORT 956 CFLAGS += $(shell $(LLVM_CONFIG) --cflags) 957 CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT 958 CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags) 959 LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs) 960 EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM) 961 EXTLIBS += -lstdc++ 962 $(call detected,CONFIG_LIBLLVM) 963 else 964 $(warning No libllvm 13+ found, slower source file resolution, please install llvm-devel/llvm-dev) 965 NO_LIBLLVM := 1 966 endif 967endif 968 969ifndef NO_DEMANGLE 970 $(call feature_check,cxa-demangle) 971 ifeq ($(feature-cxa-demangle), 1) 972 EXTLIBS += -lstdc++ 973 CFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT 974 CXXFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT 975 $(call detected,CONFIG_CXX_DEMANGLE) 976 endif 977 ifdef BUILD_NONDISTRO 978 ifeq ($(filter -liberty,$(EXTLIBS)),) 979 $(call feature_check,cplus-demangle) 980 ifeq ($(feature-cplus-demangle), 1) 981 EXTLIBS += -liberty 982 endif 983 endif 984 ifneq ($(filter -liberty,$(EXTLIBS)),) 985 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 986 CXXFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT 987 endif 988 endif 989endif 990 991ifndef NO_LZMA 992 ifeq ($(feature-lzma), 1) 993 CFLAGS += -DHAVE_LZMA_SUPPORT 994 EXTLIBS += -llzma 995 $(call detected,CONFIG_LZMA) 996 else 997 $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev) 998 NO_LZMA := 1 999 endif 1000endif 1001 1002ifndef NO_LIBZSTD 1003 ifeq ($(feature-libzstd), 1) 1004 CFLAGS += -DHAVE_ZSTD_SUPPORT 1005 CFLAGS += $(LIBZSTD_CFLAGS) 1006 LDFLAGS += $(LIBZSTD_LDFLAGS) 1007 EXTLIBS += -lzstd 1008 $(call detected,CONFIG_ZSTD) 1009 else 1010 $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR) 1011 NO_LIBZSTD := 1 1012 endif 1013endif 1014 1015ifndef NO_BACKTRACE 1016 ifeq ($(feature-backtrace), 1) 1017 CFLAGS += -DHAVE_BACKTRACE_SUPPORT 1018 endif 1019endif 1020 1021ifndef NO_LIBNUMA 1022 ifeq ($(feature-libnuma), 0) 1023 $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev) 1024 NO_LIBNUMA := 1 1025 else 1026 ifeq ($(feature-numa_num_possible_cpus), 0) 1027 $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8) 1028 NO_LIBNUMA := 1 1029 else 1030 CFLAGS += -DHAVE_LIBNUMA_SUPPORT 1031 EXTLIBS += -lnuma 1032 $(call detected,CONFIG_NUMA) 1033 endif 1034 endif 1035endif 1036 1037ifdef HAVE_KVM_STAT_SUPPORT 1038 CFLAGS += -DHAVE_KVM_STAT_SUPPORT 1039endif 1040 1041ifeq ($(feature-disassembler-four-args), 1) 1042 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 1043endif 1044 1045ifeq ($(feature-disassembler-init-styled), 1) 1046 CFLAGS += -DDISASM_INIT_STYLED 1047endif 1048 1049ifeq (${IS_64_BIT}, 1) 1050 ifndef NO_PERF_READ_VDSO32 1051 $(call feature_check,compile-32) 1052 ifeq ($(feature-compile-32), 1) 1053 CFLAGS += -DHAVE_PERF_READ_VDSO32 1054 else 1055 NO_PERF_READ_VDSO32 := 1 1056 endif 1057 endif 1058 ifneq ($(SRCARCH), x86) 1059 NO_PERF_READ_VDSOX32 := 1 1060 endif 1061 ifndef NO_PERF_READ_VDSOX32 1062 $(call feature_check,compile-x32) 1063 ifeq ($(feature-compile-x32), 1) 1064 CFLAGS += -DHAVE_PERF_READ_VDSOX32 1065 else 1066 NO_PERF_READ_VDSOX32 := 1 1067 endif 1068 endif 1069else 1070 NO_PERF_READ_VDSO32 := 1 1071 NO_PERF_READ_VDSOX32 := 1 1072endif 1073 1074ifndef NO_LIBBABELTRACE 1075 $(call feature_check,libbabeltrace) 1076 ifeq ($(feature-libbabeltrace), 1) 1077 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS) 1078 LDFLAGS += $(LIBBABELTRACE_LDFLAGS) 1079 EXTLIBS += -lbabeltrace-ctf 1080 $(call detected,CONFIG_LIBBABELTRACE) 1081 else 1082 $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev) 1083 endif 1084endif 1085 1086ifndef NO_CAPSTONE 1087 $(call feature_check,libcapstone) 1088 ifeq ($(feature-libcapstone), 1) 1089 CFLAGS += -DHAVE_LIBCAPSTONE_SUPPORT $(LIBCAPSTONE_CFLAGS) 1090 LDFLAGS += $(LICAPSTONE_LDFLAGS) 1091 EXTLIBS += -lcapstone 1092 $(call detected,CONFIG_LIBCAPSTONE) 1093 else 1094 msg := $(warning No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel); 1095 endif 1096endif 1097 1098ifndef NO_AUXTRACE 1099 ifeq ($(SRCARCH),x86) 1100 ifeq ($(feature-get_cpuid), 0) 1101 $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc) 1102 NO_AUXTRACE := 1 1103 endif 1104 endif 1105 ifndef NO_AUXTRACE 1106 $(call detected,CONFIG_AUXTRACE) 1107 CFLAGS += -DHAVE_AUXTRACE_SUPPORT 1108 endif 1109endif 1110 1111ifdef EXTRA_TESTS 1112 $(call detected,CONFIG_EXTRA_TESTS) 1113 CFLAGS += -DHAVE_EXTRA_TESTS 1114endif 1115 1116ifndef NO_JVMTI 1117 ifneq (,$(wildcard /usr/sbin/update-java-alternatives)) 1118 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}') 1119 else 1120 ifneq (,$(wildcard /usr/sbin/alternatives)) 1121 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') 1122 endif 1123 endif 1124 ifndef JDIR 1125 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory) 1126 NO_JVMTI := 1 1127 endif 1128endif 1129 1130ifndef NO_JVMTI 1131 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux 1132 $(call feature_check,jvmti) 1133 ifeq ($(feature-jvmti), 1) 1134 $(call detected_var,JDIR) 1135 ifndef NO_JVMTI_CMLR 1136 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti) 1137 $(call feature_check,jvmti-cmlr) 1138 ifeq ($(feature-jvmti-cmlr), 1) 1139 CFLAGS += -DHAVE_JVMTI_CMLR 1140 endif 1141 endif # NO_JVMTI_CMLR 1142 else 1143 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel) 1144 NO_JVMTI := 1 1145 endif 1146endif 1147 1148ifndef NO_LIBPFM4 1149 $(call feature_check,libpfm4) 1150 ifeq ($(feature-libpfm4), 1) 1151 CFLAGS += -DHAVE_LIBPFM 1152 EXTLIBS += -lpfm 1153 ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1 1154 $(call detected,CONFIG_LIBPFM4) 1155 else 1156 $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev) 1157 endif 1158endif 1159 1160# libtraceevent is a recommended dependency picked up from the system. 1161ifneq ($(NO_LIBTRACEEVENT),1) 1162 ifeq ($(feature-libtraceevent), 1) 1163 CFLAGS += -DHAVE_LIBTRACEEVENT $(shell $(PKG_CONFIG) --cflags libtraceevent) 1164 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libtraceevent) 1165 EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libtraceevent) 1166 LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent).0.0 1167 LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION))) 1168 LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION))) 1169 LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION))) 1170 LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3)) 1171 CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP) 1172 $(call detected,CONFIG_LIBTRACEEVENT) 1173 else 1174 $(error ERROR: libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel and/or set LIBTRACEEVENT_DIR or build with NO_LIBTRACEEVENT=1) 1175 endif 1176 1177 ifeq ($(feature-libtracefs), 1) 1178 CFLAGS += $(shell $(PKG_CONFIG) --cflags libtracefs) 1179 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libtracefs) 1180 EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libtracefs) 1181 LIBTRACEFS_VERSION := $(shell $(PKG_CONFIG) --modversion libtracefs).0.0 1182 LIBTRACEFS_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEFS_VERSION))) 1183 LIBTRACEFS_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEFS_VERSION))) 1184 LIBTRACEFS_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEFS_VERSION))) 1185 LIBTRACEFS_VERSION_CPP := $(shell expr $(LIBTRACEFS_VERSION_1) \* 255 \* 255 + $(LIBTRACEFS_VERSION_2) \* 255 + $(LIBTRACEFS_VERSION_3)) 1186 CFLAGS += -DLIBTRACEFS_VERSION=$(LIBTRACEFS_VERSION_CPP) 1187 else 1188 $(warning libtracefs is missing. Please install libtracefs-dev/libtracefs-devel) 1189 endif 1190endif 1191 1192# Among the variables below, these: 1193# perfexecdir 1194# libbpf_include_dir 1195# perf_examples_dir 1196# template_dir 1197# mandir 1198# infodir 1199# htmldir 1200# ETC_PERFCONFIG (but not sysconfdir) 1201# can be specified as a relative path some/where/else; 1202# this is interpreted as relative to $(prefix) and "perf" at 1203# runtime figures out where they are based on the path to the executable. 1204# This can help installing the suite in a relocatable way. 1205 1206# Make the path relative to DESTDIR, not to prefix 1207ifndef DESTDIR 1208prefix ?= $(HOME) 1209endif 1210bindir_relative = bin 1211bindir = $(abspath $(prefix)/$(bindir_relative)) 1212includedir_relative = include 1213includedir = $(abspath $(prefix)/$(includedir_relative)) 1214mandir = share/man 1215infodir = share/info 1216perfexecdir = libexec/perf-core 1217# FIXME: system's libbpf header directory, where we expect to find bpf/bpf_helpers.h, for instance 1218libbpf_include_dir = /usr/include 1219perf_examples_dir = lib/perf/examples 1220sharedir = $(prefix)/share 1221template_dir = share/perf-core/templates 1222STRACE_GROUPS_DIR = share/perf-core/strace/groups 1223htmldir = share/doc/perf-doc 1224tipdir = share/doc/perf-tip 1225srcdir = $(srctree)/tools/perf 1226ifeq ($(prefix),/usr) 1227sysconfdir = /etc 1228ETC_PERFCONFIG = $(sysconfdir)/perfconfig 1229else 1230sysconfdir = $(prefix)/etc 1231ETC_PERFCONFIG = etc/perfconfig 1232endif 1233ifndef lib 1234ifeq ($(SRCARCH)$(IS_64_BIT), x861) 1235lib = lib64 1236else 1237lib = lib 1238endif 1239endif # lib 1240libdir = $(prefix)/$(lib) 1241 1242# Shell quote (do not use $(call) to accommodate ancient setups); 1243ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG)) 1244STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR)) 1245DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) 1246bindir_SQ = $(subst ','\'',$(bindir)) 1247includedir_SQ = $(subst ','\'',$(includedir)) 1248mandir_SQ = $(subst ','\'',$(mandir)) 1249infodir_SQ = $(subst ','\'',$(infodir)) 1250perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) 1251libbpf_include_dir_SQ = $(subst ','\'',$(libbpf_include_dir)) 1252perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir)) 1253template_dir_SQ = $(subst ','\'',$(template_dir)) 1254htmldir_SQ = $(subst ','\'',$(htmldir)) 1255tipdir_SQ = $(subst ','\'',$(tipdir)) 1256prefix_SQ = $(subst ','\'',$(prefix)) 1257sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) 1258libdir_SQ = $(subst ','\'',$(libdir)) 1259srcdir_SQ = $(subst ','\'',$(srcdir)) 1260 1261ifneq ($(filter /%,$(firstword $(perfexecdir))),) 1262perfexec_instdir = $(perfexecdir) 1263perf_include_instdir = $(libbpf_include_dir) 1264perf_examples_instdir = $(perf_examples_dir) 1265STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) 1266tip_instdir = $(tipdir) 1267else 1268perfexec_instdir = $(prefix)/$(perfexecdir) 1269perf_include_instdir = $(prefix)/$(libbpf_include_dir) 1270perf_examples_instdir = $(prefix)/$(perf_examples_dir) 1271STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) 1272tip_instdir = $(prefix)/$(tipdir) 1273endif 1274perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) 1275perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir)) 1276perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir)) 1277STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) 1278tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) 1279 1280export perfexec_instdir_SQ 1281 1282print_var = $(eval $(print_var_code)) $(info $(MSG)) 1283define print_var_code 1284 MSG = $(shell printf '...%40s: %s' $(1) $($(1))) 1285endef 1286 1287ifeq ($(feature_display),1) 1288 $(call feature_display_entries) 1289endif 1290 1291ifeq ($(VF),1) 1292 # Display EXTRA features which are detected manualy 1293 # from here with feature_check call and thus cannot 1294 # be partof global state output. 1295 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),) $(info $(MSG))) 1296 $(call print_var,prefix) 1297 $(call print_var,bindir) 1298 $(call print_var,libdir) 1299 $(call print_var,sysconfdir) 1300 $(call print_var,LIBUNWIND_DIR) 1301 $(call print_var,LIBDW_DIR) 1302 $(call print_var,JDIR) 1303 1304 ifeq ($(dwarf-post-unwind),1) 1305 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) $(info $(MSG)) 1306 endif 1307endif 1308 1309$(info ) 1310 1311$(call detected_var,bindir_SQ) 1312$(call detected_var,PYTHON_WORD) 1313ifneq ($(OUTPUT),) 1314$(call detected_var,OUTPUT) 1315endif 1316$(call detected_var,htmldir_SQ) 1317$(call detected_var,infodir_SQ) 1318$(call detected_var,mandir_SQ) 1319$(call detected_var,ETC_PERFCONFIG_SQ) 1320$(call detected_var,STRACE_GROUPS_DIR_SQ) 1321$(call detected_var,prefix_SQ) 1322$(call detected_var,perfexecdir_SQ) 1323$(call detected_var,libbpf_include_dir_SQ) 1324$(call detected_var,perf_examples_dir_SQ) 1325$(call detected_var,tipdir_SQ) 1326$(call detected_var,srcdir_SQ) 1327$(call detected_var,LIBDIR) 1328$(call detected_var,GTK_CFLAGS) 1329$(call detected_var,PERL_EMBED_CCOPTS) 1330$(call detected_var,PYTHON_EMBED_CCOPTS) 1331ifneq ($(BISON_FILE_PREFIX_MAP),) 1332$(call detected_var,BISON_FILE_PREFIX_MAP) 1333endif 1334 1335# re-generate FEATURE-DUMP as we may have called feature_check, found out 1336# extra libraries to add to LDFLAGS of some other test and then redo those 1337# tests, see the block about libbfd, disassembler-four-args, for instance. 1338$(shell rm -f $(FEATURE_DUMP_FILENAME)) 1339$(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME))) 1340