GNU Linux-libre 4.19.211-gnu1
[releases.git] / tools / perf / Makefile.config
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 printf "" > $(OUTPUT).config-detected)
15 detected     = $(shell echo "$(1)=y"       >> $(OUTPUT).config-detected)
16 detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
17
18 CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
19
20 include $(srctree)/tools/scripts/Makefile.arch
21
22 $(call detected_var,SRCARCH)
23
24 NO_PERF_REGS := 1
25 NO_SYSCALL_TABLE := 1
26
27 # Additional ARCH settings for ppc
28 ifeq ($(SRCARCH),powerpc)
29   NO_PERF_REGS := 0
30   NO_SYSCALL_TABLE := 0
31   CFLAGS += -I$(OUTPUT)arch/powerpc/include/generated
32   LIBUNWIND_LIBS := -lunwind -lunwind-ppc64
33 endif
34
35 # Additional ARCH settings for x86
36 ifeq ($(SRCARCH),x86)
37   $(call detected,CONFIG_X86)
38   ifeq (${IS_64_BIT}, 1)
39     NO_SYSCALL_TABLE := 0
40     CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT -I$(OUTPUT)arch/x86/include/generated
41     ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
42     LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma
43     $(call detected,CONFIG_X86_64)
44   else
45     LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind
46   endif
47   NO_PERF_REGS := 0
48 endif
49
50 ifeq ($(SRCARCH),arm)
51   NO_PERF_REGS := 0
52   LIBUNWIND_LIBS = -lunwind -lunwind-arm
53 endif
54
55 ifeq ($(SRCARCH),arm64)
56   NO_PERF_REGS := 0
57   NO_SYSCALL_TABLE := 0
58   CFLAGS += -I$(OUTPUT)arch/arm64/include/generated
59   LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
60 endif
61
62 ifeq ($(ARCH),s390)
63   NO_PERF_REGS := 0
64   NO_SYSCALL_TABLE := 0
65   CFLAGS += -fPIC -I$(OUTPUT)arch/s390/include/generated
66 endif
67
68 ifeq ($(NO_PERF_REGS),0)
69   $(call detected,CONFIG_PERF_REGS)
70 endif
71
72 ifneq ($(NO_SYSCALL_TABLE),1)
73   CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
74 endif
75
76 # So far there's only x86 and arm libdw unwind support merged in perf.
77 # Disable it on all other architectures in case libdw unwind
78 # support is detected in system. Add supported architectures
79 # to the check.
80 ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390))
81   NO_LIBDW_DWARF_UNWIND := 1
82 endif
83
84 ifeq ($(LIBUNWIND_LIBS),)
85   NO_LIBUNWIND := 1
86 endif
87 #
88 # For linking with debug library, run like:
89 #
90 #   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
91 #
92
93 libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
94 define libunwind_arch_set_flags_code
95   FEATURE_CHECK_CFLAGS-libunwind-$(1)  = -I$(LIBUNWIND_DIR)/include
96   FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
97 endef
98
99 ifdef LIBUNWIND_DIR
100   LIBUNWIND_CFLAGS  = -I$(LIBUNWIND_DIR)/include
101   LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
102   LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
103   $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
104 endif
105
106 # Set per-feature check compilation flags
107 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
108 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
109 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
110 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
111
112 ifdef CSINCLUDES
113   LIBOPENCSD_CFLAGS := -I$(CSINCLUDES)
114 endif
115 OPENCSDLIBS := -lopencsd_c_api -lopencsd
116 ifdef CSLIBS
117   LIBOPENCSD_LDFLAGS := -L$(CSLIBS)
118 endif
119 FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS)
120 FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS)
121
122 ifeq ($(NO_PERF_REGS),0)
123   CFLAGS += -DHAVE_PERF_REGS_SUPPORT
124 endif
125
126 # for linking with debug library, run like:
127 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
128 ifdef LIBDW_DIR
129   LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
130   LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
131 endif
132 DWARFLIBS := -ldw
133 ifeq ($(findstring -static,${LDFLAGS}),-static)
134   DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
135 endif
136 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
137 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
138
139 # for linking with debug library, run like:
140 # make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
141 ifdef LIBBABELTRACE_DIR
142   LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
143   LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
144 endif
145 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
146 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
147
148 FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
149 # include ARCH specific config
150 -include $(src-perf)/arch/$(SRCARCH)/Makefile
151
152 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
153   CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
154 endif
155
156 include $(srctree)/tools/scripts/utilities.mak
157
158 ifeq ($(call get-executable,$(FLEX)),)
159   dummy := $(error Error: $(FLEX) is missing on this system, please install it)
160 endif
161
162 ifeq ($(call get-executable,$(BISON)),)
163   dummy := $(error Error: $(BISON) is missing on this system, please install it)
164 endif
165
166 # Treat warnings as errors unless directed not to
167 ifneq ($(WERROR),0)
168   CFLAGS += -Werror
169   CXXFLAGS += -Werror
170 endif
171
172 ifndef DEBUG
173   DEBUG := 0
174 endif
175
176 ifeq ($(DEBUG),0)
177 ifeq ($(CC_NO_CLANG), 0)
178   CFLAGS += -O3
179 else
180   CFLAGS += -O6
181 endif
182 endif
183
184 ifdef PARSER_DEBUG
185   PARSER_DEBUG_BISON := -t
186   PARSER_DEBUG_FLEX  := -d
187   CFLAGS             += -DPARSER_DEBUG
188   $(call detected_var,PARSER_DEBUG_BISON)
189   $(call detected_var,PARSER_DEBUG_FLEX)
190 endif
191
192 # Try different combinations to accommodate systems that only have
193 # python[2][-config] in weird combinations but always preferring
194 # python2 and python2-config as per pep-0394. If we catch a
195 # python[-config] in version 3, the version check will kill it.
196 PYTHON2 := $(if $(call get-executable,python2),python2,python)
197 override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2))
198 PYTHON2_CONFIG := \
199   $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config)
200 override PYTHON_CONFIG := \
201   $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
202
203 grep-libs  = $(filter -l%,$(1))
204 strip-libs  = $(filter-out -l%,$(1))
205
206 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
207
208 # Python 3.8 changed the output of `python-config --ldflags` to not include the
209 # '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for
210 # libpython fails if that flag is not included in LDFLAGS
211 ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0)
212   PYTHON_CONFIG_LDFLAGS := --ldflags --embed
213 else
214   PYTHON_CONFIG_LDFLAGS := --ldflags
215 endif
216
217 ifdef PYTHON_CONFIG
218   PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
219   PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
220   PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
221   PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
222   FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
223 endif
224
225 FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
226 FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
227 FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
228 FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
229
230 CFLAGS += -fno-omit-frame-pointer
231 CFLAGS += -ggdb3
232 CFLAGS += -funwind-tables
233 CFLAGS += -Wall
234 CFLAGS += -Wextra
235 CFLAGS += -std=gnu99
236
237 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
238 CXXFLAGS += -Wall
239 CXXFLAGS += -fno-omit-frame-pointer
240 CXXFLAGS += -ggdb3
241 CXXFLAGS += -funwind-tables
242 CXXFLAGS += -Wno-strict-aliasing
243
244 # Enforce a non-executable stack, as we may regress (again) in the future by
245 # adding assembler files missing the .GNU-stack linker note.
246 LDFLAGS += -Wl,-z,noexecstack
247
248 EXTLIBS = -lpthread -lrt -lm -ldl
249
250 ifeq ($(FEATURES_DUMP),)
251 include $(srctree)/tools/build/Makefile.feature
252 else
253 include $(FEATURES_DUMP)
254 endif
255
256 ifeq ($(feature-stackprotector-all), 1)
257   CFLAGS += -fstack-protector-all
258 endif
259
260 ifeq ($(DEBUG),0)
261   ifeq ($(feature-fortify-source), 1)
262     CFLAGS += -D_FORTIFY_SOURCE=2
263   endif
264 endif
265
266 INC_FLAGS += -I$(src-perf)/util/include
267 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
268 INC_FLAGS += -I$(srctree)/tools/include/uapi
269 INC_FLAGS += -I$(srctree)/tools/include/
270 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
271 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
272 INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
273
274 # $(obj-perf)      for generated common-cmds.h
275 # $(obj-perf)/util for generated bison/flex headers
276 ifneq ($(OUTPUT),)
277 INC_FLAGS += -I$(obj-perf)/util
278 INC_FLAGS += -I$(obj-perf)
279 endif
280
281 INC_FLAGS += -I$(src-perf)/util
282 INC_FLAGS += -I$(src-perf)
283 INC_FLAGS += -I$(srctree)/tools/lib/
284
285 CFLAGS   += $(INC_FLAGS)
286 CXXFLAGS += $(INC_FLAGS)
287
288 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
289
290 ifeq ($(feature-sync-compare-and-swap), 1)
291   CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
292 endif
293
294 ifeq ($(feature-pthread-attr-setaffinity-np), 1)
295   CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
296 endif
297
298 ifeq ($(feature-pthread-barrier), 1)
299   CFLAGS += -DHAVE_PTHREAD_BARRIER
300 endif
301
302 ifndef NO_BIONIC
303   $(call feature_check,bionic)
304   ifeq ($(feature-bionic), 1)
305     BIONIC := 1
306     CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
307     CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
308     EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
309     EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
310   endif
311 endif
312
313 ifeq ($(feature-eventfd), 1)
314   CFLAGS += -DHAVE_EVENTFD
315 endif
316
317 ifeq ($(feature-get_current_dir_name), 1)
318   CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
319 endif
320
321 ifeq ($(feature-gettid), 1)
322   CFLAGS += -DHAVE_GETTID
323 endif
324
325 ifdef NO_LIBELF
326   NO_DWARF := 1
327   NO_DEMANGLE := 1
328   NO_LIBUNWIND := 1
329   NO_LIBDW_DWARF_UNWIND := 1
330   NO_LIBBPF := 1
331   NO_JVMTI := 1
332 else
333   ifeq ($(feature-libelf), 0)
334     ifeq ($(feature-glibc), 1)
335       LIBC_SUPPORT := 1
336     endif
337     ifeq ($(BIONIC),1)
338       LIBC_SUPPORT := 1
339     endif
340     ifeq ($(LIBC_SUPPORT),1)
341       msg := $(warning No libelf found. Disables 'probe' tool, jvmti and BPF support in 'perf record'. Please install libelf-dev, libelf-devel or elfutils-libelf-devel);
342
343       NO_LIBELF := 1
344       NO_DWARF := 1
345       NO_DEMANGLE := 1
346       NO_LIBUNWIND := 1
347       NO_LIBDW_DWARF_UNWIND := 1
348       NO_LIBBPF := 1
349       NO_JVMTI := 1
350     else
351       ifneq ($(filter s% -static%,$(LDFLAGS),),)
352         msg := $(error No static glibc found, please install glibc-static);
353       else
354         msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
355       endif
356     endif
357   else
358     ifndef NO_LIBDW_DWARF_UNWIND
359       ifneq ($(feature-libdw-dwarf-unwind),1)
360         NO_LIBDW_DWARF_UNWIND := 1
361         msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
362       endif
363     endif
364     ifneq ($(feature-dwarf), 1)
365       ifndef NO_DWARF
366         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);
367         NO_DWARF := 1
368       endif
369     else
370       ifneq ($(feature-dwarf_getlocations), 1)
371         msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
372       else
373         CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
374       endif # dwarf_getlocations
375     endif # Dwarf support
376   endif # libelf support
377 endif # NO_LIBELF
378
379 ifeq ($(feature-glibc), 1)
380   CFLAGS += -DHAVE_GLIBC_SUPPORT
381 endif
382
383 ifdef NO_DWARF
384   NO_LIBDW_DWARF_UNWIND := 1
385 endif
386
387 ifeq ($(feature-sched_getcpu), 1)
388   CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
389 endif
390
391 ifeq ($(feature-setns), 1)
392   CFLAGS += -DHAVE_SETNS_SUPPORT
393   $(call detected,CONFIG_SETNS)
394 endif
395
396 ifndef NO_CORESIGHT
397   ifeq ($(feature-libopencsd), 1)
398     CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
399     LDFLAGS += $(LIBOPENCSD_LDFLAGS)
400     EXTLIBS += $(OPENCSDLIBS)
401     $(call detected,CONFIG_LIBOPENCSD)
402     ifdef CSTRACE_RAW
403       CFLAGS += -DCS_DEBUG_RAW
404       ifeq (${CSTRACE_RAW}, packed)
405         CFLAGS += -DCS_RAW_PACKED
406       endif
407     endif
408   endif
409 endif
410
411 ifndef NO_LIBELF
412   CFLAGS += -DHAVE_LIBELF_SUPPORT
413   EXTLIBS += -lelf
414   $(call detected,CONFIG_LIBELF)
415
416   ifeq ($(feature-libelf-mmap), 1)
417     CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
418   endif
419
420   ifeq ($(feature-libelf-getphdrnum), 1)
421     CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
422   endif
423
424   ifeq ($(feature-libelf-gelf_getnote), 1)
425     CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
426   else
427     msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
428   endif
429
430   ifeq ($(feature-libelf-getshdrstrndx), 1)
431     CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
432   endif
433
434   ifndef NO_DWARF
435     ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
436       msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);
437       NO_DWARF := 1
438     else
439       CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
440       LDFLAGS += $(LIBDW_LDFLAGS)
441       EXTLIBS += ${DWARFLIBS}
442       $(call detected,CONFIG_DWARF)
443     endif # PERF_HAVE_DWARF_REGS
444   endif # NO_DWARF
445
446   ifndef NO_LIBBPF
447     ifeq ($(feature-bpf), 1)
448       CFLAGS += -DHAVE_LIBBPF_SUPPORT
449       $(call detected,CONFIG_LIBBPF)
450     endif
451
452     ifndef NO_DWARF
453       ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
454         CFLAGS += -DHAVE_BPF_PROLOGUE
455         $(call detected,CONFIG_BPF_PROLOGUE)
456       else
457         msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
458       endif
459     else
460       msg := $(warning DWARF support is off, BPF prologue is disabled);
461     endif
462
463   endif # NO_LIBBPF
464 endif # NO_LIBELF
465
466 ifndef NO_SDT
467   ifneq ($(feature-sdt), 1)
468     msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
469     NO_SDT := 1;
470   else
471     CFLAGS += -DHAVE_SDT_EVENT
472     $(call detected,CONFIG_SDT_EVENT)
473   endif
474 endif
475
476 ifdef PERF_HAVE_JITDUMP
477   ifndef NO_LIBELF
478     $(call detected,CONFIG_JITDUMP)
479     CFLAGS += -DHAVE_JITDUMP
480   endif
481 endif
482
483 ifeq ($(SRCARCH),powerpc)
484   ifndef NO_DWARF
485     CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
486   endif
487 endif
488
489 ifndef NO_LIBUNWIND
490   have_libunwind :=
491
492   ifeq ($(feature-libunwind-x86), 1)
493     $(call detected,CONFIG_LIBUNWIND_X86)
494     CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
495     LDFLAGS += -lunwind-x86
496     EXTLIBS_LIBUNWIND += -lunwind-x86
497     have_libunwind = 1
498   endif
499
500   ifeq ($(feature-libunwind-aarch64), 1)
501     $(call detected,CONFIG_LIBUNWIND_AARCH64)
502     CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
503     LDFLAGS += -lunwind-aarch64
504     EXTLIBS_LIBUNWIND += -lunwind-aarch64
505     have_libunwind = 1
506     $(call feature_check,libunwind-debug-frame-aarch64)
507     ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
508       msg := $(warning No debug_frame support found in libunwind-aarch64);
509       CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
510     endif
511   endif
512
513   ifneq ($(feature-libunwind), 1)
514     msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
515     NO_LOCAL_LIBUNWIND := 1
516   else
517     have_libunwind := 1
518     $(call detected,CONFIG_LOCAL_LIBUNWIND)
519   endif
520
521   ifneq ($(have_libunwind), 1)
522     NO_LIBUNWIND := 1
523   endif
524 else
525   NO_LOCAL_LIBUNWIND := 1
526 endif
527
528 ifndef NO_LIBBPF
529   ifneq ($(feature-bpf), 1)
530     msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
531     NO_LIBBPF := 1
532   endif
533 endif
534
535 dwarf-post-unwind := 1
536 dwarf-post-unwind-text := BUG
537
538 # setup DWARF post unwinder
539 ifdef NO_LIBUNWIND
540   ifdef NO_LIBDW_DWARF_UNWIND
541     msg := $(warning Disabling post unwind, no support found.);
542     dwarf-post-unwind := 0
543   else
544     dwarf-post-unwind-text := libdw
545     $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
546   endif
547 else
548   dwarf-post-unwind-text := libunwind
549   $(call detected,CONFIG_LIBUNWIND)
550   # Enable libunwind support by default.
551   ifndef NO_LIBDW_DWARF_UNWIND
552     NO_LIBDW_DWARF_UNWIND := 1
553   endif
554 endif
555
556 ifeq ($(dwarf-post-unwind),1)
557   CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
558   $(call detected,CONFIG_DWARF_UNWIND)
559 else
560   NO_DWARF_UNWIND := 1
561 endif
562
563 ifndef NO_LOCAL_LIBUNWIND
564   ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
565     $(call feature_check,libunwind-debug-frame)
566     ifneq ($(feature-libunwind-debug-frame), 1)
567       msg := $(warning No debug_frame support found in libunwind);
568       CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
569     endif
570   else
571     # non-ARM has no dwarf_find_debug_frame() function:
572     CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
573   endif
574   EXTLIBS += $(LIBUNWIND_LIBS)
575   LDFLAGS += $(LIBUNWIND_LIBS)
576 endif
577 ifeq ($(findstring -static,${LDFLAGS}),-static)
578   # gcc -static links libgcc_eh which contans piece of libunwind
579   LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
580 endif
581
582 ifndef NO_LIBUNWIND
583   CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
584   CFLAGS  += $(LIBUNWIND_CFLAGS)
585   LDFLAGS += $(LIBUNWIND_LDFLAGS)
586   EXTLIBS += $(EXTLIBS_LIBUNWIND)
587 endif
588
589 ifeq ($(NO_SYSCALL_TABLE),0)
590   $(call detected,CONFIG_TRACE)
591 else
592   ifndef NO_LIBAUDIT
593     ifneq ($(feature-libaudit), 1)
594       msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
595       NO_LIBAUDIT := 1
596     else
597       CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
598       EXTLIBS += -laudit
599       $(call detected,CONFIG_TRACE)
600     endif
601   endif
602 endif
603
604 ifndef NO_LIBCRYPTO
605   ifneq ($(feature-libcrypto), 1)
606     msg := $(warning No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev);
607     NO_LIBCRYPTO := 1
608   else
609     CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
610     EXTLIBS += -lcrypto
611     $(call detected,CONFIG_CRYPTO)
612   endif
613 endif
614
615 ifdef NO_NEWT
616   NO_SLANG=1
617 endif
618
619 ifndef NO_SLANG
620   ifneq ($(feature-libslang), 1)
621     msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
622     NO_SLANG := 1
623   else
624     # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
625     CFLAGS += -I/usr/include/slang
626     CFLAGS += -DHAVE_SLANG_SUPPORT
627     EXTLIBS += -lslang
628     $(call detected,CONFIG_SLANG)
629   endif
630 endif
631
632 ifndef NO_GTK2
633   FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
634   ifneq ($(feature-gtk2), 1)
635     msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
636     NO_GTK2 := 1
637   else
638     ifeq ($(feature-gtk2-infobar), 1)
639       GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
640     endif
641     CFLAGS += -DHAVE_GTK2_SUPPORT
642     GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
643     GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
644     EXTLIBS += -ldl
645   endif
646 endif
647
648 ifdef NO_LIBPERL
649   CFLAGS += -DNO_LIBPERL
650 else
651   PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
652   PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
653   PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
654   PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
655   PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
656   PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
657   FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
658
659   ifneq ($(feature-libperl), 1)
660     CFLAGS += -DNO_LIBPERL
661     NO_LIBPERL := 1
662     msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
663   else
664     LDFLAGS += $(PERL_EMBED_LDFLAGS)
665     EXTLIBS += $(PERL_EMBED_LIBADD)
666     CFLAGS += -DHAVE_LIBPERL_SUPPORT
667     $(call detected,CONFIG_LIBPERL)
668   endif
669 endif
670
671 ifeq ($(feature-timerfd), 1)
672   CFLAGS += -DHAVE_TIMERFD_SUPPORT
673 else
674   msg := $(warning No timerfd support. Disables 'perf kvm stat live');
675 endif
676
677 disable-python = $(eval $(disable-python_code))
678 define disable-python_code
679   CFLAGS += -DNO_LIBPYTHON
680   $(warning $1)
681   NO_LIBPYTHON := 1
682 endef
683
684 ifdef NO_LIBPYTHON
685   $(call disable-python,Python support disabled by user)
686 else
687
688   ifndef PYTHON
689     $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
690   else
691     PYTHON_WORD := $(call shell-wordify,$(PYTHON))
692
693     ifndef PYTHON_CONFIG
694       $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
695     else
696
697       ifneq ($(feature-libpython), 1)
698         $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
699       else
700          LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
701          EXTLIBS += $(PYTHON_EMBED_LIBADD)
702          LANG_BINDINGS += $(obj-perf)python/perf.so
703          CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
704          $(call detected,CONFIG_LIBPYTHON)
705       endif
706     endif
707   endif
708 endif
709
710 ifeq ($(feature-libbfd), 1)
711   EXTLIBS += -lbfd
712 else
713   # we are on a system that requires -liberty and (maybe) -lz
714   # to link against -lbfd; test each case individually here
715
716   # call all detections now so we get correct
717   # status in VF output
718   $(call feature_check,libbfd-liberty)
719   $(call feature_check,libbfd-liberty-z)
720
721   ifeq ($(feature-libbfd-liberty), 1)
722     EXTLIBS += -lbfd -liberty
723   else
724     ifeq ($(feature-libbfd-liberty-z), 1)
725       EXTLIBS += -lbfd -liberty -lz
726     endif
727   endif
728 endif
729
730 ifdef NO_DEMANGLE
731   CFLAGS += -DNO_DEMANGLE
732 else
733   ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
734     EXTLIBS += -liberty
735   else
736     ifeq ($(filter -liberty,$(EXTLIBS)),)
737       $(call feature_check,cplus-demangle)
738
739       # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
740       # or any of 'bfd iberty z' trinity
741       ifeq ($(feature-cplus-demangle), 1)
742         EXTLIBS += -liberty
743       else
744         msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
745         CFLAGS += -DNO_DEMANGLE
746       endif
747     endif
748   endif
749
750   ifneq ($(filter -liberty,$(EXTLIBS)),)
751     CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
752   endif
753 endif
754
755 ifneq ($(filter -lbfd,$(EXTLIBS)),)
756   CFLAGS += -DHAVE_LIBBFD_SUPPORT
757 endif
758
759 ifndef NO_ZLIB
760   ifeq ($(feature-zlib), 1)
761     CFLAGS += -DHAVE_ZLIB_SUPPORT
762     EXTLIBS += -lz
763     $(call detected,CONFIG_ZLIB)
764   else
765     NO_ZLIB := 1
766   endif
767 endif
768
769 ifndef NO_LZMA
770   ifeq ($(feature-lzma), 1)
771     CFLAGS += -DHAVE_LZMA_SUPPORT
772     EXTLIBS += -llzma
773     $(call detected,CONFIG_LZMA)
774   else
775     msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
776     NO_LZMA := 1
777   endif
778 endif
779
780 ifndef NO_BACKTRACE
781   ifeq ($(feature-backtrace), 1)
782     CFLAGS += -DHAVE_BACKTRACE_SUPPORT
783   endif
784 endif
785
786 ifndef NO_LIBNUMA
787   ifeq ($(feature-libnuma), 0)
788     msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
789     NO_LIBNUMA := 1
790   else
791     ifeq ($(feature-numa_num_possible_cpus), 0)
792       msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
793       NO_LIBNUMA := 1
794     else
795       CFLAGS += -DHAVE_LIBNUMA_SUPPORT
796       EXTLIBS += -lnuma
797       $(call detected,CONFIG_NUMA)
798     endif
799   endif
800 endif
801
802 ifdef HAVE_KVM_STAT_SUPPORT
803     CFLAGS += -DHAVE_KVM_STAT_SUPPORT
804 endif
805
806 ifeq (${IS_64_BIT}, 1)
807   ifndef NO_PERF_READ_VDSO32
808     $(call feature_check,compile-32)
809     ifeq ($(feature-compile-32), 1)
810       CFLAGS += -DHAVE_PERF_READ_VDSO32
811     else
812       NO_PERF_READ_VDSO32 := 1
813     endif
814   endif
815   ifneq ($(SRCARCH), x86)
816     NO_PERF_READ_VDSOX32 := 1
817   endif
818   ifndef NO_PERF_READ_VDSOX32
819     $(call feature_check,compile-x32)
820     ifeq ($(feature-compile-x32), 1)
821       CFLAGS += -DHAVE_PERF_READ_VDSOX32
822     else
823       NO_PERF_READ_VDSOX32 := 1
824     endif
825   endif
826 else
827   NO_PERF_READ_VDSO32 := 1
828   NO_PERF_READ_VDSOX32 := 1
829 endif
830
831 ifndef NO_LIBBABELTRACE
832   $(call feature_check,libbabeltrace)
833   ifeq ($(feature-libbabeltrace), 1)
834     CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
835     LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
836     EXTLIBS += -lbabeltrace-ctf
837     $(call detected,CONFIG_LIBBABELTRACE)
838   else
839     msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
840   endif
841 endif
842
843 ifndef NO_AUXTRACE
844   ifeq ($(SRCARCH),x86)
845     ifeq ($(feature-get_cpuid), 0)
846       msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
847       NO_AUXTRACE := 1
848     endif
849   endif
850   ifndef NO_AUXTRACE
851     $(call detected,CONFIG_AUXTRACE)
852     CFLAGS += -DHAVE_AUXTRACE_SUPPORT
853   endif
854 endif
855
856 ifndef NO_JVMTI
857   ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
858     JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
859   else
860     ifneq (,$(wildcard /usr/sbin/alternatives))
861       JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' -f 5 | sed -e 's%/jre/bin/java.%%g' -e 's%/bin/java.%%g')
862     endif
863   endif
864   ifndef JDIR
865     $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
866     NO_JVMTI := 1
867   endif
868 endif
869
870 ifndef NO_JVMTI
871   FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
872   $(call feature_check,jvmti)
873   ifeq ($(feature-jvmti), 1)
874     $(call detected_var,JDIR)
875   else
876     $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
877     NO_JVMTI := 1
878   endif
879 endif
880
881 USE_CXX = 0
882 USE_CLANGLLVM = 0
883 ifdef LIBCLANGLLVM
884   $(call feature_check,cxx)
885   ifneq ($(feature-cxx), 1)
886     msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
887   else
888     $(call feature_check,llvm)
889     $(call feature_check,llvm-version)
890     ifneq ($(feature-llvm), 1)
891       msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
892     else
893       $(call feature_check,clang)
894       ifneq ($(feature-clang), 1)
895         msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
896       else
897         CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
898         CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
899         $(call detected,CONFIG_CXX)
900         $(call detected,CONFIG_CLANGLLVM)
901         USE_CXX = 1
902         USE_LLVM = 1
903         USE_CLANG = 1
904         ifneq ($(feature-llvm-version),1)
905           msg := $(warning This version of LLVM is not tested. May cause build errors)
906         endif
907       endif
908     endif
909   endif
910 endif
911
912 # Among the variables below, these:
913 #   perfexecdir
914 #   perf_include_dir
915 #   perf_examples_dir
916 #   template_dir
917 #   mandir
918 #   infodir
919 #   htmldir
920 #   ETC_PERFCONFIG (but not sysconfdir)
921 # can be specified as a relative path some/where/else;
922 # this is interpreted as relative to $(prefix) and "perf" at
923 # runtime figures out where they are based on the path to the executable.
924 # This can help installing the suite in a relocatable way.
925
926 # Make the path relative to DESTDIR, not to prefix
927 ifndef DESTDIR
928 prefix ?= $(HOME)
929 endif
930 bindir_relative = bin
931 bindir = $(abspath $(prefix)/$(bindir_relative))
932 mandir = share/man
933 infodir = share/info
934 perfexecdir = libexec/perf-core
935 perf_include_dir = lib/perf/include
936 perf_examples_dir = lib/perf/examples
937 sharedir = $(prefix)/share
938 template_dir = share/perf-core/templates
939 STRACE_GROUPS_DIR = share/perf-core/strace/groups
940 htmldir = share/doc/perf-doc
941 tipdir = share/doc/perf-tip
942 srcdir = $(srctree)/tools/perf
943 ifeq ($(prefix),/usr)
944 sysconfdir = /etc
945 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
946 else
947 sysconfdir = $(prefix)/etc
948 ETC_PERFCONFIG = etc/perfconfig
949 endif
950 ifndef lib
951 ifeq ($(SRCARCH)$(IS_64_BIT), x861)
952 lib = lib64
953 else
954 lib = lib
955 endif
956 endif # lib
957 libdir = $(prefix)/$(lib)
958
959 # Shell quote (do not use $(call) to accommodate ancient setups);
960 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
961 STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
962 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
963 bindir_SQ = $(subst ','\'',$(bindir))
964 mandir_SQ = $(subst ','\'',$(mandir))
965 infodir_SQ = $(subst ','\'',$(infodir))
966 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
967 perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
968 perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
969 template_dir_SQ = $(subst ','\'',$(template_dir))
970 htmldir_SQ = $(subst ','\'',$(htmldir))
971 tipdir_SQ = $(subst ','\'',$(tipdir))
972 prefix_SQ = $(subst ','\'',$(prefix))
973 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
974 libdir_SQ = $(subst ','\'',$(libdir))
975 srcdir_SQ = $(subst ','\'',$(srcdir))
976
977 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
978 perfexec_instdir = $(perfexecdir)
979 perf_include_instdir = $(perf_include_dir)
980 perf_examples_instdir = $(perf_examples_dir)
981 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
982 tip_instdir = $(tipdir)
983 else
984 perfexec_instdir = $(prefix)/$(perfexecdir)
985 perf_include_instdir = $(prefix)/$(perf_include_dir)
986 perf_examples_instdir = $(prefix)/$(perf_examples_dir)
987 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
988 tip_instdir = $(prefix)/$(tipdir)
989 endif
990 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
991 perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
992 perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
993 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
994 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
995
996 # If we install to $(HOME) we keep the traceevent default:
997 # $(HOME)/.traceevent/plugins
998 # Otherwise we install plugins into the global $(libdir).
999 ifdef DESTDIR
1000 plugindir=$(libdir)/traceevent/plugins
1001 plugindir_SQ= $(subst ','\'',$(plugindir))
1002 endif
1003
1004 print_var = $(eval $(print_var_code)) $(info $(MSG))
1005 define print_var_code
1006     MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
1007 endef
1008
1009 ifeq ($(VF),1)
1010   # Display EXTRA features which are detected manualy
1011   # from here with feature_check call and thus cannot
1012   # be partof global state output.
1013   $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
1014   $(call print_var,prefix)
1015   $(call print_var,bindir)
1016   $(call print_var,libdir)
1017   $(call print_var,sysconfdir)
1018   $(call print_var,LIBUNWIND_DIR)
1019   $(call print_var,LIBDW_DIR)
1020   $(call print_var,JDIR)
1021
1022   ifeq ($(dwarf-post-unwind),1)
1023     $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
1024   endif
1025   $(info )
1026 endif
1027
1028 $(call detected_var,bindir_SQ)
1029 $(call detected_var,PYTHON_WORD)
1030 ifneq ($(OUTPUT),)
1031 $(call detected_var,OUTPUT)
1032 endif
1033 $(call detected_var,htmldir_SQ)
1034 $(call detected_var,infodir_SQ)
1035 $(call detected_var,mandir_SQ)
1036 $(call detected_var,ETC_PERFCONFIG_SQ)
1037 $(call detected_var,STRACE_GROUPS_DIR_SQ)
1038 $(call detected_var,prefix_SQ)
1039 $(call detected_var,perfexecdir_SQ)
1040 $(call detected_var,perf_include_dir_SQ)
1041 $(call detected_var,perf_examples_dir_SQ)
1042 $(call detected_var,tipdir_SQ)
1043 $(call detected_var,srcdir_SQ)
1044 $(call detected_var,LIBDIR)
1045 $(call detected_var,GTK_CFLAGS)
1046 $(call detected_var,PERL_EMBED_CCOPTS)
1047 $(call detected_var,PYTHON_EMBED_CCOPTS)