3 src-perf := $(srctree)/tools/perf
11 obj-perf := $(abspath $(obj-perf))/
14 LIB_INCLUDE := $(srctree)/tools/lib/
15 CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
17 include $(src-perf)/config/Makefile.arch
21 # Additional ARCH settings for x86
23 ifeq (${IS_X86_64}, 1)
24 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
25 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
26 LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
28 LIBUNWIND_LIBS = -lunwind -lunwind-x86
35 LIBUNWIND_LIBS = -lunwind -lunwind-arm
40 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
43 # So far there's only x86 and arm libdw unwind support merged in perf.
44 # Disable it on all other architectures in case libdw unwind
45 # support is detected in system. Add supported architectures
47 ifneq ($(ARCH),$(filter $(ARCH),x86 arm))
48 NO_LIBDW_DWARF_UNWIND := 1
51 ifeq ($(ARCH),powerpc)
52 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
55 ifeq ($(LIBUNWIND_LIBS),)
59 # For linking with debug library, run like:
61 # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
64 LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include
65 LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
67 LIBUNWIND_LDFLAGS += $(LIBUNWIND_LIBS)
69 # Set per-feature check compilation flags
70 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
71 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS)
72 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
73 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS)
76 ifeq ($(NO_PERF_REGS),0)
77 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
81 # for linking with debug library, run like:
82 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
84 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
85 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
87 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
88 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) -ldw
91 # include ARCH specific config
92 -include $(src-perf)/arch/$(ARCH)/Makefile
94 include $(src-perf)/config/utilities.mak
96 ifeq ($(call get-executable,$(FLEX)),)
97 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
100 ifeq ($(call get-executable,$(BISON)),)
101 dummy := $(error Error: $(BISON) is missing on this system, please install it)
104 # Treat warnings as errors unless directed not to
118 PARSER_DEBUG_BISON := -t
119 PARSER_DEBUG_FLEX := -d
120 CFLAGS += -DPARSER_DEBUG
123 CFLAGS += -fno-omit-frame-pointer
125 CFLAGS += -funwind-tables
130 # Enforce a non-executable stack, as we may regress (again) in the future by
131 # adding assembler files missing the .GNU-stack linker note.
132 LDFLAGS += -Wl,-z,noexecstack
134 EXTLIBS = -lelf -lpthread -lrt -lm -ldl
137 OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
138 $(shell mkdir -p $(OUTPUT_FEATURES))
141 feature_check = $(eval $(feature_check_code))
142 define feature_check_code
143 feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C config/feature-checks test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
146 feature_set = $(eval $(feature_set_code))
147 define feature_set_code
152 # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
156 # Note that this is not a complete list of all feature tests, just
157 # those that are typically built on a fully configured system.
159 # [ Feature tests not mentioned here have to be built explicitly in
160 # the rule that uses them - an example for that is the 'bionic'
163 CORE_FEATURE_TESTS = \
167 sync-compare-and-swap \
186 LIB_FEATURE_TESTS = \
203 sync-compare-and-swap \
210 libunwind-debug-frame \
216 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features.
217 # If in the future we need per-feature checks/flags for features not
218 # mentioned in this list we need to refactor this ;-).
219 set_test_all_flags = $(eval $(set_test_all_flags_code))
220 define set_test_all_flags_code
221 FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1))
222 FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
225 $(foreach feat,$(CORE_FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
228 # Special fast-path for the 'all features are available' case:
230 $(call feature_check,all,$(MSG))
233 # Just in case the build freshly failed, make sure we print the
236 ifeq ($(feature-all), 1)
238 # test-all.c passed - just set all the core feature flags to 1:
240 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
242 $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(addsuffix .bin,$(CORE_FEATURE_TESTS)) >/dev/null 2>&1)
243 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
246 ifeq ($(feature-stackprotector-all), 1)
247 CFLAGS += -fstack-protector-all
251 ifeq ($(feature-fortify-source), 1)
252 CFLAGS += -D_FORTIFY_SOURCE=2
256 CFLAGS += -I$(src-perf)/util/include
257 CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
258 CFLAGS += -I$(srctree)/tools/include/
259 CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
260 CFLAGS += -I$(srctree)/arch/$(ARCH)/include
261 CFLAGS += -I$(srctree)/include/uapi
262 CFLAGS += -I$(srctree)/include
264 # $(obj-perf) for generated common-cmds.h
265 # $(obj-perf)/util for generated bison/flex headers
267 CFLAGS += -I$(obj-perf)/util
268 CFLAGS += -I$(obj-perf)
271 CFLAGS += -I$(src-perf)/util
272 CFLAGS += -I$(src-perf)
273 CFLAGS += -I$(LIB_INCLUDE)
275 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
277 ifeq ($(feature-sync-compare-and-swap), 1)
278 CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
282 $(call feature_check,bionic)
283 ifeq ($(feature-bionic), 1)
285 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
286 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
294 NO_LIBDW_DWARF_UNWIND := 1
296 ifeq ($(feature-libelf), 0)
297 ifeq ($(feature-glibc), 1)
303 ifeq ($(LIBC_SUPPORT),1)
304 msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
310 NO_LIBDW_DWARF_UNWIND := 1
312 ifneq ($(filter s% -static%,$(LDFLAGS),),)
313 msg := $(error No static glibc found, please install glibc-static);
315 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
319 ifndef NO_LIBDW_DWARF_UNWIND
320 ifneq ($(feature-libdw-dwarf-unwind),1)
321 NO_LIBDW_DWARF_UNWIND := 1
322 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
325 ifneq ($(feature-dwarf), 1)
326 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);
328 endif # Dwarf support
329 endif # libelf support
333 CFLAGS += -DHAVE_LIBELF_SUPPORT
335 ifeq ($(feature-libelf-mmap), 1)
336 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
339 ifeq ($(feature-libelf-getphdrnum), 1)
340 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
343 # include ARCH specific config
344 -include $(src-perf)/arch/$(ARCH)/Makefile
347 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
348 msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
351 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
352 LDFLAGS += $(LIBDW_LDFLAGS)
353 EXTLIBS += -lelf -ldw
354 endif # PERF_HAVE_DWARF_REGS
359 ifneq ($(feature-libunwind), 1)
360 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
365 dwarf-post-unwind := 1
366 dwarf-post-unwind-text := BUG
368 # setup DWARF post unwinder
370 ifdef NO_LIBDW_DWARF_UNWIND
371 msg := $(warning Disabling post unwind, no support found.);
372 dwarf-post-unwind := 0
374 dwarf-post-unwind-text := libdw
377 dwarf-post-unwind-text := libunwind
378 # Enable libunwind support by default.
379 ifndef NO_LIBDW_DWARF_UNWIND
380 NO_LIBDW_DWARF_UNWIND := 1
384 ifeq ($(dwarf-post-unwind),1)
385 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
391 ifeq ($(ARCH),$(filter $(ARCH),arm arm64))
392 $(call feature_check,libunwind-debug-frame)
393 ifneq ($(feature-libunwind-debug-frame), 1)
394 msg := $(warning No debug_frame support found in libunwind);
395 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
398 # non-ARM has no dwarf_find_debug_frame() function:
399 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
401 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
402 EXTLIBS += $(LIBUNWIND_LIBS)
403 CFLAGS += $(LIBUNWIND_CFLAGS)
404 LDFLAGS += $(LIBUNWIND_LDFLAGS)
408 ifneq ($(feature-libaudit), 1)
409 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
412 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
422 ifneq ($(feature-libslang), 1)
423 msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
426 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
427 CFLAGS += -I/usr/include/slang
428 CFLAGS += -DHAVE_SLANG_SUPPORT
434 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
435 ifneq ($(feature-gtk2), 1)
436 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
439 ifeq ($(feature-gtk2-infobar), 1)
440 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
442 CFLAGS += -DHAVE_GTK2_SUPPORT
443 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
444 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
449 grep-libs = $(filter -l%,$(1))
450 strip-libs = $(filter-out -l%,$(1))
453 CFLAGS += -DNO_LIBPERL
455 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
456 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
457 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
458 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
459 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
461 ifneq ($(feature-libperl), 1)
462 CFLAGS += -DNO_LIBPERL
464 msg := $(warning Missing perl devel files. Disabling perl scripting support, consider installing perl-ExtUtils-Embed);
466 LDFLAGS += $(PERL_EMBED_LDFLAGS)
467 EXTLIBS += $(PERL_EMBED_LIBADD)
471 ifeq ($(feature-timerfd), 1)
472 CFLAGS += -DHAVE_TIMERFD_SUPPORT
474 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
477 disable-python = $(eval $(disable-python_code))
478 define disable-python_code
479 CFLAGS += -DNO_LIBPYTHON
480 $(if $(1),$(warning No $(1) was found))
481 $(warning Python support will not be built)
486 $(call get-executable-or-default,PYTHON,python)
489 $(call disable-python,python interpreter)
492 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
495 $(call disable-python)
498 override PYTHON_CONFIG := \
499 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
502 $(call disable-python,python-config tool)
505 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
507 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
508 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
509 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
510 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
511 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
513 ifneq ($(feature-libpython), 1)
514 $(call disable-python,Python.h (for Python 2.x))
517 ifneq ($(feature-libpython-version), 1)
518 $(warning Python 3 is not yet supported; please set)
519 $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
520 $(warning If you also have Python 2 installed, then)
521 $(warning try something like:)
523 $(warning $(and ,) make PYTHON=python2)
525 $(warning Otherwise, disable Python support entirely:)
527 $(warning $(and ,) make NO_LIBPYTHON=1)
531 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
532 EXTLIBS += $(PYTHON_EMBED_LIBADD)
533 LANG_BINDINGS += $(obj-perf)python/perf.so
540 ifeq ($(feature-libbfd), 1)
543 # call all detections now so we get correct
544 # status in VF output
545 $(call feature_check,liberty)
546 $(call feature_check,liberty-z)
547 $(call feature_check,cplus-demangle)
549 ifeq ($(feature-liberty), 1)
552 ifeq ($(feature-liberty-z), 1)
553 EXTLIBS += -liberty -lz
559 CFLAGS += -DNO_DEMANGLE
561 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
563 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
565 ifneq ($(feature-libbfd), 1)
566 ifneq ($(feature-liberty), 1)
567 ifneq ($(feature-liberty-z), 1)
568 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
569 # or any of 'bfd iberty z' trinity
570 ifeq ($(feature-cplus-demangle), 1)
572 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
574 msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
575 CFLAGS += -DNO_DEMANGLE
583 ifneq ($(filter -lbfd,$(EXTLIBS)),)
584 CFLAGS += -DHAVE_LIBBFD_SUPPORT
588 ifeq ($(feature-backtrace), 1)
589 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
594 ifeq ($(feature-libnuma), 0)
595 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
598 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
603 ifdef HAVE_KVM_STAT_SUPPORT
604 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
607 # Among the variables below, these:
613 # ETC_PERFCONFIG (but not sysconfdir)
614 # can be specified as a relative path some/where/else;
615 # this is interpreted as relative to $(prefix) and "perf" at
616 # runtime figures out where they are based on the path to the executable.
617 # This can help installing the suite in a relocatable way.
619 # Make the path relative to DESTDIR, not to prefix
623 bindir_relative = bin
624 bindir = $(prefix)/$(bindir_relative)
627 perfexecdir = libexec/perf-core
628 sharedir = $(prefix)/share
629 template_dir = share/perf-core/templates
630 htmldir = share/doc/perf-doc
631 ifeq ($(prefix),/usr)
633 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
635 sysconfdir = $(prefix)/etc
636 ETC_PERFCONFIG = etc/perfconfig
638 ifeq ($(IS_X86_64),1)
643 libdir = $(prefix)/$(lib)
645 # Shell quote (do not use $(call) to accommodate ancient setups);
646 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
647 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
648 bindir_SQ = $(subst ','\'',$(bindir))
649 mandir_SQ = $(subst ','\'',$(mandir))
650 infodir_SQ = $(subst ','\'',$(infodir))
651 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
652 template_dir_SQ = $(subst ','\'',$(template_dir))
653 htmldir_SQ = $(subst ','\'',$(htmldir))
654 prefix_SQ = $(subst ','\'',$(prefix))
655 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
656 libdir_SQ = $(subst ','\'',$(libdir))
658 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
659 perfexec_instdir = $(perfexecdir)
661 perfexec_instdir = $(prefix)/$(perfexecdir)
663 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
665 # If we install to $(HOME) we keep the traceevent default:
666 # $(HOME)/.traceevent/plugins
667 # Otherwise we install plugins into the global $(libdir).
669 plugindir=$(libdir)/traceevent/plugins
670 plugindir_SQ= $(subst ','\'',$(plugindir))
674 # Print the result of the feature test:
676 feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
678 define feature_print_status_code
679 ifeq ($(feature-$(1)), 1)
680 MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
682 MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
686 feature_print_var = $(eval $(feature_print_var_code)) $(info $(MSG))
687 define feature_print_var_code
688 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
691 feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
692 define feature_print_text_code
693 MSG = $(shell printf '...%30s: %s' $(1) $(2))
696 PERF_FEATURES := $(foreach feat,$(LIB_FEATURE_TESTS),feature-$(feat)($(feature-$(feat))))
697 PERF_FEATURES_FILE := $(shell touch $(OUTPUT)PERF-FEATURES; cat $(OUTPUT)PERF-FEATURES)
699 ifeq ($(dwarf-post-unwind),1)
700 PERF_FEATURES += dwarf-post-unwind($(dwarf-post-unwind-text))
703 # The $(display_lib) controls the default detection message
704 # output. It's set if:
705 # - detected features differes from stored features from
706 # last build (in PERF-FEATURES file)
707 # - one of the $(LIB_FEATURE_TESTS) is not detected
710 ifneq ("$(PERF_FEATURES)","$(PERF_FEATURES_FILE)")
711 $(shell echo "$(PERF_FEATURES)" > $(OUTPUT)PERF-FEATURES)
715 feature_check = $(eval $(feature_check_code))
716 define feature_check_code
717 ifneq ($(feature-$(1)), 1)
722 $(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_check,$(feat)))
729 ifeq ($(display_lib),1)
731 $(info Auto-detecting system features:)
732 $(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_print_status,$(feat),))
734 ifeq ($(dwarf-post-unwind),1)
735 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
739 ifeq ($(display_vf),1)
740 $(foreach feat,$(VF_FEATURE_TESTS),$(call feature_print_status,$(feat),))
742 $(call feature_print_var,prefix)
743 $(call feature_print_var,bindir)
744 $(call feature_print_var,libdir)
745 $(call feature_print_var,sysconfdir)
746 $(call feature_print_var,LIBUNWIND_DIR)
747 $(call feature_print_var,LIBDW_DIR)
750 ifeq ($(display_lib),1)