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