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