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