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