b3bf931dd2a0cfc512afcd961e8a49fc37f40670
[firefly-linux-kernel-4.4.55.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/feature-tests.mak
55 include $(src-perf)/config/utilities.mak
56
57 ifeq ($(call get-executable,$(FLEX)),)
58   dummy := $(error Error: $(FLEX) is missing on this system, please install it)
59 endif
60
61 ifeq ($(call get-executable,$(BISON)),)
62   dummy := $(error Error: $(BISON) is missing on this system, please install it)
63 endif
64
65 # Treat warnings as errors unless directed not to
66 ifneq ($(WERROR),0)
67   CFLAGS += -Werror
68 endif
69
70 ifeq ("$(origin DEBUG)", "command line")
71   PERF_DEBUG = $(DEBUG)
72 endif
73 ifndef PERF_DEBUG
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 feature_check = $(eval $(feature_check_code)); $(info CHK: config/feature-checks/test-$(1))
93 define feature_check_code
94   feature-$(2) := $(shell make -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
95 endef
96
97 #
98 # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
99 #
100 $(info Testing features:)
101 $(shell make -i -j -C config/feature-checks >/dev/null 2>&1)
102 $(info done)
103
104 FEATURE_TESTS =                         \
105         hello                           \
106         stackprotector-all              \
107         stackprotector                  \
108         volatile-register-var           \
109         fortify-source                  \
110         bionic                          \
111         libelf                          \
112         glibc                           \
113         dwarf                           \
114         libelf-mmap                     \
115         libelf-getphdrnum               \
116         libunwind                       \
117         libaudit                        \
118         libslang                        \
119         gtk2                            \
120         libnuma
121
122 $(foreach test,$(FEATURE_TESTS),$(call feature_check,$(test),$(test)))
123
124 ifeq ($(feature-stackprotector-all), 1)
125   CFLAGS += -fstack-protector-all
126 endif
127
128 ifeq ($(feature-stackprotector), 1)
129   CFLAGS += -Wstack-protector
130 endif
131
132 ifeq ($(feature-volatile-register-var), 1)
133   CFLAGS += -Wvolatile-register-var
134 endif
135
136 ifndef PERF_DEBUG
137   ifeq ($(feature-fortify-source), 1)
138     CFLAGS += -D_FORTIFY_SOURCE=2
139   endif
140 endif
141
142 CFLAGS += -I$(src-perf)/util/include
143 CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
144 CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
145 CFLAGS += -I$(srctree)/arch/$(ARCH)/include
146 CFLAGS += -I$(srctree)/include/uapi
147 CFLAGS += -I$(srctree)/include
148
149 # $(obj-perf)      for generated common-cmds.h
150 # $(obj-perf)/util for generated bison/flex headers
151 ifneq ($(OUTPUT),)
152 CFLAGS += -I$(obj-perf)/util
153 CFLAGS += -I$(obj-perf)
154 endif
155
156 CFLAGS += -I$(src-perf)/util
157 CFLAGS += -I$(src-perf)
158 CFLAGS += -I$(LIB_INCLUDE)
159
160 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
161
162 ifndef NO_BIONIC
163   $(feature_check,bionic)
164   ifeq ($(feature-bionic), 1)
165     BIONIC := 1
166     EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
167     EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
168   endif
169 endif
170
171 ifdef NO_LIBELF
172   NO_DWARF := 1
173   NO_DEMANGLE := 1
174   NO_LIBUNWIND := 1
175 else
176   ifeq ($(feature-libelf), 0)
177     ifeq ($(feature-glibc), 1)
178       LIBC_SUPPORT := 1
179     endif
180     ifeq ($(BIONIC),1)
181       LIBC_SUPPORT := 1
182     endif
183     ifeq ($(LIBC_SUPPORT),1)
184       msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
185
186       NO_LIBELF := 1
187       NO_DWARF := 1
188       NO_DEMANGLE := 1
189     else
190       msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
191     endif
192   else
193     # for linking with debug library, run like:
194     # make DEBUG=1 LIBDW_DIR=/opt/libdw/
195     ifdef LIBDW_DIR
196       LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
197       LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
198     endif
199
200     ifneq ($(feature-dwarf), 1)
201       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);
202       NO_DWARF := 1
203     endif # Dwarf support
204   endif # SOURCE_LIBELF
205 endif # NO_LIBELF
206
207 ifndef NO_LIBELF
208   CFLAGS += -DHAVE_LIBELF_SUPPORT
209   FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
210
211   ifeq ($(feature-libelf-mmap), 1)
212     CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
213   endif
214
215   ifeq ($(feature-libelf-getphdrnum), 1)
216     CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
217   endif
218
219   # include ARCH specific config
220   -include $(src-perf)/arch/$(ARCH)/Makefile
221
222   ifndef NO_DWARF
223     ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
224       msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
225       NO_DWARF := 1
226     else
227       CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
228       LDFLAGS += $(LIBDW_LDFLAGS)
229       EXTLIBS += -lelf -ldw
230     endif # PERF_HAVE_DWARF_REGS
231   endif # NO_DWARF
232 endif # NO_LIBELF
233
234 ifndef NO_LIBELF
235   CFLAGS += -DHAVE_LIBELF_SUPPORT
236   ifeq ($(feature-libelf-mmap), 1)
237     CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
238   endif
239 endif # NO_LIBELF
240
241 # There's only x86 (both 32 and 64) support for CFI unwind so far
242 ifneq ($(ARCH),x86)
243   NO_LIBUNWIND := 1
244 endif
245
246 ifndef NO_LIBUNWIND
247   #
248   # For linking with debug library, run like:
249   #
250   #   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
251   #
252   ifdef LIBUNWIND_DIR
253     LIBUNWIND_CFLAGS  := -I$(LIBUNWIND_DIR)/include
254     LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
255   endif
256
257   ifneq ($(feature-libunwind), 1)
258     msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
259     NO_LIBUNWIND := 1
260   endif
261 endif
262
263 ifndef NO_LIBUNWIND
264   CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
265   EXTLIBS += $(LIBUNWIND_LIBS)
266   CFLAGS += $(LIBUNWIND_CFLAGS)
267   LDFLAGS += $(LIBUNWIND_LDFLAGS)
268 endif
269
270 ifndef NO_LIBAUDIT
271   ifneq ($(feature-libaudit), 1)
272     msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
273     NO_LIBAUDIT := 1
274   else
275     CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
276     EXTLIBS += -laudit
277   endif
278 endif
279
280 ifdef NO_NEWT
281   NO_SLANG=1
282 endif
283
284 ifndef NO_SLANG
285   ifneq ($(feature-libslang), 1)
286     msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
287     NO_SLANG := 1
288   else
289     # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
290     CFLAGS += -I/usr/include/slang
291     CFLAGS += -DHAVE_SLANG_SUPPORT
292     EXTLIBS += -lslang
293   endif
294 endif
295
296 ifndef NO_GTK2
297   FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
298   ifneq ($(feature-gtk2), 1)
299     msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
300     NO_GTK2 := 1
301   else
302     ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2),-DHAVE_GTK_INFO_BAR_SUPPORT),y)
303       CFLAGS += -DHAVE_GTK_INFO_BAR_SUPPORT
304     endif
305     CFLAGS += -DHAVE_GTK2_SUPPORT
306     CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
307     EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
308   endif
309 endif
310
311 grep-libs  = $(filter -l%,$(1))
312 strip-libs = $(filter-out -l%,$(1))
313
314 ifdef NO_LIBPERL
315   CFLAGS += -DNO_LIBPERL
316 else
317   PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
318   PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
319   PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
320   PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
321   FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
322
323   ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED),perl),y)
324     CFLAGS += -DNO_LIBPERL
325     NO_LIBPERL := 1
326   else
327     LDFLAGS += $(PERL_EMBED_LDFLAGS)
328     EXTLIBS += $(PERL_EMBED_LIBADD)
329   endif
330 endif
331
332 disable-python = $(eval $(disable-python_code))
333 define disable-python_code
334   CFLAGS += -DNO_LIBPYTHON
335   $(if $(1),$(warning No $(1) was found))
336   $(warning Python support will not be built)
337   NO_LIBPYTHON := 1
338 endef
339
340 override PYTHON := \
341   $(call get-executable-or-default,PYTHON,python)
342
343 ifndef PYTHON
344   $(call disable-python,python interpreter)
345 else
346
347   PYTHON_WORD := $(call shell-wordify,$(PYTHON))
348
349   ifdef NO_LIBPYTHON
350     $(call disable-python)
351   else
352
353     override PYTHON_CONFIG := \
354       $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
355
356     ifndef PYTHON_CONFIG
357       $(call disable-python,python-config tool)
358     else
359
360       PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
361
362       PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
363       PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
364       PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
365       PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
366       FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
367
368       ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED),python),y)
369         $(call disable-python,Python.h (for Python 2.x))
370       else
371
372         ifneq ($(call try-cc,$(SOURCE_PYTHON_VERSION),$(FLAGS_PYTHON_EMBED),python version),y)
373           $(warning Python 3 is not yet supported; please set)
374           $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
375           $(warning If you also have Python 2 installed, then)
376           $(warning try something like:)
377           $(warning $(and ,))
378           $(warning $(and ,)  make PYTHON=python2)
379           $(warning $(and ,))
380           $(warning Otherwise, disable Python support entirely:)
381           $(warning $(and ,))
382           $(warning $(and ,)  make NO_LIBPYTHON=1)
383           $(warning $(and ,))
384           $(error   $(and ,))
385         else
386           LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
387           EXTLIBS += $(PYTHON_EMBED_LIBADD)
388           LANG_BINDINGS += $(obj-perf)python/perf.so
389         endif
390       endif
391     endif
392   endif
393 endif
394
395 ifdef NO_DEMANGLE
396   CFLAGS += -DNO_DEMANGLE
397 else
398   ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
399     EXTLIBS += -liberty
400     CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
401   else
402     FLAGS_BFD=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -lbfd
403     has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD),libbfd)
404     ifeq ($(has_bfd),y)
405       EXTLIBS += -lbfd
406     else
407       FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
408       has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY),liberty)
409       ifeq ($(has_bfd_iberty),y)
410         EXTLIBS += -lbfd -liberty
411       else
412         FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
413         has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z),libz)
414         ifeq ($(has_bfd_iberty_z),y)
415           EXTLIBS += -lbfd -liberty -lz
416         else
417           FLAGS_CPLUS_DEMANGLE=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -liberty
418           has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE),demangle)
419           ifeq ($(has_cplus_demangle),y)
420             EXTLIBS += -liberty
421             CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
422           else
423             msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
424             CFLAGS += -DNO_DEMANGLE
425           endif
426         endif
427       endif
428     endif
429   endif
430 endif
431
432 ifndef NO_STRLCPY
433   ifeq ($(call try-cc,$(SOURCE_STRLCPY),,-DHAVE_STRLCPY_SUPPORT),y)
434     CFLAGS += -DHAVE_STRLCPY_SUPPORT
435   endif
436 endif
437
438 ifndef NO_ON_EXIT
439   ifeq ($(call try-cc,$(SOURCE_ON_EXIT),,-DHAVE_ON_EXIT_SUPPORT),y)
440     CFLAGS += -DHAVE_ON_EXIT_SUPPORT
441   endif
442 endif
443
444 ifndef NO_BACKTRACE
445   ifeq ($(call try-cc,$(SOURCE_BACKTRACE),,-DHAVE_BACKTRACE_SUPPORT),y)
446     CFLAGS += -DHAVE_BACKTRACE_SUPPORT
447   endif
448 endif
449
450 ifndef NO_LIBNUMA
451   ifeq ($(feature-libnuma), 0)
452     msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
453     NO_LIBNUMA := 1
454   else
455     CFLAGS += -DHAVE_LIBNUMA_SUPPORT
456     EXTLIBS += -lnuma
457   endif
458 endif
459
460 # Among the variables below, these:
461 #   perfexecdir
462 #   template_dir
463 #   mandir
464 #   infodir
465 #   htmldir
466 #   ETC_PERFCONFIG (but not sysconfdir)
467 # can be specified as a relative path some/where/else;
468 # this is interpreted as relative to $(prefix) and "perf" at
469 # runtime figures out where they are based on the path to the executable.
470 # This can help installing the suite in a relocatable way.
471
472 # Make the path relative to DESTDIR, not to prefix
473 ifndef DESTDIR
474 prefix = $(HOME)
475 endif
476 bindir_relative = bin
477 bindir = $(prefix)/$(bindir_relative)
478 mandir = share/man
479 infodir = share/info
480 perfexecdir = libexec/perf-core
481 sharedir = $(prefix)/share
482 template_dir = share/perf-core/templates
483 htmldir = share/doc/perf-doc
484 ifeq ($(prefix),/usr)
485 sysconfdir = /etc
486 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
487 else
488 sysconfdir = $(prefix)/etc
489 ETC_PERFCONFIG = etc/perfconfig
490 endif
491 lib = lib
492
493 # Shell quote (do not use $(call) to accommodate ancient setups);
494 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
495 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
496 bindir_SQ = $(subst ','\'',$(bindir))
497 mandir_SQ = $(subst ','\'',$(mandir))
498 infodir_SQ = $(subst ','\'',$(infodir))
499 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
500 template_dir_SQ = $(subst ','\'',$(template_dir))
501 htmldir_SQ = $(subst ','\'',$(htmldir))
502 prefix_SQ = $(subst ','\'',$(prefix))
503 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
504
505 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
506 perfexec_instdir = $(perfexecdir)
507 else
508 perfexec_instdir = $(prefix)/$(perfexecdir)
509 endif
510 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))