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