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