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))
232 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
233 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
234 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
235 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
236 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
239 FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
240 FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
241 FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
242 FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
244 FEATURE_CHECK_LDFLAGS-libaio = -lrt
246 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
248 CORE_CFLAGS += -fno-omit-frame-pointer
249 CORE_CFLAGS += -ggdb3
250 CORE_CFLAGS += -funwind-tables
252 CORE_CFLAGS += -Wextra
253 CORE_CFLAGS += -std=gnu99
255 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
257 CXXFLAGS += -fno-omit-frame-pointer
259 CXXFLAGS += -funwind-tables
260 CXXFLAGS += -Wno-strict-aliasing
262 # Enforce a non-executable stack, as we may regress (again) in the future by
263 # adding assembler files missing the .GNU-stack linker note.
264 LDFLAGS += -Wl,-z,noexecstack
266 EXTLIBS = -lpthread -lrt -lm -ldl
269 CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
270 EXTLIBS += -ltcmalloc
273 ifeq ($(FEATURES_DUMP),)
274 include $(srctree)/tools/build/Makefile.feature
276 include $(FEATURES_DUMP)
279 ifeq ($(feature-stackprotector-all), 1)
280 CORE_CFLAGS += -fstack-protector-all
284 ifeq ($(feature-fortify-source), 1)
285 CORE_CFLAGS += -D_FORTIFY_SOURCE=2
289 INC_FLAGS += -I$(srctree)/tools/lib/perf/include
290 INC_FLAGS += -I$(src-perf)/util/include
291 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
292 INC_FLAGS += -I$(srctree)/tools/include/
293 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
294 INC_FLAGS += -I$(srctree)/tools/include/uapi
295 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
296 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
298 # $(obj-perf) for generated common-cmds.h
299 # $(obj-perf)/util for generated bison/flex headers
301 INC_FLAGS += -I$(obj-perf)/util
302 INC_FLAGS += -I$(obj-perf)
305 INC_FLAGS += -I$(src-perf)/util
306 INC_FLAGS += -I$(src-perf)
307 INC_FLAGS += -I$(srctree)/tools/lib/
309 CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
311 CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS)
312 CXXFLAGS += $(INC_FLAGS)
314 LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)
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)
487 # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
488 $(call feature_check,libbpf)
490 ifeq ($(feature-libbpf), 1)
493 dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
499 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
500 CFLAGS += -DHAVE_BPF_PROLOGUE
501 $(call detected,CONFIG_BPF_PROLOGUE)
503 msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
506 msg := $(warning DWARF support is off, BPF prologue is disabled);
513 ifneq ($(feature-sdt), 1)
514 msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
517 CFLAGS += -DHAVE_SDT_EVENT
518 $(call detected,CONFIG_SDT_EVENT)
522 ifdef PERF_HAVE_JITDUMP
524 $(call detected,CONFIG_JITDUMP)
525 CFLAGS += -DHAVE_JITDUMP
529 ifeq ($(SRCARCH),powerpc)
531 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
538 $(call feature_check,libunwind-x86)
539 ifeq ($(feature-libunwind-x86), 1)
540 $(call detected,CONFIG_LIBUNWIND_X86)
541 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
542 LDFLAGS += -lunwind-x86
543 EXTLIBS_LIBUNWIND += -lunwind-x86
547 $(call feature_check,libunwind-aarch64)
548 ifeq ($(feature-libunwind-aarch64), 1)
549 $(call detected,CONFIG_LIBUNWIND_AARCH64)
550 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
551 LDFLAGS += -lunwind-aarch64
552 EXTLIBS_LIBUNWIND += -lunwind-aarch64
554 $(call feature_check,libunwind-debug-frame-aarch64)
555 ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
556 msg := $(warning No debug_frame support found in libunwind-aarch64);
557 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
561 ifneq ($(feature-libunwind), 1)
562 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
563 NO_LOCAL_LIBUNWIND := 1
566 $(call detected,CONFIG_LOCAL_LIBUNWIND)
569 ifneq ($(have_libunwind), 1)
573 NO_LOCAL_LIBUNWIND := 1
577 ifneq ($(feature-bpf), 1)
578 msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
583 dwarf-post-unwind := 1
584 dwarf-post-unwind-text := BUG
586 # setup DWARF post unwinder
588 ifdef NO_LIBDW_DWARF_UNWIND
589 msg := $(warning Disabling post unwind, no support found.);
590 dwarf-post-unwind := 0
592 dwarf-post-unwind-text := libdw
593 $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
596 dwarf-post-unwind-text := libunwind
597 $(call detected,CONFIG_LIBUNWIND)
598 # Enable libunwind support by default.
599 ifndef NO_LIBDW_DWARF_UNWIND
600 NO_LIBDW_DWARF_UNWIND := 1
604 ifeq ($(dwarf-post-unwind),1)
605 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
606 $(call detected,CONFIG_DWARF_UNWIND)
611 ifndef NO_LOCAL_LIBUNWIND
612 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
613 $(call feature_check,libunwind-debug-frame)
614 ifneq ($(feature-libunwind-debug-frame), 1)
615 msg := $(warning No debug_frame support found in libunwind);
616 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
619 # non-ARM has no dwarf_find_debug_frame() function:
620 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
622 EXTLIBS += $(LIBUNWIND_LIBS)
623 LDFLAGS += $(LIBUNWIND_LIBS)
625 ifeq ($(findstring -static,${LDFLAGS}),-static)
626 # gcc -static links libgcc_eh which contans piece of libunwind
627 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
631 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
632 CFLAGS += $(LIBUNWIND_CFLAGS)
633 LDFLAGS += $(LIBUNWIND_LDFLAGS)
634 EXTLIBS += $(EXTLIBS_LIBUNWIND)
637 ifeq ($(NO_SYSCALL_TABLE),0)
638 $(call detected,CONFIG_TRACE)
641 ifneq ($(feature-libaudit), 1)
642 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
645 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
647 $(call detected,CONFIG_TRACE)
653 ifneq ($(feature-libcrypto), 1)
654 msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev);
657 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
659 $(call detected,CONFIG_CRYPTO)
668 ifneq ($(feature-libslang), 1)
669 ifneq ($(feature-libslang-include-subdir), 1)
670 msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
673 CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR
677 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
678 CFLAGS += -DHAVE_SLANG_SUPPORT
680 $(call detected,CONFIG_SLANG)
685 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
686 ifneq ($(feature-gtk2), 1)
687 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
690 ifeq ($(feature-gtk2-infobar), 1)
691 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
693 CFLAGS += -DHAVE_GTK2_SUPPORT
694 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
695 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
701 CFLAGS += -DNO_LIBPERL
703 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
704 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
705 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
706 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
707 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
708 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
709 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
711 ifneq ($(feature-libperl), 1)
712 CFLAGS += -DNO_LIBPERL
714 msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
716 LDFLAGS += $(PERL_EMBED_LDFLAGS)
717 EXTLIBS += $(PERL_EMBED_LIBADD)
718 CFLAGS += -DHAVE_LIBPERL_SUPPORT
719 $(call detected,CONFIG_LIBPERL)
723 ifeq ($(feature-timerfd), 1)
724 CFLAGS += -DHAVE_TIMERFD_SUPPORT
726 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
729 disable-python = $(eval $(disable-python_code))
730 define disable-python_code
731 CFLAGS += -DNO_LIBPYTHON
737 $(call disable-python,Python support disabled by user)
741 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
743 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
746 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
749 ifneq ($(feature-libpython), 1)
750 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
752 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
753 EXTLIBS += $(PYTHON_EMBED_LIBADD)
754 LANG_BINDINGS += $(obj-perf)python/perf.so
755 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
756 $(call detected,CONFIG_LIBPYTHON)
762 ifeq ($(feature-libbfd), 1)
763 EXTLIBS += -lbfd -lopcodes
765 # we are on a system that requires -liberty and (maybe) -lz
766 # to link against -lbfd; test each case individually here
768 # call all detections now so we get correct
769 # status in VF output
770 $(call feature_check,libbfd-liberty)
771 $(call feature_check,libbfd-liberty-z)
773 ifeq ($(feature-libbfd-liberty), 1)
774 EXTLIBS += -lbfd -lopcodes -liberty
775 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
777 ifeq ($(feature-libbfd-liberty-z), 1)
778 EXTLIBS += -lbfd -lopcodes -liberty -lz
779 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
782 $(call feature_check,disassembler-four-args)
786 CFLAGS += -DNO_DEMANGLE
788 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
791 ifeq ($(filter -liberty,$(EXTLIBS)),)
792 $(call feature_check,cplus-demangle)
794 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
795 # or any of 'bfd iberty z' trinity
796 ifeq ($(feature-cplus-demangle), 1)
799 msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
800 CFLAGS += -DNO_DEMANGLE
805 ifneq ($(filter -liberty,$(EXTLIBS)),)
806 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
810 ifneq ($(filter -lbfd,$(EXTLIBS)),)
811 CFLAGS += -DHAVE_LIBBFD_SUPPORT
815 ifeq ($(feature-zlib), 1)
816 CFLAGS += -DHAVE_ZLIB_SUPPORT
818 $(call detected,CONFIG_ZLIB)
825 ifeq ($(feature-lzma), 1)
826 CFLAGS += -DHAVE_LZMA_SUPPORT
828 $(call detected,CONFIG_LZMA)
830 msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
836 ifeq ($(feature-libzstd), 1)
837 CFLAGS += -DHAVE_ZSTD_SUPPORT
838 CFLAGS += $(LIBZSTD_CFLAGS)
839 LDFLAGS += $(LIBZSTD_LDFLAGS)
841 $(call detected,CONFIG_ZSTD)
843 msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
849 ifeq ($(feature-libcap), 1)
850 CFLAGS += -DHAVE_LIBCAP_SUPPORT
852 $(call detected,CONFIG_LIBCAP)
854 msg := $(warning No libcap found, disables capability support, please install libcap-devel/libcap-dev);
860 ifeq ($(feature-backtrace), 1)
861 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
866 ifeq ($(feature-libnuma), 0)
867 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
870 ifeq ($(feature-numa_num_possible_cpus), 0)
871 msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
874 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
876 $(call detected,CONFIG_NUMA)
881 ifdef HAVE_KVM_STAT_SUPPORT
882 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
885 ifeq ($(feature-disassembler-four-args), 1)
886 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
889 ifeq (${IS_64_BIT}, 1)
890 ifndef NO_PERF_READ_VDSO32
891 $(call feature_check,compile-32)
892 ifeq ($(feature-compile-32), 1)
893 CFLAGS += -DHAVE_PERF_READ_VDSO32
895 NO_PERF_READ_VDSO32 := 1
898 ifneq ($(SRCARCH), x86)
899 NO_PERF_READ_VDSOX32 := 1
901 ifndef NO_PERF_READ_VDSOX32
902 $(call feature_check,compile-x32)
903 ifeq ($(feature-compile-x32), 1)
904 CFLAGS += -DHAVE_PERF_READ_VDSOX32
906 NO_PERF_READ_VDSOX32 := 1
910 NO_PERF_READ_VDSO32 := 1
911 NO_PERF_READ_VDSOX32 := 1
914 ifndef NO_LIBBABELTRACE
915 $(call feature_check,libbabeltrace)
916 ifeq ($(feature-libbabeltrace), 1)
917 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
918 LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
919 EXTLIBS += -lbabeltrace-ctf
920 $(call detected,CONFIG_LIBBABELTRACE)
922 msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
927 ifeq ($(SRCARCH),x86)
928 ifeq ($(feature-get_cpuid), 0)
929 msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
934 $(call detected,CONFIG_AUXTRACE)
935 CFLAGS += -DHAVE_AUXTRACE_SUPPORT
940 ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
941 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
943 ifneq (,$(wildcard /usr/sbin/alternatives))
944 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')
948 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
954 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
955 $(call feature_check,jvmti)
956 ifeq ($(feature-jvmti), 1)
957 $(call detected_var,JDIR)
959 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
960 $(call feature_check,jvmti-cmlr)
961 ifeq ($(feature-jvmti-cmlr), 1)
962 CFLAGS += -DHAVE_JVMTI_CMLR
964 endif # NO_JVMTI_CMLR
966 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
974 $(call feature_check,cxx)
975 ifneq ($(feature-cxx), 1)
976 msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
978 $(call feature_check,llvm)
979 $(call feature_check,llvm-version)
980 ifneq ($(feature-llvm), 1)
981 msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
983 $(call feature_check,clang)
984 ifneq ($(feature-clang), 1)
985 msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
987 CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
988 CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
989 $(call detected,CONFIG_CXX)
990 $(call detected,CONFIG_CLANGLLVM)
994 ifneq ($(feature-llvm-version),1)
995 msg := $(warning This version of LLVM is not tested. May cause build errors)
1002 # Among the variables below, these:
1010 # ETC_PERFCONFIG (but not sysconfdir)
1011 # can be specified as a relative path some/where/else;
1012 # this is interpreted as relative to $(prefix) and "perf" at
1013 # runtime figures out where they are based on the path to the executable.
1014 # This can help installing the suite in a relocatable way.
1016 # Make the path relative to DESTDIR, not to prefix
1020 bindir_relative = bin
1021 bindir = $(abspath $(prefix)/$(bindir_relative))
1023 infodir = share/info
1024 perfexecdir = libexec/perf-core
1025 perf_include_dir = lib/perf/include
1026 perf_examples_dir = lib/perf/examples
1027 sharedir = $(prefix)/share
1028 template_dir = share/perf-core/templates
1029 STRACE_GROUPS_DIR = share/perf-core/strace/groups
1030 htmldir = share/doc/perf-doc
1031 tipdir = share/doc/perf-tip
1032 srcdir = $(srctree)/tools/perf
1033 ifeq ($(prefix),/usr)
1035 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
1037 sysconfdir = $(prefix)/etc
1038 ETC_PERFCONFIG = etc/perfconfig
1041 ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1047 libdir = $(prefix)/$(lib)
1049 # Shell quote (do not use $(call) to accommodate ancient setups);
1050 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1051 STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1052 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1053 bindir_SQ = $(subst ','\'',$(bindir))
1054 mandir_SQ = $(subst ','\'',$(mandir))
1055 infodir_SQ = $(subst ','\'',$(infodir))
1056 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1057 perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
1058 perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1059 template_dir_SQ = $(subst ','\'',$(template_dir))
1060 htmldir_SQ = $(subst ','\'',$(htmldir))
1061 tipdir_SQ = $(subst ','\'',$(tipdir))
1062 prefix_SQ = $(subst ','\'',$(prefix))
1063 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1064 libdir_SQ = $(subst ','\'',$(libdir))
1065 srcdir_SQ = $(subst ','\'',$(srcdir))
1067 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1068 perfexec_instdir = $(perfexecdir)
1069 perf_include_instdir = $(perf_include_dir)
1070 perf_examples_instdir = $(perf_examples_dir)
1071 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1072 tip_instdir = $(tipdir)
1074 perfexec_instdir = $(prefix)/$(perfexecdir)
1075 perf_include_instdir = $(prefix)/$(perf_include_dir)
1076 perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1077 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1078 tip_instdir = $(prefix)/$(tipdir)
1080 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1081 perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1082 perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1083 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1084 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1086 # If we install to $(HOME) we keep the traceevent default:
1087 # $(HOME)/.traceevent/plugins
1088 # Otherwise we install plugins into the global $(libdir).
1090 plugindir=$(libdir)/traceevent/plugins
1091 plugindir_SQ= $(subst ','\'',$(plugindir))
1094 print_var = $(eval $(print_var_code)) $(info $(MSG))
1095 define print_var_code
1096 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
1100 # Display EXTRA features which are detected manualy
1101 # from here with feature_check call and thus cannot
1102 # be partof global state output.
1103 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
1104 $(call print_var,prefix)
1105 $(call print_var,bindir)
1106 $(call print_var,libdir)
1107 $(call print_var,sysconfdir)
1108 $(call print_var,LIBUNWIND_DIR)
1109 $(call print_var,LIBDW_DIR)
1110 $(call print_var,JDIR)
1112 ifeq ($(dwarf-post-unwind),1)
1113 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
1118 $(call detected_var,bindir_SQ)
1119 $(call detected_var,PYTHON_WORD)
1121 $(call detected_var,OUTPUT)
1123 $(call detected_var,htmldir_SQ)
1124 $(call detected_var,infodir_SQ)
1125 $(call detected_var,mandir_SQ)
1126 $(call detected_var,ETC_PERFCONFIG_SQ)
1127 $(call detected_var,STRACE_GROUPS_DIR_SQ)
1128 $(call detected_var,prefix_SQ)
1129 $(call detected_var,perfexecdir_SQ)
1130 $(call detected_var,perf_include_dir_SQ)
1131 $(call detected_var,perf_examples_dir_SQ)
1132 $(call detected_var,tipdir_SQ)
1133 $(call detected_var,srcdir_SQ)
1134 $(call detected_var,LIBDIR)
1135 $(call detected_var,GTK_CFLAGS)
1136 $(call detected_var,PERL_EMBED_CCOPTS)
1137 $(call detected_var,PYTHON_EMBED_CCOPTS)