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