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) $(EXTRA_WARNINGS)
21 include $(srctree)/tools/scripts/Makefile.arch
23 $(call detected_var,SRCARCH)
28 # Additional ARCH settings for ppc
29 ifeq ($(SRCARCH),powerpc)
32 CFLAGS += -I$(OUTPUT)arch/powerpc/include/generated
33 LIBUNWIND_LIBS := -lunwind -lunwind-ppc64
36 # Additional ARCH settings for x86
38 $(call detected,CONFIG_X86)
39 ifeq (${IS_64_BIT}, 1)
41 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT -I$(OUTPUT)arch/x86/include/generated
42 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
43 LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma
44 $(call detected,CONFIG_X86_64)
46 LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind
53 LIBUNWIND_LIBS = -lunwind -lunwind-arm
56 ifeq ($(SRCARCH),arm64)
59 CFLAGS += -I$(OUTPUT)arch/arm64/include/generated
60 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
63 ifeq ($(SRCARCH),riscv)
67 ifeq ($(SRCARCH),csky)
74 CFLAGS += -fPIC -I$(OUTPUT)arch/s390/include/generated
77 ifeq ($(NO_PERF_REGS),0)
78 $(call detected,CONFIG_PERF_REGS)
81 ifneq ($(NO_SYSCALL_TABLE),1)
82 CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
85 # So far there's only x86 and arm libdw unwind support merged in perf.
86 # Disable it on all other architectures in case libdw unwind
87 # support is detected in system. Add supported architectures
89 ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky riscv))
90 NO_LIBDW_DWARF_UNWIND := 1
93 ifeq ($(LIBUNWIND_LIBS),)
97 # For linking with debug library, run like:
99 # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
102 libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
103 define libunwind_arch_set_flags_code
104 FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include
105 FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
109 LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include
110 LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
111 LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
112 $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
115 # Set per-feature check compilation flags
116 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
117 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
118 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
119 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
121 FEATURE_CHECK_LDFLAGS-libunwind-arm = -lunwind -lunwind-arm
122 FEATURE_CHECK_LDFLAGS-libunwind-aarch64 = -lunwind -lunwind-aarch64
123 FEATURE_CHECK_LDFLAGS-libunwind-x86 = -lunwind -llzma -lunwind-x86
124 FEATURE_CHECK_LDFLAGS-libunwind-x86_64 = -lunwind -llzma -lunwind-x86_64
126 FEATURE_CHECK_LDFLAGS-libcrypto = -lcrypto
129 LIBOPENCSD_CFLAGS := -I$(CSINCLUDES)
131 OPENCSDLIBS := -lopencsd_c_api -lopencsd
133 LIBOPENCSD_LDFLAGS := -L$(CSLIBS)
135 FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS)
136 FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS)
138 ifeq ($(NO_PERF_REGS),0)
139 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
142 # for linking with debug library, run like:
143 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
145 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
146 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
149 ifeq ($(findstring -static,${LDFLAGS}),-static)
150 DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
152 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
153 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
155 # for linking with debug library, run like:
156 # make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
157 ifdef LIBBABELTRACE_DIR
158 LIBBABELTRACE_CFLAGS := -I$(LIBBABELTRACE_DIR)/include
159 LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
161 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
162 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
165 LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib
166 LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
168 FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
169 FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
171 FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
172 # include ARCH specific config
173 -include $(src-perf)/arch/$(SRCARCH)/Makefile
175 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
176 CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
179 include $(srctree)/tools/scripts/utilities.mak
181 ifeq ($(call get-executable,$(FLEX)),)
182 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
185 ifeq ($(call get-executable,$(BISON)),)
186 dummy := $(error Error: $(BISON) is missing on this system, please install it)
189 # Treat warnings as errors unless directed not to
191 CORE_CFLAGS += -Werror
200 ifeq ($(CC_NO_CLANG), 0)
208 PARSER_DEBUG_BISON := -t
209 PARSER_DEBUG_FLEX := -d
210 CFLAGS += -DPARSER_DEBUG
211 $(call detected_var,PARSER_DEBUG_BISON)
212 $(call detected_var,PARSER_DEBUG_FLEX)
215 # Try different combinations to accommodate systems that only have
216 # python[2][-config] in weird combinations but always preferring
217 # python2 and python2-config as per pep-0394. If we catch a
218 # python[-config] in version 3, the version check will kill it.
219 PYTHON2 := $(if $(call get-executable,python2),python2,python)
220 override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2))
222 $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config)
223 override PYTHON_CONFIG := \
224 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
226 grep-libs = $(filter -l%,$(1))
227 strip-libs = $(filter-out -l%,$(1))
229 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
231 # Python 3.8 changed the output of `python-config --ldflags` to not include the
232 # '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for
233 # libpython fails if that flag is not included in LDFLAGS
234 ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0)
235 PYTHON_CONFIG_LDFLAGS := --ldflags --embed
237 PYTHON_CONFIG_LDFLAGS := --ldflags
241 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
242 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
243 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
244 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
245 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
248 FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
249 FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
250 FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
251 FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
253 FEATURE_CHECK_LDFLAGS-libaio = -lrt
255 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
257 CORE_CFLAGS += -fno-omit-frame-pointer
258 CORE_CFLAGS += -ggdb3
259 CORE_CFLAGS += -funwind-tables
261 CORE_CFLAGS += -Wextra
262 CORE_CFLAGS += -std=gnu99
264 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
266 CXXFLAGS += -fno-omit-frame-pointer
268 CXXFLAGS += -funwind-tables
269 CXXFLAGS += -Wno-strict-aliasing
271 # Enforce a non-executable stack, as we may regress (again) in the future by
272 # adding assembler files missing the .GNU-stack linker note.
273 LDFLAGS += -Wl,-z,noexecstack
275 EXTLIBS = -lpthread -lrt -lm -ldl
278 CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
279 EXTLIBS += -ltcmalloc
282 ifeq ($(FEATURES_DUMP),)
283 include $(srctree)/tools/build/Makefile.feature
285 include $(FEATURES_DUMP)
288 ifeq ($(feature-stackprotector-all), 1)
289 CORE_CFLAGS += -fstack-protector-all
293 ifeq ($(feature-fortify-source), 1)
294 CORE_CFLAGS += -D_FORTIFY_SOURCE=2
298 INC_FLAGS += -I$(srctree)/tools/lib/perf/include
299 INC_FLAGS += -I$(src-perf)/util/include
300 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
301 INC_FLAGS += -I$(srctree)/tools/include/
302 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
303 INC_FLAGS += -I$(srctree)/tools/include/uapi
304 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
305 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
307 # $(obj-perf) for generated common-cmds.h
308 # $(obj-perf)/util for generated bison/flex headers
310 INC_FLAGS += -I$(obj-perf)/util
311 INC_FLAGS += -I$(obj-perf)
314 INC_FLAGS += -I$(src-perf)/util
315 INC_FLAGS += -I$(src-perf)
316 INC_FLAGS += -I$(srctree)/tools/lib/
318 CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
320 CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS)
321 CXXFLAGS += $(INC_FLAGS)
323 LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)
325 ifeq ($(feature-sync-compare-and-swap), 1)
326 CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
329 ifeq ($(feature-pthread-attr-setaffinity-np), 1)
330 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
333 ifeq ($(feature-pthread-barrier), 1)
334 CFLAGS += -DHAVE_PTHREAD_BARRIER
338 $(call feature_check,bionic)
339 ifeq ($(feature-bionic), 1)
341 CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
342 CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
343 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
344 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
348 ifeq ($(feature-eventfd), 1)
349 CFLAGS += -DHAVE_EVENTFD
352 ifeq ($(feature-get_current_dir_name), 1)
353 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
356 ifeq ($(feature-gettid), 1)
357 CFLAGS += -DHAVE_GETTID
360 ifeq ($(feature-file-handle), 1)
361 CFLAGS += -DHAVE_FILE_HANDLE
368 NO_LIBDW_DWARF_UNWIND := 1
372 ifeq ($(feature-libelf), 0)
373 ifeq ($(feature-glibc), 1)
379 ifeq ($(LIBC_SUPPORT),1)
380 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);
386 NO_LIBDW_DWARF_UNWIND := 1
390 ifneq ($(filter s% -static%,$(LDFLAGS),),)
391 msg := $(error No static glibc found, please install glibc-static);
393 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
397 ifndef NO_LIBDW_DWARF_UNWIND
398 ifneq ($(feature-libdw-dwarf-unwind),1)
399 NO_LIBDW_DWARF_UNWIND := 1
400 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
403 ifneq ($(feature-dwarf), 1)
405 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);
409 ifneq ($(feature-dwarf_getlocations), 1)
410 msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
412 CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
413 endif # dwarf_getlocations
414 endif # Dwarf support
415 endif # libelf support
418 ifeq ($(feature-glibc), 1)
419 CFLAGS += -DHAVE_GLIBC_SUPPORT
422 ifeq ($(feature-libaio), 1)
424 CFLAGS += -DHAVE_AIO_SUPPORT
429 NO_LIBDW_DWARF_UNWIND := 1
432 ifeq ($(feature-sched_getcpu), 1)
433 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
436 ifeq ($(feature-setns), 1)
437 CFLAGS += -DHAVE_SETNS_SUPPORT
438 $(call detected,CONFIG_SETNS)
442 $(call feature_check,libopencsd)
443 ifeq ($(feature-libopencsd), 1)
444 CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
445 ifeq ($(feature-reallocarray), 0)
446 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
448 LDFLAGS += $(LIBOPENCSD_LDFLAGS)
449 EXTLIBS += $(OPENCSDLIBS)
450 $(call detected,CONFIG_LIBOPENCSD)
452 CFLAGS += -DCS_DEBUG_RAW
453 ifeq (${CSTRACE_RAW}, packed)
454 CFLAGS += -DCS_RAW_PACKED
461 CFLAGS += -DHAVE_LIBELF_SUPPORT
463 $(call detected,CONFIG_LIBELF)
465 ifeq ($(feature-libelf-mmap), 1)
466 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
469 ifeq ($(feature-libelf-getphdrnum), 1)
470 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
473 ifeq ($(feature-libelf-gelf_getnote), 1)
474 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
476 msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
479 ifeq ($(feature-libelf-getshdrstrndx), 1)
480 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
484 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
485 msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);
488 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
489 LDFLAGS += $(LIBDW_LDFLAGS)
490 EXTLIBS += ${DWARFLIBS}
491 $(call detected,CONFIG_DWARF)
492 endif # PERF_HAVE_DWARF_REGS
496 ifeq ($(feature-bpf), 1)
497 CFLAGS += -DHAVE_LIBBPF_SUPPORT
498 $(call detected,CONFIG_LIBBPF)
500 # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
501 $(call feature_check,libbpf)
503 ifeq ($(feature-libbpf), 1)
506 dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
512 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
513 CFLAGS += -DHAVE_BPF_PROLOGUE
514 $(call detected,CONFIG_BPF_PROLOGUE)
516 msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
519 msg := $(warning DWARF support is off, BPF prologue is disabled);
526 ifneq ($(feature-sdt), 1)
527 msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
530 CFLAGS += -DHAVE_SDT_EVENT
531 $(call detected,CONFIG_SDT_EVENT)
535 ifdef PERF_HAVE_JITDUMP
537 $(call detected,CONFIG_JITDUMP)
538 CFLAGS += -DHAVE_JITDUMP
542 ifeq ($(SRCARCH),powerpc)
544 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
551 $(call feature_check,libunwind-x86)
552 ifeq ($(feature-libunwind-x86), 1)
553 $(call detected,CONFIG_LIBUNWIND_X86)
554 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
555 LDFLAGS += -lunwind-x86
556 EXTLIBS_LIBUNWIND += -lunwind-x86
560 $(call feature_check,libunwind-aarch64)
561 ifeq ($(feature-libunwind-aarch64), 1)
562 $(call detected,CONFIG_LIBUNWIND_AARCH64)
563 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
564 LDFLAGS += -lunwind-aarch64
565 EXTLIBS_LIBUNWIND += -lunwind-aarch64
567 $(call feature_check,libunwind-debug-frame-aarch64)
568 ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
569 msg := $(warning No debug_frame support found in libunwind-aarch64);
570 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
574 ifneq ($(feature-libunwind), 1)
575 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
576 NO_LOCAL_LIBUNWIND := 1
579 $(call detected,CONFIG_LOCAL_LIBUNWIND)
582 ifneq ($(have_libunwind), 1)
586 NO_LOCAL_LIBUNWIND := 1
590 ifneq ($(feature-bpf), 1)
591 msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
596 dwarf-post-unwind := 1
597 dwarf-post-unwind-text := BUG
599 # setup DWARF post unwinder
601 ifdef NO_LIBDW_DWARF_UNWIND
602 msg := $(warning Disabling post unwind, no support found.);
603 dwarf-post-unwind := 0
605 dwarf-post-unwind-text := libdw
606 $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
609 dwarf-post-unwind-text := libunwind
610 $(call detected,CONFIG_LIBUNWIND)
611 # Enable libunwind support by default.
612 ifndef NO_LIBDW_DWARF_UNWIND
613 NO_LIBDW_DWARF_UNWIND := 1
617 ifeq ($(dwarf-post-unwind),1)
618 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
619 $(call detected,CONFIG_DWARF_UNWIND)
624 ifndef NO_LOCAL_LIBUNWIND
625 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
626 $(call feature_check,libunwind-debug-frame)
627 ifneq ($(feature-libunwind-debug-frame), 1)
628 msg := $(warning No debug_frame support found in libunwind);
629 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
632 # non-ARM has no dwarf_find_debug_frame() function:
633 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
635 EXTLIBS += $(LIBUNWIND_LIBS)
636 LDFLAGS += $(LIBUNWIND_LIBS)
638 ifeq ($(findstring -static,${LDFLAGS}),-static)
639 # gcc -static links libgcc_eh which contans piece of libunwind
640 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
644 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
645 CFLAGS += $(LIBUNWIND_CFLAGS)
646 LDFLAGS += $(LIBUNWIND_LDFLAGS)
647 EXTLIBS += $(EXTLIBS_LIBUNWIND)
650 ifeq ($(NO_SYSCALL_TABLE),0)
651 $(call detected,CONFIG_TRACE)
654 ifneq ($(feature-libaudit), 1)
655 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
658 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
660 $(call detected,CONFIG_TRACE)
666 ifneq ($(feature-libcrypto), 1)
667 msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev);
670 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
672 $(call detected,CONFIG_CRYPTO)
681 ifneq ($(feature-libslang), 1)
682 ifneq ($(feature-libslang-include-subdir), 1)
683 msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
686 CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR
690 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
691 CFLAGS += -DHAVE_SLANG_SUPPORT
693 $(call detected,CONFIG_SLANG)
698 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
699 ifneq ($(feature-gtk2), 1)
700 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
703 ifeq ($(feature-gtk2-infobar), 1)
704 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
706 CFLAGS += -DHAVE_GTK2_SUPPORT
707 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
708 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
714 CFLAGS += -DNO_LIBPERL
716 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
717 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
718 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
719 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
720 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
721 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
722 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
724 ifneq ($(feature-libperl), 1)
725 CFLAGS += -DNO_LIBPERL
727 msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
729 LDFLAGS += $(PERL_EMBED_LDFLAGS)
730 EXTLIBS += $(PERL_EMBED_LIBADD)
731 CFLAGS += -DHAVE_LIBPERL_SUPPORT
732 $(call detected,CONFIG_LIBPERL)
736 ifeq ($(feature-timerfd), 1)
737 CFLAGS += -DHAVE_TIMERFD_SUPPORT
739 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
742 disable-python = $(eval $(disable-python_code))
743 define disable-python_code
744 CFLAGS += -DNO_LIBPYTHON
750 $(call disable-python,Python support disabled by user)
754 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
756 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
759 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
762 ifneq ($(feature-libpython), 1)
763 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
765 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
766 EXTLIBS += $(PYTHON_EMBED_LIBADD)
767 LANG_BINDINGS += $(obj-perf)python/perf.so
768 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
769 $(call detected,CONFIG_LIBPYTHON)
775 ifeq ($(feature-libbfd), 1)
776 EXTLIBS += -lbfd -lopcodes
778 # we are on a system that requires -liberty and (maybe) -lz
779 # to link against -lbfd; test each case individually here
781 # call all detections now so we get correct
782 # status in VF output
783 $(call feature_check,libbfd-liberty)
784 $(call feature_check,libbfd-liberty-z)
786 ifeq ($(feature-libbfd-liberty), 1)
787 EXTLIBS += -lbfd -lopcodes -liberty
788 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
790 ifeq ($(feature-libbfd-liberty-z), 1)
791 EXTLIBS += -lbfd -lopcodes -liberty -lz
792 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
795 $(call feature_check,disassembler-four-args)
799 CFLAGS += -DNO_DEMANGLE
801 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
804 ifeq ($(filter -liberty,$(EXTLIBS)),)
805 $(call feature_check,cplus-demangle)
807 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
808 # or any of 'bfd iberty z' trinity
809 ifeq ($(feature-cplus-demangle), 1)
812 msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
813 CFLAGS += -DNO_DEMANGLE
818 ifneq ($(filter -liberty,$(EXTLIBS)),)
819 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
823 ifneq ($(filter -lbfd,$(EXTLIBS)),)
824 CFLAGS += -DHAVE_LIBBFD_SUPPORT
828 ifeq ($(feature-zlib), 1)
829 CFLAGS += -DHAVE_ZLIB_SUPPORT
831 $(call detected,CONFIG_ZLIB)
838 ifeq ($(feature-lzma), 1)
839 CFLAGS += -DHAVE_LZMA_SUPPORT
841 $(call detected,CONFIG_LZMA)
843 msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
849 ifeq ($(feature-libzstd), 1)
850 CFLAGS += -DHAVE_ZSTD_SUPPORT
851 CFLAGS += $(LIBZSTD_CFLAGS)
852 LDFLAGS += $(LIBZSTD_LDFLAGS)
854 $(call detected,CONFIG_ZSTD)
856 msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
862 ifeq ($(feature-libcap), 1)
863 CFLAGS += -DHAVE_LIBCAP_SUPPORT
865 $(call detected,CONFIG_LIBCAP)
867 msg := $(warning No libcap found, disables capability support, please install libcap-devel/libcap-dev);
873 ifeq ($(feature-backtrace), 1)
874 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
879 ifeq ($(feature-libnuma), 0)
880 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
883 ifeq ($(feature-numa_num_possible_cpus), 0)
884 msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
887 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
889 $(call detected,CONFIG_NUMA)
894 ifdef HAVE_KVM_STAT_SUPPORT
895 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
898 ifeq ($(feature-disassembler-four-args), 1)
899 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
902 ifeq (${IS_64_BIT}, 1)
903 ifndef NO_PERF_READ_VDSO32
904 $(call feature_check,compile-32)
905 ifeq ($(feature-compile-32), 1)
906 CFLAGS += -DHAVE_PERF_READ_VDSO32
908 NO_PERF_READ_VDSO32 := 1
911 ifneq ($(SRCARCH), x86)
912 NO_PERF_READ_VDSOX32 := 1
914 ifndef NO_PERF_READ_VDSOX32
915 $(call feature_check,compile-x32)
916 ifeq ($(feature-compile-x32), 1)
917 CFLAGS += -DHAVE_PERF_READ_VDSOX32
919 NO_PERF_READ_VDSOX32 := 1
923 NO_PERF_READ_VDSO32 := 1
924 NO_PERF_READ_VDSOX32 := 1
927 ifndef NO_LIBBABELTRACE
928 $(call feature_check,libbabeltrace)
929 ifeq ($(feature-libbabeltrace), 1)
930 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
931 LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
932 EXTLIBS += -lbabeltrace-ctf
933 $(call detected,CONFIG_LIBBABELTRACE)
935 msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
940 ifeq ($(SRCARCH),x86)
941 ifeq ($(feature-get_cpuid), 0)
942 msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
947 $(call detected,CONFIG_AUXTRACE)
948 CFLAGS += -DHAVE_AUXTRACE_SUPPORT
953 ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
954 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
956 ifneq (,$(wildcard /usr/sbin/alternatives))
957 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')
961 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
967 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
968 $(call feature_check,jvmti)
969 ifeq ($(feature-jvmti), 1)
970 $(call detected_var,JDIR)
972 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
973 $(call feature_check,jvmti-cmlr)
974 ifeq ($(feature-jvmti-cmlr), 1)
975 CFLAGS += -DHAVE_JVMTI_CMLR
977 endif # NO_JVMTI_CMLR
979 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
987 $(call feature_check,cxx)
988 ifneq ($(feature-cxx), 1)
989 msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
991 $(call feature_check,llvm)
992 $(call feature_check,llvm-version)
993 ifneq ($(feature-llvm), 1)
994 msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
996 $(call feature_check,clang)
997 ifneq ($(feature-clang), 1)
998 msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
1000 CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
1001 CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
1002 $(call detected,CONFIG_CXX)
1003 $(call detected,CONFIG_CLANGLLVM)
1007 ifneq ($(feature-llvm-version),1)
1008 msg := $(warning This version of LLVM is not tested. May cause build errors)
1015 # Among the variables below, these:
1023 # ETC_PERFCONFIG (but not sysconfdir)
1024 # can be specified as a relative path some/where/else;
1025 # this is interpreted as relative to $(prefix) and "perf" at
1026 # runtime figures out where they are based on the path to the executable.
1027 # This can help installing the suite in a relocatable way.
1029 # Make the path relative to DESTDIR, not to prefix
1033 bindir_relative = bin
1034 bindir = $(abspath $(prefix)/$(bindir_relative))
1036 infodir = share/info
1037 perfexecdir = libexec/perf-core
1038 perf_include_dir = lib/perf/include
1039 perf_examples_dir = lib/perf/examples
1040 sharedir = $(prefix)/share
1041 template_dir = share/perf-core/templates
1042 STRACE_GROUPS_DIR = share/perf-core/strace/groups
1043 htmldir = share/doc/perf-doc
1044 tipdir = share/doc/perf-tip
1045 srcdir = $(srctree)/tools/perf
1046 ifeq ($(prefix),/usr)
1048 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
1050 sysconfdir = $(prefix)/etc
1051 ETC_PERFCONFIG = etc/perfconfig
1054 ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1060 libdir = $(prefix)/$(lib)
1062 # Shell quote (do not use $(call) to accommodate ancient setups);
1063 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1064 STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1065 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1066 bindir_SQ = $(subst ','\'',$(bindir))
1067 mandir_SQ = $(subst ','\'',$(mandir))
1068 infodir_SQ = $(subst ','\'',$(infodir))
1069 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1070 perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
1071 perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1072 template_dir_SQ = $(subst ','\'',$(template_dir))
1073 htmldir_SQ = $(subst ','\'',$(htmldir))
1074 tipdir_SQ = $(subst ','\'',$(tipdir))
1075 prefix_SQ = $(subst ','\'',$(prefix))
1076 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1077 libdir_SQ = $(subst ','\'',$(libdir))
1078 srcdir_SQ = $(subst ','\'',$(srcdir))
1080 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1081 perfexec_instdir = $(perfexecdir)
1082 perf_include_instdir = $(perf_include_dir)
1083 perf_examples_instdir = $(perf_examples_dir)
1084 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1085 tip_instdir = $(tipdir)
1087 perfexec_instdir = $(prefix)/$(perfexecdir)
1088 perf_include_instdir = $(prefix)/$(perf_include_dir)
1089 perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1090 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1091 tip_instdir = $(prefix)/$(tipdir)
1093 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1094 perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1095 perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1096 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1097 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1099 # If we install to $(HOME) we keep the traceevent default:
1100 # $(HOME)/.traceevent/plugins
1101 # Otherwise we install plugins into the global $(libdir).
1103 plugindir=$(libdir)/traceevent/plugins
1104 plugindir_SQ= $(subst ','\'',$(plugindir))
1107 print_var = $(eval $(print_var_code)) $(info $(MSG))
1108 define print_var_code
1109 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
1113 # Display EXTRA features which are detected manualy
1114 # from here with feature_check call and thus cannot
1115 # be partof global state output.
1116 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
1117 $(call print_var,prefix)
1118 $(call print_var,bindir)
1119 $(call print_var,libdir)
1120 $(call print_var,sysconfdir)
1121 $(call print_var,LIBUNWIND_DIR)
1122 $(call print_var,LIBDW_DIR)
1123 $(call print_var,JDIR)
1125 ifeq ($(dwarf-post-unwind),1)
1126 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
1131 $(call detected_var,bindir_SQ)
1132 $(call detected_var,PYTHON_WORD)
1134 $(call detected_var,OUTPUT)
1136 $(call detected_var,htmldir_SQ)
1137 $(call detected_var,infodir_SQ)
1138 $(call detected_var,mandir_SQ)
1139 $(call detected_var,ETC_PERFCONFIG_SQ)
1140 $(call detected_var,STRACE_GROUPS_DIR_SQ)
1141 $(call detected_var,prefix_SQ)
1142 $(call detected_var,perfexecdir_SQ)
1143 $(call detected_var,perf_include_dir_SQ)
1144 $(call detected_var,perf_examples_dir_SQ)
1145 $(call detected_var,tipdir_SQ)
1146 $(call detected_var,srcdir_SQ)
1147 $(call detected_var,LIBDIR)
1148 $(call detected_var,GTK_CFLAGS)
1149 $(call detected_var,PERL_EMBED_CCOPTS)
1150 $(call detected_var,PYTHON_EMBED_CCOPTS)