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