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