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