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