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