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