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