xref: /openbmc/linux/tools/perf/Makefile.config (revision dff03381)
1# SPDX-License-Identifier: GPL-2.0-only
2
3ifeq ($(src-perf),)
4src-perf := $(srctree)/tools/perf
5endif
6
7ifeq ($(obj-perf),)
8obj-perf := $(OUTPUT)
9endif
10
11ifneq ($(obj-perf),)
12obj-perf := $(abspath $(obj-perf))/
13endif
14
15$(shell printf "" > $(OUTPUT).config-detected)
16detected     = $(shell echo "$(1)=y"       >> $(OUTPUT).config-detected)
17detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
18
19CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
20HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
21
22include $(srctree)/tools/scripts/Makefile.arch
23
24$(call detected_var,SRCARCH)
25
26NO_PERF_REGS := 1
27
28ifneq ($(NO_SYSCALL_TABLE),1)
29  NO_SYSCALL_TABLE := 1
30
31  ifeq ($(SRCARCH),x86)
32    ifeq (${IS_64_BIT}, 1)
33      NO_SYSCALL_TABLE := 0
34    endif
35  else
36    ifeq ($(SRCARCH),$(filter $(SRCARCH),powerpc arm64 s390 mips))
37      NO_SYSCALL_TABLE := 0
38    endif
39  endif
40
41  ifneq ($(NO_SYSCALL_TABLE),1)
42    CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
43  endif
44endif
45
46# Additional ARCH settings for ppc
47ifeq ($(SRCARCH),powerpc)
48  NO_PERF_REGS := 0
49  CFLAGS += -I$(OUTPUT)arch/powerpc/include/generated
50  LIBUNWIND_LIBS := -lunwind -lunwind-ppc64
51endif
52
53# Additional ARCH settings for x86
54ifeq ($(SRCARCH),x86)
55  $(call detected,CONFIG_X86)
56  ifeq (${IS_64_BIT}, 1)
57    CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT -I$(OUTPUT)arch/x86/include/generated
58    ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
59    LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma
60    $(call detected,CONFIG_X86_64)
61  else
62    LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind
63  endif
64  NO_PERF_REGS := 0
65endif
66
67ifeq ($(SRCARCH),arm)
68  NO_PERF_REGS := 0
69  LIBUNWIND_LIBS = -lunwind -lunwind-arm
70endif
71
72ifeq ($(SRCARCH),arm64)
73  NO_PERF_REGS := 0
74  CFLAGS += -I$(OUTPUT)arch/arm64/include/generated
75  LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
76endif
77
78ifeq ($(SRCARCH),riscv)
79  NO_PERF_REGS := 0
80endif
81
82ifeq ($(SRCARCH),csky)
83  NO_PERF_REGS := 0
84endif
85
86ifeq ($(ARCH),s390)
87  NO_PERF_REGS := 0
88  CFLAGS += -fPIC -I$(OUTPUT)arch/s390/include/generated
89endif
90
91ifeq ($(ARCH),mips)
92  NO_PERF_REGS := 0
93  CFLAGS += -I$(OUTPUT)arch/mips/include/generated
94  LIBUNWIND_LIBS = -lunwind -lunwind-mips
95endif
96
97ifeq ($(NO_PERF_REGS),0)
98  $(call detected,CONFIG_PERF_REGS)
99endif
100
101# So far there's only x86 and arm libdw unwind support merged in perf.
102# Disable it on all other architectures in case libdw unwind
103# support is detected in system. Add supported architectures
104# to the check.
105ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky riscv))
106  NO_LIBDW_DWARF_UNWIND := 1
107endif
108
109ifeq ($(LIBUNWIND_LIBS),)
110  NO_LIBUNWIND := 1
111endif
112#
113# For linking with debug library, run like:
114#
115#   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
116#
117
118libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
119define libunwind_arch_set_flags_code
120  FEATURE_CHECK_CFLAGS-libunwind-$(1)  = -I$(LIBUNWIND_DIR)/include
121  FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
122endef
123
124ifdef LIBUNWIND_DIR
125  LIBUNWIND_CFLAGS  = -I$(LIBUNWIND_DIR)/include
126  LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
127  LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
128  $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
129endif
130
131# Set per-feature check compilation flags
132FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
133FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
134FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
135FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
136
137FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm
138FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64
139FEATURE_CHECK_LDFLAGS-libunwind-x86 += -lunwind -llzma -lunwind-x86
140FEATURE_CHECK_LDFLAGS-libunwind-x86_64 += -lunwind -llzma -lunwind-x86_64
141
142FEATURE_CHECK_LDFLAGS-libcrypto = -lcrypto
143
144ifdef CSINCLUDES
145  LIBOPENCSD_CFLAGS := -I$(CSINCLUDES)
146endif
147OPENCSDLIBS := -lopencsd_c_api
148ifeq ($(findstring -static,${LDFLAGS}),-static)
149  OPENCSDLIBS += -lopencsd -lstdc++
150endif
151ifdef CSLIBS
152  LIBOPENCSD_LDFLAGS := -L$(CSLIBS)
153endif
154FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS)
155FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS)
156
157ifeq ($(NO_PERF_REGS),0)
158  CFLAGS += -DHAVE_PERF_REGS_SUPPORT
159endif
160
161# for linking with debug library, run like:
162# make DEBUG=1 LIBDW_DIR=/opt/libdw/
163ifdef LIBDW_DIR
164  LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
165  LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
166endif
167DWARFLIBS := -ldw
168ifeq ($(findstring -static,${LDFLAGS}),-static)
169  DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
170endif
171FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
172FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
173
174# for linking with debug library, run like:
175# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
176ifdef LIBBABELTRACE_DIR
177  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
178  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
179endif
180FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
181FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
182
183ifdef LIBZSTD_DIR
184  LIBZSTD_CFLAGS  := -I$(LIBZSTD_DIR)/lib
185  LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
186endif
187FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
188FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
189
190FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
191# include ARCH specific config
192-include $(src-perf)/arch/$(SRCARCH)/Makefile
193
194ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
195  CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
196endif
197
198include $(srctree)/tools/scripts/utilities.mak
199
200ifeq ($(call get-executable,$(FLEX)),)
201  dummy := $(error Error: $(FLEX) is missing on this system, please install it)
202endif
203
204ifeq ($(call get-executable,$(BISON)),)
205  dummy := $(error Error: $(BISON) is missing on this system, please install it)
206endif
207
208ifneq ($(OUTPUT),)
209  ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1)
210    BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)=
211  endif
212endif
213
214# Treat warnings as errors unless directed not to
215ifneq ($(WERROR),0)
216  CORE_CFLAGS += -Werror
217  CXXFLAGS += -Werror
218  HOSTCFLAGS += -Werror
219endif
220
221ifndef DEBUG
222  DEBUG := 0
223endif
224
225ifeq ($(DEBUG),0)
226ifeq ($(CC_NO_CLANG), 0)
227  CORE_CFLAGS += -O3
228else
229  CORE_CFLAGS += -O6
230endif
231endif
232
233ifdef PARSER_DEBUG
234  PARSER_DEBUG_BISON := -t
235  PARSER_DEBUG_FLEX  := -d
236  CFLAGS             += -DPARSER_DEBUG
237  $(call detected_var,PARSER_DEBUG_BISON)
238  $(call detected_var,PARSER_DEBUG_FLEX)
239endif
240
241# Try different combinations to accommodate systems that only have
242# python[2][3]-config in weird combinations in the following order of
243# priority from lowest to highest:
244#   * python2-config as per pep-0394.
245#   * python-config
246#   * python3-config
247#   * $(PYTHON)-config (If PYTHON is user supplied but PYTHON_CONFIG isn't)
248#
249PYTHON_AUTO := python-config
250PYTHON_AUTO := $(if $(call get-executable,python2-config),python2-config,$(PYTHON_AUTO))
251PYTHON_AUTO := $(if $(call get-executable,python-config),python-config,$(PYTHON_AUTO))
252PYTHON_AUTO := $(if $(call get-executable,python3-config),python3-config,$(PYTHON_AUTO))
253
254# If PYTHON is defined but PYTHON_CONFIG isn't, then take $(PYTHON)-config as if it was the user
255# supplied value for PYTHON_CONFIG. Because it's "user supplied", error out if it doesn't exist.
256ifdef PYTHON
257  ifndef PYTHON_CONFIG
258    PYTHON_CONFIG_AUTO := $(call get-executable,$(PYTHON)-config)
259    PYTHON_CONFIG := $(if $(PYTHON_CONFIG_AUTO),$(PYTHON_CONFIG_AUTO),\
260                          $(call $(error $(PYTHON)-config not found)))
261  endif
262endif
263
264# Select either auto detected python and python-config or use user supplied values if they are
265# defined. get-executable-or-default fails with an error if the first argument is supplied but
266# doesn't exist.
267override PYTHON_CONFIG := $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON_AUTO))
268override PYTHON := $(call get-executable-or-default,PYTHON,$(subst -config,,$(PYTHON_AUTO)))
269
270grep-libs  = $(filter -l%,$(1))
271strip-libs  = $(filter-out -l%,$(1))
272
273PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
274
275# Python 3.8 changed the output of `python-config --ldflags` to not include the
276# '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for
277# libpython fails if that flag is not included in LDFLAGS
278ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0)
279  PYTHON_CONFIG_LDFLAGS := --ldflags --embed
280else
281  PYTHON_CONFIG_LDFLAGS := --ldflags
282endif
283
284ifdef PYTHON_CONFIG
285  PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
286  PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
287  PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
288  PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
289  FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
290  ifeq ($(CC_NO_CLANG), 0)
291    PYTHON_EMBED_CCOPTS := $(filter-out -ffat-lto-objects, $(PYTHON_EMBED_CCOPTS))
292  endif
293endif
294
295FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
296FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
297
298FEATURE_CHECK_LDFLAGS-libaio = -lrt
299
300FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
301FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl
302
303CORE_CFLAGS += -fno-omit-frame-pointer
304CORE_CFLAGS += -ggdb3
305CORE_CFLAGS += -funwind-tables
306CORE_CFLAGS += -Wall
307CORE_CFLAGS += -Wextra
308CORE_CFLAGS += -std=gnu99
309
310CXXFLAGS += -std=gnu++14 -fno-exceptions -fno-rtti
311CXXFLAGS += -Wall
312CXXFLAGS += -fno-omit-frame-pointer
313CXXFLAGS += -ggdb3
314CXXFLAGS += -funwind-tables
315CXXFLAGS += -Wno-strict-aliasing
316
317HOSTCFLAGS += -Wall
318HOSTCFLAGS += -Wextra
319
320# Enforce a non-executable stack, as we may regress (again) in the future by
321# adding assembler files missing the .GNU-stack linker note.
322LDFLAGS += -Wl,-z,noexecstack
323
324EXTLIBS = -lpthread -lrt -lm -ldl
325
326ifneq ($(TCMALLOC),)
327  CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
328  EXTLIBS += -ltcmalloc
329endif
330
331ifeq ($(FEATURES_DUMP),)
332# We will display at the end of this Makefile.config, using $(call feature_display_entries)
333# As we may retry some feature detection here, see the disassembler-four-args case, for instance
334  FEATURE_DISPLAY_DEFERRED := 1
335include $(srctree)/tools/build/Makefile.feature
336else
337include $(FEATURES_DUMP)
338endif
339
340ifeq ($(feature-stackprotector-all), 1)
341  CORE_CFLAGS += -fstack-protector-all
342endif
343
344ifeq ($(DEBUG),0)
345  ifeq ($(feature-fortify-source), 1)
346    CORE_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
347  endif
348endif
349
350INC_FLAGS += -I$(srctree)/tools/lib/perf/include
351INC_FLAGS += -I$(src-perf)/util/include
352INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
353INC_FLAGS += -I$(srctree)/tools/include/
354INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
355INC_FLAGS += -I$(srctree)/tools/include/uapi
356INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
357INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
358
359# $(obj-perf)      for generated common-cmds.h
360# $(obj-perf)/util for generated bison/flex headers
361ifneq ($(OUTPUT),)
362INC_FLAGS += -I$(obj-perf)/util
363INC_FLAGS += -I$(obj-perf)
364endif
365
366INC_FLAGS += -I$(src-perf)/util
367INC_FLAGS += -I$(src-perf)
368INC_FLAGS += -I$(srctree)/tools/lib/
369
370CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
371
372CFLAGS   += $(CORE_CFLAGS) $(INC_FLAGS)
373CXXFLAGS += $(INC_FLAGS)
374
375LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)
376
377ifeq ($(feature-pthread-attr-setaffinity-np), 1)
378  CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
379endif
380
381ifeq ($(feature-pthread-barrier), 1)
382  CFLAGS += -DHAVE_PTHREAD_BARRIER
383endif
384
385ifndef NO_BIONIC
386  $(call feature_check,bionic)
387  ifeq ($(feature-bionic), 1)
388    BIONIC := 1
389    CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
390    CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
391    EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
392    EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
393  endif
394endif
395
396ifeq ($(feature-eventfd), 1)
397  CFLAGS += -DHAVE_EVENTFD_SUPPORT
398endif
399
400ifeq ($(feature-get_current_dir_name), 1)
401  CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
402endif
403
404ifeq ($(feature-gettid), 1)
405  CFLAGS += -DHAVE_GETTID
406endif
407
408ifeq ($(feature-file-handle), 1)
409  CFLAGS += -DHAVE_FILE_HANDLE
410endif
411
412ifdef NO_LIBELF
413  NO_DWARF := 1
414  NO_DEMANGLE := 1
415  NO_LIBUNWIND := 1
416  NO_LIBDW_DWARF_UNWIND := 1
417  NO_LIBBPF := 1
418  NO_JVMTI := 1
419else
420  ifeq ($(feature-libelf), 0)
421    ifeq ($(feature-glibc), 1)
422      LIBC_SUPPORT := 1
423    endif
424    ifeq ($(BIONIC),1)
425      LIBC_SUPPORT := 1
426    endif
427    ifeq ($(LIBC_SUPPORT),1)
428      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);
429
430      NO_LIBELF := 1
431      NO_DWARF := 1
432      NO_DEMANGLE := 1
433      NO_LIBUNWIND := 1
434      NO_LIBDW_DWARF_UNWIND := 1
435      NO_LIBBPF := 1
436      NO_JVMTI := 1
437    else
438      ifneq ($(filter s% -fsanitize=address%,$(EXTRA_CFLAGS),),)
439        ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0)
440          msg := $(error No libasan found, please install libasan);
441        endif
442      endif
443
444      ifneq ($(filter s% -fsanitize=undefined%,$(EXTRA_CFLAGS),),)
445        ifneq ($(shell ldconfig -p | grep libubsan >/dev/null 2>&1; echo $$?), 0)
446          msg := $(error No libubsan found, please install libubsan);
447        endif
448      endif
449
450      ifneq ($(filter s% -static%,$(LDFLAGS),),)
451        msg := $(error No static glibc found, please install glibc-static);
452      else
453        msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
454      endif
455    endif
456  else
457    ifndef NO_LIBDW_DWARF_UNWIND
458      ifneq ($(feature-libdw-dwarf-unwind),1)
459        NO_LIBDW_DWARF_UNWIND := 1
460        msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
461      endif
462    endif
463    ifneq ($(feature-dwarf), 1)
464      ifndef NO_DWARF
465        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);
466        NO_DWARF := 1
467      endif
468    else
469      ifneq ($(feature-dwarf_getlocations), 1)
470        msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
471      else
472        CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
473      endif # dwarf_getlocations
474    endif # Dwarf support
475  endif # libelf support
476endif # NO_LIBELF
477
478ifeq ($(feature-glibc), 1)
479  CFLAGS += -DHAVE_GLIBC_SUPPORT
480endif
481
482ifeq ($(feature-libaio), 1)
483  ifndef NO_AIO
484    CFLAGS += -DHAVE_AIO_SUPPORT
485  endif
486endif
487
488ifdef NO_DWARF
489  NO_LIBDW_DWARF_UNWIND := 1
490endif
491
492ifeq ($(feature-sched_getcpu), 1)
493  CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
494endif
495
496ifeq ($(feature-setns), 1)
497  CFLAGS += -DHAVE_SETNS_SUPPORT
498  $(call detected,CONFIG_SETNS)
499endif
500
501ifdef CORESIGHT
502  $(call feature_check,libopencsd)
503  ifeq ($(feature-libopencsd), 1)
504    CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
505    ifeq ($(feature-reallocarray), 0)
506      CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
507    endif
508    LDFLAGS += $(LIBOPENCSD_LDFLAGS)
509    EXTLIBS += $(OPENCSDLIBS)
510    $(call detected,CONFIG_LIBOPENCSD)
511    ifdef CSTRACE_RAW
512      CFLAGS += -DCS_DEBUG_RAW
513      ifeq (${CSTRACE_RAW}, packed)
514        CFLAGS += -DCS_RAW_PACKED
515      endif
516    endif
517  else
518    dummy := $(error Error: No libopencsd library found or the version is not up-to-date. Please install recent libopencsd to build with CORESIGHT=1)
519  endif
520endif
521
522ifndef NO_LIBELF
523  CFLAGS += -DHAVE_LIBELF_SUPPORT
524  EXTLIBS += -lelf
525  $(call detected,CONFIG_LIBELF)
526
527  ifeq ($(feature-libelf-getphdrnum), 1)
528    CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
529  endif
530
531  ifeq ($(feature-libelf-gelf_getnote), 1)
532    CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
533  else
534    msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
535  endif
536
537  ifeq ($(feature-libelf-getshdrstrndx), 1)
538    CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
539  endif
540
541  ifndef NO_LIBDEBUGINFOD
542    $(call feature_check,libdebuginfod)
543    ifeq ($(feature-libdebuginfod), 1)
544      CFLAGS += -DHAVE_DEBUGINFOD_SUPPORT
545      EXTLIBS += -ldebuginfod
546    endif
547  endif
548
549  ifndef NO_DWARF
550    ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
551      msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);
552      NO_DWARF := 1
553    else
554      CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
555      LDFLAGS += $(LIBDW_LDFLAGS)
556      EXTLIBS += ${DWARFLIBS}
557      $(call detected,CONFIG_DWARF)
558    endif # PERF_HAVE_DWARF_REGS
559  endif # NO_DWARF
560
561  ifndef NO_LIBBPF
562    ifeq ($(feature-bpf), 1)
563      CFLAGS += -DHAVE_LIBBPF_SUPPORT
564      $(call detected,CONFIG_LIBBPF)
565
566      # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
567      $(call feature_check,libbpf)
568      ifdef LIBBPF_DYNAMIC
569        ifeq ($(feature-libbpf), 1)
570          EXTLIBS += -lbpf
571          $(call detected,CONFIG_LIBBPF_DYNAMIC)
572
573          $(call feature_check,libbpf-btf__load_from_kernel_by_id)
574          ifeq ($(feature-libbpf-btf__load_from_kernel_by_id), 1)
575            CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
576          endif
577          $(call feature_check,libbpf-bpf_prog_load)
578          ifeq ($(feature-libbpf-bpf_prog_load), 1)
579            CFLAGS += -DHAVE_LIBBPF_BPF_PROG_LOAD
580          endif
581          $(call feature_check,libbpf-bpf_object__next_program)
582          ifeq ($(feature-libbpf-bpf_object__next_program), 1)
583            CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
584          endif
585          $(call feature_check,libbpf-bpf_object__next_map)
586          ifeq ($(feature-libbpf-bpf_object__next_map), 1)
587            CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_MAP
588          endif
589          $(call feature_check,libbpf-btf__raw_data)
590          ifeq ($(feature-libbpf-btf__raw_data), 1)
591            CFLAGS += -DHAVE_LIBBPF_BTF__RAW_DATA
592          endif
593          $(call feature_check,libbpf-bpf_map_create)
594          ifeq ($(feature-libbpf-bpf_map_create), 1)
595            CFLAGS += -DHAVE_LIBBPF_BPF_MAP_CREATE
596          endif
597        else
598          dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
599        endif
600      else
601	CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
602        CFLAGS += -DHAVE_LIBBPF_BPF_PROG_LOAD
603        CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
604        CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_MAP
605        CFLAGS += -DHAVE_LIBBPF_BTF__RAW_DATA
606        CFLAGS += -DHAVE_LIBBPF_BPF_MAP_CREATE
607      endif
608    endif
609
610    ifndef NO_DWARF
611      ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
612        CFLAGS += -DHAVE_BPF_PROLOGUE
613        $(call detected,CONFIG_BPF_PROLOGUE)
614      else
615        msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
616      endif
617    else
618      msg := $(warning DWARF support is off, BPF prologue is disabled);
619    endif
620
621  endif # NO_LIBBPF
622endif # NO_LIBELF
623
624ifndef NO_SDT
625  ifneq ($(feature-sdt), 1)
626    msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
627    NO_SDT := 1;
628  else
629    CFLAGS += -DHAVE_SDT_EVENT
630    $(call detected,CONFIG_SDT_EVENT)
631  endif
632endif
633
634ifdef PERF_HAVE_JITDUMP
635  ifndef NO_LIBELF
636    $(call detected,CONFIG_JITDUMP)
637    CFLAGS += -DHAVE_JITDUMP
638  endif
639endif
640
641ifeq ($(SRCARCH),powerpc)
642  ifndef NO_DWARF
643    CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
644  endif
645endif
646
647ifndef NO_LIBUNWIND
648  have_libunwind :=
649
650  $(call feature_check,libunwind-x86)
651  ifeq ($(feature-libunwind-x86), 1)
652    $(call detected,CONFIG_LIBUNWIND_X86)
653    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
654    LDFLAGS += -lunwind-x86
655    EXTLIBS_LIBUNWIND += -lunwind-x86
656    have_libunwind = 1
657  endif
658
659  $(call feature_check,libunwind-aarch64)
660  ifeq ($(feature-libunwind-aarch64), 1)
661    $(call detected,CONFIG_LIBUNWIND_AARCH64)
662    CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
663    LDFLAGS += -lunwind-aarch64
664    EXTLIBS_LIBUNWIND += -lunwind-aarch64
665    have_libunwind = 1
666    $(call feature_check,libunwind-debug-frame-aarch64)
667    ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
668      msg := $(warning No debug_frame support found in libunwind-aarch64);
669      CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
670    endif
671  endif
672
673  ifneq ($(feature-libunwind), 1)
674    msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
675    NO_LOCAL_LIBUNWIND := 1
676  else
677    have_libunwind := 1
678    $(call detected,CONFIG_LOCAL_LIBUNWIND)
679  endif
680
681  ifneq ($(have_libunwind), 1)
682    NO_LIBUNWIND := 1
683  endif
684else
685  NO_LOCAL_LIBUNWIND := 1
686endif
687
688ifndef NO_LIBBPF
689  ifneq ($(feature-bpf), 1)
690    msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
691    NO_LIBBPF := 1
692  endif
693endif
694
695ifdef BUILD_BPF_SKEL
696  $(call feature_check,clang-bpf-co-re)
697  ifeq ($(feature-clang-bpf-co-re), 0)
698    dummy := $(error Error: clang too old/not installed. Please install recent clang to build with BUILD_BPF_SKEL)
699  endif
700  ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),)
701    dummy := $(error Error: BPF skeleton support requires libbpf)
702  endif
703  $(call detected,CONFIG_PERF_BPF_SKEL)
704  CFLAGS += -DHAVE_BPF_SKEL
705endif
706
707dwarf-post-unwind := 1
708dwarf-post-unwind-text := BUG
709
710# setup DWARF post unwinder
711ifdef NO_LIBUNWIND
712  ifdef NO_LIBDW_DWARF_UNWIND
713    msg := $(warning Disabling post unwind, no support found.);
714    dwarf-post-unwind := 0
715  else
716    dwarf-post-unwind-text := libdw
717    $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
718  endif
719else
720  dwarf-post-unwind-text := libunwind
721  $(call detected,CONFIG_LIBUNWIND)
722  # Enable libunwind support by default.
723  ifndef NO_LIBDW_DWARF_UNWIND
724    NO_LIBDW_DWARF_UNWIND := 1
725  endif
726endif
727
728ifeq ($(dwarf-post-unwind),1)
729  CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
730  $(call detected,CONFIG_DWARF_UNWIND)
731else
732  NO_DWARF_UNWIND := 1
733endif
734
735ifndef NO_LOCAL_LIBUNWIND
736  ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
737    $(call feature_check,libunwind-debug-frame)
738    ifneq ($(feature-libunwind-debug-frame), 1)
739      msg := $(warning No debug_frame support found in libunwind);
740      CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
741    endif
742  else
743    # non-ARM has no dwarf_find_debug_frame() function:
744    CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
745  endif
746  EXTLIBS += $(LIBUNWIND_LIBS)
747  LDFLAGS += $(LIBUNWIND_LIBS)
748endif
749ifeq ($(findstring -static,${LDFLAGS}),-static)
750  # gcc -static links libgcc_eh which contans piece of libunwind
751  LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
752endif
753
754ifndef NO_LIBUNWIND
755  CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
756  CFLAGS  += $(LIBUNWIND_CFLAGS)
757  LDFLAGS += $(LIBUNWIND_LDFLAGS)
758  EXTLIBS += $(EXTLIBS_LIBUNWIND)
759endif
760
761ifeq ($(NO_SYSCALL_TABLE),0)
762  $(call detected,CONFIG_TRACE)
763else
764  ifndef NO_LIBAUDIT
765    $(call feature_check,libaudit)
766    ifneq ($(feature-libaudit), 1)
767      msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
768      NO_LIBAUDIT := 1
769    else
770      CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
771      EXTLIBS += -laudit
772      $(call detected,CONFIG_TRACE)
773    endif
774  endif
775endif
776
777ifndef NO_LIBCRYPTO
778  ifneq ($(feature-libcrypto), 1)
779    msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev);
780    NO_LIBCRYPTO := 1
781  else
782    CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
783    EXTLIBS += -lcrypto
784    $(call detected,CONFIG_CRYPTO)
785  endif
786endif
787
788ifdef NO_NEWT
789  NO_SLANG=1
790endif
791
792ifndef NO_SLANG
793  ifneq ($(feature-libslang), 1)
794    ifneq ($(feature-libslang-include-subdir), 1)
795      msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
796      NO_SLANG := 1
797    else
798      CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR
799    endif
800  endif
801  ifndef NO_SLANG
802    # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
803    CFLAGS += -DHAVE_SLANG_SUPPORT
804    EXTLIBS += -lslang
805    $(call detected,CONFIG_SLANG)
806  endif
807endif
808
809ifdef GTK2
810  FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
811  $(call feature_check,gtk2)
812  ifneq ($(feature-gtk2), 1)
813    msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
814    NO_GTK2 := 1
815  else
816    $(call feature_check,gtk2-infobar)
817    ifeq ($(feature-gtk2-infobar), 1)
818      GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
819    endif
820    CFLAGS += -DHAVE_GTK2_SUPPORT
821    GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
822    GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
823    EXTLIBS += -ldl
824  endif
825endif
826
827ifdef NO_LIBPERL
828  CFLAGS += -DNO_LIBPERL
829else
830  PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
831  PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
832  PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
833  PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
834  PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
835  PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
836  PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
837  FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
838
839  ifneq ($(feature-libperl), 1)
840    CFLAGS += -DNO_LIBPERL
841    NO_LIBPERL := 1
842    msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
843  else
844    LDFLAGS += $(PERL_EMBED_LDFLAGS)
845    EXTLIBS += $(PERL_EMBED_LIBADD)
846    CFLAGS += -DHAVE_LIBPERL_SUPPORT
847    ifeq ($(CC_NO_CLANG), 0)
848      CFLAGS += -Wno-compound-token-split-by-macro
849    endif
850    $(call detected,CONFIG_LIBPERL)
851  endif
852endif
853
854ifeq ($(feature-timerfd), 1)
855  CFLAGS += -DHAVE_TIMERFD_SUPPORT
856else
857  msg := $(warning No timerfd support. Disables 'perf kvm stat live');
858endif
859
860disable-python = $(eval $(disable-python_code))
861define disable-python_code
862  CFLAGS += -DNO_LIBPYTHON
863  $(warning $1)
864  NO_LIBPYTHON := 1
865endef
866
867ifdef NO_LIBPYTHON
868  $(call disable-python,Python support disabled by user)
869else
870
871  ifndef PYTHON
872    $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
873  else
874    PYTHON_WORD := $(call shell-wordify,$(PYTHON))
875
876    ifndef PYTHON_CONFIG
877      $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
878    else
879
880      ifneq ($(feature-libpython), 1)
881        $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
882      else
883         LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
884         EXTLIBS += $(PYTHON_EMBED_LIBADD)
885         LANG_BINDINGS += $(obj-perf)python/perf.so
886         CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
887         $(call detected,CONFIG_LIBPYTHON)
888      endif
889    endif
890  endif
891endif
892
893ifneq ($(NO_JEVENTS),1)
894  ifeq ($(wildcard pmu-events/arch/$(SRCARCH)/mapfile.csv),)
895    NO_JEVENTS := 1
896  endif
897endif
898ifneq ($(NO_JEVENTS),1)
899  NO_JEVENTS := 0
900  ifndef PYTHON
901    $(warning No python interpreter disabling jevent generation)
902    NO_JEVENTS := 1
903  else
904    # jevents.py uses f-strings present in Python 3.6 released in Dec. 2016.
905    JEVENTS_PYTHON_GOOD := $(shell $(PYTHON) -c 'import sys;print("1" if(sys.version_info.major >= 3 and sys.version_info.minor >= 6) else "0")' 2> /dev/null)
906    ifneq ($(JEVENTS_PYTHON_GOOD), 1)
907      $(warning Python interpreter too old (older than 3.6) disabling jevent generation)
908      NO_JEVENTS := 1
909    endif
910  endif
911endif
912
913ifndef NO_LIBBFD
914  ifeq ($(feature-libbfd), 1)
915    EXTLIBS += -lbfd -lopcodes
916  else
917    # we are on a system that requires -liberty and (maybe) -lz
918    # to link against -lbfd; test each case individually here
919
920    # call all detections now so we get correct
921    # status in VF output
922    $(call feature_check,libbfd-liberty)
923    $(call feature_check,libbfd-liberty-z)
924
925    ifeq ($(feature-libbfd-liberty), 1)
926      EXTLIBS += -lbfd -lopcodes -liberty
927      FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
928      FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl
929    else
930      ifeq ($(feature-libbfd-liberty-z), 1)
931        EXTLIBS += -lbfd -lopcodes -liberty -lz
932        FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
933        FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl
934      endif
935    endif
936    $(call feature_check,disassembler-four-args)
937    $(call feature_check,disassembler-init-styled)
938  endif
939
940  ifeq ($(feature-libbfd-buildid), 1)
941    CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT
942  else
943    msg := $(warning Old version of libbfd/binutils things like PE executable profiling will not be available);
944  endif
945endif
946
947ifdef NO_DEMANGLE
948  CFLAGS += -DNO_DEMANGLE
949else
950  ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
951    EXTLIBS += -liberty
952  else
953    ifeq ($(filter -liberty,$(EXTLIBS)),)
954      $(call feature_check,cplus-demangle)
955
956      # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
957      # or any of 'bfd iberty z' trinity
958      ifeq ($(feature-cplus-demangle), 1)
959        EXTLIBS += -liberty
960      else
961        msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
962        CFLAGS += -DNO_DEMANGLE
963      endif
964    endif
965  endif
966
967  ifneq ($(filter -liberty,$(EXTLIBS)),)
968    CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
969  endif
970endif
971
972ifneq ($(filter -lbfd,$(EXTLIBS)),)
973  CFLAGS += -DHAVE_LIBBFD_SUPPORT
974endif
975
976ifndef NO_ZLIB
977  ifeq ($(feature-zlib), 1)
978    CFLAGS += -DHAVE_ZLIB_SUPPORT
979    EXTLIBS += -lz
980    $(call detected,CONFIG_ZLIB)
981  else
982    NO_ZLIB := 1
983  endif
984endif
985
986ifndef NO_LZMA
987  ifeq ($(feature-lzma), 1)
988    CFLAGS += -DHAVE_LZMA_SUPPORT
989    EXTLIBS += -llzma
990    $(call detected,CONFIG_LZMA)
991  else
992    msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
993    NO_LZMA := 1
994  endif
995endif
996
997ifndef NO_LIBZSTD
998  ifeq ($(feature-libzstd), 1)
999    CFLAGS += -DHAVE_ZSTD_SUPPORT
1000    CFLAGS += $(LIBZSTD_CFLAGS)
1001    LDFLAGS += $(LIBZSTD_LDFLAGS)
1002    EXTLIBS += -lzstd
1003    $(call detected,CONFIG_ZSTD)
1004  else
1005    msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
1006    NO_LIBZSTD := 1
1007  endif
1008endif
1009
1010ifndef NO_LIBCAP
1011  ifeq ($(feature-libcap), 1)
1012    CFLAGS += -DHAVE_LIBCAP_SUPPORT
1013    EXTLIBS += -lcap
1014    $(call detected,CONFIG_LIBCAP)
1015  else
1016    msg := $(warning No libcap found, disables capability support, please install libcap-devel/libcap-dev);
1017    NO_LIBCAP := 1
1018  endif
1019endif
1020
1021ifndef NO_BACKTRACE
1022  ifeq ($(feature-backtrace), 1)
1023    CFLAGS += -DHAVE_BACKTRACE_SUPPORT
1024  endif
1025endif
1026
1027ifndef NO_LIBNUMA
1028  ifeq ($(feature-libnuma), 0)
1029    msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
1030    NO_LIBNUMA := 1
1031  else
1032    ifeq ($(feature-numa_num_possible_cpus), 0)
1033      msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
1034      NO_LIBNUMA := 1
1035    else
1036      CFLAGS += -DHAVE_LIBNUMA_SUPPORT
1037      EXTLIBS += -lnuma
1038      $(call detected,CONFIG_NUMA)
1039    endif
1040  endif
1041endif
1042
1043ifdef HAVE_KVM_STAT_SUPPORT
1044    CFLAGS += -DHAVE_KVM_STAT_SUPPORT
1045endif
1046
1047ifeq ($(feature-disassembler-four-args), 1)
1048    CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
1049endif
1050
1051ifeq ($(feature-disassembler-init-styled), 1)
1052    CFLAGS += -DDISASM_INIT_STYLED
1053endif
1054
1055ifeq (${IS_64_BIT}, 1)
1056  ifndef NO_PERF_READ_VDSO32
1057    $(call feature_check,compile-32)
1058    ifeq ($(feature-compile-32), 1)
1059      CFLAGS += -DHAVE_PERF_READ_VDSO32
1060    else
1061      NO_PERF_READ_VDSO32 := 1
1062    endif
1063  endif
1064  ifneq ($(SRCARCH), x86)
1065    NO_PERF_READ_VDSOX32 := 1
1066  endif
1067  ifndef NO_PERF_READ_VDSOX32
1068    $(call feature_check,compile-x32)
1069    ifeq ($(feature-compile-x32), 1)
1070      CFLAGS += -DHAVE_PERF_READ_VDSOX32
1071    else
1072      NO_PERF_READ_VDSOX32 := 1
1073    endif
1074  endif
1075else
1076  NO_PERF_READ_VDSO32 := 1
1077  NO_PERF_READ_VDSOX32 := 1
1078endif
1079
1080ifndef NO_LIBBABELTRACE
1081  $(call feature_check,libbabeltrace)
1082  ifeq ($(feature-libbabeltrace), 1)
1083    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
1084    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
1085    EXTLIBS += -lbabeltrace-ctf
1086    $(call detected,CONFIG_LIBBABELTRACE)
1087  else
1088    msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
1089  endif
1090endif
1091
1092ifndef NO_AUXTRACE
1093  ifeq ($(SRCARCH),x86)
1094    ifeq ($(feature-get_cpuid), 0)
1095      msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
1096      NO_AUXTRACE := 1
1097    endif
1098  endif
1099  ifndef NO_AUXTRACE
1100    $(call detected,CONFIG_AUXTRACE)
1101    CFLAGS += -DHAVE_AUXTRACE_SUPPORT
1102    ifeq ($(feature-reallocarray), 0)
1103      CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
1104    endif
1105  endif
1106endif
1107
1108ifndef NO_JVMTI
1109  ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
1110    JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
1111  else
1112    ifneq (,$(wildcard /usr/sbin/alternatives))
1113      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')
1114    endif
1115  endif
1116  ifndef JDIR
1117    $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
1118    NO_JVMTI := 1
1119  endif
1120endif
1121
1122ifndef NO_JVMTI
1123  FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
1124  $(call feature_check,jvmti)
1125  ifeq ($(feature-jvmti), 1)
1126    $(call detected_var,JDIR)
1127    ifndef NO_JVMTI_CMLR
1128      FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
1129      $(call feature_check,jvmti-cmlr)
1130      ifeq ($(feature-jvmti-cmlr), 1)
1131        CFLAGS += -DHAVE_JVMTI_CMLR
1132      endif
1133    endif # NO_JVMTI_CMLR
1134  else
1135    $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
1136    NO_JVMTI := 1
1137  endif
1138endif
1139
1140USE_CXX = 0
1141USE_CLANGLLVM = 0
1142ifdef LIBCLANGLLVM
1143  $(call feature_check,cxx)
1144  ifneq ($(feature-cxx), 1)
1145    msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
1146  else
1147    $(call feature_check,llvm)
1148    $(call feature_check,llvm-version)
1149    ifneq ($(feature-llvm), 1)
1150      msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
1151    else
1152      $(call feature_check,clang)
1153      ifneq ($(feature-clang), 1)
1154        msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
1155      else
1156        CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
1157        CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
1158        $(call detected,CONFIG_CXX)
1159        $(call detected,CONFIG_CLANGLLVM)
1160	USE_CXX = 1
1161	USE_LLVM = 1
1162	USE_CLANG = 1
1163        ifneq ($(feature-llvm-version),1)
1164          msg := $(warning This version of LLVM is not tested. May cause build errors)
1165        endif
1166      endif
1167    endif
1168  endif
1169endif
1170
1171ifdef LIBPFM4
1172  $(call feature_check,libpfm4)
1173  ifeq ($(feature-libpfm4), 1)
1174    CFLAGS += -DHAVE_LIBPFM
1175    EXTLIBS += -lpfm
1176    ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1
1177    $(call detected,CONFIG_LIBPFM4)
1178  else
1179    msg := $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev);
1180    NO_LIBPFM4 := 1
1181  endif
1182endif
1183
1184ifdef LIBTRACEEVENT_DYNAMIC
1185  $(call feature_check,libtraceevent)
1186  ifeq ($(feature-libtraceevent), 1)
1187    EXTLIBS += -ltraceevent
1188    LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent)
1189    LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1190    LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1191    LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1192    LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3))
1193    CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP)
1194  else
1195    dummy := $(error Error: No libtraceevent devel library found, please install libtraceevent-devel);
1196  endif
1197endif
1198
1199ifdef LIBTRACEFS_DYNAMIC
1200  $(call feature_check,libtracefs)
1201  ifeq ($(feature-libtracefs), 1)
1202    EXTLIBS += -ltracefs
1203    LIBTRACEFS_VERSION := $(shell $(PKG_CONFIG) --modversion libtracefs)
1204    LIBTRACEFS_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEFS_VERSION)))
1205    LIBTRACEFS_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEFS_VERSION)))
1206    LIBTRACEFS_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEFS_VERSION)))
1207    LIBTRACEFS_VERSION_CPP := $(shell expr $(LIBTRACEFS_VERSION_1) \* 255 \* 255 + $(LIBTRACEFS_VERSION_2) \* 255 + $(LIBTRACEFS_VERSION_3))
1208    CFLAGS += -DLIBTRACEFS_VERSION=$(LIBTRACEFS_VERSION_CPP)
1209  else
1210    dummy := $(error Error: No libtracefs devel library found, please install libtracefs-dev);
1211  endif
1212endif
1213
1214# Among the variables below, these:
1215#   perfexecdir
1216#   perf_include_dir
1217#   perf_examples_dir
1218#   template_dir
1219#   mandir
1220#   infodir
1221#   htmldir
1222#   ETC_PERFCONFIG (but not sysconfdir)
1223# can be specified as a relative path some/where/else;
1224# this is interpreted as relative to $(prefix) and "perf" at
1225# runtime figures out where they are based on the path to the executable.
1226# This can help installing the suite in a relocatable way.
1227
1228# Make the path relative to DESTDIR, not to prefix
1229ifndef DESTDIR
1230prefix ?= $(HOME)
1231endif
1232bindir_relative = bin
1233bindir = $(abspath $(prefix)/$(bindir_relative))
1234includedir_relative = include
1235includedir = $(abspath $(prefix)/$(includedir_relative))
1236mandir = share/man
1237infodir = share/info
1238perfexecdir = libexec/perf-core
1239perf_include_dir = lib/perf/include
1240perf_examples_dir = lib/perf/examples
1241sharedir = $(prefix)/share
1242template_dir = share/perf-core/templates
1243STRACE_GROUPS_DIR = share/perf-core/strace/groups
1244htmldir = share/doc/perf-doc
1245tipdir = share/doc/perf-tip
1246srcdir = $(srctree)/tools/perf
1247ifeq ($(prefix),/usr)
1248sysconfdir = /etc
1249ETC_PERFCONFIG = $(sysconfdir)/perfconfig
1250else
1251sysconfdir = $(prefix)/etc
1252ETC_PERFCONFIG = etc/perfconfig
1253endif
1254ifndef lib
1255ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1256lib = lib64
1257else
1258lib = lib
1259endif
1260endif # lib
1261libdir = $(prefix)/$(lib)
1262
1263# Shell quote (do not use $(call) to accommodate ancient setups);
1264ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1265STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1266DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1267bindir_SQ = $(subst ','\'',$(bindir))
1268includedir_SQ = $(subst ','\'',$(includedir))
1269mandir_SQ = $(subst ','\'',$(mandir))
1270infodir_SQ = $(subst ','\'',$(infodir))
1271perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1272perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
1273perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1274template_dir_SQ = $(subst ','\'',$(template_dir))
1275htmldir_SQ = $(subst ','\'',$(htmldir))
1276tipdir_SQ = $(subst ','\'',$(tipdir))
1277prefix_SQ = $(subst ','\'',$(prefix))
1278sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1279libdir_SQ = $(subst ','\'',$(libdir))
1280srcdir_SQ = $(subst ','\'',$(srcdir))
1281
1282ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1283perfexec_instdir = $(perfexecdir)
1284perf_include_instdir = $(perf_include_dir)
1285perf_examples_instdir = $(perf_examples_dir)
1286STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1287tip_instdir = $(tipdir)
1288else
1289perfexec_instdir = $(prefix)/$(perfexecdir)
1290perf_include_instdir = $(prefix)/$(perf_include_dir)
1291perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1292STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1293tip_instdir = $(prefix)/$(tipdir)
1294endif
1295perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1296perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1297perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1298STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1299tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1300
1301# If we install to $(HOME) we keep the traceevent default:
1302# $(HOME)/.traceevent/plugins
1303# Otherwise we install plugins into the global $(libdir).
1304ifdef DESTDIR
1305plugindir=$(libdir)/traceevent/plugins
1306plugindir_SQ= $(subst ','\'',$(plugindir))
1307endif
1308
1309print_var = $(eval $(print_var_code)) $(info $(MSG))
1310define print_var_code
1311    MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
1312endef
1313
1314ifeq ($(VF),1)
1315  # Display EXTRA features which are detected manualy
1316  # from here with feature_check call and thus cannot
1317  # be partof global state output.
1318  $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),))
1319  $(call print_var,prefix)
1320  $(call print_var,bindir)
1321  $(call print_var,libdir)
1322  $(call print_var,sysconfdir)
1323  $(call print_var,LIBUNWIND_DIR)
1324  $(call print_var,LIBDW_DIR)
1325  $(call print_var,JDIR)
1326
1327  ifeq ($(dwarf-post-unwind),1)
1328    $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
1329  endif
1330  $(info )
1331endif
1332
1333$(call detected_var,bindir_SQ)
1334$(call detected_var,PYTHON_WORD)
1335ifneq ($(OUTPUT),)
1336$(call detected_var,OUTPUT)
1337endif
1338$(call detected_var,htmldir_SQ)
1339$(call detected_var,infodir_SQ)
1340$(call detected_var,mandir_SQ)
1341$(call detected_var,ETC_PERFCONFIG_SQ)
1342$(call detected_var,STRACE_GROUPS_DIR_SQ)
1343$(call detected_var,prefix_SQ)
1344$(call detected_var,perfexecdir_SQ)
1345$(call detected_var,perf_include_dir_SQ)
1346$(call detected_var,perf_examples_dir_SQ)
1347$(call detected_var,tipdir_SQ)
1348$(call detected_var,srcdir_SQ)
1349$(call detected_var,LIBDIR)
1350$(call detected_var,GTK_CFLAGS)
1351$(call detected_var,PERL_EMBED_CCOPTS)
1352$(call detected_var,PYTHON_EMBED_CCOPTS)
1353ifneq ($(BISON_FILE_PREFIX_MAP),)
1354$(call detected_var,BISON_FILE_PREFIX_MAP)
1355endif
1356
1357# re-generate FEATURE-DUMP as we may have called feature_check, found out
1358# extra libraries to add to LDFLAGS of some other test and then redo those
1359# tests, see the block about libbfd, disassembler-four-args, for instance.
1360$(shell rm -f $(FEATURE_DUMP_FILENAME))
1361$(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
1362
1363ifeq ($(feature_display),1)
1364  $(call feature_display_entries)
1365endif
1366