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