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