1 # SPDX-License-Identifier: GPL-2.0-only
4 src-perf := $(srctree)/tools/perf
12 obj-perf := $(abspath $(obj-perf))/
15 $(shell printf "" > $(OUTPUT).config-detected)
16 detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected)
17 detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
19 CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
21 include $(srctree)/tools/scripts/Makefile.arch
23 $(call detected_var,SRCARCH)
27 ifneq ($(NO_SYSCALL_TABLE),1)
31 ifeq (${IS_64_BIT}, 1)
35 ifeq ($(SRCARCH),$(filter $(SRCARCH),powerpc arm64 s390 mips))
40 ifneq ($(NO_SYSCALL_TABLE),1)
41 CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
45 # Additional ARCH settings for ppc
46 ifeq ($(SRCARCH),powerpc)
48 CFLAGS += -I$(OUTPUT)arch/powerpc/include/generated
49 LIBUNWIND_LIBS := -lunwind -lunwind-ppc64
52 # Additional ARCH settings for x86
54 $(call detected,CONFIG_X86)
55 ifeq (${IS_64_BIT}, 1)
56 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT -I$(OUTPUT)arch/x86/include/generated
57 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
58 LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma
59 $(call detected,CONFIG_X86_64)
61 LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind
68 LIBUNWIND_LIBS = -lunwind -lunwind-arm
71 ifeq ($(SRCARCH),arm64)
73 CFLAGS += -I$(OUTPUT)arch/arm64/include/generated
74 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
77 ifeq ($(SRCARCH),riscv)
81 ifeq ($(SRCARCH),csky)
87 CFLAGS += -fPIC -I$(OUTPUT)arch/s390/include/generated
92 CFLAGS += -I$(OUTPUT)arch/mips/include/generated
93 LIBUNWIND_LIBS = -lunwind -lunwind-mips
96 ifeq ($(NO_PERF_REGS),0)
97 $(call detected,CONFIG_PERF_REGS)
100 # So far there's only x86 and arm libdw unwind support merged in perf.
101 # Disable it on all other architectures in case libdw unwind
102 # support is detected in system. Add supported architectures
104 ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky riscv))
105 NO_LIBDW_DWARF_UNWIND := 1
108 ifeq ($(LIBUNWIND_LIBS),)
112 # For linking with debug library, run like:
114 # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
117 libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
118 define libunwind_arch_set_flags_code
119 FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include
120 FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
124 LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include
125 LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
126 LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
127 $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
130 # Set per-feature check compilation flags
131 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
132 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
133 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
134 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
136 FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm
137 FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64
138 FEATURE_CHECK_LDFLAGS-libunwind-x86 += -lunwind -llzma -lunwind-x86
139 FEATURE_CHECK_LDFLAGS-libunwind-x86_64 += -lunwind -llzma -lunwind-x86_64
141 FEATURE_CHECK_LDFLAGS-libcrypto = -lcrypto
144 LIBOPENCSD_CFLAGS := -I$(CSINCLUDES)
146 OPENCSDLIBS := -lopencsd_c_api
147 ifeq ($(findstring -static,${LDFLAGS}),-static)
148 OPENCSDLIBS += -lopencsd -lstdc++
151 LIBOPENCSD_LDFLAGS := -L$(CSLIBS)
153 FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS)
154 FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS)
156 ifeq ($(NO_PERF_REGS),0)
157 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
160 # for linking with debug library, run like:
161 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
163 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
164 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
167 ifeq ($(findstring -static,${LDFLAGS}),-static)
168 DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
170 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
171 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
173 # for linking with debug library, run like:
174 # make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
175 ifdef LIBBABELTRACE_DIR
176 LIBBABELTRACE_CFLAGS := -I$(LIBBABELTRACE_DIR)/include
177 LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
179 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
180 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
183 LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib
184 LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
186 FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
187 FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
189 FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
190 # include ARCH specific config
191 -include $(src-perf)/arch/$(SRCARCH)/Makefile
193 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
194 CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
197 include $(srctree)/tools/scripts/utilities.mak
199 ifeq ($(call get-executable,$(FLEX)),)
200 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
203 ifeq ($(call get-executable,$(BISON)),)
204 dummy := $(error Error: $(BISON) is missing on this system, please install it)
208 ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1)
209 BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)=
213 # Treat warnings as errors unless directed not to
215 CORE_CFLAGS += -Werror
224 ifeq ($(CC_NO_CLANG), 0)
232 PARSER_DEBUG_BISON := -t
233 PARSER_DEBUG_FLEX := -d
234 CFLAGS += -DPARSER_DEBUG
235 $(call detected_var,PARSER_DEBUG_BISON)
236 $(call detected_var,PARSER_DEBUG_FLEX)
239 # Try different combinations to accommodate systems that only have
240 # python[2][3]-config in weird combinations in the following order of
241 # priority from lowest to highest:
244 # * python2-config as per pep-0394.
245 # * $(PYTHON)-config (If PYTHON is user supplied but PYTHON_CONFIG isn't)
247 PYTHON_AUTO := python-config
248 PYTHON_AUTO := $(if $(call get-executable,python3-config),python3-config,$(PYTHON_AUTO))
249 PYTHON_AUTO := $(if $(call get-executable,python-config),python-config,$(PYTHON_AUTO))
250 PYTHON_AUTO := $(if $(call get-executable,python2-config),python2-config,$(PYTHON_AUTO))
252 # If PYTHON is defined but PYTHON_CONFIG isn't, then take $(PYTHON)-config as if it was the user
253 # supplied value for PYTHON_CONFIG. Because it's "user supplied", error out if it doesn't exist.
256 PYTHON_CONFIG_AUTO := $(call get-executable,$(PYTHON)-config)
257 PYTHON_CONFIG := $(if $(PYTHON_CONFIG_AUTO),$(PYTHON_CONFIG_AUTO),\
258 $(call $(error $(PYTHON)-config not found)))
262 # Select either auto detected python and python-config or use user supplied values if they are
263 # defined. get-executable-or-default fails with an error if the first argument is supplied but
265 override PYTHON_CONFIG := $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON_AUTO))
266 override PYTHON := $(call get-executable-or-default,PYTHON,$(subst -config,,$(PYTHON_AUTO)))
268 grep-libs = $(filter -l%,$(1))
269 strip-libs = $(filter-out -l%,$(1))
271 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
273 # Python 3.8 changed the output of `python-config --ldflags` to not include the
274 # '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for
275 # libpython fails if that flag is not included in LDFLAGS
276 ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0)
277 PYTHON_CONFIG_LDFLAGS := --ldflags --embed
279 PYTHON_CONFIG_LDFLAGS := --ldflags
283 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
284 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
285 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
286 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
287 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
288 ifeq ($(CC_NO_CLANG), 0)
289 PYTHON_EMBED_CCOPTS := $(filter-out -ffat-lto-objects, $(PYTHON_EMBED_CCOPTS))
293 FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
294 FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
296 FEATURE_CHECK_LDFLAGS-libaio = -lrt
298 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
300 CORE_CFLAGS += -fno-omit-frame-pointer
301 CORE_CFLAGS += -ggdb3
302 CORE_CFLAGS += -funwind-tables
304 CORE_CFLAGS += -Wextra
305 CORE_CFLAGS += -std=gnu99
307 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
309 CXXFLAGS += -fno-omit-frame-pointer
311 CXXFLAGS += -funwind-tables
312 CXXFLAGS += -Wno-strict-aliasing
314 # Enforce a non-executable stack, as we may regress (again) in the future by
315 # adding assembler files missing the .GNU-stack linker note.
316 LDFLAGS += -Wl,-z,noexecstack
318 EXTLIBS = -lpthread -lrt -lm -ldl
321 CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
322 EXTLIBS += -ltcmalloc
325 ifeq ($(FEATURES_DUMP),)
326 # We will display at the end of this Makefile.config, using $(call feature_display_entries)
327 # As we may retry some feature detection here, see the disassembler-four-args case, for instance
328 FEATURE_DISPLAY_DEFERRED := 1
329 include $(srctree)/tools/build/Makefile.feature
331 include $(FEATURES_DUMP)
334 ifeq ($(feature-stackprotector-all), 1)
335 CORE_CFLAGS += -fstack-protector-all
339 ifeq ($(feature-fortify-source), 1)
340 CORE_CFLAGS += -D_FORTIFY_SOURCE=2
344 INC_FLAGS += -I$(srctree)/tools/lib/perf/include
345 INC_FLAGS += -I$(src-perf)/util/include
346 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
347 INC_FLAGS += -I$(srctree)/tools/include/
348 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
349 INC_FLAGS += -I$(srctree)/tools/include/uapi
350 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
351 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
353 # $(obj-perf) for generated common-cmds.h
354 # $(obj-perf)/util for generated bison/flex headers
356 INC_FLAGS += -I$(obj-perf)/util
357 INC_FLAGS += -I$(obj-perf)
360 INC_FLAGS += -I$(src-perf)/util
361 INC_FLAGS += -I$(src-perf)
362 INC_FLAGS += -I$(srctree)/tools/lib/
364 CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
366 CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS)
367 CXXFLAGS += $(INC_FLAGS)
369 LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)
371 ifeq ($(feature-pthread-attr-setaffinity-np), 1)
372 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
375 ifeq ($(feature-pthread-barrier), 1)
376 CFLAGS += -DHAVE_PTHREAD_BARRIER
380 $(call feature_check,bionic)
381 ifeq ($(feature-bionic), 1)
383 CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
384 CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
385 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
386 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
390 ifeq ($(feature-eventfd), 1)
391 CFLAGS += -DHAVE_EVENTFD_SUPPORT
394 ifeq ($(feature-get_current_dir_name), 1)
395 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
398 ifeq ($(feature-gettid), 1)
399 CFLAGS += -DHAVE_GETTID
402 ifeq ($(feature-file-handle), 1)
403 CFLAGS += -DHAVE_FILE_HANDLE
410 NO_LIBDW_DWARF_UNWIND := 1
414 ifeq ($(feature-libelf), 0)
415 ifeq ($(feature-glibc), 1)
421 ifeq ($(LIBC_SUPPORT),1)
422 msg := $(warning No libelf found. Disables 'probe' tool, jvmti and BPF support in 'perf record'. Please install libelf-dev, libelf-devel or elfutils-libelf-devel);
428 NO_LIBDW_DWARF_UNWIND := 1
432 ifneq ($(filter s% -fsanitize=address%,$(EXTRA_CFLAGS),),)
433 ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0)
434 msg := $(error No libasan found, please install libasan);
438 ifneq ($(filter s% -fsanitize=undefined%,$(EXTRA_CFLAGS),),)
439 ifneq ($(shell ldconfig -p | grep libubsan >/dev/null 2>&1; echo $$?), 0)
440 msg := $(error No libubsan found, please install libubsan);
444 ifneq ($(filter s% -static%,$(LDFLAGS),),)
445 msg := $(error No static glibc found, please install glibc-static);
447 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
451 ifndef NO_LIBDW_DWARF_UNWIND
452 ifneq ($(feature-libdw-dwarf-unwind),1)
453 NO_LIBDW_DWARF_UNWIND := 1
454 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
457 ifneq ($(feature-dwarf), 1)
459 msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
463 ifneq ($(feature-dwarf_getlocations), 1)
464 msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
466 CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
467 endif # dwarf_getlocations
468 endif # Dwarf support
469 endif # libelf support
472 ifeq ($(feature-glibc), 1)
473 CFLAGS += -DHAVE_GLIBC_SUPPORT
476 ifeq ($(feature-libaio), 1)
478 CFLAGS += -DHAVE_AIO_SUPPORT
483 NO_LIBDW_DWARF_UNWIND := 1
486 ifeq ($(feature-sched_getcpu), 1)
487 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
490 ifeq ($(feature-setns), 1)
491 CFLAGS += -DHAVE_SETNS_SUPPORT
492 $(call detected,CONFIG_SETNS)
496 $(call feature_check,libopencsd)
497 ifeq ($(feature-libopencsd), 1)
498 CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
499 ifeq ($(feature-reallocarray), 0)
500 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
502 LDFLAGS += $(LIBOPENCSD_LDFLAGS)
503 EXTLIBS += $(OPENCSDLIBS)
504 $(call detected,CONFIG_LIBOPENCSD)
506 CFLAGS += -DCS_DEBUG_RAW
507 ifeq (${CSTRACE_RAW}, packed)
508 CFLAGS += -DCS_RAW_PACKED
512 dummy := $(error Error: No libopencsd library found or the version is not up-to-date. Please install recent libopencsd to build with CORESIGHT=1)
517 CFLAGS += -DHAVE_LIBELF_SUPPORT
519 $(call detected,CONFIG_LIBELF)
521 ifeq ($(feature-libelf-getphdrnum), 1)
522 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
525 ifeq ($(feature-libelf-gelf_getnote), 1)
526 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
528 msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
531 ifeq ($(feature-libelf-getshdrstrndx), 1)
532 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
535 ifndef NO_LIBDEBUGINFOD
536 $(call feature_check,libdebuginfod)
537 ifeq ($(feature-libdebuginfod), 1)
538 CFLAGS += -DHAVE_DEBUGINFOD_SUPPORT
539 EXTLIBS += -ldebuginfod
544 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
545 msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);
548 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
549 LDFLAGS += $(LIBDW_LDFLAGS)
550 EXTLIBS += ${DWARFLIBS}
551 $(call detected,CONFIG_DWARF)
552 endif # PERF_HAVE_DWARF_REGS
556 ifeq ($(feature-bpf), 1)
557 CFLAGS += -DHAVE_LIBBPF_SUPPORT
558 $(call detected,CONFIG_LIBBPF)
560 # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
561 $(call feature_check,libbpf)
563 ifeq ($(feature-libbpf), 1)
565 $(call detected,CONFIG_LIBBPF_DYNAMIC)
567 $(call feature_check,libbpf-btf__load_from_kernel_by_id)
568 ifeq ($(feature-libbpf-btf__load_from_kernel_by_id), 1)
569 CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
572 dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
575 CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
580 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
581 CFLAGS += -DHAVE_BPF_PROLOGUE
582 $(call detected,CONFIG_BPF_PROLOGUE)
584 msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
587 msg := $(warning DWARF support is off, BPF prologue is disabled);
594 ifneq ($(feature-sdt), 1)
595 msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
598 CFLAGS += -DHAVE_SDT_EVENT
599 $(call detected,CONFIG_SDT_EVENT)
603 ifdef PERF_HAVE_JITDUMP
605 $(call detected,CONFIG_JITDUMP)
606 CFLAGS += -DHAVE_JITDUMP
610 ifeq ($(SRCARCH),powerpc)
612 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
619 $(call feature_check,libunwind-x86)
620 ifeq ($(feature-libunwind-x86), 1)
621 $(call detected,CONFIG_LIBUNWIND_X86)
622 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
623 LDFLAGS += -lunwind-x86
624 EXTLIBS_LIBUNWIND += -lunwind-x86
628 $(call feature_check,libunwind-aarch64)
629 ifeq ($(feature-libunwind-aarch64), 1)
630 $(call detected,CONFIG_LIBUNWIND_AARCH64)
631 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
632 LDFLAGS += -lunwind-aarch64
633 EXTLIBS_LIBUNWIND += -lunwind-aarch64
635 $(call feature_check,libunwind-debug-frame-aarch64)
636 ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
637 msg := $(warning No debug_frame support found in libunwind-aarch64);
638 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
642 ifneq ($(feature-libunwind), 1)
643 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
644 NO_LOCAL_LIBUNWIND := 1
647 $(call detected,CONFIG_LOCAL_LIBUNWIND)
650 ifneq ($(have_libunwind), 1)
654 NO_LOCAL_LIBUNWIND := 1
658 ifneq ($(feature-bpf), 1)
659 msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
665 $(call feature_check,clang-bpf-co-re)
666 ifeq ($(feature-clang-bpf-co-re), 0)
667 dummy := $(error Error: clang too old/not installed. Please install recent clang to build with BUILD_BPF_SKEL)
669 $(call detected,CONFIG_PERF_BPF_SKEL)
670 CFLAGS += -DHAVE_BPF_SKEL
673 dwarf-post-unwind := 1
674 dwarf-post-unwind-text := BUG
676 # setup DWARF post unwinder
678 ifdef NO_LIBDW_DWARF_UNWIND
679 msg := $(warning Disabling post unwind, no support found.);
680 dwarf-post-unwind := 0
682 dwarf-post-unwind-text := libdw
683 $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
686 dwarf-post-unwind-text := libunwind
687 $(call detected,CONFIG_LIBUNWIND)
688 # Enable libunwind support by default.
689 ifndef NO_LIBDW_DWARF_UNWIND
690 NO_LIBDW_DWARF_UNWIND := 1
694 ifeq ($(dwarf-post-unwind),1)
695 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
696 $(call detected,CONFIG_DWARF_UNWIND)
701 ifndef NO_LOCAL_LIBUNWIND
702 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
703 $(call feature_check,libunwind-debug-frame)
704 ifneq ($(feature-libunwind-debug-frame), 1)
705 msg := $(warning No debug_frame support found in libunwind);
706 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
709 # non-ARM has no dwarf_find_debug_frame() function:
710 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
712 EXTLIBS += $(LIBUNWIND_LIBS)
713 LDFLAGS += $(LIBUNWIND_LIBS)
715 ifeq ($(findstring -static,${LDFLAGS}),-static)
716 # gcc -static links libgcc_eh which contans piece of libunwind
717 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
721 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
722 CFLAGS += $(LIBUNWIND_CFLAGS)
723 LDFLAGS += $(LIBUNWIND_LDFLAGS)
724 EXTLIBS += $(EXTLIBS_LIBUNWIND)
727 ifeq ($(NO_SYSCALL_TABLE),0)
728 $(call detected,CONFIG_TRACE)
731 $(call feature_check,libaudit)
732 ifneq ($(feature-libaudit), 1)
733 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
736 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
738 $(call detected,CONFIG_TRACE)
744 ifneq ($(feature-libcrypto), 1)
745 msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev);
748 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
750 $(call detected,CONFIG_CRYPTO)
759 ifneq ($(feature-libslang), 1)
760 ifneq ($(feature-libslang-include-subdir), 1)
761 msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
764 CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR
768 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
769 CFLAGS += -DHAVE_SLANG_SUPPORT
771 $(call detected,CONFIG_SLANG)
776 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
777 $(call feature_check,gtk2)
778 ifneq ($(feature-gtk2), 1)
779 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
782 $(call feature_check,gtk2-infobar)
783 ifeq ($(feature-gtk2-infobar), 1)
784 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
786 CFLAGS += -DHAVE_GTK2_SUPPORT
787 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
788 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
794 CFLAGS += -DNO_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=auto -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)
805 ifneq ($(feature-libperl), 1)
806 CFLAGS += -DNO_LIBPERL
808 msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
810 LDFLAGS += $(PERL_EMBED_LDFLAGS)
811 EXTLIBS += $(PERL_EMBED_LIBADD)
812 CFLAGS += -DHAVE_LIBPERL_SUPPORT
813 ifeq ($(CC_NO_CLANG), 0)
814 CFLAGS += -Wno-compound-token-split-by-macro
816 $(call detected,CONFIG_LIBPERL)
820 ifeq ($(feature-timerfd), 1)
821 CFLAGS += -DHAVE_TIMERFD_SUPPORT
823 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
826 disable-python = $(eval $(disable-python_code))
827 define disable-python_code
828 CFLAGS += -DNO_LIBPYTHON
834 $(call disable-python,Python support disabled by user)
838 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
840 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
843 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
846 ifneq ($(feature-libpython), 1)
847 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
849 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
850 EXTLIBS += $(PYTHON_EMBED_LIBADD)
851 LANG_BINDINGS += $(obj-perf)python/perf.so
852 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
853 $(call detected,CONFIG_LIBPYTHON)
861 ifeq ($(feature-libbfd), 1)
862 EXTLIBS += -lbfd -lopcodes
864 # we are on a system that requires -liberty and (maybe) -lz
865 # to link against -lbfd; test each case individually here
867 # call all detections now so we get correct
868 # status in VF output
869 $(call feature_check,libbfd-liberty)
870 $(call feature_check,libbfd-liberty-z)
872 ifeq ($(feature-libbfd-liberty), 1)
873 EXTLIBS += -lbfd -lopcodes -liberty
874 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
876 ifeq ($(feature-libbfd-liberty-z), 1)
877 EXTLIBS += -lbfd -lopcodes -liberty -lz
878 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
881 $(call feature_check,disassembler-four-args)
884 ifeq ($(feature-libbfd-buildid), 1)
885 CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT
887 msg := $(warning Old version of libbfd/binutils things like PE executable profiling will not be available);
892 CFLAGS += -DNO_DEMANGLE
894 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
897 ifeq ($(filter -liberty,$(EXTLIBS)),)
898 $(call feature_check,cplus-demangle)
900 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
901 # or any of 'bfd iberty z' trinity
902 ifeq ($(feature-cplus-demangle), 1)
905 msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
906 CFLAGS += -DNO_DEMANGLE
911 ifneq ($(filter -liberty,$(EXTLIBS)),)
912 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
916 ifneq ($(filter -lbfd,$(EXTLIBS)),)
917 CFLAGS += -DHAVE_LIBBFD_SUPPORT
921 ifeq ($(feature-zlib), 1)
922 CFLAGS += -DHAVE_ZLIB_SUPPORT
924 $(call detected,CONFIG_ZLIB)
931 ifeq ($(feature-lzma), 1)
932 CFLAGS += -DHAVE_LZMA_SUPPORT
934 $(call detected,CONFIG_LZMA)
936 msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
942 ifeq ($(feature-libzstd), 1)
943 CFLAGS += -DHAVE_ZSTD_SUPPORT
944 CFLAGS += $(LIBZSTD_CFLAGS)
945 LDFLAGS += $(LIBZSTD_LDFLAGS)
947 $(call detected,CONFIG_ZSTD)
949 msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
955 ifeq ($(feature-libcap), 1)
956 CFLAGS += -DHAVE_LIBCAP_SUPPORT
958 $(call detected,CONFIG_LIBCAP)
960 msg := $(warning No libcap found, disables capability support, please install libcap-devel/libcap-dev);
966 ifeq ($(feature-backtrace), 1)
967 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
972 ifeq ($(feature-libnuma), 0)
973 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
976 ifeq ($(feature-numa_num_possible_cpus), 0)
977 msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
980 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
982 $(call detected,CONFIG_NUMA)
987 ifdef HAVE_KVM_STAT_SUPPORT
988 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
991 ifeq ($(feature-disassembler-four-args), 1)
992 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
995 ifeq (${IS_64_BIT}, 1)
996 ifndef NO_PERF_READ_VDSO32
997 $(call feature_check,compile-32)
998 ifeq ($(feature-compile-32), 1)
999 CFLAGS += -DHAVE_PERF_READ_VDSO32
1001 NO_PERF_READ_VDSO32 := 1
1004 ifneq ($(SRCARCH), x86)
1005 NO_PERF_READ_VDSOX32 := 1
1007 ifndef NO_PERF_READ_VDSOX32
1008 $(call feature_check,compile-x32)
1009 ifeq ($(feature-compile-x32), 1)
1010 CFLAGS += -DHAVE_PERF_READ_VDSOX32
1012 NO_PERF_READ_VDSOX32 := 1
1016 NO_PERF_READ_VDSO32 := 1
1017 NO_PERF_READ_VDSOX32 := 1
1020 ifndef NO_LIBBABELTRACE
1021 $(call feature_check,libbabeltrace)
1022 ifeq ($(feature-libbabeltrace), 1)
1023 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
1024 LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
1025 EXTLIBS += -lbabeltrace-ctf
1026 $(call detected,CONFIG_LIBBABELTRACE)
1028 msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
1033 ifeq ($(SRCARCH),x86)
1034 ifeq ($(feature-get_cpuid), 0)
1035 msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
1040 $(call detected,CONFIG_AUXTRACE)
1041 CFLAGS += -DHAVE_AUXTRACE_SUPPORT
1046 ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
1047 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
1049 ifneq (,$(wildcard /usr/sbin/alternatives))
1050 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')
1054 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
1060 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
1061 $(call feature_check,jvmti)
1062 ifeq ($(feature-jvmti), 1)
1063 $(call detected_var,JDIR)
1064 ifndef NO_JVMTI_CMLR
1065 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
1066 $(call feature_check,jvmti-cmlr)
1067 ifeq ($(feature-jvmti-cmlr), 1)
1068 CFLAGS += -DHAVE_JVMTI_CMLR
1070 endif # NO_JVMTI_CMLR
1072 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
1080 $(call feature_check,cxx)
1081 ifneq ($(feature-cxx), 1)
1082 msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
1084 $(call feature_check,llvm)
1085 $(call feature_check,llvm-version)
1086 ifneq ($(feature-llvm), 1)
1087 msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
1089 $(call feature_check,clang)
1090 ifneq ($(feature-clang), 1)
1091 msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
1093 CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
1094 CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
1095 $(call detected,CONFIG_CXX)
1096 $(call detected,CONFIG_CLANGLLVM)
1100 ifneq ($(feature-llvm-version),1)
1101 msg := $(warning This version of LLVM is not tested. May cause build errors)
1109 $(call feature_check,libpfm4)
1110 ifeq ($(feature-libpfm4), 1)
1111 CFLAGS += -DHAVE_LIBPFM
1113 ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1
1114 $(call detected,CONFIG_LIBPFM4)
1116 msg := $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev);
1121 ifdef LIBTRACEEVENT_DYNAMIC
1122 $(call feature_check,libtraceevent)
1123 ifeq ($(feature-libtraceevent), 1)
1124 EXTLIBS += -ltraceevent
1126 dummy := $(error Error: No libtraceevent devel library found, please install libtraceevent-devel);
1130 # Among the variables below, these:
1138 # ETC_PERFCONFIG (but not sysconfdir)
1139 # can be specified as a relative path some/where/else;
1140 # this is interpreted as relative to $(prefix) and "perf" at
1141 # runtime figures out where they are based on the path to the executable.
1142 # This can help installing the suite in a relocatable way.
1144 # Make the path relative to DESTDIR, not to prefix
1148 bindir_relative = bin
1149 bindir = $(abspath $(prefix)/$(bindir_relative))
1150 includedir_relative = include
1151 includedir = $(abspath $(prefix)/$(includedir_relative))
1153 infodir = share/info
1154 perfexecdir = libexec/perf-core
1155 perf_include_dir = lib/perf/include
1156 perf_examples_dir = lib/perf/examples
1157 sharedir = $(prefix)/share
1158 template_dir = share/perf-core/templates
1159 STRACE_GROUPS_DIR = share/perf-core/strace/groups
1160 htmldir = share/doc/perf-doc
1161 tipdir = share/doc/perf-tip
1162 srcdir = $(srctree)/tools/perf
1163 ifeq ($(prefix),/usr)
1165 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
1167 sysconfdir = $(prefix)/etc
1168 ETC_PERFCONFIG = etc/perfconfig
1171 ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1177 libdir = $(prefix)/$(lib)
1179 # Shell quote (do not use $(call) to accommodate ancient setups);
1180 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1181 STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1182 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1183 bindir_SQ = $(subst ','\'',$(bindir))
1184 includedir_SQ = $(subst ','\'',$(includedir))
1185 mandir_SQ = $(subst ','\'',$(mandir))
1186 infodir_SQ = $(subst ','\'',$(infodir))
1187 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1188 perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
1189 perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1190 template_dir_SQ = $(subst ','\'',$(template_dir))
1191 htmldir_SQ = $(subst ','\'',$(htmldir))
1192 tipdir_SQ = $(subst ','\'',$(tipdir))
1193 prefix_SQ = $(subst ','\'',$(prefix))
1194 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1195 libdir_SQ = $(subst ','\'',$(libdir))
1196 srcdir_SQ = $(subst ','\'',$(srcdir))
1198 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1199 perfexec_instdir = $(perfexecdir)
1200 perf_include_instdir = $(perf_include_dir)
1201 perf_examples_instdir = $(perf_examples_dir)
1202 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1203 tip_instdir = $(tipdir)
1205 perfexec_instdir = $(prefix)/$(perfexecdir)
1206 perf_include_instdir = $(prefix)/$(perf_include_dir)
1207 perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1208 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1209 tip_instdir = $(prefix)/$(tipdir)
1211 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1212 perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1213 perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1214 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1215 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1217 # If we install to $(HOME) we keep the traceevent default:
1218 # $(HOME)/.traceevent/plugins
1219 # Otherwise we install plugins into the global $(libdir).
1221 plugindir=$(libdir)/traceevent/plugins
1222 plugindir_SQ= $(subst ','\'',$(plugindir))
1225 print_var = $(eval $(print_var_code)) $(info $(MSG))
1226 define print_var_code
1227 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
1231 # Display EXTRA features which are detected manualy
1232 # from here with feature_check call and thus cannot
1233 # be partof global state output.
1234 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
1235 $(call print_var,prefix)
1236 $(call print_var,bindir)
1237 $(call print_var,libdir)
1238 $(call print_var,sysconfdir)
1239 $(call print_var,LIBUNWIND_DIR)
1240 $(call print_var,LIBDW_DIR)
1241 $(call print_var,JDIR)
1243 ifeq ($(dwarf-post-unwind),1)
1244 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
1249 $(call detected_var,bindir_SQ)
1250 $(call detected_var,PYTHON_WORD)
1252 $(call detected_var,OUTPUT)
1254 $(call detected_var,htmldir_SQ)
1255 $(call detected_var,infodir_SQ)
1256 $(call detected_var,mandir_SQ)
1257 $(call detected_var,ETC_PERFCONFIG_SQ)
1258 $(call detected_var,STRACE_GROUPS_DIR_SQ)
1259 $(call detected_var,prefix_SQ)
1260 $(call detected_var,perfexecdir_SQ)
1261 $(call detected_var,perf_include_dir_SQ)
1262 $(call detected_var,perf_examples_dir_SQ)
1263 $(call detected_var,tipdir_SQ)
1264 $(call detected_var,srcdir_SQ)
1265 $(call detected_var,LIBDIR)
1266 $(call detected_var,GTK_CFLAGS)
1267 $(call detected_var,PERL_EMBED_CCOPTS)
1268 $(call detected_var,PYTHON_EMBED_CCOPTS)
1269 ifneq ($(BISON_FILE_PREFIX_MAP),)
1270 $(call detected_var,BISON_FILE_PREFIX_MAP)
1273 # re-generate FEATURE-DUMP as we may have called feature_check, found out
1274 # extra libraries to add to LDFLAGS of some other test and then redo those
1275 # tests, see the block about libbfd, disassembler-four-args, for instance.
1276 $(shell rm -f $(FEATURE_DUMP_FILENAME))
1277 $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
1279 ifeq ($(feature_display),1)
1280 $(call feature_display_entries)