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