e80ffe8262b0d1246c77f99e872313a83efde789
[profile/ivi/kernel-x86-ivi.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
33 ifeq ($(NO_PERF_REGS),0)
34   CFLAGS += -DHAVE_PERF_REGS_SUPPORT
35 endif
36
37 ifeq ($(src-perf),)
38 src-perf := $(srctree)/tools/perf
39 endif
40
41 ifeq ($(obj-perf),)
42 obj-perf := $(OUTPUT)
43 endif
44
45 ifneq ($(obj-perf),)
46 obj-perf := $(abspath $(obj-perf))/
47 endif
48
49 LIB_INCLUDE := $(srctree)/tools/lib/
50
51 # include ARCH specific config
52 -include $(src-perf)/arch/$(ARCH)/Makefile
53
54 include $(src-perf)/config/utilities.mak
55
56 ifeq ($(call get-executable,$(FLEX)),)
57   dummy := $(error Error: $(FLEX) is missing on this system, please install it)
58 endif
59
60 ifeq ($(call get-executable,$(BISON)),)
61   dummy := $(error Error: $(BISON) is missing on this system, please install it)
62 endif
63
64 # Treat warnings as errors unless directed not to
65 ifneq ($(WERROR),0)
66   CFLAGS += -Werror
67 endif
68
69 ifeq ("$(origin DEBUG)", "command line")
70   PERF_DEBUG = $(DEBUG)
71 endif
72 ifndef PERF_DEBUG
73   CFLAGS += -O6
74 endif
75
76 ifdef PARSER_DEBUG
77   PARSER_DEBUG_BISON := -t
78   PARSER_DEBUG_FLEX  := -d
79   CFLAGS             += -DPARSER_DEBUG
80 endif
81
82 CFLAGS += -fno-omit-frame-pointer
83 CFLAGS += -ggdb3
84 CFLAGS += -funwind-tables
85 CFLAGS += -Wall
86 CFLAGS += -Wextra
87 CFLAGS += -std=gnu99
88
89 EXTLIBS = -lelf -lpthread -lrt -lm -ldl
90
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)
94 endef
95
96 feature_set = $(eval $(feature_set_code))
97 define feature_set_code
98   feature-$(1) := 1
99 endef
100
101 #
102 # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
103 #
104
105 #
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.
108 #
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'
111 #   feature check. ]
112 #
113 CORE_FEATURE_TESTS =                    \
114         backtrace                       \
115         dwarf                           \
116         fortify-source                  \
117         glibc                           \
118         gtk2                            \
119         gtk2-infobar                    \
120         libaudit                        \
121         libbfd                          \
122         libelf                          \
123         libelf-getphdrnum               \
124         libelf-mmap                     \
125         libnuma                         \
126         libperl                         \
127         libpython                       \
128         libpython-version               \
129         libslang                        \
130         libunwind                       \
131         on-exit                         \
132         stackprotector                  \
133         stackprotector-all              \
134         volatile-register-var
135
136 #
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:
140 #
141 ifeq ($(wildcard config/feature-checks/test-all),)
142   test-all-failed := 1
143 else
144   test-all-failed := 0
145 endif
146
147 #
148 # Special fast-path for the 'all features are available' case:
149 #
150 $(call feature_check,all,$(MSG))
151
152 #
153 # Just in case the build freshly failed, make sure we print the
154 # feature matrix:
155 #
156 ifeq ($(feature-all), 0)
157   test-all-failed := 1
158 endif
159
160 ifeq ($(test-all-failed),1)
161   $(info )
162   $(info Auto-detecting system features:)
163 endif
164
165 ifeq ($(feature-all), 1)
166   #
167   # test-all.c passed - just set all the core feature flags to 1:
168   #
169   $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
170 else
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)))
173 endif
174
175 #
176 # Print the result of the feature test:
177 #
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))
182   else
183     MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
184   endif
185   $(info $(MSG))
186 endef
187
188 #
189 # Only print out our features if we rebuilt the testcases or if a test failed:
190 #
191 ifeq ($(test-all-failed), 1)
192   $(foreach feat,$(CORE_FEATURE_TESTS) DUMMY,$(call feature_print,$(feat)))
193   $(info )
194 endif
195
196 ifeq ($(feature-stackprotector-all), 1)
197   CFLAGS += -fstack-protector-all
198 endif
199
200 ifeq ($(feature-stackprotector), 1)
201   CFLAGS += -Wstack-protector
202 endif
203
204 ifeq ($(feature-volatile-register-var), 1)
205   CFLAGS += -Wvolatile-register-var
206 endif
207
208 ifndef PERF_DEBUG
209   ifeq ($(feature-fortify-source), 1)
210     CFLAGS += -D_FORTIFY_SOURCE=2
211   endif
212 endif
213
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
220
221 # $(obj-perf)      for generated common-cmds.h
222 # $(obj-perf)/util for generated bison/flex headers
223 ifneq ($(OUTPUT),)
224 CFLAGS += -I$(obj-perf)/util
225 CFLAGS += -I$(obj-perf)
226 endif
227
228 CFLAGS += -I$(src-perf)/util
229 CFLAGS += -I$(src-perf)
230 CFLAGS += -I$(LIB_INCLUDE)
231
232 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
233
234 ifndef NO_BIONIC
235   $(feature_check,bionic)
236   ifeq ($(feature-bionic), 1)
237     BIONIC := 1
238     EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
239     EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
240   endif
241 endif
242
243 ifdef NO_LIBELF
244   NO_DWARF := 1
245   NO_DEMANGLE := 1
246   NO_LIBUNWIND := 1
247 else
248   ifeq ($(feature-libelf), 0)
249     ifeq ($(feature-glibc), 1)
250       LIBC_SUPPORT := 1
251     endif
252     ifeq ($(BIONIC),1)
253       LIBC_SUPPORT := 1
254     endif
255     ifeq ($(LIBC_SUPPORT),1)
256       msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
257
258       NO_LIBELF := 1
259       NO_DWARF := 1
260       NO_DEMANGLE := 1
261     else
262       msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
263     endif
264   else
265     # for linking with debug library, run like:
266     # make DEBUG=1 LIBDW_DIR=/opt/libdw/
267     ifdef LIBDW_DIR
268       LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
269       LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
270     endif
271
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);
274       NO_DWARF := 1
275     endif # Dwarf support
276   endif # libelf support
277 endif # NO_LIBELF
278
279 ifndef NO_LIBELF
280   CFLAGS += -DHAVE_LIBELF_SUPPORT
281   FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
282
283   ifeq ($(feature-libelf-mmap), 1)
284     CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
285   endif
286
287   ifeq ($(feature-libelf-getphdrnum), 1)
288     CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
289   endif
290
291   # include ARCH specific config
292   -include $(src-perf)/arch/$(ARCH)/Makefile
293
294   ifndef NO_DWARF
295     ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
296       msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
297       NO_DWARF := 1
298     else
299       CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
300       LDFLAGS += $(LIBDW_LDFLAGS)
301       EXTLIBS += -lelf -ldw
302     endif # PERF_HAVE_DWARF_REGS
303   endif # NO_DWARF
304 endif # NO_LIBELF
305
306 ifndef NO_LIBELF
307   CFLAGS += -DHAVE_LIBELF_SUPPORT
308   ifeq ($(feature-libelf-mmap), 1)
309     CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
310   endif
311 endif # NO_LIBELF
312
313 # There's only x86 (both 32 and 64) support for CFI unwind so far
314 ifneq ($(ARCH),x86)
315   NO_LIBUNWIND := 1
316 endif
317
318 ifndef NO_LIBUNWIND
319   #
320   # For linking with debug library, run like:
321   #
322   #   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
323   #
324   ifdef LIBUNWIND_DIR
325     LIBUNWIND_CFLAGS  := -I$(LIBUNWIND_DIR)/include
326     LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
327   endif
328
329   ifneq ($(feature-libunwind), 1)
330     msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
331     NO_LIBUNWIND := 1
332   endif
333 endif
334
335 ifndef NO_LIBUNWIND
336   CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
337   EXTLIBS += $(LIBUNWIND_LIBS)
338   CFLAGS += $(LIBUNWIND_CFLAGS)
339   LDFLAGS += $(LIBUNWIND_LDFLAGS)
340 endif
341
342 ifndef NO_LIBAUDIT
343   ifneq ($(feature-libaudit), 1)
344     msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
345     NO_LIBAUDIT := 1
346   else
347     CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
348     EXTLIBS += -laudit
349   endif
350 endif
351
352 ifdef NO_NEWT
353   NO_SLANG=1
354 endif
355
356 ifndef NO_SLANG
357   ifneq ($(feature-libslang), 1)
358     msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
359     NO_SLANG := 1
360   else
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
364     EXTLIBS += -lslang
365   endif
366 endif
367
368 ifndef NO_GTK2
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);
372     NO_GTK2 := 1
373   else
374     ifeq ($(feature-gtk2-infobar), 1)
375       CFLAGS += -DHAVE_GTK_INFO_BAR_SUPPORT
376     endif
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)
380   endif
381 endif
382
383 grep-libs  = $(filter -l%,$(1))
384 strip-libs = $(filter-out -l%,$(1))
385
386 ifdef NO_LIBPERL
387   CFLAGS += -DNO_LIBPERL
388 else
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)
394
395   ifneq ($(feature-libperl), 1)
396     CFLAGS += -DNO_LIBPERL
397     NO_LIBPERL := 1
398   else
399     LDFLAGS += $(PERL_EMBED_LDFLAGS)
400     EXTLIBS += $(PERL_EMBED_LIBADD)
401   endif
402 endif
403
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)
409   NO_LIBPYTHON := 1
410 endef
411
412 override PYTHON := \
413   $(call get-executable-or-default,PYTHON,python)
414
415 ifndef PYTHON
416   $(call disable-python,python interpreter)
417 else
418
419   PYTHON_WORD := $(call shell-wordify,$(PYTHON))
420
421   ifdef NO_LIBPYTHON
422     $(call disable-python)
423   else
424
425     override PYTHON_CONFIG := \
426       $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
427
428     ifndef PYTHON_CONFIG
429       $(call disable-python,python-config tool)
430     else
431
432       PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
433
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)
439
440       ifneq ($(feature-libpython), 1)
441         $(call disable-python,Python.h (for Python 2.x))
442       else
443
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:)
449           $(warning $(and ,))
450           $(warning $(and ,)  make PYTHON=python2)
451           $(warning $(and ,))
452           $(warning Otherwise, disable Python support entirely:)
453           $(warning $(and ,))
454           $(warning $(and ,)  make NO_LIBPYTHON=1)
455           $(warning $(and ,))
456           $(error   $(and ,))
457         else
458           LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
459           EXTLIBS += $(PYTHON_EMBED_LIBADD)
460           LANG_BINDINGS += $(obj-perf)python/perf.so
461         endif
462       endif
463     endif
464   endif
465 endif
466
467 ifdef NO_DEMANGLE
468   CFLAGS += -DNO_DEMANGLE
469 else
470   ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
471     EXTLIBS += -liberty
472     CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
473   else
474     ifeq ($(feature-libbfd), 1)
475       EXTLIBS += -lbfd
476     else
477       $(feature_check,liberty)
478       ifeq ($(feature-liberty), 1)
479         EXTLIBS += -lbfd -liberty
480       else
481         $(feature_check,liberty-z)
482         ifeq ($(feature-liberty-z), 1)
483           EXTLIBS += -lbfd -liberty -lz
484         else
485           $(feature_check,cplus-demangle)
486           ifeq ($(feature-cplus-demangle), 1)
487             EXTLIBS += -liberty
488             CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
489           else
490             msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
491             CFLAGS += -DNO_DEMANGLE
492           endif
493         endif
494       endif
495     endif
496   endif
497 endif
498
499 ifndef NO_ON_EXIT
500   ifeq ($(feature-on-exit), 1)
501     CFLAGS += -DHAVE_ON_EXIT_SUPPORT
502   endif
503 endif
504
505 ifndef NO_BACKTRACE
506   ifeq ($(feature-backtrace), 1)
507     CFLAGS += -DHAVE_BACKTRACE_SUPPORT
508   endif
509 endif
510
511 ifndef NO_LIBNUMA
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);
514     NO_LIBNUMA := 1
515   else
516     CFLAGS += -DHAVE_LIBNUMA_SUPPORT
517     EXTLIBS += -lnuma
518   endif
519 endif
520
521 # Among the variables below, these:
522 #   perfexecdir
523 #   template_dir
524 #   mandir
525 #   infodir
526 #   htmldir
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.
532
533 # Make the path relative to DESTDIR, not to prefix
534 ifndef DESTDIR
535 prefix = $(HOME)
536 endif
537 bindir_relative = bin
538 bindir = $(prefix)/$(bindir_relative)
539 mandir = share/man
540 infodir = share/info
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)
546 sysconfdir = /etc
547 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
548 else
549 sysconfdir = $(prefix)/etc
550 ETC_PERFCONFIG = etc/perfconfig
551 endif
552 lib = lib
553
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))
565
566 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
567 perfexec_instdir = $(perfexecdir)
568 else
569 perfexec_instdir = $(prefix)/$(perfexecdir)
570 endif
571 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))