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
357FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
358FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl
359
360CORE_CFLAGS += -fno-omit-frame-pointer
361CORE_CFLAGS += -Wall
362CORE_CFLAGS += -Wextra
363CORE_CFLAGS += -std=gnu11
364
365CXXFLAGS += -std=gnu++17 -fno-exceptions -fno-rtti
366CXXFLAGS += -Wall
367CXXFLAGS += -Wextra
368CXXFLAGS += -fno-omit-frame-pointer
369
370HOSTCFLAGS += -Wall
371HOSTCFLAGS += -Wextra
372
373# Enforce a non-executable stack, as we may regress (again) in the future by
374# adding assembler files missing the .GNU-stack linker note.
375LDFLAGS += -Wl,-z,noexecstack
376
377EXTLIBS = -lpthread -lrt -lm -ldl
378
379ifneq ($(TCMALLOC),)
380 CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
381 EXTLIBS += -ltcmalloc
382endif
383
384ifeq ($(FEATURES_DUMP),)
385# We will display at the end of this Makefile.config, using $(call feature_display_entries)
386# As we may retry some feature detection here, see the disassembler-four-args case, for instance
387 FEATURE_DISPLAY_DEFERRED := 1
388include $(srctree)/tools/build/Makefile.feature
389else
390include $(FEATURES_DUMP)
391endif
392
393ifeq ($(feature-stackprotector-all), 1)
394 CORE_CFLAGS += -fstack-protector-all
395endif
396
397ifeq ($(DEBUG),0)
398 ifeq ($(feature-fortify-source), 1)
399 CORE_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
400 endif
401endif
402
403INC_FLAGS += -I$(src-perf)/util/include
404INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
405INC_FLAGS += -I$(srctree)/tools/include/
406INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
407INC_FLAGS += -I$(srctree)/tools/include/uapi
408INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
409INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
410
411# $(obj-perf) for generated common-cmds.h
412# $(obj-perf)/util for generated bison/flex headers
413ifneq ($(OUTPUT),)
414INC_FLAGS += -I$(obj-perf)/util
415INC_FLAGS += -I$(obj-perf)
416endif
417
418INC_FLAGS += -I$(src-perf)/util
419INC_FLAGS += -I$(src-perf)
420
421CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
422
423CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS)
424CXXFLAGS += $(INC_FLAGS)
425
426LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)
427
428ifeq ($(feature-pthread-attr-setaffinity-np), 1)
429 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
430endif
431
432ifeq ($(feature-pthread-barrier), 1)
433 CFLAGS += -DHAVE_PTHREAD_BARRIER
434endif
435
436ifndef NO_BIONIC
437 $(call feature_check,bionic)
438 ifeq ($(feature-bionic), 1)
439 BIONIC := 1
440 CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
441 CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
442 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
443 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
444 endif
445endif
446
447ifeq ($(feature-eventfd), 1)
448 CFLAGS += -DHAVE_EVENTFD_SUPPORT
449endif
450
451ifeq ($(feature-gettid), 1)
452 CFLAGS += -DHAVE_GETTID
453endif
454
455ifeq ($(feature-file-handle), 1)
456 CFLAGS += -DHAVE_FILE_HANDLE
457endif
458
459ifdef NO_LIBELF
460 NO_LIBDW := 1
461 NO_LIBUNWIND := 1
462 NO_LIBDW_DWARF_UNWIND := 1
463 NO_LIBBPF := 1
464 NO_JVMTI := 1
465else
466 ifeq ($(feature-libelf), 0)
467 ifeq ($(feature-glibc), 1)
468 LIBC_SUPPORT := 1
469 endif
470 ifeq ($(BIONIC),1)
471 LIBC_SUPPORT := 1
472 endif
473 ifeq ($(LIBC_SUPPORT),1)
474 $(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.)
475 else
476 ifneq ($(filter s% -fsanitize=address%,$(EXTRA_CFLAGS),),)
477 ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0)
478 $(error No libasan found, please install libasan)
479 endif
480 endif
481
482 ifneq ($(filter s% -fsanitize=undefined%,$(EXTRA_CFLAGS),),)
483 ifneq ($(shell ldconfig -p | grep libubsan >/dev/null 2>&1; echo $$?), 0)
484 $(error No libubsan found, please install libubsan)
485 endif
486 endif
487
488 ifneq ($(filter s% -static%,$(LDFLAGS),),)
489 $(error No static glibc found, please install glibc-static)
490 else
491 $(error No gnu/libc-version.h found, please install glibc-dev[el])
492 endif
493 endif
494 else
495 ifneq ($(feature-libdw), 1)
496 ifndef NO_LIBDW
497 $(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)
498 NO_LIBDW := 1
499 endif
500 endif # Dwarf support
501 endif # libelf support
502endif # NO_LIBELF
503
504ifeq ($(feature-libaio), 1)
505 ifndef NO_AIO
506 CFLAGS += -DHAVE_AIO_SUPPORT
507 endif
508endif
509
510ifdef NO_LIBDW
511 NO_LIBDW_DWARF_UNWIND := 1
512endif
513
514ifeq ($(feature-scandirat), 1)
515 # Ignore having scandirat with memory sanitizer that lacks an interceptor.
516 ifeq ($(filter s% -fsanitize=memory%,$(EXTRA_CFLAGS),),)
517 CFLAGS += -DHAVE_SCANDIRAT_SUPPORT
518 endif
519endif
520
521ifeq ($(feature-sched_getcpu), 1)
522 CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
523endif
524
525ifeq ($(feature-setns), 1)
526 CFLAGS += -DHAVE_SETNS_SUPPORT
527 $(call detected,CONFIG_SETNS)
528endif
529
530ifeq ($(feature-reallocarray), 0)
531 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
532endif
533
534ifdef CORESIGHT
535 $(call feature_check,libopencsd)
536 ifeq ($(feature-libopencsd), 1)
537 CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
538 LDFLAGS += $(LIBOPENCSD_LDFLAGS)
539 EXTLIBS += $(OPENCSDLIBS)
540 $(call detected,CONFIG_LIBOPENCSD)
541 ifdef CSTRACE_RAW
542 CFLAGS += -DCS_DEBUG_RAW
543 ifeq (${CSTRACE_RAW}, packed)
544 CFLAGS += -DCS_RAW_PACKED
545 endif
546 endif
547 else
548 $(error Error: No libopencsd library found or the version is not up-to-date. Please install recent libopencsd to build with CORESIGHT=1)
549 endif
550endif
551
552ifndef NO_ZLIB
553 ifeq ($(feature-zlib), 1)
554 CFLAGS += -DHAVE_ZLIB_SUPPORT
555 EXTLIBS += -lz
556 $(call detected,CONFIG_ZLIB)
557 else
558 NO_ZLIB := 1
559 endif
560endif
561
562ifndef NO_LIBELF
563 CFLAGS += -DHAVE_LIBELF_SUPPORT
564 EXTLIBS += -lelf
565 $(call detected,CONFIG_LIBELF)
566
567 ifeq ($(feature-libelf-getphdrnum), 1)
568 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
569 endif
570
571 ifeq ($(feature-libelf-gelf_getnote), 1)
572 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
573 else
574 $(warning gelf_getnote() not found on libelf, SDT support disabled)
575 endif
576
577 ifeq ($(feature-libelf-getshdrstrndx), 1)
578 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
579 endif
580
581 ifeq ($(feature-libelf-zstd), 1)
582 ifdef NO_LIBZSTD
583 $(error Error: libzstd is required by libelf, please do not set NO_LIBZSTD)
584 endif
585 endif
586
587 ifndef NO_LIBDEBUGINFOD
588 $(call feature_check,libdebuginfod)
589 ifeq ($(feature-libdebuginfod), 1)
590 CFLAGS += -DHAVE_DEBUGINFOD_SUPPORT
591 EXTLIBS += -ldebuginfod
592 else
593 $(warning No elfutils/debuginfod.h found, no debuginfo server support, please install libdebuginfod-dev/elfutils-debuginfod-client-devel or equivalent)
594 endif
595 endif
596
597 ifndef NO_LIBDW
598 CFLAGS += -DHAVE_LIBDW_SUPPORT $(LIBDW_CFLAGS)
599 LDFLAGS += $(LIBDW_LDFLAGS)
600 EXTLIBS += ${DWARFLIBS}
601 $(call detected,CONFIG_LIBDW)
602 endif # NO_LIBDW
603
604 ifndef NO_LIBBPF
605 ifeq ($(feature-bpf), 1)
606 # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
607 $(call feature_check,libbpf)
608
609 ifdef LIBBPF_DYNAMIC
610 ifeq ($(feature-libbpf), 1)
611 EXTLIBS += -lbpf
612 CFLAGS += -DHAVE_LIBBPF_SUPPORT
613 $(call detected,CONFIG_LIBBPF)
614 $(call detected,CONFIG_LIBBPF_DYNAMIC)
615 else
616 $(error Error: No libbpf devel library found or older than v1.0, please install/update libbpf-devel)
617 endif
618 else
619 ifeq ($(NO_ZLIB), 1)
620 $(warning Warning: Statically building libbpf not possible as zlib is missing)
621 NO_LIBBPF := 1
622 else
623 # Libbpf will be built as a static library from tools/lib/bpf.
624 LIBBPF_STATIC := 1
625 $(call detected,CONFIG_LIBBPF)
626 CFLAGS += -DHAVE_LIBBPF_SUPPORT
627 LIBBPF_INCLUDE = $(LIBBPF_DIR)/..
628 endif
629 endif
630 endif
631 endif # NO_LIBBPF
632endif # NO_LIBELF
633
634ifndef NO_SDT
635 ifneq ($(feature-sdt), 1)
636 $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev)
637 NO_SDT := 1;
638 else
639 CFLAGS += -DHAVE_SDT_EVENT
640 $(call detected,CONFIG_SDT_EVENT)
641 endif
642endif
643
644ifdef PERF_HAVE_JITDUMP
645 ifndef NO_LIBELF
646 $(call detected,CONFIG_JITDUMP)
647 CFLAGS += -DHAVE_JITDUMP
648 endif
649endif
650
651ifeq ($(SRCARCH),powerpc)
652 ifndef NO_LIBDW
653 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
654 endif
655endif
656
657ifndef NO_LIBUNWIND
658 have_libunwind :=
659
660 $(call feature_check,libunwind)
661
662 $(call feature_check,libunwind-x86)
663 ifeq ($(feature-libunwind-x86), 1)
664 $(call detected,CONFIG_LIBUNWIND_X86)
665 CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
666 LDFLAGS += -lunwind-x86
667 EXTLIBS_LIBUNWIND += -lunwind-x86
668 have_libunwind = 1
669 endif
670
671 $(call feature_check,libunwind-aarch64)
672 ifeq ($(feature-libunwind-aarch64), 1)
673 $(call detected,CONFIG_LIBUNWIND_AARCH64)
674 CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
675 LDFLAGS += -lunwind-aarch64
676 EXTLIBS_LIBUNWIND += -lunwind-aarch64
677 have_libunwind = 1
678 $(call feature_check,libunwind-debug-frame-aarch64)
679 ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
680 $(warning No debug_frame support found in libunwind-aarch64)
681 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
682 endif
683 endif
684
685 ifneq ($(feature-libunwind), 1)
686 $(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)
687 NO_LOCAL_LIBUNWIND := 1
688 else
689 have_libunwind := 1
690 $(call detected,CONFIG_LOCAL_LIBUNWIND)
691 endif
692
693 ifneq ($(have_libunwind), 1)
694 NO_LIBUNWIND := 1
695 endif
696else
697 NO_LOCAL_LIBUNWIND := 1
698endif
699
700ifndef NO_LIBBPF
701 ifneq ($(feature-bpf), 1)
702 $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
703 NO_LIBBPF := 1
704 endif
705endif
706
707ifndef BUILD_BPF_SKEL
708 # BPF skeletons control a large number of perf features, by default
709 # they are enabled.
710 BUILD_BPF_SKEL := 1
711endif
712
713ifeq ($(BUILD_BPF_SKEL),1)
714 ifeq ($(filter -DHAVE_LIBELF_SUPPORT, $(CFLAGS)),)
715 $(warning Warning: Disabled BPF skeletons as libelf is required by bpftool)
716 BUILD_BPF_SKEL := 0
717 else ifeq ($(filter -DHAVE_ZLIB_SUPPORT, $(CFLAGS)),)
718 $(warning Warning: Disabled BPF skeletons as zlib is required by bpftool)
719 BUILD_BPF_SKEL := 0
720 else ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),)
721 $(warning Warning: Disabled BPF skeletons as libbpf is required)
722 BUILD_BPF_SKEL := 0
723 else ifeq ($(call get-executable,$(CLANG)),)
724 $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing)
725 BUILD_BPF_SKEL := 0
726 else
727 CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g')
728 ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1)
729 $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1)
730 BUILD_BPF_SKEL := 0
731 endif
732 endif
733 ifeq ($(BUILD_BPF_SKEL),1)
734 $(call feature_check,clang-bpf-co-re)
735 ifeq ($(feature-clang-bpf-co-re), 0)
736 $(warning Warning: Disabled BPF skeletons as clang is too old)
737 BUILD_BPF_SKEL := 0
738 endif
739 endif
740 ifeq ($(BUILD_BPF_SKEL),1)
741 $(call detected,CONFIG_PERF_BPF_SKEL)
742 CFLAGS += -DHAVE_BPF_SKEL
743 endif
744endif
745
746ifndef GEN_VMLINUX_H
747 VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h
748endif
749
750dwarf-post-unwind := 1
751dwarf-post-unwind-text := BUG
752
753# setup DWARF post unwinder
754ifdef NO_LIBUNWIND
755 ifdef NO_LIBDW_DWARF_UNWIND
756 $(warning Disabling post unwind, no support found.)
757 dwarf-post-unwind := 0
758 else
759 dwarf-post-unwind-text := libdw
760 $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
761 endif
762else
763 dwarf-post-unwind-text := libunwind
764 $(call detected,CONFIG_LIBUNWIND)
765 # Enable libunwind support by default.
766 ifndef NO_LIBDW_DWARF_UNWIND
767 NO_LIBDW_DWARF_UNWIND := 1
768 endif
769endif
770
771ifeq ($(dwarf-post-unwind),1)
772 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
773 $(call detected,CONFIG_DWARF_UNWIND)
774endif
775
776ifndef NO_LIBUNWIND
777 ifndef NO_LOCAL_LIBUNWIND
778 ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
779 $(call feature_check,libunwind-debug-frame)
780 ifneq ($(feature-libunwind-debug-frame), 1)
781 $(warning No debug_frame support found in libunwind)
782 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
783 endif
784 else
785 # non-ARM has no dwarf_find_debug_frame() function:
786 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
787 endif
788 EXTLIBS += $(LIBUNWIND_LIBS)
789 LDFLAGS += $(LIBUNWIND_LIBS)
790 endif
791 ifeq ($(findstring -static,${LDFLAGS}),-static)
792 # gcc -static links libgcc_eh which contans piece of libunwind
793 LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
794 endif
795 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
796 CFLAGS += $(LIBUNWIND_CFLAGS)
797 LDFLAGS += $(LIBUNWIND_LDFLAGS)
798 EXTLIBS += $(EXTLIBS_LIBUNWIND)
799endif
800
801ifneq ($(NO_LIBTRACEEVENT),1)
802 $(call detected,CONFIG_TRACE)
803endif
804
805ifndef NO_SLANG
806 ifneq ($(feature-libslang), 1)
807 $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev)
808 NO_SLANG := 1
809 endif
810 ifndef NO_SLANG
811 CFLAGS += -DHAVE_SLANG_SUPPORT
812 EXTLIBS += -lslang
813 $(call detected,CONFIG_SLANG)
814 endif
815endif
816
817ifdef GTK2
818 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
819 $(call feature_check,gtk2)
820 ifneq ($(feature-gtk2), 1)
821 $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev)
822 NO_GTK2 := 1
823 else
824 $(call feature_check,gtk2-infobar)
825 ifeq ($(feature-gtk2-infobar), 1)
826 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
827 endif
828 CFLAGS += -DHAVE_GTK2_SUPPORT
829 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
830 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
831 EXTLIBS += -ldl
832 endif
833endif
834
835ifdef LIBPERL
836 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
837 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
838 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
839 PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
840 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
841 PERL_EMBED_CCOPTS := $(filter-out -flto% -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
842 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
843 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
844
845 $(call feature_check,libperl)
846 ifneq ($(feature-libperl), 1)
847 $(error Missing perl devel files. Please install perl-ExtUtils-Embed/libperl-dev)
848 else
849 LDFLAGS += $(PERL_EMBED_LDFLAGS)
850 EXTLIBS += $(PERL_EMBED_LIBADD)
851 CFLAGS += -DHAVE_LIBPERL_SUPPORT
852 $(call detected,CONFIG_LIBPERL)
853 endif
854endif
855
856ifeq ($(feature-timerfd), 1)
857 CFLAGS += -DHAVE_TIMERFD_SUPPORT
858else
859 $(warning No timerfd support. Disables 'perf kvm stat live')
860endif
861
862disable-python = $(eval $(disable-python_code))
863define disable-python_code
864 CFLAGS += -DNO_LIBPYTHON
865 $(warning $1)
866 NO_LIBPYTHON := 1
867endef
868
869PYTHON_EXTENSION_SUFFIX := '.so'
870ifdef NO_LIBPYTHON
871 $(call disable-python,Python support disabled by user)
872else
873
874 ifndef PYTHON
875 $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
876 else
877 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
878
879 ifndef PYTHON_CONFIG
880 $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
881 else
882
883 ifneq ($(feature-libpython), 1)
884 $(call disable-python,No 'Python.h' was found: disables Python support - please install python-devel/python-dev)
885 else
886 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
887 EXTLIBS += $(PYTHON_EMBED_LIBADD)
888 PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no")
889 ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes)
890 PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])')
891 ifdef CROSS_COMPILE
892 PYTHON_EXTENSION_SUFFIX := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EXTENSION_SUFFIX))
893 endif
894 LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX)
895 else
896 $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent)
897 endif
898 CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
899 $(call detected,CONFIG_LIBPYTHON)
900 ifeq ($(filter -fPIC,$(CFLAGS)),)
901 # Building a shared library requires position independent code.
902 CFLAGS += -fPIC
903 CXXFLAGS += -fPIC
904 endif
905 endif
906 endif
907 endif
908endif
909
910ifneq ($(NO_JEVENTS),1)
911 ifeq ($(wildcard pmu-events/arch/$(SRCARCH)/mapfile.csv),)
912 NO_JEVENTS := 1
913 endif
914endif
915ifneq ($(NO_JEVENTS),1)
916 NO_JEVENTS := 0
917 ifndef PYTHON
918 $(error ERROR: No python interpreter needed for jevents generation. Install python or build with NO_JEVENTS=1.)
919 else
920 # jevents.py uses f-strings present in Python 3.6 released in Dec. 2016.
921 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)
922 ifneq ($(JEVENTS_PYTHON_GOOD), 1)
923 $(error ERROR: Python interpreter needed for jevents generation too old (older than 3.6). Install a newer python or build with NO_JEVENTS=1.)
924 endif
925 endif
926endif
927
928ifdef BUILD_NONDISTRO
929 $(call feature_check,libbfd)
930
931 ifeq ($(feature-libbfd), 1)
932 EXTLIBS += -lbfd -lopcodes
933 else
934 # we are on a system that requires -liberty and (maybe) -lz
935 # to link against -lbfd; test each case individually here
936
937 # call all detections now so we get correct
938 # status in VF output
939 $(call feature_check,libbfd-liberty)
940 $(call feature_check,libbfd-liberty-z)
941
942 ifeq ($(feature-libbfd-liberty), 1)
943 EXTLIBS += -lbfd -lopcodes -liberty
944 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
945 FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl
946 else
947 ifeq ($(feature-libbfd-liberty-z), 1)
948 EXTLIBS += -lbfd -lopcodes -liberty -lz
949 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
950 FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl
951 endif
952 endif
953 $(call feature_check,disassembler-four-args)
954 $(call feature_check,disassembler-init-styled)
955 endif
956
957 CFLAGS += -DHAVE_LIBBFD_SUPPORT
958 CXXFLAGS += -DHAVE_LIBBFD_SUPPORT
959 $(call detected,CONFIG_LIBBFD)
960
961 $(call feature_check,libbfd-buildid)
962
963 ifeq ($(feature-libbfd-buildid), 1)
964 CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT
965 else
966 $(warning Old version of libbfd/binutils things like PE executable profiling will not be available)
967 endif
968
969 ifeq ($(feature-disassembler-four-args), 1)
970 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
971 endif
972
973 ifeq ($(feature-disassembler-init-styled), 1)
974 CFLAGS += -DDISASM_INIT_STYLED
975 endif
976endif
977
978ifndef NO_LIBLLVM
979 $(call feature_check,llvm-perf)
980 ifeq ($(feature-llvm-perf), 1)
981 CFLAGS += -DHAVE_LIBLLVM_SUPPORT
982 CFLAGS += $(shell $(LLVM_CONFIG) --cflags)
983 CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT
984 CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags)
985 LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs)
986 EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM)
987 EXTLIBS += -lstdc++
988 $(call detected,CONFIG_LIBLLVM)
989 else
990 $(warning No libllvm 13+ found, slower source file resolution, please install llvm-devel/llvm-dev)
991 NO_LIBLLVM := 1
992 endif
993endif
994
995ifndef NO_DEMANGLE
996 $(call feature_check,cxa-demangle)
997 ifeq ($(feature-cxa-demangle), 1)
998 EXTLIBS += -lstdc++
999 CFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
1000 CXXFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
1001 $(call detected,CONFIG_CXX_DEMANGLE)
1002 endif
1003 ifdef BUILD_NONDISTRO
1004 ifeq ($(filter -liberty,$(EXTLIBS)),)
1005 $(call feature_check,cplus-demangle)
1006 ifeq ($(feature-cplus-demangle), 1)
1007 EXTLIBS += -liberty
1008 endif
1009 endif
1010 ifneq ($(filter -liberty,$(EXTLIBS)),)
1011 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
1012 CXXFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
1013 endif
1014 endif
1015endif
1016
1017ifndef NO_LZMA
1018 ifeq ($(feature-lzma), 1)
1019 CFLAGS += -DHAVE_LZMA_SUPPORT
1020 EXTLIBS += -llzma
1021 $(call detected,CONFIG_LZMA)
1022 else
1023 $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev)
1024 NO_LZMA := 1
1025 endif
1026endif
1027
1028ifndef NO_LIBZSTD
1029 ifeq ($(feature-libzstd), 1)
1030 CFLAGS += -DHAVE_ZSTD_SUPPORT
1031 CFLAGS += $(LIBZSTD_CFLAGS)
1032 LDFLAGS += $(LIBZSTD_LDFLAGS)
1033 EXTLIBS += -lzstd
1034 $(call detected,CONFIG_ZSTD)
1035 else
1036 $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR)
1037 NO_LIBZSTD := 1
1038 endif
1039endif
1040
1041ifndef NO_BACKTRACE
1042 ifeq ($(feature-backtrace), 1)
1043 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
1044 endif
1045endif
1046
1047ifndef NO_LIBNUMA
1048 ifeq ($(feature-libnuma), 0)
1049 $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev)
1050 NO_LIBNUMA := 1
1051 else
1052 ifeq ($(feature-numa_num_possible_cpus), 0)
1053 $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8)
1054 NO_LIBNUMA := 1
1055 else
1056 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
1057 EXTLIBS += -lnuma
1058 $(call detected,CONFIG_NUMA)
1059 endif
1060 endif
1061endif
1062
1063ifdef HAVE_KVM_STAT_SUPPORT
1064 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
1065endif
1066
1067ifeq (${IS_64_BIT}, 1)
1068 ifndef NO_PERF_READ_VDSO32
1069 $(call feature_check,compile-32)
1070 ifeq ($(feature-compile-32), 1)
1071 CFLAGS += -DHAVE_PERF_READ_VDSO32
1072 else
1073 NO_PERF_READ_VDSO32 := 1
1074 endif
1075 endif
1076 ifneq ($(SRCARCH), x86)
1077 NO_PERF_READ_VDSOX32 := 1
1078 endif
1079 ifndef NO_PERF_READ_VDSOX32
1080 $(call feature_check,compile-x32)
1081 ifeq ($(feature-compile-x32), 1)
1082 CFLAGS += -DHAVE_PERF_READ_VDSOX32
1083 else
1084 NO_PERF_READ_VDSOX32 := 1
1085 endif
1086 endif
1087else
1088 NO_PERF_READ_VDSO32 := 1
1089 NO_PERF_READ_VDSOX32 := 1
1090endif
1091
1092ifndef NO_LIBBABELTRACE
1093 $(call feature_check,libbabeltrace)
1094 ifeq ($(feature-libbabeltrace), 1)
1095 CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
1096 LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
1097 EXTLIBS += -lbabeltrace-ctf
1098 $(call detected,CONFIG_LIBBABELTRACE)
1099 else
1100 $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
1101 endif
1102endif
1103
1104ifndef NO_CAPSTONE
1105 $(call feature_check,libcapstone)
1106 ifeq ($(feature-libcapstone), 1)
1107 CFLAGS += -DHAVE_LIBCAPSTONE_SUPPORT $(LIBCAPSTONE_CFLAGS)
1108 LDFLAGS += $(LICAPSTONE_LDFLAGS)
1109 EXTLIBS += -lcapstone
1110 $(call detected,CONFIG_LIBCAPSTONE)
1111 else
1112 msg := $(warning No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel);
1113 endif
1114endif
1115
1116ifndef NO_AUXTRACE
1117 ifeq ($(SRCARCH),x86)
1118 ifeq ($(feature-get_cpuid), 0)
1119 $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc)
1120 NO_AUXTRACE := 1
1121 endif
1122 endif
1123 ifndef NO_AUXTRACE
1124 $(call detected,CONFIG_AUXTRACE)
1125 CFLAGS += -DHAVE_AUXTRACE_SUPPORT
1126 endif
1127endif
1128
1129ifdef EXTRA_TESTS
1130 $(call detected,CONFIG_EXTRA_TESTS)
1131 CFLAGS += -DHAVE_EXTRA_TESTS
1132endif
1133
1134ifndef NO_JVMTI
1135 ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
1136 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
1137 else
1138 ifneq (,$(wildcard /usr/sbin/alternatives))
1139 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')
1140 endif
1141 endif
1142 ifndef JDIR
1143 $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
1144 NO_JVMTI := 1
1145 endif
1146endif
1147
1148ifndef NO_JVMTI
1149 FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
1150 $(call feature_check,jvmti)
1151 ifeq ($(feature-jvmti), 1)
1152 $(call detected_var,JDIR)
1153 ifndef NO_JVMTI_CMLR
1154 FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
1155 $(call feature_check,jvmti-cmlr)
1156 ifeq ($(feature-jvmti-cmlr), 1)
1157 CFLAGS += -DHAVE_JVMTI_CMLR
1158 endif
1159 endif # NO_JVMTI_CMLR
1160 else
1161 $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-latest-openjdk-devel)
1162 NO_JVMTI := 1
1163 endif
1164endif
1165
1166ifndef NO_LIBPFM4
1167 $(call feature_check,libpfm4)
1168 ifeq ($(feature-libpfm4), 1)
1169 CFLAGS += -DHAVE_LIBPFM
1170 EXTLIBS += -lpfm
1171 ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1
1172 $(call detected,CONFIG_LIBPFM4)
1173 else
1174 $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev)
1175 endif
1176endif
1177
1178# libtraceevent is a recommended dependency picked up from the system.
1179ifneq ($(NO_LIBTRACEEVENT),1)
1180 ifeq ($(feature-libtraceevent), 1)
1181 CFLAGS += -DHAVE_LIBTRACEEVENT $(shell $(PKG_CONFIG) --cflags libtraceevent)
1182 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libtraceevent)
1183 EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libtraceevent)
1184 LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent).0.0
1185 LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1186 LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1187 LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1188 LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3))
1189 CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP)
1190 $(call detected,CONFIG_LIBTRACEEVENT)
1191 else
1192 $(error ERROR: libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel and/or set LIBTRACEEVENT_DIR or build with NO_LIBTRACEEVENT=1)
1193 endif
1194endif
1195
1196# Among the variables below, these:
1197# perfexecdir
1198# libbpf_include_dir
1199# perf_examples_dir
1200# template_dir
1201# mandir
1202# infodir
1203# htmldir
1204# ETC_PERFCONFIG (but not sysconfdir)
1205# can be specified as a relative path some/where/else;
1206# this is interpreted as relative to $(prefix) and "perf" at
1207# runtime figures out where they are based on the path to the executable.
1208# This can help installing the suite in a relocatable way.
1209
1210# Make the path relative to DESTDIR, not to prefix
1211ifndef DESTDIR
1212prefix ?= $(HOME)
1213endif
1214bindir_relative = bin
1215bindir = $(abspath $(prefix)/$(bindir_relative))
1216includedir_relative = include
1217includedir = $(abspath $(prefix)/$(includedir_relative))
1218mandir = share/man
1219infodir = share/info
1220perfexecdir = libexec/perf-core
1221# FIXME: system's libbpf header directory, where we expect to find bpf/bpf_helpers.h, for instance
1222libbpf_include_dir = /usr/include
1223perf_examples_dir = lib/perf/examples
1224sharedir = $(prefix)/share
1225template_dir = share/perf-core/templates
1226STRACE_GROUPS_DIR = share/perf-core/strace/groups
1227htmldir = share/doc/perf-doc
1228tipdir = share/doc/perf-tip
1229srcdir = $(srctree)/tools/perf
1230ifeq ($(prefix),/usr)
1231sysconfdir = /etc
1232ETC_PERFCONFIG = $(sysconfdir)/perfconfig
1233else
1234sysconfdir = $(prefix)/etc
1235ETC_PERFCONFIG = etc/perfconfig
1236endif
1237ifndef lib
1238ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1239lib = lib64
1240else
1241lib = lib
1242endif
1243endif # lib
1244libdir = $(prefix)/$(lib)
1245
1246# Shell quote (do not use $(call) to accommodate ancient setups);
1247ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1248STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1249DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1250bindir_SQ = $(subst ','\'',$(bindir))
1251includedir_SQ = $(subst ','\'',$(includedir))
1252mandir_SQ = $(subst ','\'',$(mandir))
1253infodir_SQ = $(subst ','\'',$(infodir))
1254perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1255libbpf_include_dir_SQ = $(subst ','\'',$(libbpf_include_dir))
1256perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1257template_dir_SQ = $(subst ','\'',$(template_dir))
1258htmldir_SQ = $(subst ','\'',$(htmldir))
1259tipdir_SQ = $(subst ','\'',$(tipdir))
1260prefix_SQ = $(subst ','\'',$(prefix))
1261sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1262libdir_SQ = $(subst ','\'',$(libdir))
1263srcdir_SQ = $(subst ','\'',$(srcdir))
1264
1265ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1266perfexec_instdir = $(perfexecdir)
1267perf_include_instdir = $(libbpf_include_dir)
1268perf_examples_instdir = $(perf_examples_dir)
1269STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1270tip_instdir = $(tipdir)
1271else
1272perfexec_instdir = $(prefix)/$(perfexecdir)
1273perf_include_instdir = $(prefix)/$(libbpf_include_dir)
1274perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1275STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1276tip_instdir = $(prefix)/$(tipdir)
1277endif
1278perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1279perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1280perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1281STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1282tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1283
1284export perfexec_instdir_SQ
1285
1286print_var = $(eval $(print_var_code)) $(info $(MSG))
1287define print_var_code
1288 MSG = $(shell printf '...%40s: %s' $(1) $($(1)))
1289endef
1290
1291ifeq ($(feature_display),1)
1292 $(call feature_display_entries)
1293endif
1294
1295ifeq ($(VF),1)
1296 # Display EXTRA features which are detected manualy
1297 # from here with feature_check call and thus cannot
1298 # be partof global state output.
1299 $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),) $(info $(MSG)))
1300 $(call print_var,prefix)
1301 $(call print_var,bindir)
1302 $(call print_var,libdir)
1303 $(call print_var,sysconfdir)
1304 $(call print_var,LIBUNWIND_DIR)
1305 $(call print_var,LIBDW_DIR)
1306 $(call print_var,JDIR)
1307
1308 ifeq ($(dwarf-post-unwind),1)
1309 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) $(info $(MSG))
1310 endif
1311endif
1312
1313$(info )
1314
1315$(call detected_var,bindir_SQ)
1316$(call detected_var,PYTHON_WORD)
1317ifneq ($(OUTPUT),)
1318$(call detected_var,OUTPUT)
1319endif
1320$(call detected_var,htmldir_SQ)
1321$(call detected_var,infodir_SQ)
1322$(call detected_var,mandir_SQ)
1323$(call detected_var,ETC_PERFCONFIG_SQ)
1324$(call detected_var,STRACE_GROUPS_DIR_SQ)
1325$(call detected_var,prefix_SQ)
1326$(call detected_var,perfexecdir_SQ)
1327$(call detected_var,libbpf_include_dir_SQ)
1328$(call detected_var,perf_examples_dir_SQ)
1329$(call detected_var,tipdir_SQ)
1330$(call detected_var,srcdir_SQ)
1331$(call detected_var,LIBDIR)
1332$(call detected_var,GTK_CFLAGS)
1333$(call detected_var,PERL_EMBED_CCOPTS)
1334$(call detected_var,PYTHON_EMBED_CCOPTS)
1335ifneq ($(BISON_FILE_PREFIX_MAP),)
1336$(call detected_var,BISON_FILE_PREFIX_MAP)
1337endif
1338
1339# re-generate FEATURE-DUMP as we may have called feature_check, found out
1340# extra libraries to add to LDFLAGS of some other test and then redo those
1341# tests, see the block about libbfd, disassembler-four-args, for instance.
1342$(shell rm -f $(FEATURE_DUMP_FILENAME))
1343$(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))