1 uname_M := $(shell uname -m 2>/dev/null || echo not)
3 ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
4 -e s/arm.*/arm/ -e s/sa110/arm/ \
5 -e s/s390x/s390/ -e s/parisc64/parisc/ \
6 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
7 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
9 CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
11 # Additional ARCH settings for x86
15 LIBUNWIND_LIBS = -lunwind -lunwind-x86
21 ifeq (, $(findstring m32,$(CFLAGS)))
22 IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1)
24 ifeq (${IS_X86_64}, 1)
26 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
27 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
30 LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
34 LIBUNWIND_LIBS = -lunwind -lunwind-arm
37 ifeq ($(NO_PERF_REGS),0)
38 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
42 src-perf := $(srctree)/tools/perf
50 obj-perf := $(abspath $(obj-perf))/
53 LIB_INCLUDE := $(srctree)/tools/lib/
55 # include ARCH specific config
56 -include $(src-perf)/arch/$(ARCH)/Makefile
58 include $(src-perf)/config/utilities.mak
60 ifeq ($(call get-executable,$(FLEX)),)
61 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
64 ifeq ($(call get-executable,$(BISON)),)
65 dummy := $(error Error: $(BISON) is missing on this system, please install it)
68 # Treat warnings as errors unless directed not to
78 PARSER_DEBUG_BISON := -t
79 PARSER_DEBUG_FLEX := -d
80 CFLAGS += -DPARSER_DEBUG
83 CFLAGS += -fno-omit-frame-pointer
85 CFLAGS += -funwind-tables
90 EXTLIBS = -lelf -lpthread -lrt -lm -ldl
93 OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
94 $(shell mkdir -p $(OUTPUT_FEATURES))
97 feature_check = $(eval $(feature_check_code))
98 define feature_check_code
99 feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
102 feature_set = $(eval $(feature_set_code))
103 define feature_set_code
108 # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
112 # Note that this is not a complete list of all feature tests, just
113 # those that are typically built on a fully configured system.
115 # [ Feature tests not mentioned here have to be built explicitly in
116 # the rule that uses them - an example for that is the 'bionic'
119 CORE_FEATURE_TESTS = \
137 libunwind-debug-frame \
143 # So here we detect whether test-all was rebuilt, to be able
144 # to skip the print-out of the long features list if the file
145 # existed before and after it was built:
147 ifeq ($(wildcard $(OUTPUT)config/feature-checks/test-all),)
154 # Special fast-path for the 'all features are available' case:
156 $(call feature_check,all,$(MSG))
159 # Just in case the build freshly failed, make sure we print the
162 ifeq ($(feature-all), 0)
166 ifeq ($(test-all-failed),1)
168 $(info Auto-detecting system features:)
171 ifeq ($(feature-all), 1)
173 # test-all.c passed - just set all the core feature flags to 1:
175 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
177 $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
178 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
182 # Print the result of the feature test:
184 feature_print = $(eval $(feature_print_code)) $(info $(MSG))
186 define feature_print_code
187 ifeq ($(feature-$(1)), 1)
188 MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
190 MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
195 # Only print out our features if we rebuilt the testcases or if a test failed:
197 ifeq ($(test-all-failed), 1)
198 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_print,$(feat)))
202 ifeq ($(feature-stackprotector-all), 1)
203 CFLAGS += -fstack-protector-all
206 ifeq ($(feature-stackprotector), 1)
207 CFLAGS += -Wstack-protector
211 ifeq ($(feature-fortify-source), 1)
212 CFLAGS += -D_FORTIFY_SOURCE=2
216 CFLAGS += -I$(src-perf)/util/include
217 CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
218 CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
219 CFLAGS += -I$(srctree)/arch/$(ARCH)/include
220 CFLAGS += -I$(srctree)/include/uapi
221 CFLAGS += -I$(srctree)/include
223 # $(obj-perf) for generated common-cmds.h
224 # $(obj-perf)/util for generated bison/flex headers
226 CFLAGS += -I$(obj-perf)/util
227 CFLAGS += -I$(obj-perf)
230 CFLAGS += -I$(src-perf)/util
231 CFLAGS += -I$(src-perf)
232 CFLAGS += -I$(LIB_INCLUDE)
234 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
237 $(feature_check,bionic)
238 ifeq ($(feature-bionic), 1)
240 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
241 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
250 ifeq ($(feature-libelf), 0)
251 ifeq ($(feature-glibc), 1)
257 ifeq ($(LIBC_SUPPORT),1)
258 msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
264 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
267 # for linking with debug library, run like:
268 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
270 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
271 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
274 ifneq ($(feature-dwarf), 1)
275 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);
277 endif # Dwarf support
278 endif # libelf support
282 CFLAGS += -DHAVE_LIBELF_SUPPORT
284 ifeq ($(feature-libelf-mmap), 1)
285 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
288 ifeq ($(feature-libelf-getphdrnum), 1)
289 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
292 # include ARCH specific config
293 -include $(src-perf)/arch/$(ARCH)/Makefile
296 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
297 msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
300 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
301 LDFLAGS += $(LIBDW_LDFLAGS)
302 EXTLIBS += -lelf -ldw
303 endif # PERF_HAVE_DWARF_REGS
307 ifeq ($(LIBUNWIND_LIBS),)
313 # For linking with debug library, run like:
315 # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
318 LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
319 LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
322 ifneq ($(feature-libunwind), 1)
323 msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 1.1);
326 ifneq ($(feature-libunwind-debug-frame), 1)
327 msg := $(warning No debug_frame support found in libunwind);
328 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
334 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
335 EXTLIBS += $(LIBUNWIND_LIBS)
336 CFLAGS += $(LIBUNWIND_CFLAGS)
337 LDFLAGS += $(LIBUNWIND_LDFLAGS)
341 ifneq ($(feature-libaudit), 1)
342 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
345 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
355 ifneq ($(feature-libslang), 1)
356 msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
359 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
360 CFLAGS += -I/usr/include/slang
361 CFLAGS += -DHAVE_SLANG_SUPPORT
367 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
368 ifneq ($(feature-gtk2), 1)
369 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
372 ifeq ($(feature-gtk2-infobar), 1)
373 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
375 CFLAGS += -DHAVE_GTK2_SUPPORT
376 GTK_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
377 GTK_LIBS := $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
382 grep-libs = $(filter -l%,$(1))
383 strip-libs = $(filter-out -l%,$(1))
386 CFLAGS += -DNO_LIBPERL
388 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
389 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
390 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
391 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
392 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
394 ifneq ($(feature-libperl), 1)
395 CFLAGS += -DNO_LIBPERL
398 LDFLAGS += $(PERL_EMBED_LDFLAGS)
399 EXTLIBS += $(PERL_EMBED_LIBADD)
403 disable-python = $(eval $(disable-python_code))
404 define disable-python_code
405 CFLAGS += -DNO_LIBPYTHON
406 $(if $(1),$(warning No $(1) was found))
407 $(warning Python support will not be built)
412 $(call get-executable-or-default,PYTHON,python)
415 $(call disable-python,python interpreter)
418 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
421 $(call disable-python)
424 override PYTHON_CONFIG := \
425 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
428 $(call disable-python,python-config tool)
431 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
433 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
434 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
435 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
436 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
437 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
439 ifneq ($(feature-libpython), 1)
440 $(call disable-python,Python.h (for Python 2.x))
443 ifneq ($(feature-libpython-version), 1)
444 $(warning Python 3 is not yet supported; please set)
445 $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
446 $(warning If you also have Python 2 installed, then)
447 $(warning try something like:)
449 $(warning $(and ,) make PYTHON=python2)
451 $(warning Otherwise, disable Python support entirely:)
453 $(warning $(and ,) make NO_LIBPYTHON=1)
457 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
458 EXTLIBS += $(PYTHON_EMBED_LIBADD)
459 LANG_BINDINGS += $(obj-perf)python/perf.so
466 ifeq ($(feature-libbfd), 1)
471 CFLAGS += -DNO_DEMANGLE
473 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
475 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
477 ifneq ($(feature-libbfd), 1)
478 $(feature_check,liberty)
479 ifeq ($(feature-liberty), 1)
480 EXTLIBS += -lbfd -liberty
482 $(feature_check,liberty-z)
483 ifeq ($(feature-liberty-z), 1)
484 EXTLIBS += -lbfd -liberty -lz
486 $(feature_check,cplus-demangle)
487 ifeq ($(feature-cplus-demangle), 1)
489 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
491 msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
492 CFLAGS += -DNO_DEMANGLE
500 ifneq ($(filter -lbfd,$(EXTLIBS)),)
501 CFLAGS += -DHAVE_LIBBFD_SUPPORT
505 ifeq ($(feature-on-exit), 1)
506 CFLAGS += -DHAVE_ON_EXIT_SUPPORT
511 ifeq ($(feature-backtrace), 1)
512 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
517 ifeq ($(feature-libnuma), 0)
518 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
521 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
526 # Among the variables below, these:
532 # ETC_PERFCONFIG (but not sysconfdir)
533 # can be specified as a relative path some/where/else;
534 # this is interpreted as relative to $(prefix) and "perf" at
535 # runtime figures out where they are based on the path to the executable.
536 # This can help installing the suite in a relocatable way.
538 # Make the path relative to DESTDIR, not to prefix
542 bindir_relative = bin
543 bindir = $(prefix)/$(bindir_relative)
546 perfexecdir = libexec/perf-core
547 sharedir = $(prefix)/share
548 template_dir = share/perf-core/templates
549 htmldir = share/doc/perf-doc
550 ifeq ($(prefix),/usr)
552 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
554 sysconfdir = $(prefix)/etc
555 ETC_PERFCONFIG = etc/perfconfig
557 ifeq ($(IS_X86_64),1)
562 libdir = $(prefix)/$(lib)
564 # Shell quote (do not use $(call) to accommodate ancient setups);
565 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
566 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
567 bindir_SQ = $(subst ','\'',$(bindir))
568 mandir_SQ = $(subst ','\'',$(mandir))
569 infodir_SQ = $(subst ','\'',$(infodir))
570 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
571 template_dir_SQ = $(subst ','\'',$(template_dir))
572 htmldir_SQ = $(subst ','\'',$(htmldir))
573 prefix_SQ = $(subst ','\'',$(prefix))
574 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
575 libdir_SQ = $(subst ','\'',$(libdir))
577 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
578 perfexec_instdir = $(perfexecdir)
580 perfexec_instdir = $(prefix)/$(perfexecdir)
582 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))