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