]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/perf/config/Makefile
Merge remote-tracking branch 'tip/auto-latest'
[karo-tx-linux.git] / tools / perf / config / Makefile
1 uname_M := $(shell uname -m 2>/dev/null || echo not)
2
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/ )
8 NO_PERF_REGS := 1
9 CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
10
11 # Additional ARCH settings for x86
12 ifeq ($(ARCH),i386)
13   override ARCH := x86
14   NO_PERF_REGS := 0
15   LIBUNWIND_LIBS = -lunwind -lunwind-x86
16 endif
17
18 ifeq ($(ARCH),x86_64)
19   override ARCH := x86
20   IS_X86_64 := 0
21   ifeq (, $(findstring m32,$(CFLAGS)))
22     IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1)
23   endif
24   ifeq (${IS_X86_64}, 1)
25     RAW_ARCH := x86_64
26     CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
27     ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
28   endif
29   NO_PERF_REGS := 0
30   LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
31 endif
32 ifeq ($(ARCH),arm)
33   NO_PERF_REGS := 0
34   LIBUNWIND_LIBS = -lunwind -lunwind-arm
35 endif
36
37 ifeq ($(NO_PERF_REGS),0)
38   CFLAGS += -DHAVE_PERF_REGS_SUPPORT
39 endif
40
41 ifeq ($(src-perf),)
42 src-perf := $(srctree)/tools/perf
43 endif
44
45 ifeq ($(obj-perf),)
46 obj-perf := $(OUTPUT)
47 endif
48
49 ifneq ($(obj-perf),)
50 obj-perf := $(abspath $(obj-perf))/
51 endif
52
53 LIB_INCLUDE := $(srctree)/tools/lib/
54
55 # include ARCH specific config
56 -include $(src-perf)/arch/$(ARCH)/Makefile
57
58 include $(src-perf)/config/utilities.mak
59
60 ifeq ($(call get-executable,$(FLEX)),)
61   dummy := $(error Error: $(FLEX) is missing on this system, please install it)
62 endif
63
64 ifeq ($(call get-executable,$(BISON)),)
65   dummy := $(error Error: $(BISON) is missing on this system, please install it)
66 endif
67
68 # Treat warnings as errors unless directed not to
69 ifneq ($(WERROR),0)
70   CFLAGS += -Werror
71 endif
72
73 ifeq ($(DEBUG),0)
74   CFLAGS += -O6
75 endif
76
77 ifdef PARSER_DEBUG
78   PARSER_DEBUG_BISON := -t
79   PARSER_DEBUG_FLEX  := -d
80   CFLAGS             += -DPARSER_DEBUG
81 endif
82
83 CFLAGS += -fno-omit-frame-pointer
84 CFLAGS += -ggdb3
85 CFLAGS += -funwind-tables
86 CFLAGS += -Wall
87 CFLAGS += -Wextra
88 CFLAGS += -std=gnu99
89
90 EXTLIBS = -lelf -lpthread -lrt -lm -ldl
91
92 ifneq ($(OUTPUT),)
93   OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
94   $(shell mkdir -p $(OUTPUT_FEATURES))
95 endif
96
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)
100 endef
101
102 feature_set = $(eval $(feature_set_code))
103 define feature_set_code
104   feature-$(1) := 1
105 endef
106
107 #
108 # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
109 #
110
111 #
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.
114 #
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'
117 #   feature check. ]
118 #
119 CORE_FEATURE_TESTS =                    \
120         backtrace                       \
121         dwarf                           \
122         fortify-source                  \
123         glibc                           \
124         gtk2                            \
125         gtk2-infobar                    \
126         libaudit                        \
127         libbfd                          \
128         libelf                          \
129         libelf-getphdrnum               \
130         libelf-mmap                     \
131         libnuma                         \
132         libperl                         \
133         libpython                       \
134         libpython-version               \
135         libslang                        \
136         libunwind                       \
137         libunwind-debug-frame           \
138         on-exit                         \
139         stackprotector                  \
140         stackprotector-all
141
142 #
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:
146 #
147 ifeq ($(wildcard $(OUTPUT)config/feature-checks/test-all),)
148   test-all-failed := 1
149 else
150   test-all-failed := 0
151 endif
152
153 #
154 # Special fast-path for the 'all features are available' case:
155 #
156 $(call feature_check,all,$(MSG))
157
158 #
159 # Just in case the build freshly failed, make sure we print the
160 # feature matrix:
161 #
162 ifeq ($(feature-all), 0)
163   test-all-failed := 1
164 endif
165
166 ifeq ($(test-all-failed),1)
167   $(info )
168   $(info Auto-detecting system features:)
169 endif
170
171 ifeq ($(feature-all), 1)
172   #
173   # test-all.c passed - just set all the core feature flags to 1:
174   #
175   $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
176 else
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)))
179 endif
180
181 #
182 # Print the result of the feature test:
183 #
184 feature_print = $(eval $(feature_print_code)) $(info $(MSG))
185
186 define feature_print_code
187   ifeq ($(feature-$(1)), 1)
188     MSG = $(shell printf '...%30s: [ \033[32mon\033[m  ]' $(1))
189   else
190     MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
191   endif
192 endef
193
194 #
195 # Only print out our features if we rebuilt the testcases or if a test failed:
196 #
197 ifeq ($(test-all-failed), 1)
198   $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_print,$(feat)))
199   $(info )
200 endif
201
202 ifeq ($(feature-stackprotector-all), 1)
203   CFLAGS += -fstack-protector-all
204 endif
205
206 ifeq ($(feature-stackprotector), 1)
207   CFLAGS += -Wstack-protector
208 endif
209
210 ifeq ($(DEBUG),0)
211   ifeq ($(feature-fortify-source), 1)
212     CFLAGS += -D_FORTIFY_SOURCE=2
213   endif
214 endif
215
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
222
223 # $(obj-perf)      for generated common-cmds.h
224 # $(obj-perf)/util for generated bison/flex headers
225 ifneq ($(OUTPUT),)
226 CFLAGS += -I$(obj-perf)/util
227 CFLAGS += -I$(obj-perf)
228 endif
229
230 CFLAGS += -I$(src-perf)/util
231 CFLAGS += -I$(src-perf)
232 CFLAGS += -I$(LIB_INCLUDE)
233
234 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
235
236 ifndef NO_BIONIC
237   $(feature_check,bionic)
238   ifeq ($(feature-bionic), 1)
239     BIONIC := 1
240     EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
241     EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
242   endif
243 endif
244
245 ifdef NO_LIBELF
246   NO_DWARF := 1
247   NO_DEMANGLE := 1
248   NO_LIBUNWIND := 1
249 else
250   ifeq ($(feature-libelf), 0)
251     ifeq ($(feature-glibc), 1)
252       LIBC_SUPPORT := 1
253     endif
254     ifeq ($(BIONIC),1)
255       LIBC_SUPPORT := 1
256     endif
257     ifeq ($(LIBC_SUPPORT),1)
258       msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
259
260       NO_LIBELF := 1
261       NO_DWARF := 1
262       NO_DEMANGLE := 1
263     else
264       msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
265     endif
266   else
267     # for linking with debug library, run like:
268     # make DEBUG=1 LIBDW_DIR=/opt/libdw/
269     ifdef LIBDW_DIR
270       LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
271       LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
272     endif
273
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);
276       NO_DWARF := 1
277     endif # Dwarf support
278   endif # libelf support
279 endif # NO_LIBELF
280
281 ifndef NO_LIBELF
282   CFLAGS += -DHAVE_LIBELF_SUPPORT
283
284   ifeq ($(feature-libelf-mmap), 1)
285     CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
286   endif
287
288   ifeq ($(feature-libelf-getphdrnum), 1)
289     CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
290   endif
291
292   # include ARCH specific config
293   -include $(src-perf)/arch/$(ARCH)/Makefile
294
295   ifndef NO_DWARF
296     ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
297       msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
298       NO_DWARF := 1
299     else
300       CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
301       LDFLAGS += $(LIBDW_LDFLAGS)
302       EXTLIBS += -lelf -ldw
303     endif # PERF_HAVE_DWARF_REGS
304   endif # NO_DWARF
305 endif # NO_LIBELF
306
307 ifeq ($(LIBUNWIND_LIBS),)
308   NO_LIBUNWIND := 1
309 endif
310
311 ifndef NO_LIBUNWIND
312   #
313   # For linking with debug library, run like:
314   #
315   #   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
316   #
317   ifdef LIBUNWIND_DIR
318     LIBUNWIND_CFLAGS  := -I$(LIBUNWIND_DIR)/include
319     LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
320   endif
321
322   ifneq ($(feature-libunwind), 1)
323     msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 1.1);
324     NO_LIBUNWIND := 1
325   else
326     ifneq ($(feature-libunwind-debug-frame), 1)
327       msg := $(warning No debug_frame support found in libunwind);
328       CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
329     endif
330   endif
331 endif
332
333 ifndef NO_LIBUNWIND
334   CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
335   EXTLIBS += $(LIBUNWIND_LIBS)
336   CFLAGS += $(LIBUNWIND_CFLAGS)
337   LDFLAGS += $(LIBUNWIND_LDFLAGS)
338 endif
339
340 ifndef NO_LIBAUDIT
341   ifneq ($(feature-libaudit), 1)
342     msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
343     NO_LIBAUDIT := 1
344   else
345     CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
346     EXTLIBS += -laudit
347   endif
348 endif
349
350 ifdef NO_NEWT
351   NO_SLANG=1
352 endif
353
354 ifndef NO_SLANG
355   ifneq ($(feature-libslang), 1)
356     msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
357     NO_SLANG := 1
358   else
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
362     EXTLIBS += -lslang
363   endif
364 endif
365
366 ifndef NO_GTK2
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);
370     NO_GTK2 := 1
371   else
372     ifeq ($(feature-gtk2-infobar), 1)
373       GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
374     endif
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)
378     EXTLIBS += -ldl
379   endif
380 endif
381
382 grep-libs  = $(filter -l%,$(1))
383 strip-libs = $(filter-out -l%,$(1))
384
385 ifdef NO_LIBPERL
386   CFLAGS += -DNO_LIBPERL
387 else
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)
393
394   ifneq ($(feature-libperl), 1)
395     CFLAGS += -DNO_LIBPERL
396     NO_LIBPERL := 1
397   else
398     LDFLAGS += $(PERL_EMBED_LDFLAGS)
399     EXTLIBS += $(PERL_EMBED_LIBADD)
400   endif
401 endif
402
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)
408   NO_LIBPYTHON := 1
409 endef
410
411 override PYTHON := \
412   $(call get-executable-or-default,PYTHON,python)
413
414 ifndef PYTHON
415   $(call disable-python,python interpreter)
416 else
417
418   PYTHON_WORD := $(call shell-wordify,$(PYTHON))
419
420   ifdef NO_LIBPYTHON
421     $(call disable-python)
422   else
423
424     override PYTHON_CONFIG := \
425       $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
426
427     ifndef PYTHON_CONFIG
428       $(call disable-python,python-config tool)
429     else
430
431       PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
432
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)
438
439       ifneq ($(feature-libpython), 1)
440         $(call disable-python,Python.h (for Python 2.x))
441       else
442
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:)
448           $(warning $(and ,))
449           $(warning $(and ,)  make PYTHON=python2)
450           $(warning $(and ,))
451           $(warning Otherwise, disable Python support entirely:)
452           $(warning $(and ,))
453           $(warning $(and ,)  make NO_LIBPYTHON=1)
454           $(warning $(and ,))
455           $(error   $(and ,))
456         else
457           LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
458           EXTLIBS += $(PYTHON_EMBED_LIBADD)
459           LANG_BINDINGS += $(obj-perf)python/perf.so
460         endif
461       endif
462     endif
463   endif
464 endif
465
466 ifeq ($(feature-libbfd), 1)
467   EXTLIBS += -lbfd
468 endif
469
470 ifdef NO_DEMANGLE
471   CFLAGS += -DNO_DEMANGLE
472 else
473   ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
474     EXTLIBS += -liberty
475     CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
476   else
477     ifneq ($(feature-libbfd), 1)
478       $(feature_check,liberty)
479       ifeq ($(feature-liberty), 1)
480         EXTLIBS += -lbfd -liberty
481       else
482         $(feature_check,liberty-z)
483         ifeq ($(feature-liberty-z), 1)
484           EXTLIBS += -lbfd -liberty -lz
485         else
486           $(feature_check,cplus-demangle)
487           ifeq ($(feature-cplus-demangle), 1)
488             EXTLIBS += -liberty
489             CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
490           else
491             msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
492             CFLAGS += -DNO_DEMANGLE
493           endif
494         endif
495       endif
496     endif
497   endif
498 endif
499
500 ifneq ($(filter -lbfd,$(EXTLIBS)),)
501   CFLAGS += -DHAVE_LIBBFD_SUPPORT
502 endif
503
504 ifndef NO_ON_EXIT
505   ifeq ($(feature-on-exit), 1)
506     CFLAGS += -DHAVE_ON_EXIT_SUPPORT
507   endif
508 endif
509
510 ifndef NO_BACKTRACE
511   ifeq ($(feature-backtrace), 1)
512     CFLAGS += -DHAVE_BACKTRACE_SUPPORT
513   endif
514 endif
515
516 ifndef NO_LIBNUMA
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);
519     NO_LIBNUMA := 1
520   else
521     CFLAGS += -DHAVE_LIBNUMA_SUPPORT
522     EXTLIBS += -lnuma
523   endif
524 endif
525
526 # Among the variables below, these:
527 #   perfexecdir
528 #   template_dir
529 #   mandir
530 #   infodir
531 #   htmldir
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.
537
538 # Make the path relative to DESTDIR, not to prefix
539 ifndef DESTDIR
540 prefix = $(HOME)
541 endif
542 bindir_relative = bin
543 bindir = $(prefix)/$(bindir_relative)
544 mandir = share/man
545 infodir = share/info
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)
551 sysconfdir = /etc
552 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
553 else
554 sysconfdir = $(prefix)/etc
555 ETC_PERFCONFIG = etc/perfconfig
556 endif
557 ifeq ($(IS_X86_64),1)
558 lib = lib64
559 else
560 lib = lib
561 endif
562 libdir = $(prefix)/$(lib)
563
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))
576
577 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
578 perfexec_instdir = $(perfexecdir)
579 else
580 perfexec_instdir = $(prefix)/$(perfexecdir)
581 endif
582 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))