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