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
33 ifeq ($(NO_PERF_REGS),0)
34 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
38 src-perf := $(srctree)/tools/perf
46 obj-perf := $(abspath $(obj-perf))/
49 LIB_INCLUDE := $(srctree)/tools/lib/
51 # include ARCH specific config
52 -include $(src-perf)/arch/$(ARCH)/Makefile
54 include $(src-perf)/config/utilities.mak
56 ifeq ($(call get-executable,$(FLEX)),)
57 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
60 ifeq ($(call get-executable,$(BISON)),)
61 dummy := $(error Error: $(BISON) is missing on this system, please install it)
64 # Treat warnings as errors unless directed not to
69 ifeq ("$(origin DEBUG)", "command line")
77 PARSER_DEBUG_BISON := -t
78 PARSER_DEBUG_FLEX := -d
79 CFLAGS += -DPARSER_DEBUG
82 CFLAGS += -fno-omit-frame-pointer
84 CFLAGS += -funwind-tables
89 EXTLIBS = -lelf -lpthread -lrt -lm -ldl
91 feature_check = $(eval $(feature_check_code))
92 define feature_check_code
93 feature-$(1) := $(shell $(MAKE) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
96 feature_set = $(eval $(feature_set_code))
97 define feature_set_code
102 # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
106 # Note that this is not a complete list of all feature tests, just
107 # those that are typically built on a fully configured system.
109 # [ Feature tests not mentioned here have to be built explicitly in
110 # the rule that uses them - an example for that is the 'bionic'
113 CORE_FEATURE_TESTS = \
134 volatile-register-var
137 # So here we detect whether test-all was rebuilt, to be able
138 # to skip the print-out of the long features list if the file
139 # existed before and after it was built:
141 ifeq ($(wildcard config/feature-checks/test-all),)
148 # Special fast-path for the 'all features are available' case:
150 $(call feature_check,all,$(MSG))
153 # Just in case the build freshly failed, make sure we print the
156 ifeq ($(feature-all), 0)
160 ifeq ($(test-all-failed),1)
162 $(info Auto-detecting system features:)
165 ifeq ($(feature-all), 1)
167 # test-all.c passed - just set all the core feature flags to 1:
169 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
171 $(shell $(MAKE) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
172 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
176 # Print the result of the feature test:
178 feature_print = $(eval $(feature_print_code))
179 define feature_print_code
180 ifeq ($(feature-$(1)), 1)
181 MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
183 MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
189 # Only print out our features if we rebuilt the testcases or if a test failed:
191 ifeq ($(test-all-failed), 1)
192 $(foreach feat,$(CORE_FEATURE_TESTS) DUMMY,$(call feature_print,$(feat)))
196 ifeq ($(feature-stackprotector-all), 1)
197 CFLAGS += -fstack-protector-all
200 ifeq ($(feature-stackprotector), 1)
201 CFLAGS += -Wstack-protector
204 ifeq ($(feature-volatile-register-var), 1)
205 CFLAGS += -Wvolatile-register-var
209 ifeq ($(feature-fortify-source), 1)
210 CFLAGS += -D_FORTIFY_SOURCE=2
214 CFLAGS += -I$(src-perf)/util/include
215 CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
216 CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
217 CFLAGS += -I$(srctree)/arch/$(ARCH)/include
218 CFLAGS += -I$(srctree)/include/uapi
219 CFLAGS += -I$(srctree)/include
221 # $(obj-perf) for generated common-cmds.h
222 # $(obj-perf)/util for generated bison/flex headers
224 CFLAGS += -I$(obj-perf)/util
225 CFLAGS += -I$(obj-perf)
228 CFLAGS += -I$(src-perf)/util
229 CFLAGS += -I$(src-perf)
230 CFLAGS += -I$(LIB_INCLUDE)
232 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
235 $(feature_check,bionic)
236 ifeq ($(feature-bionic), 1)
238 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
239 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
248 ifeq ($(feature-libelf), 0)
249 ifeq ($(feature-glibc), 1)
255 ifeq ($(LIBC_SUPPORT),1)
256 msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
262 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
265 # for linking with debug library, run like:
266 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
268 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
269 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
272 ifneq ($(feature-dwarf), 1)
273 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);
275 endif # Dwarf support
276 endif # libelf support
280 CFLAGS += -DHAVE_LIBELF_SUPPORT
281 FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
283 ifeq ($(feature-libelf-mmap), 1)
284 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
287 ifeq ($(feature-libelf-getphdrnum), 1)
288 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
291 # include ARCH specific config
292 -include $(src-perf)/arch/$(ARCH)/Makefile
295 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
296 msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
299 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
300 LDFLAGS += $(LIBDW_LDFLAGS)
301 EXTLIBS += -lelf -ldw
302 endif # PERF_HAVE_DWARF_REGS
307 CFLAGS += -DHAVE_LIBELF_SUPPORT
308 ifeq ($(feature-libelf-mmap), 1)
309 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
313 # There's only x86 (both 32 and 64) support for CFI unwind so far
320 # For linking with debug library, run like:
322 # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
325 LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
326 LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
329 ifneq ($(feature-libunwind), 1)
330 msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
336 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
337 EXTLIBS += $(LIBUNWIND_LIBS)
338 CFLAGS += $(LIBUNWIND_CFLAGS)
339 LDFLAGS += $(LIBUNWIND_LDFLAGS)
343 ifneq ($(feature-libaudit), 1)
344 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
347 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
357 ifneq ($(feature-libslang), 1)
358 msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
361 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
362 CFLAGS += -I/usr/include/slang
363 CFLAGS += -DHAVE_SLANG_SUPPORT
369 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
370 ifneq ($(feature-gtk2), 1)
371 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
374 ifeq ($(feature-gtk2-infobar), 1)
375 CFLAGS += -DHAVE_GTK_INFO_BAR_SUPPORT
377 CFLAGS += -DHAVE_GTK2_SUPPORT
378 CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
379 EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
383 grep-libs = $(filter -l%,$(1))
384 strip-libs = $(filter-out -l%,$(1))
387 CFLAGS += -DNO_LIBPERL
389 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
390 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
391 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
392 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
393 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
395 ifneq ($(feature-libperl), 1)
396 CFLAGS += -DNO_LIBPERL
399 LDFLAGS += $(PERL_EMBED_LDFLAGS)
400 EXTLIBS += $(PERL_EMBED_LIBADD)
404 disable-python = $(eval $(disable-python_code))
405 define disable-python_code
406 CFLAGS += -DNO_LIBPYTHON
407 $(if $(1),$(warning No $(1) was found))
408 $(warning Python support will not be built)
413 $(call get-executable-or-default,PYTHON,python)
416 $(call disable-python,python interpreter)
419 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
422 $(call disable-python)
425 override PYTHON_CONFIG := \
426 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
429 $(call disable-python,python-config tool)
432 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
434 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
435 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
436 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
437 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
438 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
440 ifneq ($(feature-libpython), 1)
441 $(call disable-python,Python.h (for Python 2.x))
444 ifneq ($(feature-libpython-version), 1)
445 $(warning Python 3 is not yet supported; please set)
446 $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
447 $(warning If you also have Python 2 installed, then)
448 $(warning try something like:)
450 $(warning $(and ,) make PYTHON=python2)
452 $(warning Otherwise, disable Python support entirely:)
454 $(warning $(and ,) make NO_LIBPYTHON=1)
458 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
459 EXTLIBS += $(PYTHON_EMBED_LIBADD)
460 LANG_BINDINGS += $(obj-perf)python/perf.so
468 CFLAGS += -DNO_DEMANGLE
470 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
472 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
474 ifeq ($(feature-libbfd), 1)
477 $(feature_check,liberty)
478 ifeq ($(feature-liberty), 1)
479 EXTLIBS += -lbfd -liberty
481 $(feature_check,liberty-z)
482 ifeq ($(feature-liberty-z), 1)
483 EXTLIBS += -lbfd -liberty -lz
485 $(feature_check,cplus-demangle)
486 ifeq ($(feature-cplus-demangle), 1)
488 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
490 msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
491 CFLAGS += -DNO_DEMANGLE
500 ifeq ($(feature-on-exit), 1)
501 CFLAGS += -DHAVE_ON_EXIT_SUPPORT
506 ifeq ($(feature-backtrace), 1)
507 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
512 ifeq ($(feature-libnuma), 0)
513 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
516 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
521 # Among the variables below, these:
527 # ETC_PERFCONFIG (but not sysconfdir)
528 # can be specified as a relative path some/where/else;
529 # this is interpreted as relative to $(prefix) and "perf" at
530 # runtime figures out where they are based on the path to the executable.
531 # This can help installing the suite in a relocatable way.
533 # Make the path relative to DESTDIR, not to prefix
537 bindir_relative = bin
538 bindir = $(prefix)/$(bindir_relative)
541 perfexecdir = libexec/perf-core
542 sharedir = $(prefix)/share
543 template_dir = share/perf-core/templates
544 htmldir = share/doc/perf-doc
545 ifeq ($(prefix),/usr)
547 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
549 sysconfdir = $(prefix)/etc
550 ETC_PERFCONFIG = etc/perfconfig
554 # Shell quote (do not use $(call) to accommodate ancient setups);
555 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
556 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
557 bindir_SQ = $(subst ','\'',$(bindir))
558 mandir_SQ = $(subst ','\'',$(mandir))
559 infodir_SQ = $(subst ','\'',$(infodir))
560 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
561 template_dir_SQ = $(subst ','\'',$(template_dir))
562 htmldir_SQ = $(subst ','\'',$(htmldir))
563 prefix_SQ = $(subst ','\'',$(prefix))
564 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
566 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
567 perfexec_instdir = $(perfexecdir)
569 perfexec_instdir = $(prefix)/$(perfexecdir)
571 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))