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