3 src-perf := $(srctree)/tools/perf
11 obj-perf := $(abspath $(obj-perf))/
14 $(shell printf "" > $(OUTPUT).config-detected)
15 detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected)
16 detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
18 CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
20 include $(srctree)/tools/scripts/Makefile.arch
22 $(call detected_var,SRCARCH)
27 # Additional ARCH settings for ppc
28 ifeq ($(SRCARCH),powerpc)
31 CFLAGS += -I$(OUTPUT)arch/powerpc/include/generated
32 LIBUNWIND_LIBS := -lunwind -lunwind-ppc64
35 # Additional ARCH settings for x86
37 $(call detected,CONFIG_X86)
38 ifeq (${IS_64_BIT}, 1)
40 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT -I$(OUTPUT)arch/x86/include/generated
41 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
42 LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma
43 $(call detected,CONFIG_X86_64)
45 LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind
52 LIBUNWIND_LIBS = -lunwind -lunwind-arm
55 ifeq ($(SRCARCH),arm64)
58 CFLAGS += -I$(OUTPUT)arch/arm64/include/generated
59 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
65 CFLAGS += -fPIC -I$(OUTPUT)arch/s390/include/generated
68 ifeq ($(NO_PERF_REGS),0)
69 $(call detected,CONFIG_PERF_REGS)
72 ifneq ($(NO_SYSCALL_TABLE),1)
73 CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
76 # So far there's only x86 and arm libdw unwind support merged in perf.
77 # Disable it on all other architectures in case libdw unwind
78 # support is detected in system. Add supported architectures
80 ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390))
81 NO_LIBDW_DWARF_UNWIND := 1
84 ifeq ($(LIBUNWIND_LIBS),)
88 # For linking with debug library, run like:
90 # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
93 libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
94 define libunwind_arch_set_flags_code
95 FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include
96 FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
100 LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include
101 LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
102 LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
103 $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
106 # Set per-feature check compilation flags
107 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
108 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
109 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
110 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
112 FEATURE_CHECK_LDFLAGS-libunwind-arm = -lunwind -lunwind-arm
113 FEATURE_CHECK_LDFLAGS-libunwind-aarch64 = -lunwind -lunwind-aarch64
114 FEATURE_CHECK_LDFLAGS-libunwind-x86 = -lunwind -llzma -lunwind-x86
115 FEATURE_CHECK_LDFLAGS-libunwind-x86_64 = -lunwind -llzma -lunwind-x86_64
117 FEATURE_CHECK_LDFLAGS-libcrypto = -lcrypto
120 LIBOPENCSD_CFLAGS := -I$(CSINCLUDES)
122 OPENCSDLIBS := -lopencsd_c_api -lopencsd
124 LIBOPENCSD_LDFLAGS := -L$(CSLIBS)
126 FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS)
127 FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS)
129 ifeq ($(NO_PERF_REGS),0)
130 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
133 # for linking with debug library, run like:
134 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
136 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
137 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
140 ifeq ($(findstring -static,${LDFLAGS}),-static)
141 DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
143 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
144 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
146 # for linking with debug library, run like:
147 # make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
148 ifdef LIBBABELTRACE_DIR
149 LIBBABELTRACE_CFLAGS := -I$(LIBBABELTRACE_DIR)/include
150 LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
152 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
153 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
156 LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib
157 LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
159 FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
160 FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
162 FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
163 # include ARCH specific config
164 -include $(src-perf)/arch/$(SRCARCH)/Makefile
166 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
167 CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
170 include $(srctree)/tools/scripts/utilities.mak
172 ifeq ($(call get-executable,$(FLEX)),)
173 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
176 ifeq ($(call get-executable,$(BISON)),)
177 dummy := $(error Error: $(BISON) is missing on this system, please install it)
180 # Treat warnings as errors unless directed not to
191 ifeq ($(CC_NO_CLANG), 0)
199 PARSER_DEBUG_BISON := -t
200 PARSER_DEBUG_FLEX := -d
201 CFLAGS += -DPARSER_DEBUG
202 $(call detected_var,PARSER_DEBUG_BISON)
203 $(call detected_var,PARSER_DEBUG_FLEX)
206 # Try different combinations to accommodate systems that only have
207 # python[2][-config] in weird combinations but always preferring
208 # python2 and python2-config as per pep-0394. If we catch a
209 # python[-config] in version 3, the version check will kill it.
210 PYTHON2 := $(if $(call get-executable,python2),python2,python)
211 override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2))
213 $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config)
214 override PYTHON_CONFIG := \
215 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
217 grep-libs = $(filter -l%,$(1))
218 strip-libs = $(filter-out -l%,$(1))
220 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
223 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
224 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
225 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
226 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
227 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
230 FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
231 FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
232 FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
233 FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
235 FEATURE_CHECK_LDFLAGS-libaio = -lrt
237 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
239 CFLAGS += -fno-omit-frame-pointer
241 CFLAGS += -funwind-tables
246 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
248 CXXFLAGS += -fno-omit-frame-pointer
250 CXXFLAGS += -funwind-tables
251 CXXFLAGS += -Wno-strict-aliasing
253 # Enforce a non-executable stack, as we may regress (again) in the future by
254 # adding assembler files missing the .GNU-stack linker note.
255 LDFLAGS += -Wl,-z,noexecstack
257 EXTLIBS = -lpthread -lrt -lm -ldl
259 ifeq ($(FEATURES_DUMP),)
260 include $(srctree)/tools/build/Makefile.feature
262 include $(FEATURES_DUMP)
265 ifeq ($(feature-stackprotector-all), 1)
266 CFLAGS += -fstack-protector-all
270 ifeq ($(feature-fortify-source), 1)
271 CFLAGS += -D_FORTIFY_SOURCE=2
275 INC_FLAGS += -I$(src-perf)/util/include
276 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
277 INC_FLAGS += -I$(srctree)/tools/include/uapi
278 INC_FLAGS += -I$(srctree)/tools/include/
279 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
280 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
281 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
283 # $(obj-perf) for generated common-cmds.h
284 # $(obj-perf)/util for generated bison/flex headers
286 INC_FLAGS += -I$(obj-perf)/util
287 INC_FLAGS += -I$(obj-perf)
290 INC_FLAGS += -I$(src-perf)/util
291 INC_FLAGS += -I$(src-perf)
292 INC_FLAGS += -I$(srctree)/tools/lib/
294 CFLAGS += $(INC_FLAGS)
295 CXXFLAGS += $(INC_FLAGS)
297 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
299 ifeq ($(feature-sync-compare-and-swap), 1)
300 CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
303 ifeq ($(feature-pthread-attr-setaffinity-np), 1)
304 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
307 ifeq ($(feature-pthread-barrier), 1)
308 CFLAGS += -DHAVE_PTHREAD_BARRIER
312 $(call feature_check,bionic)
313 ifeq ($(feature-bionic), 1)
315 CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
316 CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
317 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
318 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
322 ifeq ($(feature-eventfd), 1)
323 CFLAGS += -DHAVE_EVENTFD
326 ifeq ($(feature-get_current_dir_name), 1)
327 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
334 NO_LIBDW_DWARF_UNWIND := 1
338 ifeq ($(feature-libelf), 0)
339 ifeq ($(feature-glibc), 1)
345 ifeq ($(LIBC_SUPPORT),1)
346 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);
352 NO_LIBDW_DWARF_UNWIND := 1
356 ifneq ($(filter s% -static%,$(LDFLAGS),),)
357 msg := $(error No static glibc found, please install glibc-static);
359 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
363 ifndef NO_LIBDW_DWARF_UNWIND
364 ifneq ($(feature-libdw-dwarf-unwind),1)
365 NO_LIBDW_DWARF_UNWIND := 1
366 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
369 ifneq ($(feature-dwarf), 1)
371 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);
375 ifneq ($(feature-dwarf_getlocations), 1)
376 msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
378 CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
379 endif # dwarf_getlocations
380 endif # Dwarf support
381 endif # libelf support
384 ifeq ($(feature-glibc), 1)
385 CFLAGS += -DHAVE_GLIBC_SUPPORT
388 ifeq ($(feature-libaio), 1)
390 CFLAGS += -DHAVE_AIO_SUPPORT
395 NO_LIBDW_DWARF_UNWIND := 1
398 ifeq ($(feature-sched_getcpu), 1)
399 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
402 ifeq ($(feature-setns), 1)
403 CFLAGS += -DHAVE_SETNS_SUPPORT
404 $(call detected,CONFIG_SETNS)
408 $(call feature_check,libopencsd)
409 ifeq ($(feature-libopencsd), 1)
410 CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
411 LDFLAGS += $(LIBOPENCSD_LDFLAGS)
412 EXTLIBS += $(OPENCSDLIBS)
413 $(call detected,CONFIG_LIBOPENCSD)
415 CFLAGS += -DCS_DEBUG_RAW
416 ifeq (${CSTRACE_RAW}, packed)
417 CFLAGS += -DCS_RAW_PACKED
424 CFLAGS += -DHAVE_LIBELF_SUPPORT
426 $(call detected,CONFIG_LIBELF)
428 ifeq ($(feature-libelf-mmap), 1)
429 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
432 ifeq ($(feature-libelf-getphdrnum), 1)
433 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
436 ifeq ($(feature-libelf-gelf_getnote), 1)
437 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
439 msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
442 ifeq ($(feature-libelf-getshdrstrndx), 1)
443 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
447 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
448 msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);
451 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
452 LDFLAGS += $(LIBDW_LDFLAGS)
453 EXTLIBS += ${DWARFLIBS}
454 $(call detected,CONFIG_DWARF)
455 endif # PERF_HAVE_DWARF_REGS
459 ifeq ($(feature-bpf), 1)
460 CFLAGS += -DHAVE_LIBBPF_SUPPORT
461 $(call detected,CONFIG_LIBBPF)
465 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
466 CFLAGS += -DHAVE_BPF_PROLOGUE
467 $(call detected,CONFIG_BPF_PROLOGUE)
469 msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
472 msg := $(warning DWARF support is off, BPF prologue is disabled);
479 ifneq ($(feature-sdt), 1)
480 msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
483 CFLAGS += -DHAVE_SDT_EVENT
484 $(call detected,CONFIG_SDT_EVENT)
488 ifdef PERF_HAVE_JITDUMP
490 $(call detected,CONFIG_JITDUMP)
491 CFLAGS += -DHAVE_JITDUMP
495 ifeq ($(SRCARCH),powerpc)
497 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
504 $(call feature_check,libunwind-x86)
505 ifeq ($(feature-libunwind-x86), 1)
506 $(call detected,CONFIG_LIBUNWIND_X86)
507 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
508 LDFLAGS += -lunwind-x86
509 EXTLIBS_LIBUNWIND += -lunwind-x86
513 $(call feature_check,libunwind-aarch64)
514 ifeq ($(feature-libunwind-aarch64), 1)
515 $(call detected,CONFIG_LIBUNWIND_AARCH64)
516 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
517 LDFLAGS += -lunwind-aarch64
518 EXTLIBS_LIBUNWIND += -lunwind-aarch64
520 $(call feature_check,libunwind-debug-frame-aarch64)
521 ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
522 msg := $(warning No debug_frame support found in libunwind-aarch64);
523 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
527 ifneq ($(feature-libunwind), 1)
528 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
529 NO_LOCAL_LIBUNWIND := 1
532 $(call detected,CONFIG_LOCAL_LIBUNWIND)
535 ifneq ($(have_libunwind), 1)
539 NO_LOCAL_LIBUNWIND := 1
543 ifneq ($(feature-bpf), 1)
544 msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
549 dwarf-post-unwind := 1
550 dwarf-post-unwind-text := BUG
552 # setup DWARF post unwinder
554 ifdef NO_LIBDW_DWARF_UNWIND
555 msg := $(warning Disabling post unwind, no support found.);
556 dwarf-post-unwind := 0
558 dwarf-post-unwind-text := libdw
559 $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
562 dwarf-post-unwind-text := libunwind
563 $(call detected,CONFIG_LIBUNWIND)
564 # Enable libunwind support by default.
565 ifndef NO_LIBDW_DWARF_UNWIND
566 NO_LIBDW_DWARF_UNWIND := 1
570 ifeq ($(dwarf-post-unwind),1)
571 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
572 $(call detected,CONFIG_DWARF_UNWIND)
577 ifndef NO_LOCAL_LIBUNWIND
578 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
579 $(call feature_check,libunwind-debug-frame)
580 ifneq ($(feature-libunwind-debug-frame), 1)
581 msg := $(warning No debug_frame support found in libunwind);
582 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
585 # non-ARM has no dwarf_find_debug_frame() function:
586 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
588 EXTLIBS += $(LIBUNWIND_LIBS)
589 LDFLAGS += $(LIBUNWIND_LIBS)
591 ifeq ($(findstring -static,${LDFLAGS}),-static)
592 # gcc -static links libgcc_eh which contans piece of libunwind
593 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
597 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
598 CFLAGS += $(LIBUNWIND_CFLAGS)
599 LDFLAGS += $(LIBUNWIND_LDFLAGS)
600 EXTLIBS += $(EXTLIBS_LIBUNWIND)
603 ifeq ($(NO_SYSCALL_TABLE),0)
604 $(call detected,CONFIG_TRACE)
607 ifneq ($(feature-libaudit), 1)
608 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
611 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
613 $(call detected,CONFIG_TRACE)
619 ifneq ($(feature-libcrypto), 1)
620 msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev);
623 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
625 $(call detected,CONFIG_CRYPTO)
634 ifneq ($(feature-libslang), 1)
635 msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
638 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
639 CFLAGS += -I/usr/include/slang
640 CFLAGS += -DHAVE_SLANG_SUPPORT
642 $(call detected,CONFIG_SLANG)
647 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
648 ifneq ($(feature-gtk2), 1)
649 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
652 ifeq ($(feature-gtk2-infobar), 1)
653 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
655 CFLAGS += -DHAVE_GTK2_SUPPORT
656 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
657 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
663 CFLAGS += -DNO_LIBPERL
665 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
666 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
667 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
668 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
669 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
670 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
671 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
673 ifneq ($(feature-libperl), 1)
674 CFLAGS += -DNO_LIBPERL
676 msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
678 LDFLAGS += $(PERL_EMBED_LDFLAGS)
679 EXTLIBS += $(PERL_EMBED_LIBADD)
680 CFLAGS += -DHAVE_LIBPERL_SUPPORT
681 $(call detected,CONFIG_LIBPERL)
685 ifeq ($(feature-timerfd), 1)
686 CFLAGS += -DHAVE_TIMERFD_SUPPORT
688 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
691 disable-python = $(eval $(disable-python_code))
692 define disable-python_code
693 CFLAGS += -DNO_LIBPYTHON
699 $(call disable-python,Python support disabled by user)
703 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
705 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
708 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
711 ifneq ($(feature-libpython), 1)
712 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
714 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
715 EXTLIBS += $(PYTHON_EMBED_LIBADD)
716 LANG_BINDINGS += $(obj-perf)python/perf.so
717 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
718 $(call detected,CONFIG_LIBPYTHON)
724 ifeq ($(feature-libbfd), 1)
725 EXTLIBS += -lbfd -lopcodes
727 # we are on a system that requires -liberty and (maybe) -lz
728 # to link against -lbfd; test each case individually here
730 # call all detections now so we get correct
731 # status in VF output
732 $(call feature_check,libbfd-liberty)
733 $(call feature_check,libbfd-liberty-z)
735 ifeq ($(feature-libbfd-liberty), 1)
736 EXTLIBS += -lbfd -lopcodes -liberty
737 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
739 ifeq ($(feature-libbfd-liberty-z), 1)
740 EXTLIBS += -lbfd -lopcodes -liberty -lz
741 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
744 $(call feature_check,disassembler-four-args)
748 CFLAGS += -DNO_DEMANGLE
750 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
753 ifeq ($(filter -liberty,$(EXTLIBS)),)
754 $(call feature_check,cplus-demangle)
756 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
757 # or any of 'bfd iberty z' trinity
758 ifeq ($(feature-cplus-demangle), 1)
761 msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
762 CFLAGS += -DNO_DEMANGLE
767 ifneq ($(filter -liberty,$(EXTLIBS)),)
768 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
772 ifneq ($(filter -lbfd,$(EXTLIBS)),)
773 CFLAGS += -DHAVE_LIBBFD_SUPPORT
777 ifeq ($(feature-zlib), 1)
778 CFLAGS += -DHAVE_ZLIB_SUPPORT
780 $(call detected,CONFIG_ZLIB)
787 ifeq ($(feature-lzma), 1)
788 CFLAGS += -DHAVE_LZMA_SUPPORT
790 $(call detected,CONFIG_LZMA)
792 msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
798 ifeq ($(feature-libzstd), 1)
799 CFLAGS += -DHAVE_ZSTD_SUPPORT
800 CFLAGS += $(LIBZSTD_CFLAGS)
801 LDFLAGS += $(LIBZSTD_LDFLAGS)
803 $(call detected,CONFIG_ZSTD)
805 msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
811 ifeq ($(feature-backtrace), 1)
812 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
817 ifeq ($(feature-libnuma), 0)
818 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
821 ifeq ($(feature-numa_num_possible_cpus), 0)
822 msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
825 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
827 $(call detected,CONFIG_NUMA)
832 ifdef HAVE_KVM_STAT_SUPPORT
833 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
836 ifeq ($(feature-disassembler-four-args), 1)
837 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
840 ifeq (${IS_64_BIT}, 1)
841 ifndef NO_PERF_READ_VDSO32
842 $(call feature_check,compile-32)
843 ifeq ($(feature-compile-32), 1)
844 CFLAGS += -DHAVE_PERF_READ_VDSO32
846 NO_PERF_READ_VDSO32 := 1
849 ifneq ($(SRCARCH), x86)
850 NO_PERF_READ_VDSOX32 := 1
852 ifndef NO_PERF_READ_VDSOX32
853 $(call feature_check,compile-x32)
854 ifeq ($(feature-compile-x32), 1)
855 CFLAGS += -DHAVE_PERF_READ_VDSOX32
857 NO_PERF_READ_VDSOX32 := 1
861 NO_PERF_READ_VDSO32 := 1
862 NO_PERF_READ_VDSOX32 := 1
865 ifndef NO_LIBBABELTRACE
866 $(call feature_check,libbabeltrace)
867 ifeq ($(feature-libbabeltrace), 1)
868 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
869 LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
870 EXTLIBS += -lbabeltrace-ctf
871 $(call detected,CONFIG_LIBBABELTRACE)
873 msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
878 ifeq ($(SRCARCH),x86)
879 ifeq ($(feature-get_cpuid), 0)
880 msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
885 $(call detected,CONFIG_AUXTRACE)
886 CFLAGS += -DHAVE_AUXTRACE_SUPPORT
891 ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
892 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
894 ifneq (,$(wildcard /usr/sbin/alternatives))
895 JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' -f 5 | sed 's%/jre/bin/java.%%g')
899 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
905 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
906 $(call feature_check,jvmti)
907 ifeq ($(feature-jvmti), 1)
908 $(call detected_var,JDIR)
910 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
911 $(call feature_check,jvmti-cmlr)
912 ifeq ($(feature-jvmti-cmlr), 1)
913 CFLAGS += -DHAVE_JVMTI_CMLR
915 endif # NO_JVMTI_CMLR
917 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
925 $(call feature_check,cxx)
926 ifneq ($(feature-cxx), 1)
927 msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
929 $(call feature_check,llvm)
930 $(call feature_check,llvm-version)
931 ifneq ($(feature-llvm), 1)
932 msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
934 $(call feature_check,clang)
935 ifneq ($(feature-clang), 1)
936 msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
938 CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
939 CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
940 $(call detected,CONFIG_CXX)
941 $(call detected,CONFIG_CLANGLLVM)
945 ifneq ($(feature-llvm-version),1)
946 msg := $(warning This version of LLVM is not tested. May cause build errors)
953 # Among the variables below, these:
961 # ETC_PERFCONFIG (but not sysconfdir)
962 # can be specified as a relative path some/where/else;
963 # this is interpreted as relative to $(prefix) and "perf" at
964 # runtime figures out where they are based on the path to the executable.
965 # This can help installing the suite in a relocatable way.
967 # Make the path relative to DESTDIR, not to prefix
971 bindir_relative = bin
972 bindir = $(abspath $(prefix)/$(bindir_relative))
975 perfexecdir = libexec/perf-core
976 perf_include_dir = lib/perf/include
977 perf_examples_dir = lib/perf/examples
978 sharedir = $(prefix)/share
979 template_dir = share/perf-core/templates
980 STRACE_GROUPS_DIR = share/perf-core/strace/groups
981 htmldir = share/doc/perf-doc
982 tipdir = share/doc/perf-tip
983 srcdir = $(srctree)/tools/perf
984 ifeq ($(prefix),/usr)
986 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
988 sysconfdir = $(prefix)/etc
989 ETC_PERFCONFIG = etc/perfconfig
992 ifeq ($(SRCARCH)$(IS_64_BIT), x861)
998 libdir = $(prefix)/$(lib)
1000 # Shell quote (do not use $(call) to accommodate ancient setups);
1001 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1002 STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1003 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1004 bindir_SQ = $(subst ','\'',$(bindir))
1005 mandir_SQ = $(subst ','\'',$(mandir))
1006 infodir_SQ = $(subst ','\'',$(infodir))
1007 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1008 perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
1009 perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1010 template_dir_SQ = $(subst ','\'',$(template_dir))
1011 htmldir_SQ = $(subst ','\'',$(htmldir))
1012 tipdir_SQ = $(subst ','\'',$(tipdir))
1013 prefix_SQ = $(subst ','\'',$(prefix))
1014 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1015 libdir_SQ = $(subst ','\'',$(libdir))
1016 srcdir_SQ = $(subst ','\'',$(srcdir))
1018 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1019 perfexec_instdir = $(perfexecdir)
1020 perf_include_instdir = $(perf_include_dir)
1021 perf_examples_instdir = $(perf_examples_dir)
1022 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1023 tip_instdir = $(tipdir)
1025 perfexec_instdir = $(prefix)/$(perfexecdir)
1026 perf_include_instdir = $(prefix)/$(perf_include_dir)
1027 perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1028 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1029 tip_instdir = $(prefix)/$(tipdir)
1031 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1032 perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1033 perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1034 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1035 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1037 # If we install to $(HOME) we keep the traceevent default:
1038 # $(HOME)/.traceevent/plugins
1039 # Otherwise we install plugins into the global $(libdir).
1041 plugindir=$(libdir)/traceevent/plugins
1042 plugindir_SQ= $(subst ','\'',$(plugindir))
1045 print_var = $(eval $(print_var_code)) $(info $(MSG))
1046 define print_var_code
1047 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
1051 # Display EXTRA features which are detected manualy
1052 # from here with feature_check call and thus cannot
1053 # be partof global state output.
1054 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
1055 $(call print_var,prefix)
1056 $(call print_var,bindir)
1057 $(call print_var,libdir)
1058 $(call print_var,sysconfdir)
1059 $(call print_var,LIBUNWIND_DIR)
1060 $(call print_var,LIBDW_DIR)
1061 $(call print_var,JDIR)
1063 ifeq ($(dwarf-post-unwind),1)
1064 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
1069 $(call detected_var,bindir_SQ)
1070 $(call detected_var,PYTHON_WORD)
1072 $(call detected_var,OUTPUT)
1074 $(call detected_var,htmldir_SQ)
1075 $(call detected_var,infodir_SQ)
1076 $(call detected_var,mandir_SQ)
1077 $(call detected_var,ETC_PERFCONFIG_SQ)
1078 $(call detected_var,STRACE_GROUPS_DIR_SQ)
1079 $(call detected_var,prefix_SQ)
1080 $(call detected_var,perfexecdir_SQ)
1081 $(call detected_var,perf_include_dir_SQ)
1082 $(call detected_var,perf_examples_dir_SQ)
1083 $(call detected_var,tipdir_SQ)
1084 $(call detected_var,srcdir_SQ)
1085 $(call detected_var,LIBDIR)
1086 $(call detected_var,GTK_CFLAGS)
1087 $(call detected_var,PERL_EMBED_CCOPTS)
1088 $(call detected_var,PYTHON_EMBED_CCOPTS)