perf build: Rename feature_print_var_code to print_var_code
[firefly-linux-kernel-4.4.55.git] / tools / perf / config / Makefile
1
2 ifeq ($(src-perf),)
3 src-perf := $(srctree)/tools/perf
4 endif
5
6 ifeq ($(obj-perf),)
7 obj-perf := $(OUTPUT)
8 endif
9
10 ifneq ($(obj-perf),)
11 obj-perf := $(abspath $(obj-perf))/
12 endif
13
14 $(shell echo -n > .config-detected)
15 detected     = $(shell echo "$(1)=y"       >> .config-detected)
16 detected_var = $(shell echo "$(1)=$($(1))" >> .config-detected)
17
18 CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
19
20 include $(src-perf)/config/Makefile.arch
21
22 $(call detected_var,ARCH)
23
24 NO_PERF_REGS := 1
25
26 # Additional ARCH settings for x86
27 ifeq ($(ARCH),x86)
28   $(call detected,CONFIG_X86)
29   ifeq (${IS_64_BIT}, 1)
30     CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
31     ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
32     LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
33     $(call detected,CONFIG_X86_64)
34   else
35     LIBUNWIND_LIBS = -lunwind -lunwind-x86
36   endif
37   NO_PERF_REGS := 0
38 endif
39
40 ifeq ($(ARCH),arm)
41   NO_PERF_REGS := 0
42   LIBUNWIND_LIBS = -lunwind -lunwind-arm
43 endif
44
45 ifeq ($(ARCH),arm64)
46   NO_PERF_REGS := 0
47   LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
48 endif
49
50 ifeq ($(NO_PERF_REGS),0)
51   $(call detected,CONFIG_PERF_REGS)
52 endif
53
54 # So far there's only x86 and arm libdw unwind support merged in perf.
55 # Disable it on all other architectures in case libdw unwind
56 # support is detected in system. Add supported architectures
57 # to the check.
58 ifneq ($(ARCH),$(filter $(ARCH),x86 arm))
59   NO_LIBDW_DWARF_UNWIND := 1
60 endif
61
62 ifeq ($(LIBUNWIND_LIBS),)
63   NO_LIBUNWIND := 1
64 else
65   #
66   # For linking with debug library, run like:
67   #
68   #   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
69   #
70   ifdef LIBUNWIND_DIR
71     LIBUNWIND_CFLAGS  = -I$(LIBUNWIND_DIR)/include
72     LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
73   endif
74   LIBUNWIND_LDFLAGS += $(LIBUNWIND_LIBS)
75
76   # Set per-feature check compilation flags
77   FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
78   FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS)
79   FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
80   FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS)
81 endif
82
83 ifeq ($(NO_PERF_REGS),0)
84   CFLAGS += -DHAVE_PERF_REGS_SUPPORT
85 endif
86
87 ifndef NO_LIBELF
88   # for linking with debug library, run like:
89   # make DEBUG=1 LIBDW_DIR=/opt/libdw/
90   ifdef LIBDW_DIR
91     LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
92     LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
93   endif
94   FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
95   FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) -ldw
96 endif
97
98 ifndef NO_LIBBABELTRACE
99   # for linking with debug library, run like:
100   # make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
101   ifdef LIBBABELTRACE_DIR
102     LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
103     LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
104   endif
105   FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
106   FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
107 endif
108
109 # include ARCH specific config
110 -include $(src-perf)/arch/$(ARCH)/Makefile
111
112 include $(src-perf)/config/utilities.mak
113
114 ifeq ($(call get-executable,$(FLEX)),)
115   dummy := $(error Error: $(FLEX) is missing on this system, please install it)
116 endif
117
118 ifeq ($(call get-executable,$(BISON)),)
119   dummy := $(error Error: $(BISON) is missing on this system, please install it)
120 endif
121
122 # Treat warnings as errors unless directed not to
123 ifneq ($(WERROR),0)
124   CFLAGS += -Werror
125 endif
126
127 ifndef DEBUG
128   DEBUG := 0
129 endif
130
131 ifeq ($(DEBUG),0)
132   CFLAGS += -O6
133 endif
134
135 ifdef PARSER_DEBUG
136   PARSER_DEBUG_BISON := -t
137   PARSER_DEBUG_FLEX  := -d
138   CFLAGS             += -DPARSER_DEBUG
139   $(call detected_var,PARSER_DEBUG_BISON)
140   $(call detected_var,PARSER_DEBUG_FLEX)
141 endif
142
143 ifndef NO_LIBPYTHON
144   # Try different combinations to accommodate systems that only have
145   # python[2][-config] in weird combinations but always preferring
146   # python2 and python2-config as per pep-0394. If we catch a
147   # python[-config] in version 3, the version check will kill it.
148   PYTHON2 := $(if $(call get-executable,python2),python2,python)
149   override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2))
150   PYTHON2_CONFIG := \
151     $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config)
152   override PYTHON_CONFIG := \
153     $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
154
155   PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
156
157   PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
158   PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
159
160   FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
161   FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
162   FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
163   FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
164 endif
165
166 CFLAGS += -fno-omit-frame-pointer
167 CFLAGS += -ggdb3
168 CFLAGS += -funwind-tables
169 CFLAGS += -Wall
170 CFLAGS += -Wextra
171 CFLAGS += -std=gnu99
172
173 # Enforce a non-executable stack, as we may regress (again) in the future by
174 # adding assembler files missing the .GNU-stack linker note.
175 LDFLAGS += -Wl,-z,noexecstack
176
177 EXTLIBS = -lpthread -lrt -lm -ldl
178
179 ifneq ($(OUTPUT),)
180   OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
181   $(shell mkdir -p $(OUTPUT_FEATURES))
182 endif
183
184 feature_check = $(eval $(feature_check_code))
185 define feature_check_code
186   feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C config/feature-checks test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
187 endef
188
189 feature_set = $(eval $(feature_set_code))
190 define feature_set_code
191   feature-$(1) := 1
192 endef
193
194 #
195 # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
196 #
197
198 #
199 # Note that this is not a complete list of all feature tests, just
200 # those that are typically built on a fully configured system.
201 #
202 # [ Feature tests not mentioned here have to be built explicitly in
203 #   the rule that uses them - an example for that is the 'bionic'
204 #   feature check. ]
205 #
206 FEATURE_TESTS =                 \
207         backtrace                       \
208         dwarf                           \
209         fortify-source                  \
210         sync-compare-and-swap           \
211         glibc                           \
212         gtk2                            \
213         gtk2-infobar                    \
214         libaudit                        \
215         libbfd                          \
216         libelf                          \
217         libelf-getphdrnum               \
218         libelf-mmap                     \
219         libnuma                         \
220         libperl                         \
221         libpython                       \
222         libpython-version               \
223         libslang                        \
224         libunwind                       \
225         pthread-attr-setaffinity-np     \
226         stackprotector-all              \
227         timerfd                         \
228         libdw-dwarf-unwind              \
229         zlib
230
231 FEATURE_DISPLAY =                       \
232         dwarf                           \
233         glibc                           \
234         gtk2                            \
235         libaudit                        \
236         libbfd                          \
237         libelf                          \
238         libnuma                         \
239         libperl                         \
240         libpython                       \
241         libslang                        \
242         libunwind                       \
243         libdw-dwarf-unwind              \
244         zlib
245
246 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
247 # If in the future we need per-feature checks/flags for features not
248 # mentioned in this list we need to refactor this ;-).
249 set_test_all_flags = $(eval $(set_test_all_flags_code))
250 define set_test_all_flags_code
251   FEATURE_CHECK_CFLAGS-all  += $(FEATURE_CHECK_CFLAGS-$(1))
252   FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
253 endef
254
255 $(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
256
257 #
258 # Special fast-path for the 'all features are available' case:
259 #
260 $(call feature_check,all,$(MSG))
261
262 #
263 # Just in case the build freshly failed, make sure we print the
264 # feature matrix:
265 #
266 ifeq ($(feature-all), 1)
267   #
268   # test-all.c passed - just set all the core feature flags to 1:
269   #
270   $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
271 else
272   $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(addsuffix .bin,$(FEATURE_TESTS)) >/dev/null 2>&1)
273   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
274 endif
275
276 ifeq ($(feature-stackprotector-all), 1)
277   CFLAGS += -fstack-protector-all
278 endif
279
280 ifeq ($(DEBUG),0)
281   ifeq ($(feature-fortify-source), 1)
282     CFLAGS += -D_FORTIFY_SOURCE=2
283   endif
284 endif
285
286 CFLAGS += -I$(src-perf)/util/include
287 CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
288 CFLAGS += -I$(srctree)/tools/include/
289 CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
290 CFLAGS += -I$(srctree)/arch/$(ARCH)/include
291 CFLAGS += -I$(srctree)/include/uapi
292 CFLAGS += -I$(srctree)/include
293
294 # $(obj-perf)      for generated common-cmds.h
295 # $(obj-perf)/util for generated bison/flex headers
296 ifneq ($(OUTPUT),)
297 CFLAGS += -I$(obj-perf)/util
298 CFLAGS += -I$(obj-perf)
299 endif
300
301 CFLAGS += -I$(src-perf)/util
302 CFLAGS += -I$(src-perf)
303 CFLAGS += -I$(srctree)/tools/lib/
304
305 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
306
307 ifeq ($(feature-sync-compare-and-swap), 1)
308   CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
309 endif
310
311 ifeq ($(feature-pthread-attr-setaffinity-np), 1)
312   CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
313 endif
314
315 ifndef NO_BIONIC
316   $(call feature_check,bionic)
317   ifeq ($(feature-bionic), 1)
318     BIONIC := 1
319     EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
320     EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
321   endif
322 endif
323
324 ifdef NO_LIBELF
325   NO_DWARF := 1
326   NO_DEMANGLE := 1
327   NO_LIBUNWIND := 1
328   NO_LIBDW_DWARF_UNWIND := 1
329 else
330   ifeq ($(feature-libelf), 0)
331     ifeq ($(feature-glibc), 1)
332       LIBC_SUPPORT := 1
333     endif
334     ifeq ($(BIONIC),1)
335       LIBC_SUPPORT := 1
336     endif
337     ifeq ($(LIBC_SUPPORT),1)
338       msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
339
340       NO_LIBELF := 1
341       NO_DWARF := 1
342       NO_DEMANGLE := 1
343       NO_LIBUNWIND := 1
344       NO_LIBDW_DWARF_UNWIND := 1
345     else
346       ifneq ($(filter s% -static%,$(LDFLAGS),),)
347         msg := $(error No static glibc found, please install glibc-static);
348       else
349         msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
350       endif
351     endif
352   else
353     ifndef NO_LIBDW_DWARF_UNWIND
354       ifneq ($(feature-libdw-dwarf-unwind),1)
355         NO_LIBDW_DWARF_UNWIND := 1
356         msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
357       endif
358     endif
359     ifneq ($(feature-dwarf), 1)
360       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);
361       NO_DWARF := 1
362     endif # Dwarf support
363   endif # libelf support
364 endif # NO_LIBELF
365
366 ifndef NO_LIBELF
367   CFLAGS += -DHAVE_LIBELF_SUPPORT
368   EXTLIBS += -lelf
369   $(call detected,CONFIG_LIBELF)
370
371   ifeq ($(feature-libelf-mmap), 1)
372     CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
373   endif
374
375   ifeq ($(feature-libelf-getphdrnum), 1)
376     CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
377   endif
378
379   # include ARCH specific config
380   -include $(src-perf)/arch/$(ARCH)/Makefile
381
382   ifndef NO_DWARF
383     ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
384       msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
385       NO_DWARF := 1
386     else
387       CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
388       LDFLAGS += $(LIBDW_LDFLAGS)
389       EXTLIBS += -ldw
390       $(call detected,CONFIG_DWARF)
391     endif # PERF_HAVE_DWARF_REGS
392   endif # NO_DWARF
393 endif # NO_LIBELF
394
395 ifeq ($(ARCH),powerpc)
396   ifndef NO_DWARF
397     CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
398   endif
399 endif
400
401 ifndef NO_LIBUNWIND
402   ifneq ($(feature-libunwind), 1)
403     msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
404     NO_LIBUNWIND := 1
405   endif
406 endif
407
408 dwarf-post-unwind := 1
409 dwarf-post-unwind-text := BUG
410
411 # setup DWARF post unwinder
412 ifdef NO_LIBUNWIND
413   ifdef NO_LIBDW_DWARF_UNWIND
414     msg := $(warning Disabling post unwind, no support found.);
415     dwarf-post-unwind := 0
416   else
417     dwarf-post-unwind-text := libdw
418     $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
419   endif
420 else
421   dwarf-post-unwind-text := libunwind
422   $(call detected,CONFIG_LIBUNWIND)
423   # Enable libunwind support by default.
424   ifndef NO_LIBDW_DWARF_UNWIND
425     NO_LIBDW_DWARF_UNWIND := 1
426   endif
427 endif
428
429 ifeq ($(dwarf-post-unwind),1)
430   CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
431   $(call detected,CONFIG_DWARF_UNWIND)
432 else
433   NO_DWARF_UNWIND := 1
434 endif
435
436 ifndef NO_LIBUNWIND
437   ifeq ($(ARCH),$(filter $(ARCH),arm arm64))
438     $(call feature_check,libunwind-debug-frame)
439     ifneq ($(feature-libunwind-debug-frame), 1)
440       msg := $(warning No debug_frame support found in libunwind);
441       CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
442     endif
443   else
444     # non-ARM has no dwarf_find_debug_frame() function:
445     CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
446   endif
447   CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
448   EXTLIBS += $(LIBUNWIND_LIBS)
449   CFLAGS  += $(LIBUNWIND_CFLAGS)
450   LDFLAGS += $(LIBUNWIND_LDFLAGS)
451 endif
452
453 ifndef NO_LIBAUDIT
454   ifneq ($(feature-libaudit), 1)
455     msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
456     NO_LIBAUDIT := 1
457   else
458     CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
459     EXTLIBS += -laudit
460     $(call detected,CONFIG_AUDIT)
461   endif
462 endif
463
464 ifdef NO_NEWT
465   NO_SLANG=1
466 endif
467
468 ifndef NO_SLANG
469   ifneq ($(feature-libslang), 1)
470     msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
471     NO_SLANG := 1
472   else
473     # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
474     CFLAGS += -I/usr/include/slang
475     CFLAGS += -DHAVE_SLANG_SUPPORT
476     EXTLIBS += -lslang
477     $(call detected,CONFIG_SLANG)
478   endif
479 endif
480
481 ifndef NO_GTK2
482   FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
483   ifneq ($(feature-gtk2), 1)
484     msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
485     NO_GTK2 := 1
486   else
487     ifeq ($(feature-gtk2-infobar), 1)
488       GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
489     endif
490     CFLAGS += -DHAVE_GTK2_SUPPORT
491     GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
492     GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
493     EXTLIBS += -ldl
494   endif
495 endif
496
497 grep-libs  = $(filter -l%,$(1))
498 strip-libs = $(filter-out -l%,$(1))
499
500 ifdef NO_LIBPERL
501   CFLAGS += -DNO_LIBPERL
502 else
503   PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
504   PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
505   PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
506   PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
507   FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
508
509   ifneq ($(feature-libperl), 1)
510     CFLAGS += -DNO_LIBPERL
511     NO_LIBPERL := 1
512     msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
513   else
514     LDFLAGS += $(PERL_EMBED_LDFLAGS)
515     EXTLIBS += $(PERL_EMBED_LIBADD)
516     $(call detected,CONFIG_LIBPERL)
517   endif
518 endif
519
520 ifeq ($(feature-timerfd), 1)
521   CFLAGS += -DHAVE_TIMERFD_SUPPORT
522 else
523   msg := $(warning No timerfd support. Disables 'perf kvm stat live');
524 endif
525
526 disable-python = $(eval $(disable-python_code))
527 define disable-python_code
528   CFLAGS += -DNO_LIBPYTHON
529   $(warning $1)
530   NO_LIBPYTHON := 1
531 endef
532
533 ifdef NO_LIBPYTHON
534   $(call disable-python,Python support disabled by user)
535 else
536
537   ifndef PYTHON
538     $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
539   else
540     PYTHON_WORD := $(call shell-wordify,$(PYTHON))
541
542     ifndef PYTHON_CONFIG
543       $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
544     else
545
546       PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
547
548       PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
549       PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
550       PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
551       PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
552       FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
553
554       ifneq ($(feature-libpython), 1)
555         $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
556       else
557
558         ifneq ($(feature-libpython-version), 1)
559           $(warning Python 3 is not yet supported; please set)
560           $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
561           $(warning If you also have Python 2 installed, then)
562           $(warning try something like:)
563           $(warning $(and ,))
564           $(warning $(and ,)  make PYTHON=python2)
565           $(warning $(and ,))
566           $(warning Otherwise, disable Python support entirely:)
567           $(warning $(and ,))
568           $(warning $(and ,)  make NO_LIBPYTHON=1)
569           $(warning $(and ,))
570           $(error   $(and ,))
571         else
572           LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
573           EXTLIBS += $(PYTHON_EMBED_LIBADD)
574           LANG_BINDINGS += $(obj-perf)python/perf.so
575           $(call detected,CONFIG_LIBPYTHON)
576         endif
577       endif
578     endif
579   endif
580 endif
581
582 ifeq ($(feature-libbfd), 1)
583   EXTLIBS += -lbfd
584
585   # call all detections now so we get correct
586   # status in VF output
587   $(call feature_check,liberty)
588   $(call feature_check,liberty-z)
589   $(call feature_check,cplus-demangle)
590
591   ifeq ($(feature-liberty), 1)
592     EXTLIBS += -liberty
593   else
594     ifeq ($(feature-liberty-z), 1)
595       EXTLIBS += -liberty -lz
596     endif
597   endif
598 endif
599
600 ifdef NO_DEMANGLE
601   CFLAGS += -DNO_DEMANGLE
602 else
603   ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
604     EXTLIBS += -liberty
605     CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
606   else
607     ifneq ($(feature-libbfd), 1)
608       ifneq ($(feature-liberty), 1)
609         ifneq ($(feature-liberty-z), 1)
610           # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
611           # or any of 'bfd iberty z' trinity
612           ifeq ($(feature-cplus-demangle), 1)
613             EXTLIBS += -liberty
614             CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
615           else
616             msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
617             CFLAGS += -DNO_DEMANGLE
618           endif
619         endif
620       endif
621     endif
622   endif
623 endif
624
625 ifneq ($(filter -lbfd,$(EXTLIBS)),)
626   CFLAGS += -DHAVE_LIBBFD_SUPPORT
627 endif
628
629 ifndef NO_ZLIB
630   ifeq ($(feature-zlib), 1)
631     CFLAGS += -DHAVE_ZLIB_SUPPORT
632     EXTLIBS += -lz
633     $(call detected,CONFIG_ZLIB)
634   else
635     NO_ZLIB := 1
636   endif
637 endif
638
639 ifndef NO_BACKTRACE
640   ifeq ($(feature-backtrace), 1)
641     CFLAGS += -DHAVE_BACKTRACE_SUPPORT
642   endif
643 endif
644
645 ifndef NO_LIBNUMA
646   ifeq ($(feature-libnuma), 0)
647     msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
648     NO_LIBNUMA := 1
649   else
650     CFLAGS += -DHAVE_LIBNUMA_SUPPORT
651     EXTLIBS += -lnuma
652     $(call detected,CONFIG_NUMA)
653   endif
654 endif
655
656 ifdef HAVE_KVM_STAT_SUPPORT
657     CFLAGS += -DHAVE_KVM_STAT_SUPPORT
658 endif
659
660 ifeq (${IS_64_BIT}, 1)
661   ifndef NO_PERF_READ_VDSO32
662     $(call feature_check,compile-32)
663     ifeq ($(feature-compile-32), 1)
664       CFLAGS += -DHAVE_PERF_READ_VDSO32
665     else
666       NO_PERF_READ_VDSO32 := 1
667     endif
668   endif
669   ifneq (${IS_X86_64}, 1)
670     NO_PERF_READ_VDSOX32 := 1
671   endif
672   ifndef NO_PERF_READ_VDSOX32
673     $(call feature_check,compile-x32)
674     ifeq ($(feature-compile-x32), 1)
675       CFLAGS += -DHAVE_PERF_READ_VDSOX32
676     else
677       NO_PERF_READ_VDSOX32 := 1
678     endif
679   endif
680 else
681   NO_PERF_READ_VDSO32 := 1
682   NO_PERF_READ_VDSOX32 := 1
683 endif
684
685 ifndef NO_LIBBABELTRACE
686   $(call feature_check,libbabeltrace)
687   ifeq ($(feature-libbabeltrace), 1)
688     CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
689     LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
690     EXTLIBS += -lbabeltrace-ctf
691     $(call detected,CONFIG_LIBBABELTRACE)
692   else
693     msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
694     NO_LIBBABELTRACE := 1
695   endif
696 endif
697
698 # Among the variables below, these:
699 #   perfexecdir
700 #   template_dir
701 #   mandir
702 #   infodir
703 #   htmldir
704 #   ETC_PERFCONFIG (but not sysconfdir)
705 # can be specified as a relative path some/where/else;
706 # this is interpreted as relative to $(prefix) and "perf" at
707 # runtime figures out where they are based on the path to the executable.
708 # This can help installing the suite in a relocatable way.
709
710 # Make the path relative to DESTDIR, not to prefix
711 ifndef DESTDIR
712 prefix ?= $(HOME)
713 endif
714 bindir_relative = bin
715 bindir = $(prefix)/$(bindir_relative)
716 mandir = share/man
717 infodir = share/info
718 perfexecdir = libexec/perf-core
719 sharedir = $(prefix)/share
720 template_dir = share/perf-core/templates
721 htmldir = share/doc/perf-doc
722 ifeq ($(prefix),/usr)
723 sysconfdir = /etc
724 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
725 else
726 sysconfdir = $(prefix)/etc
727 ETC_PERFCONFIG = etc/perfconfig
728 endif
729 ifndef lib
730 ifeq ($(IS_X86_64),1)
731 lib = lib64
732 else
733 lib = lib
734 endif
735 endif # lib
736 libdir = $(prefix)/$(lib)
737
738 # Shell quote (do not use $(call) to accommodate ancient setups);
739 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
740 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
741 bindir_SQ = $(subst ','\'',$(bindir))
742 mandir_SQ = $(subst ','\'',$(mandir))
743 infodir_SQ = $(subst ','\'',$(infodir))
744 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
745 template_dir_SQ = $(subst ','\'',$(template_dir))
746 htmldir_SQ = $(subst ','\'',$(htmldir))
747 prefix_SQ = $(subst ','\'',$(prefix))
748 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
749 libdir_SQ = $(subst ','\'',$(libdir))
750
751 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
752 perfexec_instdir = $(perfexecdir)
753 else
754 perfexec_instdir = $(prefix)/$(perfexecdir)
755 endif
756 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
757
758 # If we install to $(HOME) we keep the traceevent default:
759 # $(HOME)/.traceevent/plugins
760 # Otherwise we install plugins into the global $(libdir).
761 ifdef DESTDIR
762 plugindir=$(libdir)/traceevent/plugins
763 plugindir_SQ= $(subst ','\'',$(plugindir))
764 endif
765
766 #
767 # Print the result of the feature test:
768 #
769 feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
770
771 define feature_print_status_code
772   ifeq ($(feature-$(1)), 1)
773     MSG = $(shell printf '...%30s: [ \033[32mon\033[m  ]' $(1))
774   else
775     MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
776   endif
777 endef
778
779 print_var = $(eval $(print_var_code)) $(info $(MSG))
780 define print_var_code
781     MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
782 endef
783
784 feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
785 define feature_print_text_code
786     MSG = $(shell printf '...%30s: %s' $(1) $(2))
787 endef
788
789 FEATURE_DUMP := $(foreach feat,$(FEATURE_DISPLAY),feature-$(feat)($(feature-$(feat))))
790 FEATURE_DUMP_FILE := $(shell touch $(OUTPUT)FEATURE-DUMP; cat $(OUTPUT)FEATURE-DUMP)
791
792 ifeq ($(dwarf-post-unwind),1)
793   FEATURE_DUMP += dwarf-post-unwind($(dwarf-post-unwind-text))
794 endif
795
796 # The $(feature_display) controls the default detection message
797 # output. It's set if:
798 # - detected features differes from stored features from
799 #   last build (in FEATURE-DUMP file)
800 # - one of the $(FEATURE_DISPLAY) is not detected
801 # - VF is enabled
802
803 ifneq ("$(FEATURE_DUMP)","$(FEATURE_DUMP_FILE)")
804   $(shell echo "$(FEATURE_DUMP)" > $(OUTPUT)FEATURE-DUMP)
805   feature_display := 1
806 endif
807
808 feature_check = $(eval $(feature_check_code))
809 define feature_check_code
810   ifneq ($(feature-$(1)), 1)
811     feature_display := 1
812   endif
813 endef
814
815 $(foreach feat,$(FEATURE_DISPLAY),$(call feature_check,$(feat)))
816
817 ifeq ($(VF),1)
818   feature_display := 1
819   feature_verbose := 1
820 endif
821
822 ifeq ($(feature_display),1)
823   $(info )
824   $(info Auto-detecting system features:)
825   $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
826
827   ifeq ($(dwarf-post-unwind),1)
828     $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
829   endif
830
831   ifneq ($(feature_verbose),1)
832     $(info )
833   endif
834 endif
835
836 ifeq ($(feature_verbose),1)
837   TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
838   $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
839   $(info )
840   $(call print_var,prefix)
841   $(call print_var,bindir)
842   $(call print_var,libdir)
843   $(call print_var,sysconfdir)
844   $(call print_var,LIBUNWIND_DIR)
845   $(call print_var,LIBDW_DIR)
846   $(info )
847 endif
848
849 $(call detected_var,bindir_SQ)
850 $(call detected_var,PYTHON_WORD)
851 ifneq ($(OUTPUT),)
852 $(call detected_var,OUTPUT)
853 endif
854 $(call detected_var,htmldir_SQ)
855 $(call detected_var,infodir_SQ)
856 $(call detected_var,mandir_SQ)
857 $(call detected_var,ETC_PERFCONFIG_SQ)
858 $(call detected_var,prefix_SQ)
859 $(call detected_var,perfexecdir_SQ)
860 $(call detected_var,LIBDIR)
861 $(call detected_var,GTK_CFLAGS)
862 $(call detected_var,PERL_EMBED_CCOPTS)
863 $(call detected_var,PYTHON_EMBED_CCOPTS)