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