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