xref: /linux/tools/perf/Makefile.config (revision 1672f3707a6ef4b386c30bb76df2f62e58a39430)
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.
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 all detections now so we get correct status in VF output
935  $(call feature_check,libbfd)
936  $(call feature_check,disassembler-four-args)
937  $(call feature_check,disassembler-init-styled)
938  $(call feature_check,libbfd-threadsafe)
939  $(call feature_check,libbfd-liberty)
940  $(call feature_check,libbfd-liberty-z)
941
942  ifneq ($(feature-libbfd-threadsafe), 1)
943    $(error binutils 2.42 or later is required for non-distro builds)
944  endif
945
946  # we may be on a system that requires -liberty and (maybe) -lz
947  # to link against -lbfd; test each case individually here
948  ifeq ($(feature-libbfd), 1)
949    EXTLIBS += -lbfd -lopcodes
950  else ifeq ($(feature-libbfd-liberty), 1)
951    EXTLIBS += -lbfd -lopcodes -liberty
952  else ifeq ($(feature-libbfd-liberty-z), 1)
953    EXTLIBS += -lbfd -lopcodes -liberty -lz
954  endif
955
956  CFLAGS += -DHAVE_LIBBFD_SUPPORT
957  CXXFLAGS += -DHAVE_LIBBFD_SUPPORT
958  $(call detected,CONFIG_LIBBFD)
959
960  ifeq ($(feature-disassembler-four-args), 1)
961    CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
962  endif
963
964  ifeq ($(feature-disassembler-init-styled), 1)
965    CFLAGS += -DDISASM_INIT_STYLED
966  endif
967endif
968
969ifndef NO_LIBLLVM
970  $(call feature_check,llvm-perf)
971  ifeq ($(feature-llvm-perf), 1)
972    CFLAGS += -DHAVE_LIBLLVM_SUPPORT
973    CFLAGS += $(shell $(LLVM_CONFIG) --cflags)
974    CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT
975    CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags)
976    LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs)
977    EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM)
978    EXTLIBS += -lstdc++
979    $(call detected,CONFIG_LIBLLVM)
980  else
981    $(warning No libllvm 13+ found, slower source file resolution, please install llvm-devel/llvm-dev)
982    NO_LIBLLVM := 1
983  endif
984endif
985
986ifndef NO_DEMANGLE
987  $(call feature_check,cxa-demangle)
988  ifeq ($(feature-cxa-demangle), 1)
989    EXTLIBS += -lstdc++
990    CFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
991    CXXFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
992    $(call detected,CONFIG_CXX_DEMANGLE)
993  endif
994  ifdef BUILD_NONDISTRO
995    ifeq ($(filter -liberty,$(EXTLIBS)),)
996      $(call feature_check,cplus-demangle)
997      ifeq ($(feature-cplus-demangle), 1)
998        EXTLIBS += -liberty
999      endif
1000    endif
1001    ifneq ($(filter -liberty,$(EXTLIBS)),)
1002      CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
1003      CXXFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
1004    endif
1005  endif
1006endif
1007
1008ifndef NO_LZMA
1009  ifeq ($(feature-lzma), 1)
1010    CFLAGS += -DHAVE_LZMA_SUPPORT
1011    EXTLIBS += -llzma
1012    $(call detected,CONFIG_LZMA)
1013  else
1014    $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev)
1015    NO_LZMA := 1
1016  endif
1017endif
1018
1019ifndef NO_LIBZSTD
1020  ifeq ($(feature-libzstd), 1)
1021    CFLAGS += -DHAVE_ZSTD_SUPPORT
1022    CFLAGS += $(LIBZSTD_CFLAGS)
1023    LDFLAGS += $(LIBZSTD_LDFLAGS)
1024    EXTLIBS += -lzstd
1025    $(call detected,CONFIG_ZSTD)
1026  else
1027    $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR)
1028    NO_LIBZSTD := 1
1029  endif
1030endif
1031
1032ifndef NO_BACKTRACE
1033  ifeq ($(feature-backtrace), 1)
1034    CFLAGS += -DHAVE_BACKTRACE_SUPPORT
1035  endif
1036endif
1037
1038ifndef NO_LIBNUMA
1039  ifeq ($(feature-libnuma), 0)
1040    $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev)
1041    NO_LIBNUMA := 1
1042  else
1043    ifeq ($(feature-numa_num_possible_cpus), 0)
1044      $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8)
1045      NO_LIBNUMA := 1
1046    else
1047      CFLAGS += -DHAVE_LIBNUMA_SUPPORT
1048      EXTLIBS += -lnuma
1049      $(call detected,CONFIG_NUMA)
1050    endif
1051  endif
1052endif
1053
1054ifdef HAVE_KVM_STAT_SUPPORT
1055    CFLAGS += -DHAVE_KVM_STAT_SUPPORT
1056endif
1057
1058ifeq (${IS_64_BIT}, 1)
1059  ifndef NO_PERF_READ_VDSO32
1060    $(call feature_check,compile-32)
1061    ifeq ($(feature-compile-32), 1)
1062      CFLAGS += -DHAVE_PERF_READ_VDSO32
1063    else
1064      NO_PERF_READ_VDSO32 := 1
1065    endif
1066  endif
1067  ifneq ($(SRCARCH), x86)
1068    NO_PERF_READ_VDSOX32 := 1
1069  endif
1070  ifndef NO_PERF_READ_VDSOX32
1071    $(call feature_check,compile-x32)
1072    ifeq ($(feature-compile-x32), 1)
1073      CFLAGS += -DHAVE_PERF_READ_VDSOX32
1074    else
1075      NO_PERF_READ_VDSOX32 := 1
1076    endif
1077  endif
1078else
1079  NO_PERF_READ_VDSO32 := 1
1080  NO_PERF_READ_VDSOX32 := 1
1081endif
1082
1083ifndef NO_LIBBABELTRACE
1084  $(call feature_check,libbabeltrace)
1085  ifeq ($(feature-libbabeltrace), 1)
1086    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
1087    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
1088    EXTLIBS += -lbabeltrace-ctf
1089    $(call detected,CONFIG_LIBBABELTRACE)
1090  else
1091    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
1092  endif
1093endif
1094
1095ifndef NO_CAPSTONE
1096  $(call feature_check,libcapstone)
1097  ifeq ($(feature-libcapstone), 1)
1098    CFLAGS += -DHAVE_LIBCAPSTONE_SUPPORT $(LIBCAPSTONE_CFLAGS)
1099    LDFLAGS += $(LICAPSTONE_LDFLAGS)
1100    EXTLIBS += -lcapstone
1101    $(call detected,CONFIG_LIBCAPSTONE)
1102  else
1103    msg := $(warning No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel);
1104  endif
1105endif
1106
1107ifdef EXTRA_TESTS
1108    $(call detected,CONFIG_EXTRA_TESTS)
1109    CFLAGS += -DHAVE_EXTRA_TESTS
1110endif
1111
1112ifndef NO_JVMTI
1113  ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
1114    JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
1115  else
1116    ifneq (,$(wildcard /usr/sbin/alternatives))
1117      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')
1118    endif
1119  endif
1120  ifndef JDIR
1121    $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
1122    NO_JVMTI := 1
1123  endif
1124endif
1125
1126ifndef NO_JVMTI
1127  FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
1128  $(call feature_check,jvmti)
1129  ifeq ($(feature-jvmti), 1)
1130    $(call detected_var,JDIR)
1131    ifndef NO_JVMTI_CMLR
1132      FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
1133      $(call feature_check,jvmti-cmlr)
1134      ifeq ($(feature-jvmti-cmlr), 1)
1135        CFLAGS += -DHAVE_JVMTI_CMLR
1136      endif
1137    endif # NO_JVMTI_CMLR
1138  else
1139    $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-latest-openjdk-devel)
1140    NO_JVMTI := 1
1141  endif
1142endif
1143
1144ifndef NO_LIBPFM4
1145  $(call feature_check,libpfm4)
1146  ifeq ($(feature-libpfm4), 1)
1147    CFLAGS += -DHAVE_LIBPFM
1148    EXTLIBS += -lpfm
1149    ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1
1150    $(call detected,CONFIG_LIBPFM4)
1151  else
1152    $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm-devel or libpfm4-dev)
1153  endif
1154endif
1155
1156# libtraceevent is a recommended dependency picked up from the system.
1157ifneq ($(NO_LIBTRACEEVENT),1)
1158  ifeq ($(feature-libtraceevent), 1)
1159    CFLAGS += -DHAVE_LIBTRACEEVENT $(shell $(PKG_CONFIG) --cflags libtraceevent)
1160    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libtraceevent)
1161    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libtraceevent)
1162    LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent).0.0
1163    LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1164    LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1165    LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1166    LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3))
1167    CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP)
1168    $(call detected,CONFIG_LIBTRACEEVENT)
1169  else
1170    $(error ERROR: libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel and/or set LIBTRACEEVENT_DIR or build with NO_LIBTRACEEVENT=1)
1171  endif
1172endif
1173
1174# Among the variables below, these:
1175#   perfexecdir
1176#   libbpf_include_dir
1177#   perf_examples_dir
1178#   template_dir
1179#   mandir
1180#   infodir
1181#   htmldir
1182#   ETC_PERFCONFIG (but not sysconfdir)
1183# can be specified as a relative path some/where/else;
1184# this is interpreted as relative to $(prefix) and "perf" at
1185# runtime figures out where they are based on the path to the executable.
1186# This can help installing the suite in a relocatable way.
1187
1188# Make the path relative to DESTDIR, not to prefix
1189ifndef DESTDIR
1190prefix ?= $(HOME)
1191endif
1192bindir_relative = bin
1193bindir = $(abspath $(prefix)/$(bindir_relative))
1194includedir_relative = include
1195includedir = $(abspath $(prefix)/$(includedir_relative))
1196mandir = share/man
1197infodir = share/info
1198perfexecdir = libexec/perf-core
1199# FIXME: system's libbpf header directory, where we expect to find bpf/bpf_helpers.h, for instance
1200libbpf_include_dir = /usr/include
1201perf_examples_dir = lib/perf/examples
1202sharedir = $(prefix)/share
1203template_dir = share/perf-core/templates
1204STRACE_GROUPS_DIR = share/perf-core/strace/groups
1205htmldir = share/doc/perf-doc
1206tipdir = share/doc/perf-tip
1207srcdir = $(srctree)/tools/perf
1208ifeq ($(prefix),/usr)
1209sysconfdir = /etc
1210ETC_PERFCONFIG = $(sysconfdir)/perfconfig
1211else
1212sysconfdir = $(prefix)/etc
1213ETC_PERFCONFIG = etc/perfconfig
1214endif
1215ifndef lib
1216ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1217lib = lib64
1218else
1219lib = lib
1220endif
1221endif # lib
1222libdir = $(prefix)/$(lib)
1223
1224# Shell quote (do not use $(call) to accommodate ancient setups);
1225ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1226STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1227DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1228bindir_SQ = $(subst ','\'',$(bindir))
1229includedir_SQ = $(subst ','\'',$(includedir))
1230mandir_SQ = $(subst ','\'',$(mandir))
1231infodir_SQ = $(subst ','\'',$(infodir))
1232perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1233libbpf_include_dir_SQ = $(subst ','\'',$(libbpf_include_dir))
1234perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1235template_dir_SQ = $(subst ','\'',$(template_dir))
1236htmldir_SQ = $(subst ','\'',$(htmldir))
1237tipdir_SQ = $(subst ','\'',$(tipdir))
1238prefix_SQ = $(subst ','\'',$(prefix))
1239sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1240libdir_SQ = $(subst ','\'',$(libdir))
1241srcdir_SQ = $(subst ','\'',$(srcdir))
1242
1243ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1244perfexec_instdir = $(perfexecdir)
1245perf_include_instdir = $(libbpf_include_dir)
1246perf_examples_instdir = $(perf_examples_dir)
1247STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1248tip_instdir = $(tipdir)
1249else
1250perfexec_instdir = $(prefix)/$(perfexecdir)
1251perf_include_instdir = $(prefix)/$(libbpf_include_dir)
1252perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1253STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1254tip_instdir = $(prefix)/$(tipdir)
1255endif
1256perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1257perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1258perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1259STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1260tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1261
1262export perfexec_instdir_SQ
1263
1264print_var = $(eval $(print_var_code)) $(info $(MSG))
1265define print_var_code
1266    MSG = $(shell printf '...%40s: %s' $(1) $($(1)))
1267endef
1268
1269ifeq ($(feature_display),1)
1270  $(call feature_display_entries)
1271endif
1272
1273ifeq ($(VF),1)
1274  # Display EXTRA features which are detected manualy
1275  # from here with feature_check call and thus cannot
1276  # be partof global state output.
1277  $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),) $(info $(MSG)))
1278  $(call print_var,prefix)
1279  $(call print_var,bindir)
1280  $(call print_var,libdir)
1281  $(call print_var,sysconfdir)
1282  $(call print_var,LIBUNWIND_DIR)
1283  $(call print_var,LIBDW_DIR)
1284  $(call print_var,JDIR)
1285
1286  ifeq ($(dwarf-post-unwind),1)
1287    $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) $(info $(MSG))
1288  endif
1289endif
1290
1291$(info )
1292
1293$(call detected_var,bindir_SQ)
1294$(call detected_var,PYTHON_WORD)
1295ifneq ($(OUTPUT),)
1296$(call detected_var,OUTPUT)
1297endif
1298$(call detected_var,htmldir_SQ)
1299$(call detected_var,infodir_SQ)
1300$(call detected_var,mandir_SQ)
1301$(call detected_var,ETC_PERFCONFIG_SQ)
1302$(call detected_var,STRACE_GROUPS_DIR_SQ)
1303$(call detected_var,prefix_SQ)
1304$(call detected_var,perfexecdir_SQ)
1305$(call detected_var,libbpf_include_dir_SQ)
1306$(call detected_var,perf_examples_dir_SQ)
1307$(call detected_var,tipdir_SQ)
1308$(call detected_var,srcdir_SQ)
1309$(call detected_var,LIBDIR)
1310$(call detected_var,GTK_CFLAGS)
1311$(call detected_var,PERL_EMBED_CCOPTS)
1312$(call detected_var,PYTHON_EMBED_CCOPTS)
1313ifneq ($(BISON_FILE_PREFIX_MAP),)
1314$(call detected_var,BISON_FILE_PREFIX_MAP)
1315endif
1316
1317# re-generate FEATURE-DUMP as we may have called feature_check, found out
1318# extra libraries to add to LDFLAGS of some other test and then redo those
1319# tests.
1320$(shell rm -f $(FEATURE_DUMP_FILENAME))
1321$(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
1322