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