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