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