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