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
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)
251 FEATURE_CHECK_LDFLAGS-libaio = -lrt
253 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
255 CFLAGS += -fno-omit-frame-pointer
257 CFLAGS += -funwind-tables
262 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
264 CXXFLAGS += -fno-omit-frame-pointer
266 CXXFLAGS += -funwind-tables
267 CXXFLAGS += -Wno-strict-aliasing
269 # Enforce a non-executable stack, as we may regress (again) in the future by
270 # adding assembler files missing the .GNU-stack linker note.
271 LDFLAGS += -Wl,-z,noexecstack
273 EXTLIBS = -lpthread -lrt -lm -ldl
275 ifeq ($(FEATURES_DUMP),)
276 include $(srctree)/tools/build/Makefile.feature
278 include $(FEATURES_DUMP)
281 ifeq ($(feature-stackprotector-all), 1)
282 CFLAGS += -fstack-protector-all
286 ifeq ($(feature-fortify-source), 1)
287 CFLAGS += -D_FORTIFY_SOURCE=2
291 INC_FLAGS += -I$(src-perf)/lib/include
292 INC_FLAGS += -I$(src-perf)/util/include
293 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
294 INC_FLAGS += -I$(srctree)/tools/include/
295 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
296 INC_FLAGS += -I$(srctree)/tools/include/uapi
297 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
298 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
300 # $(obj-perf) for generated common-cmds.h
301 # $(obj-perf)/util for generated bison/flex headers
303 INC_FLAGS += -I$(obj-perf)/util
304 INC_FLAGS += -I$(obj-perf)
307 INC_FLAGS += -I$(src-perf)/util
308 INC_FLAGS += -I$(src-perf)
309 INC_FLAGS += -I$(srctree)/tools/lib/
311 CFLAGS += $(INC_FLAGS)
312 CXXFLAGS += $(INC_FLAGS)
314 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
316 ifeq ($(feature-sync-compare-and-swap), 1)
317 CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
320 ifeq ($(feature-pthread-attr-setaffinity-np), 1)
321 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
324 ifeq ($(feature-pthread-barrier), 1)
325 CFLAGS += -DHAVE_PTHREAD_BARRIER
329 $(call feature_check,bionic)
330 ifeq ($(feature-bionic), 1)
332 CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
333 CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
334 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
335 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
339 ifeq ($(feature-eventfd), 1)
340 CFLAGS += -DHAVE_EVENTFD
343 ifeq ($(feature-get_current_dir_name), 1)
344 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
347 ifeq ($(feature-gettid), 1)
348 CFLAGS += -DHAVE_GETTID
355 NO_LIBDW_DWARF_UNWIND := 1
359 ifeq ($(feature-libelf), 0)
360 ifeq ($(feature-glibc), 1)
366 ifeq ($(LIBC_SUPPORT),1)
367 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);
373 NO_LIBDW_DWARF_UNWIND := 1
377 ifneq ($(filter s% -static%,$(LDFLAGS),),)
378 msg := $(error No static glibc found, please install glibc-static);
380 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
384 ifndef NO_LIBDW_DWARF_UNWIND
385 ifneq ($(feature-libdw-dwarf-unwind),1)
386 NO_LIBDW_DWARF_UNWIND := 1
387 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
390 ifneq ($(feature-dwarf), 1)
392 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);
396 ifneq ($(feature-dwarf_getlocations), 1)
397 msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
399 CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
400 endif # dwarf_getlocations
401 endif # Dwarf support
402 endif # libelf support
405 ifeq ($(feature-glibc), 1)
406 CFLAGS += -DHAVE_GLIBC_SUPPORT
409 ifeq ($(feature-libaio), 1)
411 CFLAGS += -DHAVE_AIO_SUPPORT
416 NO_LIBDW_DWARF_UNWIND := 1
419 ifeq ($(feature-sched_getcpu), 1)
420 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
423 ifeq ($(feature-setns), 1)
424 CFLAGS += -DHAVE_SETNS_SUPPORT
425 $(call detected,CONFIG_SETNS)
429 $(call feature_check,libopencsd)
430 ifeq ($(feature-libopencsd), 1)
431 CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
432 ifeq ($(feature-reallocarray), 0)
433 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
435 LDFLAGS += $(LIBOPENCSD_LDFLAGS)
436 EXTLIBS += $(OPENCSDLIBS)
437 $(call detected,CONFIG_LIBOPENCSD)
439 CFLAGS += -DCS_DEBUG_RAW
440 ifeq (${CSTRACE_RAW}, packed)
441 CFLAGS += -DCS_RAW_PACKED
448 CFLAGS += -DHAVE_LIBELF_SUPPORT
450 $(call detected,CONFIG_LIBELF)
452 ifeq ($(feature-libelf-mmap), 1)
453 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
456 ifeq ($(feature-libelf-getphdrnum), 1)
457 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
460 ifeq ($(feature-libelf-gelf_getnote), 1)
461 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
463 msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
466 ifeq ($(feature-libelf-getshdrstrndx), 1)
467 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
471 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
472 msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);
475 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
476 LDFLAGS += $(LIBDW_LDFLAGS)
477 EXTLIBS += ${DWARFLIBS}
478 $(call detected,CONFIG_DWARF)
479 endif # PERF_HAVE_DWARF_REGS
483 ifeq ($(feature-bpf), 1)
484 CFLAGS += -DHAVE_LIBBPF_SUPPORT
485 $(call detected,CONFIG_LIBBPF)
489 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
490 CFLAGS += -DHAVE_BPF_PROLOGUE
491 $(call detected,CONFIG_BPF_PROLOGUE)
493 msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
496 msg := $(warning DWARF support is off, BPF prologue is disabled);
503 ifneq ($(feature-sdt), 1)
504 msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
507 CFLAGS += -DHAVE_SDT_EVENT
508 $(call detected,CONFIG_SDT_EVENT)
512 ifdef PERF_HAVE_JITDUMP
514 $(call detected,CONFIG_JITDUMP)
515 CFLAGS += -DHAVE_JITDUMP
519 ifeq ($(SRCARCH),powerpc)
521 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
528 $(call feature_check,libunwind-x86)
529 ifeq ($(feature-libunwind-x86), 1)
530 $(call detected,CONFIG_LIBUNWIND_X86)
531 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
532 LDFLAGS += -lunwind-x86
533 EXTLIBS_LIBUNWIND += -lunwind-x86
537 $(call feature_check,libunwind-aarch64)
538 ifeq ($(feature-libunwind-aarch64), 1)
539 $(call detected,CONFIG_LIBUNWIND_AARCH64)
540 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
541 LDFLAGS += -lunwind-aarch64
542 EXTLIBS_LIBUNWIND += -lunwind-aarch64
544 $(call feature_check,libunwind-debug-frame-aarch64)
545 ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
546 msg := $(warning No debug_frame support found in libunwind-aarch64);
547 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
551 ifneq ($(feature-libunwind), 1)
552 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
553 NO_LOCAL_LIBUNWIND := 1
556 $(call detected,CONFIG_LOCAL_LIBUNWIND)
559 ifneq ($(have_libunwind), 1)
563 NO_LOCAL_LIBUNWIND := 1
567 ifneq ($(feature-bpf), 1)
568 msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
573 dwarf-post-unwind := 1
574 dwarf-post-unwind-text := BUG
576 # setup DWARF post unwinder
578 ifdef NO_LIBDW_DWARF_UNWIND
579 msg := $(warning Disabling post unwind, no support found.);
580 dwarf-post-unwind := 0
582 dwarf-post-unwind-text := libdw
583 $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
586 dwarf-post-unwind-text := libunwind
587 $(call detected,CONFIG_LIBUNWIND)
588 # Enable libunwind support by default.
589 ifndef NO_LIBDW_DWARF_UNWIND
590 NO_LIBDW_DWARF_UNWIND := 1
594 ifeq ($(dwarf-post-unwind),1)
595 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
596 $(call detected,CONFIG_DWARF_UNWIND)
601 ifndef NO_LOCAL_LIBUNWIND
602 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
603 $(call feature_check,libunwind-debug-frame)
604 ifneq ($(feature-libunwind-debug-frame), 1)
605 msg := $(warning No debug_frame support found in libunwind);
606 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
609 # non-ARM has no dwarf_find_debug_frame() function:
610 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
612 EXTLIBS += $(LIBUNWIND_LIBS)
613 LDFLAGS += $(LIBUNWIND_LIBS)
615 ifeq ($(findstring -static,${LDFLAGS}),-static)
616 # gcc -static links libgcc_eh which contans piece of libunwind
617 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
621 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
622 CFLAGS += $(LIBUNWIND_CFLAGS)
623 LDFLAGS += $(LIBUNWIND_LDFLAGS)
624 EXTLIBS += $(EXTLIBS_LIBUNWIND)
627 ifeq ($(NO_SYSCALL_TABLE),0)
628 $(call detected,CONFIG_TRACE)
631 ifneq ($(feature-libaudit), 1)
632 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
635 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
637 $(call detected,CONFIG_TRACE)
643 ifneq ($(feature-libcrypto), 1)
644 msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev);
647 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
649 $(call detected,CONFIG_CRYPTO)
658 ifneq ($(feature-libslang), 1)
659 ifneq ($(feature-libslang-include-subdir), 1)
660 msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
663 CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR
667 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
668 CFLAGS += -DHAVE_SLANG_SUPPORT
670 $(call detected,CONFIG_SLANG)
675 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
676 ifneq ($(feature-gtk2), 1)
677 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
680 ifeq ($(feature-gtk2-infobar), 1)
681 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
683 CFLAGS += -DHAVE_GTK2_SUPPORT
684 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
685 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
691 CFLAGS += -DNO_LIBPERL
693 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
694 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
695 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
696 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
697 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
698 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
699 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
701 ifneq ($(feature-libperl), 1)
702 CFLAGS += -DNO_LIBPERL
704 msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
706 LDFLAGS += $(PERL_EMBED_LDFLAGS)
707 EXTLIBS += $(PERL_EMBED_LIBADD)
708 CFLAGS += -DHAVE_LIBPERL_SUPPORT
709 ifeq ($(CC_NO_CLANG), 0)
710 CFLAGS += -Wno-compound-token-split-by-macro
712 $(call detected,CONFIG_LIBPERL)
716 ifeq ($(feature-timerfd), 1)
717 CFLAGS += -DHAVE_TIMERFD_SUPPORT
719 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
722 disable-python = $(eval $(disable-python_code))
723 define disable-python_code
724 CFLAGS += -DNO_LIBPYTHON
730 $(call disable-python,Python support disabled by user)
734 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
736 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
739 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
742 ifneq ($(feature-libpython), 1)
743 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
745 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
746 EXTLIBS += $(PYTHON_EMBED_LIBADD)
747 LANG_BINDINGS += $(obj-perf)python/perf.so
748 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
749 $(call detected,CONFIG_LIBPYTHON)
755 ifeq ($(feature-libbfd), 1)
756 EXTLIBS += -lbfd -lopcodes
758 # we are on a system that requires -liberty and (maybe) -lz
759 # to link against -lbfd; test each case individually here
761 # call all detections now so we get correct
762 # status in VF output
763 $(call feature_check,libbfd-liberty)
764 $(call feature_check,libbfd-liberty-z)
766 ifeq ($(feature-libbfd-liberty), 1)
767 EXTLIBS += -lbfd -lopcodes -liberty
768 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
770 ifeq ($(feature-libbfd-liberty-z), 1)
771 EXTLIBS += -lbfd -lopcodes -liberty -lz
772 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
775 $(call feature_check,disassembler-four-args)
779 CFLAGS += -DNO_DEMANGLE
781 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
784 ifeq ($(filter -liberty,$(EXTLIBS)),)
785 $(call feature_check,cplus-demangle)
787 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
788 # or any of 'bfd iberty z' trinity
789 ifeq ($(feature-cplus-demangle), 1)
792 msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
793 CFLAGS += -DNO_DEMANGLE
798 ifneq ($(filter -liberty,$(EXTLIBS)),)
799 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
803 ifneq ($(filter -lbfd,$(EXTLIBS)),)
804 CFLAGS += -DHAVE_LIBBFD_SUPPORT
808 ifeq ($(feature-zlib), 1)
809 CFLAGS += -DHAVE_ZLIB_SUPPORT
811 $(call detected,CONFIG_ZLIB)
818 ifeq ($(feature-lzma), 1)
819 CFLAGS += -DHAVE_LZMA_SUPPORT
821 $(call detected,CONFIG_LZMA)
823 msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
829 ifeq ($(feature-libzstd), 1)
830 CFLAGS += -DHAVE_ZSTD_SUPPORT
831 CFLAGS += $(LIBZSTD_CFLAGS)
832 LDFLAGS += $(LIBZSTD_LDFLAGS)
834 $(call detected,CONFIG_ZSTD)
836 msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
842 ifeq ($(feature-libcap), 1)
843 CFLAGS += -DHAVE_LIBCAP_SUPPORT
845 $(call detected,CONFIG_LIBCAP)
847 msg := $(warning No libcap found, disables capability support, please install libcap-devel/libcap-dev);
853 ifeq ($(feature-backtrace), 1)
854 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
859 ifeq ($(feature-libnuma), 0)
860 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
863 ifeq ($(feature-numa_num_possible_cpus), 0)
864 msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
867 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
869 $(call detected,CONFIG_NUMA)
874 ifdef HAVE_KVM_STAT_SUPPORT
875 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
878 ifeq ($(feature-disassembler-four-args), 1)
879 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
882 ifeq (${IS_64_BIT}, 1)
883 ifndef NO_PERF_READ_VDSO32
884 $(call feature_check,compile-32)
885 ifeq ($(feature-compile-32), 1)
886 CFLAGS += -DHAVE_PERF_READ_VDSO32
888 NO_PERF_READ_VDSO32 := 1
891 ifneq ($(SRCARCH), x86)
892 NO_PERF_READ_VDSOX32 := 1
894 ifndef NO_PERF_READ_VDSOX32
895 $(call feature_check,compile-x32)
896 ifeq ($(feature-compile-x32), 1)
897 CFLAGS += -DHAVE_PERF_READ_VDSOX32
899 NO_PERF_READ_VDSOX32 := 1
903 NO_PERF_READ_VDSO32 := 1
904 NO_PERF_READ_VDSOX32 := 1
907 ifndef NO_LIBBABELTRACE
908 $(call feature_check,libbabeltrace)
909 ifeq ($(feature-libbabeltrace), 1)
910 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
911 LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
912 EXTLIBS += -lbabeltrace-ctf
913 $(call detected,CONFIG_LIBBABELTRACE)
915 msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
920 ifeq ($(SRCARCH),x86)
921 ifeq ($(feature-get_cpuid), 0)
922 msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
927 $(call detected,CONFIG_AUXTRACE)
928 CFLAGS += -DHAVE_AUXTRACE_SUPPORT
933 ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
934 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
936 ifneq (,$(wildcard /usr/sbin/alternatives))
937 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')
941 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
947 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
948 $(call feature_check,jvmti)
949 ifeq ($(feature-jvmti), 1)
950 $(call detected_var,JDIR)
952 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
953 $(call feature_check,jvmti-cmlr)
954 ifeq ($(feature-jvmti-cmlr), 1)
955 CFLAGS += -DHAVE_JVMTI_CMLR
957 endif # NO_JVMTI_CMLR
959 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
967 $(call feature_check,cxx)
968 ifneq ($(feature-cxx), 1)
969 msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
971 $(call feature_check,llvm)
972 $(call feature_check,llvm-version)
973 ifneq ($(feature-llvm), 1)
974 msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
976 $(call feature_check,clang)
977 ifneq ($(feature-clang), 1)
978 msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
980 CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
981 CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
982 $(call detected,CONFIG_CXX)
983 $(call detected,CONFIG_CLANGLLVM)
987 ifneq ($(feature-llvm-version),1)
988 msg := $(warning This version of LLVM is not tested. May cause build errors)
995 # Among the variables below, these:
1003 # ETC_PERFCONFIG (but not sysconfdir)
1004 # can be specified as a relative path some/where/else;
1005 # this is interpreted as relative to $(prefix) and "perf" at
1006 # runtime figures out where they are based on the path to the executable.
1007 # This can help installing the suite in a relocatable way.
1009 # Make the path relative to DESTDIR, not to prefix
1013 bindir_relative = bin
1014 bindir = $(abspath $(prefix)/$(bindir_relative))
1016 infodir = share/info
1017 perfexecdir = libexec/perf-core
1018 perf_include_dir = lib/perf/include
1019 perf_examples_dir = lib/perf/examples
1020 sharedir = $(prefix)/share
1021 template_dir = share/perf-core/templates
1022 STRACE_GROUPS_DIR = share/perf-core/strace/groups
1023 htmldir = share/doc/perf-doc
1024 tipdir = share/doc/perf-tip
1025 srcdir = $(srctree)/tools/perf
1026 ifeq ($(prefix),/usr)
1028 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
1030 sysconfdir = $(prefix)/etc
1031 ETC_PERFCONFIG = etc/perfconfig
1034 ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1040 libdir = $(prefix)/$(lib)
1042 # Shell quote (do not use $(call) to accommodate ancient setups);
1043 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1044 STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1045 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1046 bindir_SQ = $(subst ','\'',$(bindir))
1047 mandir_SQ = $(subst ','\'',$(mandir))
1048 infodir_SQ = $(subst ','\'',$(infodir))
1049 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1050 perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
1051 perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1052 template_dir_SQ = $(subst ','\'',$(template_dir))
1053 htmldir_SQ = $(subst ','\'',$(htmldir))
1054 tipdir_SQ = $(subst ','\'',$(tipdir))
1055 prefix_SQ = $(subst ','\'',$(prefix))
1056 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1057 libdir_SQ = $(subst ','\'',$(libdir))
1058 srcdir_SQ = $(subst ','\'',$(srcdir))
1060 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1061 perfexec_instdir = $(perfexecdir)
1062 perf_include_instdir = $(perf_include_dir)
1063 perf_examples_instdir = $(perf_examples_dir)
1064 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1065 tip_instdir = $(tipdir)
1067 perfexec_instdir = $(prefix)/$(perfexecdir)
1068 perf_include_instdir = $(prefix)/$(perf_include_dir)
1069 perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1070 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1071 tip_instdir = $(prefix)/$(tipdir)
1073 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1074 perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1075 perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1076 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1077 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1079 # If we install to $(HOME) we keep the traceevent default:
1080 # $(HOME)/.traceevent/plugins
1081 # Otherwise we install plugins into the global $(libdir).
1083 plugindir=$(libdir)/traceevent/plugins
1084 plugindir_SQ= $(subst ','\'',$(plugindir))
1087 print_var = $(eval $(print_var_code)) $(info $(MSG))
1088 define print_var_code
1089 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
1093 # Display EXTRA features which are detected manualy
1094 # from here with feature_check call and thus cannot
1095 # be partof global state output.
1096 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
1097 $(call print_var,prefix)
1098 $(call print_var,bindir)
1099 $(call print_var,libdir)
1100 $(call print_var,sysconfdir)
1101 $(call print_var,LIBUNWIND_DIR)
1102 $(call print_var,LIBDW_DIR)
1103 $(call print_var,JDIR)
1105 ifeq ($(dwarf-post-unwind),1)
1106 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
1111 $(call detected_var,bindir_SQ)
1112 $(call detected_var,PYTHON_WORD)
1114 $(call detected_var,OUTPUT)
1116 $(call detected_var,htmldir_SQ)
1117 $(call detected_var,infodir_SQ)
1118 $(call detected_var,mandir_SQ)
1119 $(call detected_var,ETC_PERFCONFIG_SQ)
1120 $(call detected_var,STRACE_GROUPS_DIR_SQ)
1121 $(call detected_var,prefix_SQ)
1122 $(call detected_var,perfexecdir_SQ)
1123 $(call detected_var,perf_include_dir_SQ)
1124 $(call detected_var,perf_examples_dir_SQ)
1125 $(call detected_var,tipdir_SQ)
1126 $(call detected_var,srcdir_SQ)
1127 $(call detected_var,LIBDIR)
1128 $(call detected_var,GTK_CFLAGS)
1129 $(call detected_var,PERL_EMBED_CCOPTS)
1130 $(call detected_var,PYTHON_EMBED_CCOPTS)