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
62 ifeq ($(SRCARCH),csky)
69 CFLAGS += -fPIC -I$(OUTPUT)arch/s390/include/generated
72 ifeq ($(NO_PERF_REGS),0)
73 $(call detected,CONFIG_PERF_REGS)
76 ifneq ($(NO_SYSCALL_TABLE),1)
77 CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
80 # So far there's only x86 and arm libdw unwind support merged in perf.
81 # Disable it on all other architectures in case libdw unwind
82 # support is detected in system. Add supported architectures
84 ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky))
85 NO_LIBDW_DWARF_UNWIND := 1
88 ifeq ($(LIBUNWIND_LIBS),)
92 # For linking with debug library, run like:
94 # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
97 libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
98 define libunwind_arch_set_flags_code
99 FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include
100 FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
104 LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include
105 LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
106 LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
107 $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
110 # Set per-feature check compilation flags
111 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
112 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
113 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
114 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
116 FEATURE_CHECK_LDFLAGS-libunwind-arm = -lunwind -lunwind-arm
117 FEATURE_CHECK_LDFLAGS-libunwind-aarch64 = -lunwind -lunwind-aarch64
118 FEATURE_CHECK_LDFLAGS-libunwind-x86 = -lunwind -llzma -lunwind-x86
119 FEATURE_CHECK_LDFLAGS-libunwind-x86_64 = -lunwind -llzma -lunwind-x86_64
121 FEATURE_CHECK_LDFLAGS-libcrypto = -lcrypto
124 LIBOPENCSD_CFLAGS := -I$(CSINCLUDES)
126 OPENCSDLIBS := -lopencsd_c_api -lopencsd
128 LIBOPENCSD_LDFLAGS := -L$(CSLIBS)
130 FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS)
131 FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS)
133 ifeq ($(NO_PERF_REGS),0)
134 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
137 # for linking with debug library, run like:
138 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
140 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
141 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
144 ifeq ($(findstring -static,${LDFLAGS}),-static)
145 DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
147 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
148 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
150 # for linking with debug library, run like:
151 # make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
152 ifdef LIBBABELTRACE_DIR
153 LIBBABELTRACE_CFLAGS := -I$(LIBBABELTRACE_DIR)/include
154 LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
156 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
157 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
160 LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib
161 LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
163 FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
164 FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
166 FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
167 # include ARCH specific config
168 -include $(src-perf)/arch/$(SRCARCH)/Makefile
170 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
171 CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
174 include $(srctree)/tools/scripts/utilities.mak
176 ifeq ($(call get-executable,$(FLEX)),)
177 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
180 ifeq ($(call get-executable,$(BISON)),)
181 dummy := $(error Error: $(BISON) is missing on this system, please install it)
184 # Treat warnings as errors unless directed not to
195 ifeq ($(CC_NO_CLANG), 0)
203 PARSER_DEBUG_BISON := -t
204 PARSER_DEBUG_FLEX := -d
205 CFLAGS += -DPARSER_DEBUG
206 $(call detected_var,PARSER_DEBUG_BISON)
207 $(call detected_var,PARSER_DEBUG_FLEX)
210 # Try different combinations to accommodate systems that only have
211 # python[2][-config] in weird combinations but always preferring
212 # python2 and python2-config as per pep-0394. If we catch a
213 # python[-config] in version 3, the version check will kill it.
214 PYTHON2 := $(if $(call get-executable,python2),python2,python)
215 override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2))
217 $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config)
218 override PYTHON_CONFIG := \
219 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
221 grep-libs = $(filter -l%,$(1))
222 strip-libs = $(filter-out -l%,$(1))
224 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
227 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
228 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
229 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
230 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
231 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
234 FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
235 FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
236 FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
237 FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
239 FEATURE_CHECK_LDFLAGS-libaio = -lrt
241 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
243 CFLAGS += -fno-omit-frame-pointer
245 CFLAGS += -funwind-tables
250 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
252 CXXFLAGS += -fno-omit-frame-pointer
254 CXXFLAGS += -funwind-tables
255 CXXFLAGS += -Wno-strict-aliasing
257 # Enforce a non-executable stack, as we may regress (again) in the future by
258 # adding assembler files missing the .GNU-stack linker note.
259 LDFLAGS += -Wl,-z,noexecstack
261 EXTLIBS = -lpthread -lrt -lm -ldl
263 ifeq ($(FEATURES_DUMP),)
264 include $(srctree)/tools/build/Makefile.feature
266 include $(FEATURES_DUMP)
269 ifeq ($(feature-stackprotector-all), 1)
270 CFLAGS += -fstack-protector-all
274 ifeq ($(feature-fortify-source), 1)
275 CFLAGS += -D_FORTIFY_SOURCE=2
279 INC_FLAGS += -I$(src-perf)/util/include
280 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
281 INC_FLAGS += -I$(srctree)/tools/include/uapi
282 INC_FLAGS += -I$(srctree)/tools/include/
283 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
284 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
285 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
287 # $(obj-perf) for generated common-cmds.h
288 # $(obj-perf)/util for generated bison/flex headers
290 INC_FLAGS += -I$(obj-perf)/util
291 INC_FLAGS += -I$(obj-perf)
294 INC_FLAGS += -I$(src-perf)/util
295 INC_FLAGS += -I$(src-perf)
296 INC_FLAGS += -I$(srctree)/tools/lib/
298 CFLAGS += $(INC_FLAGS)
299 CXXFLAGS += $(INC_FLAGS)
301 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
303 ifeq ($(feature-sync-compare-and-swap), 1)
304 CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
307 ifeq ($(feature-pthread-attr-setaffinity-np), 1)
308 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
311 ifeq ($(feature-pthread-barrier), 1)
312 CFLAGS += -DHAVE_PTHREAD_BARRIER
316 $(call feature_check,bionic)
317 ifeq ($(feature-bionic), 1)
319 CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
320 CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
321 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
322 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
326 ifeq ($(feature-eventfd), 1)
327 CFLAGS += -DHAVE_EVENTFD
330 ifeq ($(feature-get_current_dir_name), 1)
331 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
338 NO_LIBDW_DWARF_UNWIND := 1
342 ifeq ($(feature-libelf), 0)
343 ifeq ($(feature-glibc), 1)
349 ifeq ($(LIBC_SUPPORT),1)
350 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);
356 NO_LIBDW_DWARF_UNWIND := 1
360 ifneq ($(filter s% -static%,$(LDFLAGS),),)
361 msg := $(error No static glibc found, please install glibc-static);
363 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
367 ifndef NO_LIBDW_DWARF_UNWIND
368 ifneq ($(feature-libdw-dwarf-unwind),1)
369 NO_LIBDW_DWARF_UNWIND := 1
370 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
373 ifneq ($(feature-dwarf), 1)
375 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);
379 ifneq ($(feature-dwarf_getlocations), 1)
380 msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
382 CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
383 endif # dwarf_getlocations
384 endif # Dwarf support
385 endif # libelf support
388 ifeq ($(feature-glibc), 1)
389 CFLAGS += -DHAVE_GLIBC_SUPPORT
392 ifeq ($(feature-libaio), 1)
394 CFLAGS += -DHAVE_AIO_SUPPORT
399 NO_LIBDW_DWARF_UNWIND := 1
402 ifeq ($(feature-sched_getcpu), 1)
403 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
406 ifeq ($(feature-setns), 1)
407 CFLAGS += -DHAVE_SETNS_SUPPORT
408 $(call detected,CONFIG_SETNS)
412 $(call feature_check,libopencsd)
413 ifeq ($(feature-libopencsd), 1)
414 CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
415 LDFLAGS += $(LIBOPENCSD_LDFLAGS)
416 EXTLIBS += $(OPENCSDLIBS)
417 $(call detected,CONFIG_LIBOPENCSD)
419 CFLAGS += -DCS_DEBUG_RAW
420 ifeq (${CSTRACE_RAW}, packed)
421 CFLAGS += -DCS_RAW_PACKED
428 CFLAGS += -DHAVE_LIBELF_SUPPORT
430 $(call detected,CONFIG_LIBELF)
432 ifeq ($(feature-libelf-mmap), 1)
433 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
436 ifeq ($(feature-libelf-getphdrnum), 1)
437 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
440 ifeq ($(feature-libelf-gelf_getnote), 1)
441 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
443 msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
446 ifeq ($(feature-libelf-getshdrstrndx), 1)
447 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
451 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
452 msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);
455 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
456 LDFLAGS += $(LIBDW_LDFLAGS)
457 EXTLIBS += ${DWARFLIBS}
458 $(call detected,CONFIG_DWARF)
459 endif # PERF_HAVE_DWARF_REGS
463 ifeq ($(feature-bpf), 1)
464 CFLAGS += -DHAVE_LIBBPF_SUPPORT
465 $(call detected,CONFIG_LIBBPF)
469 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
470 CFLAGS += -DHAVE_BPF_PROLOGUE
471 $(call detected,CONFIG_BPF_PROLOGUE)
473 msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
476 msg := $(warning DWARF support is off, BPF prologue is disabled);
483 ifneq ($(feature-sdt), 1)
484 msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
487 CFLAGS += -DHAVE_SDT_EVENT
488 $(call detected,CONFIG_SDT_EVENT)
492 ifdef PERF_HAVE_JITDUMP
494 $(call detected,CONFIG_JITDUMP)
495 CFLAGS += -DHAVE_JITDUMP
499 ifeq ($(SRCARCH),powerpc)
501 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
508 $(call feature_check,libunwind-x86)
509 ifeq ($(feature-libunwind-x86), 1)
510 $(call detected,CONFIG_LIBUNWIND_X86)
511 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
512 LDFLAGS += -lunwind-x86
513 EXTLIBS_LIBUNWIND += -lunwind-x86
517 $(call feature_check,libunwind-aarch64)
518 ifeq ($(feature-libunwind-aarch64), 1)
519 $(call detected,CONFIG_LIBUNWIND_AARCH64)
520 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
521 LDFLAGS += -lunwind-aarch64
522 EXTLIBS_LIBUNWIND += -lunwind-aarch64
524 $(call feature_check,libunwind-debug-frame-aarch64)
525 ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
526 msg := $(warning No debug_frame support found in libunwind-aarch64);
527 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
531 ifneq ($(feature-libunwind), 1)
532 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
533 NO_LOCAL_LIBUNWIND := 1
536 $(call detected,CONFIG_LOCAL_LIBUNWIND)
539 ifneq ($(have_libunwind), 1)
543 NO_LOCAL_LIBUNWIND := 1
547 ifneq ($(feature-bpf), 1)
548 msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
553 dwarf-post-unwind := 1
554 dwarf-post-unwind-text := BUG
556 # setup DWARF post unwinder
558 ifdef NO_LIBDW_DWARF_UNWIND
559 msg := $(warning Disabling post unwind, no support found.);
560 dwarf-post-unwind := 0
562 dwarf-post-unwind-text := libdw
563 $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
566 dwarf-post-unwind-text := libunwind
567 $(call detected,CONFIG_LIBUNWIND)
568 # Enable libunwind support by default.
569 ifndef NO_LIBDW_DWARF_UNWIND
570 NO_LIBDW_DWARF_UNWIND := 1
574 ifeq ($(dwarf-post-unwind),1)
575 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
576 $(call detected,CONFIG_DWARF_UNWIND)
581 ifndef NO_LOCAL_LIBUNWIND
582 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
583 $(call feature_check,libunwind-debug-frame)
584 ifneq ($(feature-libunwind-debug-frame), 1)
585 msg := $(warning No debug_frame support found in libunwind);
586 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
589 # non-ARM has no dwarf_find_debug_frame() function:
590 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
592 EXTLIBS += $(LIBUNWIND_LIBS)
593 LDFLAGS += $(LIBUNWIND_LIBS)
595 ifeq ($(findstring -static,${LDFLAGS}),-static)
596 # gcc -static links libgcc_eh which contans piece of libunwind
597 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
601 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
602 CFLAGS += $(LIBUNWIND_CFLAGS)
603 LDFLAGS += $(LIBUNWIND_LDFLAGS)
604 EXTLIBS += $(EXTLIBS_LIBUNWIND)
607 ifeq ($(NO_SYSCALL_TABLE),0)
608 $(call detected,CONFIG_TRACE)
611 ifneq ($(feature-libaudit), 1)
612 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
615 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
617 $(call detected,CONFIG_TRACE)
623 ifneq ($(feature-libcrypto), 1)
624 msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev);
627 CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
629 $(call detected,CONFIG_CRYPTO)
638 ifneq ($(feature-libslang), 1)
639 msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
642 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
643 CFLAGS += -I/usr/include/slang
644 CFLAGS += -DHAVE_SLANG_SUPPORT
646 $(call detected,CONFIG_SLANG)
651 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
652 ifneq ($(feature-gtk2), 1)
653 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
656 ifeq ($(feature-gtk2-infobar), 1)
657 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
659 CFLAGS += -DHAVE_GTK2_SUPPORT
660 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
661 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
667 CFLAGS += -DNO_LIBPERL
669 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
670 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
671 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
672 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
673 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
674 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
675 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
677 ifneq ($(feature-libperl), 1)
678 CFLAGS += -DNO_LIBPERL
680 msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
682 LDFLAGS += $(PERL_EMBED_LDFLAGS)
683 EXTLIBS += $(PERL_EMBED_LIBADD)
684 CFLAGS += -DHAVE_LIBPERL_SUPPORT
685 $(call detected,CONFIG_LIBPERL)
689 ifeq ($(feature-timerfd), 1)
690 CFLAGS += -DHAVE_TIMERFD_SUPPORT
692 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
695 disable-python = $(eval $(disable-python_code))
696 define disable-python_code
697 CFLAGS += -DNO_LIBPYTHON
703 $(call disable-python,Python support disabled by user)
707 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
709 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
712 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
715 ifneq ($(feature-libpython), 1)
716 $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
718 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
719 EXTLIBS += $(PYTHON_EMBED_LIBADD)
720 LANG_BINDINGS += $(obj-perf)python/perf.so
721 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
722 $(call detected,CONFIG_LIBPYTHON)
728 ifeq ($(feature-libbfd), 1)
729 EXTLIBS += -lbfd -lopcodes
731 # we are on a system that requires -liberty and (maybe) -lz
732 # to link against -lbfd; test each case individually here
734 # call all detections now so we get correct
735 # status in VF output
736 $(call feature_check,libbfd-liberty)
737 $(call feature_check,libbfd-liberty-z)
739 ifeq ($(feature-libbfd-liberty), 1)
740 EXTLIBS += -lbfd -lopcodes -liberty
741 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
743 ifeq ($(feature-libbfd-liberty-z), 1)
744 EXTLIBS += -lbfd -lopcodes -liberty -lz
745 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
748 $(call feature_check,disassembler-four-args)
752 CFLAGS += -DNO_DEMANGLE
754 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
757 ifeq ($(filter -liberty,$(EXTLIBS)),)
758 $(call feature_check,cplus-demangle)
760 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
761 # or any of 'bfd iberty z' trinity
762 ifeq ($(feature-cplus-demangle), 1)
765 msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
766 CFLAGS += -DNO_DEMANGLE
771 ifneq ($(filter -liberty,$(EXTLIBS)),)
772 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
776 ifneq ($(filter -lbfd,$(EXTLIBS)),)
777 CFLAGS += -DHAVE_LIBBFD_SUPPORT
781 ifeq ($(feature-zlib), 1)
782 CFLAGS += -DHAVE_ZLIB_SUPPORT
784 $(call detected,CONFIG_ZLIB)
791 ifeq ($(feature-lzma), 1)
792 CFLAGS += -DHAVE_LZMA_SUPPORT
794 $(call detected,CONFIG_LZMA)
796 msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
802 ifeq ($(feature-libzstd), 1)
803 CFLAGS += -DHAVE_ZSTD_SUPPORT
804 CFLAGS += $(LIBZSTD_CFLAGS)
805 LDFLAGS += $(LIBZSTD_LDFLAGS)
807 $(call detected,CONFIG_ZSTD)
809 msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
815 ifeq ($(feature-backtrace), 1)
816 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
821 ifeq ($(feature-libnuma), 0)
822 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
825 ifeq ($(feature-numa_num_possible_cpus), 0)
826 msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
829 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
831 $(call detected,CONFIG_NUMA)
836 ifdef HAVE_KVM_STAT_SUPPORT
837 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
840 ifeq ($(feature-disassembler-four-args), 1)
841 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
844 ifeq (${IS_64_BIT}, 1)
845 ifndef NO_PERF_READ_VDSO32
846 $(call feature_check,compile-32)
847 ifeq ($(feature-compile-32), 1)
848 CFLAGS += -DHAVE_PERF_READ_VDSO32
850 NO_PERF_READ_VDSO32 := 1
853 ifneq ($(SRCARCH), x86)
854 NO_PERF_READ_VDSOX32 := 1
856 ifndef NO_PERF_READ_VDSOX32
857 $(call feature_check,compile-x32)
858 ifeq ($(feature-compile-x32), 1)
859 CFLAGS += -DHAVE_PERF_READ_VDSOX32
861 NO_PERF_READ_VDSOX32 := 1
865 NO_PERF_READ_VDSO32 := 1
866 NO_PERF_READ_VDSOX32 := 1
869 ifndef NO_LIBBABELTRACE
870 $(call feature_check,libbabeltrace)
871 ifeq ($(feature-libbabeltrace), 1)
872 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
873 LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
874 EXTLIBS += -lbabeltrace-ctf
875 $(call detected,CONFIG_LIBBABELTRACE)
877 msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
882 ifeq ($(SRCARCH),x86)
883 ifeq ($(feature-get_cpuid), 0)
884 msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
889 $(call detected,CONFIG_AUXTRACE)
890 CFLAGS += -DHAVE_AUXTRACE_SUPPORT
895 ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
896 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
898 ifneq (,$(wildcard /usr/sbin/alternatives))
899 JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' -f 5 | sed 's%/jre/bin/java.%%g')
903 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
909 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
910 $(call feature_check,jvmti)
911 ifeq ($(feature-jvmti), 1)
912 $(call detected_var,JDIR)
914 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
915 $(call feature_check,jvmti-cmlr)
916 ifeq ($(feature-jvmti-cmlr), 1)
917 CFLAGS += -DHAVE_JVMTI_CMLR
919 endif # NO_JVMTI_CMLR
921 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
929 $(call feature_check,cxx)
930 ifneq ($(feature-cxx), 1)
931 msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
933 $(call feature_check,llvm)
934 $(call feature_check,llvm-version)
935 ifneq ($(feature-llvm), 1)
936 msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
938 $(call feature_check,clang)
939 ifneq ($(feature-clang), 1)
940 msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
942 CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
943 CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
944 $(call detected,CONFIG_CXX)
945 $(call detected,CONFIG_CLANGLLVM)
949 ifneq ($(feature-llvm-version),1)
950 msg := $(warning This version of LLVM is not tested. May cause build errors)
957 # Among the variables below, these:
965 # ETC_PERFCONFIG (but not sysconfdir)
966 # can be specified as a relative path some/where/else;
967 # this is interpreted as relative to $(prefix) and "perf" at
968 # runtime figures out where they are based on the path to the executable.
969 # This can help installing the suite in a relocatable way.
971 # Make the path relative to DESTDIR, not to prefix
975 bindir_relative = bin
976 bindir = $(abspath $(prefix)/$(bindir_relative))
979 perfexecdir = libexec/perf-core
980 perf_include_dir = lib/perf/include
981 perf_examples_dir = lib/perf/examples
982 sharedir = $(prefix)/share
983 template_dir = share/perf-core/templates
984 STRACE_GROUPS_DIR = share/perf-core/strace/groups
985 htmldir = share/doc/perf-doc
986 tipdir = share/doc/perf-tip
987 srcdir = $(srctree)/tools/perf
988 ifeq ($(prefix),/usr)
990 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
992 sysconfdir = $(prefix)/etc
993 ETC_PERFCONFIG = etc/perfconfig
996 ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1002 libdir = $(prefix)/$(lib)
1004 # Shell quote (do not use $(call) to accommodate ancient setups);
1005 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1006 STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1007 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1008 bindir_SQ = $(subst ','\'',$(bindir))
1009 mandir_SQ = $(subst ','\'',$(mandir))
1010 infodir_SQ = $(subst ','\'',$(infodir))
1011 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1012 perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
1013 perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1014 template_dir_SQ = $(subst ','\'',$(template_dir))
1015 htmldir_SQ = $(subst ','\'',$(htmldir))
1016 tipdir_SQ = $(subst ','\'',$(tipdir))
1017 prefix_SQ = $(subst ','\'',$(prefix))
1018 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1019 libdir_SQ = $(subst ','\'',$(libdir))
1020 srcdir_SQ = $(subst ','\'',$(srcdir))
1022 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1023 perfexec_instdir = $(perfexecdir)
1024 perf_include_instdir = $(perf_include_dir)
1025 perf_examples_instdir = $(perf_examples_dir)
1026 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1027 tip_instdir = $(tipdir)
1029 perfexec_instdir = $(prefix)/$(perfexecdir)
1030 perf_include_instdir = $(prefix)/$(perf_include_dir)
1031 perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1032 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1033 tip_instdir = $(prefix)/$(tipdir)
1035 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1036 perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1037 perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1038 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1039 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1041 # If we install to $(HOME) we keep the traceevent default:
1042 # $(HOME)/.traceevent/plugins
1043 # Otherwise we install plugins into the global $(libdir).
1045 plugindir=$(libdir)/traceevent/plugins
1046 plugindir_SQ= $(subst ','\'',$(plugindir))
1049 print_var = $(eval $(print_var_code)) $(info $(MSG))
1050 define print_var_code
1051 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
1055 # Display EXTRA features which are detected manualy
1056 # from here with feature_check call and thus cannot
1057 # be partof global state output.
1058 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
1059 $(call print_var,prefix)
1060 $(call print_var,bindir)
1061 $(call print_var,libdir)
1062 $(call print_var,sysconfdir)
1063 $(call print_var,LIBUNWIND_DIR)
1064 $(call print_var,LIBDW_DIR)
1065 $(call print_var,JDIR)
1067 ifeq ($(dwarf-post-unwind),1)
1068 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
1073 $(call detected_var,bindir_SQ)
1074 $(call detected_var,PYTHON_WORD)
1076 $(call detected_var,OUTPUT)
1078 $(call detected_var,htmldir_SQ)
1079 $(call detected_var,infodir_SQ)
1080 $(call detected_var,mandir_SQ)
1081 $(call detected_var,ETC_PERFCONFIG_SQ)
1082 $(call detected_var,STRACE_GROUPS_DIR_SQ)
1083 $(call detected_var,prefix_SQ)
1084 $(call detected_var,perfexecdir_SQ)
1085 $(call detected_var,perf_include_dir_SQ)
1086 $(call detected_var,perf_examples_dir_SQ)
1087 $(call detected_var,tipdir_SQ)
1088 $(call detected_var,srcdir_SQ)
1089 $(call detected_var,LIBDIR)
1090 $(call detected_var,GTK_CFLAGS)
1091 $(call detected_var,PERL_EMBED_CCOPTS)
1092 $(call detected_var,PYTHON_EMBED_CCOPTS)