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