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