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