xref: /openbmc/linux/tools/perf/Makefile.config (revision 9a2d5178)
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_JVMTI := 1
419else
420  ifeq ($(feature-libelf), 0)
421    ifeq ($(feature-glibc), 1)
422      LIBC_SUPPORT := 1
423    endif
424    ifeq ($(BIONIC),1)
425      LIBC_SUPPORT := 1
426    endif
427    ifeq ($(LIBC_SUPPORT),1)
428      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.)
429    else
430      ifneq ($(filter s% -fsanitize=address%,$(EXTRA_CFLAGS),),)
431        ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0)
432          msg := $(error No libasan found, please install libasan);
433        endif
434      endif
435
436      ifneq ($(filter s% -fsanitize=undefined%,$(EXTRA_CFLAGS),),)
437        ifneq ($(shell ldconfig -p | grep libubsan >/dev/null 2>&1; echo $$?), 0)
438          msg := $(error No libubsan found, please install libubsan);
439        endif
440      endif
441
442      ifneq ($(filter s% -static%,$(LDFLAGS),),)
443        msg := $(error No static glibc found, please install glibc-static);
444      else
445        msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
446      endif
447    endif
448  else
449    ifndef NO_LIBDW_DWARF_UNWIND
450      ifneq ($(feature-libdw-dwarf-unwind),1)
451        NO_LIBDW_DWARF_UNWIND := 1
452        msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
453      endif
454    endif
455    ifneq ($(feature-dwarf), 1)
456      ifndef NO_DWARF
457        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);
458        NO_DWARF := 1
459      endif
460    else
461      ifneq ($(feature-dwarf_getlocations), 1)
462        msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
463      else
464        CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
465      endif # dwarf_getlocations
466    endif # Dwarf support
467  endif # libelf support
468endif # NO_LIBELF
469
470ifeq ($(feature-libaio), 1)
471  ifndef NO_AIO
472    CFLAGS += -DHAVE_AIO_SUPPORT
473  endif
474endif
475
476ifdef NO_DWARF
477  NO_LIBDW_DWARF_UNWIND := 1
478endif
479
480ifeq ($(feature-scandirat), 1)
481  CFLAGS += -DHAVE_SCANDIRAT_SUPPORT
482endif
483
484ifeq ($(feature-sched_getcpu), 1)
485  CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
486endif
487
488ifeq ($(feature-setns), 1)
489  CFLAGS += -DHAVE_SETNS_SUPPORT
490  $(call detected,CONFIG_SETNS)
491endif
492
493ifdef CORESIGHT
494  $(call feature_check,libopencsd)
495  ifeq ($(feature-libopencsd), 1)
496    CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
497    ifeq ($(feature-reallocarray), 0)
498      CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
499    endif
500    LDFLAGS += $(LIBOPENCSD_LDFLAGS)
501    EXTLIBS += $(OPENCSDLIBS)
502    $(call detected,CONFIG_LIBOPENCSD)
503    ifdef CSTRACE_RAW
504      CFLAGS += -DCS_DEBUG_RAW
505      ifeq (${CSTRACE_RAW}, packed)
506        CFLAGS += -DCS_RAW_PACKED
507      endif
508    endif
509  else
510    dummy := $(error Error: No libopencsd library found or the version is not up-to-date. Please install recent libopencsd to build with CORESIGHT=1)
511  endif
512endif
513
514ifndef NO_LIBELF
515  CFLAGS += -DHAVE_LIBELF_SUPPORT
516  EXTLIBS += -lelf
517  $(call detected,CONFIG_LIBELF)
518
519  ifeq ($(feature-libelf-getphdrnum), 1)
520    CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
521  endif
522
523  ifeq ($(feature-libelf-gelf_getnote), 1)
524    CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
525  else
526    msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
527  endif
528
529  ifeq ($(feature-libelf-getshdrstrndx), 1)
530    CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
531  endif
532
533  ifndef NO_LIBDEBUGINFOD
534    $(call feature_check,libdebuginfod)
535    ifeq ($(feature-libdebuginfod), 1)
536      CFLAGS += -DHAVE_DEBUGINFOD_SUPPORT
537      EXTLIBS += -ldebuginfod
538    endif
539  endif
540
541  ifndef NO_DWARF
542    ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
543      msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);
544      NO_DWARF := 1
545    else
546      CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
547      LDFLAGS += $(LIBDW_LDFLAGS)
548      EXTLIBS += ${DWARFLIBS}
549      $(call detected,CONFIG_DWARF)
550    endif # PERF_HAVE_DWARF_REGS
551  endif # NO_DWARF
552
553  ifndef NO_LIBBPF
554    ifeq ($(feature-bpf), 1)
555      CFLAGS += -DHAVE_LIBBPF_SUPPORT
556      $(call detected,CONFIG_LIBBPF)
557
558      # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
559      $(call feature_check,libbpf)
560
561      ifdef LIBBPF_DYNAMIC
562        ifeq ($(feature-libbpf), 1)
563          EXTLIBS += -lbpf
564          $(call detected,CONFIG_LIBBPF_DYNAMIC)
565        else
566          dummy := $(error Error: No libbpf devel library found or older than v1.0, please install/update libbpf-devel);
567        endif
568      else
569        # Libbpf will be built as a static library from tools/lib/bpf.
570	LIBBPF_STATIC := 1
571      endif
572    endif
573
574    ifndef NO_DWARF
575      ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
576        CFLAGS += -DHAVE_BPF_PROLOGUE
577        $(call detected,CONFIG_BPF_PROLOGUE)
578      else
579        msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
580      endif
581    else
582      msg := $(warning DWARF support is off, BPF prologue is disabled);
583    endif
584
585  endif # NO_LIBBPF
586endif # NO_LIBELF
587
588ifndef NO_SDT
589  ifneq ($(feature-sdt), 1)
590    msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
591    NO_SDT := 1;
592  else
593    CFLAGS += -DHAVE_SDT_EVENT
594    $(call detected,CONFIG_SDT_EVENT)
595  endif
596endif
597
598ifdef PERF_HAVE_JITDUMP
599  ifndef NO_LIBELF
600    $(call detected,CONFIG_JITDUMP)
601    CFLAGS += -DHAVE_JITDUMP
602  endif
603endif
604
605ifeq ($(SRCARCH),powerpc)
606  ifndef NO_DWARF
607    CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
608  endif
609endif
610
611ifndef NO_LIBUNWIND
612  have_libunwind :=
613
614  $(call feature_check,libunwind-x86)
615  ifeq ($(feature-libunwind-x86), 1)
616    $(call detected,CONFIG_LIBUNWIND_X86)
617    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
618    LDFLAGS += -lunwind-x86
619    EXTLIBS_LIBUNWIND += -lunwind-x86
620    have_libunwind = 1
621  endif
622
623  $(call feature_check,libunwind-aarch64)
624  ifeq ($(feature-libunwind-aarch64), 1)
625    $(call detected,CONFIG_LIBUNWIND_AARCH64)
626    CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
627    LDFLAGS += -lunwind-aarch64
628    EXTLIBS_LIBUNWIND += -lunwind-aarch64
629    have_libunwind = 1
630    $(call feature_check,libunwind-debug-frame-aarch64)
631    ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
632      msg := $(warning No debug_frame support found in libunwind-aarch64);
633      CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
634    endif
635  endif
636
637  ifneq ($(feature-libunwind), 1)
638    msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
639    NO_LOCAL_LIBUNWIND := 1
640  else
641    have_libunwind := 1
642    $(call detected,CONFIG_LOCAL_LIBUNWIND)
643  endif
644
645  ifneq ($(have_libunwind), 1)
646    NO_LIBUNWIND := 1
647  endif
648else
649  NO_LOCAL_LIBUNWIND := 1
650endif
651
652ifndef NO_LIBBPF
653  ifneq ($(feature-bpf), 1)
654    msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
655    NO_LIBBPF := 1
656  endif
657endif
658
659ifdef BUILD_BPF_SKEL
660  $(call feature_check,clang-bpf-co-re)
661  ifeq ($(feature-clang-bpf-co-re), 0)
662    dummy := $(error Error: clang too old/not installed. Please install recent clang to build with BUILD_BPF_SKEL)
663  endif
664  ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),)
665    dummy := $(error Error: BPF skeleton support requires libbpf)
666  endif
667  $(call detected,CONFIG_PERF_BPF_SKEL)
668  CFLAGS += -DHAVE_BPF_SKEL
669endif
670
671dwarf-post-unwind := 1
672dwarf-post-unwind-text := BUG
673
674# setup DWARF post unwinder
675ifdef NO_LIBUNWIND
676  ifdef NO_LIBDW_DWARF_UNWIND
677    msg := $(warning Disabling post unwind, no support found.);
678    dwarf-post-unwind := 0
679  else
680    dwarf-post-unwind-text := libdw
681    $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
682  endif
683else
684  dwarf-post-unwind-text := libunwind
685  $(call detected,CONFIG_LIBUNWIND)
686  # Enable libunwind support by default.
687  ifndef NO_LIBDW_DWARF_UNWIND
688    NO_LIBDW_DWARF_UNWIND := 1
689  endif
690endif
691
692ifeq ($(dwarf-post-unwind),1)
693  CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
694  $(call detected,CONFIG_DWARF_UNWIND)
695else
696  NO_DWARF_UNWIND := 1
697endif
698
699ifndef NO_LOCAL_LIBUNWIND
700  ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
701    $(call feature_check,libunwind-debug-frame)
702    ifneq ($(feature-libunwind-debug-frame), 1)
703      msg := $(warning No debug_frame support found in libunwind);
704      CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
705    endif
706  else
707    # non-ARM has no dwarf_find_debug_frame() function:
708    CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
709  endif
710  EXTLIBS += $(LIBUNWIND_LIBS)
711  LDFLAGS += $(LIBUNWIND_LIBS)
712endif
713ifeq ($(findstring -static,${LDFLAGS}),-static)
714  # gcc -static links libgcc_eh which contans piece of libunwind
715  LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
716endif
717
718ifndef NO_LIBUNWIND
719  CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
720  CFLAGS  += $(LIBUNWIND_CFLAGS)
721  LDFLAGS += $(LIBUNWIND_LDFLAGS)
722  EXTLIBS += $(EXTLIBS_LIBUNWIND)
723endif
724
725ifneq ($(NO_LIBTRACEEVENT),1)
726  ifeq ($(NO_SYSCALL_TABLE),0)
727    $(call detected,CONFIG_TRACE)
728  else
729    ifndef NO_LIBAUDIT
730      $(call feature_check,libaudit)
731      ifneq ($(feature-libaudit), 1)
732        msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
733        NO_LIBAUDIT := 1
734      else
735        CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
736        EXTLIBS += -laudit
737        $(call detected,CONFIG_TRACE)
738      endif
739    endif
740  endif
741endif
742
743ifndef NO_LIBCRYPTO
744  ifneq ($(feature-libcrypto), 1)
745    msg := $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev);
746    NO_LIBCRYPTO := 1
747  else
748    CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
749    EXTLIBS += -lcrypto
750    $(call detected,CONFIG_CRYPTO)
751  endif
752endif
753
754ifndef NO_SLANG
755  ifneq ($(feature-libslang), 1)
756    ifneq ($(feature-libslang-include-subdir), 1)
757      msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
758      NO_SLANG := 1
759    else
760      CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR
761    endif
762  endif
763  ifndef NO_SLANG
764    # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
765    CFLAGS += -DHAVE_SLANG_SUPPORT
766    EXTLIBS += -lslang
767    $(call detected,CONFIG_SLANG)
768  endif
769endif
770
771ifdef GTK2
772  FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
773  $(call feature_check,gtk2)
774  ifneq ($(feature-gtk2), 1)
775    msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
776    NO_GTK2 := 1
777  else
778    $(call feature_check,gtk2-infobar)
779    ifeq ($(feature-gtk2-infobar), 1)
780      GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
781    endif
782    CFLAGS += -DHAVE_GTK2_SUPPORT
783    GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
784    GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
785    EXTLIBS += -ldl
786  endif
787endif
788
789ifdef NO_LIBPERL
790  CFLAGS += -DNO_LIBPERL
791else
792  PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
793  PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
794  PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
795  PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
796  PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
797  PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
798  PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
799  FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
800
801  ifneq ($(feature-libperl), 1)
802    CFLAGS += -DNO_LIBPERL
803    NO_LIBPERL := 1
804    msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
805  else
806    LDFLAGS += $(PERL_EMBED_LDFLAGS)
807    EXTLIBS += $(PERL_EMBED_LIBADD)
808    CFLAGS += -DHAVE_LIBPERL_SUPPORT
809    ifeq ($(CC_NO_CLANG), 0)
810      CFLAGS += -Wno-compound-token-split-by-macro
811    endif
812    $(call detected,CONFIG_LIBPERL)
813  endif
814endif
815
816ifeq ($(feature-timerfd), 1)
817  CFLAGS += -DHAVE_TIMERFD_SUPPORT
818else
819  msg := $(warning No timerfd support. Disables 'perf kvm stat live');
820endif
821
822disable-python = $(eval $(disable-python_code))
823define disable-python_code
824  CFLAGS += -DNO_LIBPYTHON
825  $(warning $1)
826  NO_LIBPYTHON := 1
827endef
828
829PYTHON_EXTENSION_SUFFIX := '.so'
830ifdef NO_LIBPYTHON
831  $(call disable-python,Python support disabled by user)
832else
833
834  ifndef PYTHON
835    $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
836  else
837    PYTHON_WORD := $(call shell-wordify,$(PYTHON))
838
839    ifndef PYTHON_CONFIG
840      $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
841    else
842
843      ifneq ($(feature-libpython), 1)
844        $(call disable-python,No 'Python.h' was found: disables Python support - please install python-devel/python-dev)
845      else
846         LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
847         EXTLIBS += $(PYTHON_EMBED_LIBADD)
848         PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no")
849         ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes)
850           PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])')
851           LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX)
852	 else
853           msg := $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent);
854         endif
855         CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
856         $(call detected,CONFIG_LIBPYTHON)
857      endif
858    endif
859  endif
860endif
861
862ifneq ($(NO_JEVENTS),1)
863  ifeq ($(wildcard pmu-events/arch/$(SRCARCH)/mapfile.csv),)
864    NO_JEVENTS := 1
865  endif
866endif
867ifneq ($(NO_JEVENTS),1)
868  NO_JEVENTS := 0
869  ifndef PYTHON
870    $(error ERROR: No python interpreter needed for jevents generation. Install python or build with NO_JEVENTS=1.)
871  else
872    # jevents.py uses f-strings present in Python 3.6 released in Dec. 2016.
873    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)
874    ifneq ($(JEVENTS_PYTHON_GOOD), 1)
875      $(error ERROR: Python interpreter needed for jevents generation too old (older than 3.6). Install a newer python or build with NO_JEVENTS=1.)
876    endif
877  endif
878endif
879
880ifdef BUILD_NONDISTRO
881  ifeq ($(feature-libbfd), 1)
882    EXTLIBS += -lbfd -lopcodes
883  else
884    # we are on a system that requires -liberty and (maybe) -lz
885    # to link against -lbfd; test each case individually here
886
887    # call all detections now so we get correct
888    # status in VF output
889    $(call feature_check,libbfd-liberty)
890    $(call feature_check,libbfd-liberty-z)
891
892    ifeq ($(feature-libbfd-liberty), 1)
893      EXTLIBS += -lbfd -lopcodes -liberty
894    else
895      ifeq ($(feature-libbfd-liberty-z), 1)
896        EXTLIBS += -lbfd -lopcodes -liberty -lz
897      endif
898    endif
899    $(call feature_check,disassembler-four-args)
900    $(call feature_check,disassembler-init-styled)
901  endif
902
903  CFLAGS += -DHAVE_LIBBFD_SUPPORT
904  CXXFLAGS += -DHAVE_LIBBFD_SUPPORT
905  ifeq ($(feature-libbfd-buildid), 1)
906    CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT
907  else
908    msg := $(warning Old version of libbfd/binutils things like PE executable profiling will not be available);
909  endif
910endif
911
912ifndef NO_DEMANGLE
913  $(call feature_check,cxa-demangle)
914  ifeq ($(feature-cxa-demangle), 1)
915    EXTLIBS += -lstdc++
916    CFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
917    CXXFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
918  endif
919  ifdef BUILD_NONDISTRO
920    ifeq ($(filter -liberty,$(EXTLIBS)),)
921      $(call feature_check,cplus-demangle)
922      ifeq ($(feature-cplus-demangle), 1)
923        EXTLIBS += -liberty
924      endif
925    endif
926    ifneq ($(filter -liberty,$(EXTLIBS)),)
927      CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
928      CXXFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
929    endif
930  endif
931endif
932
933ifndef NO_ZLIB
934  ifeq ($(feature-zlib), 1)
935    CFLAGS += -DHAVE_ZLIB_SUPPORT
936    EXTLIBS += -lz
937    $(call detected,CONFIG_ZLIB)
938  else
939    NO_ZLIB := 1
940  endif
941endif
942
943ifndef NO_LZMA
944  ifeq ($(feature-lzma), 1)
945    CFLAGS += -DHAVE_LZMA_SUPPORT
946    EXTLIBS += -llzma
947    $(call detected,CONFIG_LZMA)
948  else
949    msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
950    NO_LZMA := 1
951  endif
952endif
953
954ifndef NO_LIBZSTD
955  ifeq ($(feature-libzstd), 1)
956    CFLAGS += -DHAVE_ZSTD_SUPPORT
957    CFLAGS += $(LIBZSTD_CFLAGS)
958    LDFLAGS += $(LIBZSTD_LDFLAGS)
959    EXTLIBS += -lzstd
960    $(call detected,CONFIG_ZSTD)
961  else
962    msg := $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR);
963    NO_LIBZSTD := 1
964  endif
965endif
966
967ifndef NO_LIBCAP
968  ifeq ($(feature-libcap), 1)
969    CFLAGS += -DHAVE_LIBCAP_SUPPORT
970    EXTLIBS += -lcap
971    $(call detected,CONFIG_LIBCAP)
972  else
973    msg := $(warning No libcap found, disables capability support, please install libcap-devel/libcap-dev);
974    NO_LIBCAP := 1
975  endif
976endif
977
978ifndef NO_BACKTRACE
979  ifeq ($(feature-backtrace), 1)
980    CFLAGS += -DHAVE_BACKTRACE_SUPPORT
981  endif
982endif
983
984ifndef NO_LIBNUMA
985  ifeq ($(feature-libnuma), 0)
986    msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
987    NO_LIBNUMA := 1
988  else
989    ifeq ($(feature-numa_num_possible_cpus), 0)
990      msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
991      NO_LIBNUMA := 1
992    else
993      CFLAGS += -DHAVE_LIBNUMA_SUPPORT
994      EXTLIBS += -lnuma
995      $(call detected,CONFIG_NUMA)
996    endif
997  endif
998endif
999
1000ifdef HAVE_KVM_STAT_SUPPORT
1001    CFLAGS += -DHAVE_KVM_STAT_SUPPORT
1002endif
1003
1004ifeq ($(feature-disassembler-four-args), 1)
1005    CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
1006endif
1007
1008ifeq ($(feature-disassembler-init-styled), 1)
1009    CFLAGS += -DDISASM_INIT_STYLED
1010endif
1011
1012ifeq (${IS_64_BIT}, 1)
1013  ifndef NO_PERF_READ_VDSO32
1014    $(call feature_check,compile-32)
1015    ifeq ($(feature-compile-32), 1)
1016      CFLAGS += -DHAVE_PERF_READ_VDSO32
1017    else
1018      NO_PERF_READ_VDSO32 := 1
1019    endif
1020  endif
1021  ifneq ($(SRCARCH), x86)
1022    NO_PERF_READ_VDSOX32 := 1
1023  endif
1024  ifndef NO_PERF_READ_VDSOX32
1025    $(call feature_check,compile-x32)
1026    ifeq ($(feature-compile-x32), 1)
1027      CFLAGS += -DHAVE_PERF_READ_VDSOX32
1028    else
1029      NO_PERF_READ_VDSOX32 := 1
1030    endif
1031  endif
1032else
1033  NO_PERF_READ_VDSO32 := 1
1034  NO_PERF_READ_VDSOX32 := 1
1035endif
1036
1037ifndef NO_LIBBABELTRACE
1038  $(call feature_check,libbabeltrace)
1039  ifeq ($(feature-libbabeltrace), 1)
1040    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
1041    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
1042    EXTLIBS += -lbabeltrace-ctf
1043    $(call detected,CONFIG_LIBBABELTRACE)
1044  else
1045    msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
1046  endif
1047endif
1048
1049ifndef NO_AUXTRACE
1050  ifeq ($(SRCARCH),x86)
1051    ifeq ($(feature-get_cpuid), 0)
1052      msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
1053      NO_AUXTRACE := 1
1054    endif
1055  endif
1056  ifndef NO_AUXTRACE
1057    $(call detected,CONFIG_AUXTRACE)
1058    CFLAGS += -DHAVE_AUXTRACE_SUPPORT
1059    ifeq ($(feature-reallocarray), 0)
1060      CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
1061    endif
1062  endif
1063endif
1064
1065ifndef NO_JVMTI
1066  ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
1067    JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
1068  else
1069    ifneq (,$(wildcard /usr/sbin/alternatives))
1070      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')
1071    endif
1072  endif
1073  ifndef JDIR
1074    $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
1075    NO_JVMTI := 1
1076  endif
1077endif
1078
1079ifndef NO_JVMTI
1080  FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
1081  $(call feature_check,jvmti)
1082  ifeq ($(feature-jvmti), 1)
1083    $(call detected_var,JDIR)
1084    ifndef NO_JVMTI_CMLR
1085      FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
1086      $(call feature_check,jvmti-cmlr)
1087      ifeq ($(feature-jvmti-cmlr), 1)
1088        CFLAGS += -DHAVE_JVMTI_CMLR
1089      endif
1090    endif # NO_JVMTI_CMLR
1091  else
1092    $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
1093    NO_JVMTI := 1
1094  endif
1095endif
1096
1097USE_CXX = 0
1098USE_CLANGLLVM = 0
1099ifdef LIBCLANGLLVM
1100  $(call feature_check,cxx)
1101  ifneq ($(feature-cxx), 1)
1102    msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
1103  else
1104    $(call feature_check,llvm)
1105    $(call feature_check,llvm-version)
1106    ifneq ($(feature-llvm), 1)
1107      msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
1108    else
1109      $(call feature_check,clang)
1110      ifneq ($(feature-clang), 1)
1111        msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
1112      else
1113        CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
1114        CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
1115        $(call detected,CONFIG_CXX)
1116        $(call detected,CONFIG_CLANGLLVM)
1117	USE_CXX = 1
1118	USE_LLVM = 1
1119	USE_CLANG = 1
1120        ifneq ($(feature-llvm-version),1)
1121          msg := $(warning This version of LLVM is not tested. May cause build errors)
1122        endif
1123      endif
1124    endif
1125  endif
1126endif
1127
1128ifndef NO_LIBPFM4
1129  $(call feature_check,libpfm4)
1130  ifeq ($(feature-libpfm4), 1)
1131    CFLAGS += -DHAVE_LIBPFM
1132    EXTLIBS += -lpfm
1133    ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1
1134    $(call detected,CONFIG_LIBPFM4)
1135  else
1136    msg := $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev);
1137  endif
1138endif
1139
1140# libtraceevent is a recommended dependency picked up from the system.
1141ifneq ($(NO_LIBTRACEEVENT),1)
1142  $(call feature_check,libtraceevent)
1143  ifeq ($(feature-libtraceevent), 1)
1144    CFLAGS += -DHAVE_LIBTRACEEVENT
1145    EXTLIBS += -ltraceevent
1146    LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent)
1147    LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1148    LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1149    LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
1150    LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3))
1151    CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP)
1152    $(call detected,CONFIG_LIBTRACEEVENT)
1153  else
1154    dummy := $(error ERROR: libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel or build with NO_LIBTRACEEVENT=1)
1155  endif
1156
1157  $(call feature_check,libtracefs)
1158  ifeq ($(feature-libtracefs), 1)
1159    EXTLIBS += -ltracefs
1160    LIBTRACEFS_VERSION := $(shell $(PKG_CONFIG) --modversion libtracefs)
1161    LIBTRACEFS_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEFS_VERSION)))
1162    LIBTRACEFS_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEFS_VERSION)))
1163    LIBTRACEFS_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEFS_VERSION)))
1164    LIBTRACEFS_VERSION_CPP := $(shell expr $(LIBTRACEFS_VERSION_1) \* 255 \* 255 + $(LIBTRACEFS_VERSION_2) \* 255 + $(LIBTRACEFS_VERSION_3))
1165    CFLAGS += -DLIBTRACEFS_VERSION=$(LIBTRACEFS_VERSION_CPP)
1166  endif
1167endif
1168
1169# Among the variables below, these:
1170#   perfexecdir
1171#   libbpf_include_dir
1172#   perf_examples_dir
1173#   template_dir
1174#   mandir
1175#   infodir
1176#   htmldir
1177#   ETC_PERFCONFIG (but not sysconfdir)
1178# can be specified as a relative path some/where/else;
1179# this is interpreted as relative to $(prefix) and "perf" at
1180# runtime figures out where they are based on the path to the executable.
1181# This can help installing the suite in a relocatable way.
1182
1183# Make the path relative to DESTDIR, not to prefix
1184ifndef DESTDIR
1185prefix ?= $(HOME)
1186endif
1187bindir_relative = bin
1188bindir = $(abspath $(prefix)/$(bindir_relative))
1189includedir_relative = include
1190includedir = $(abspath $(prefix)/$(includedir_relative))
1191mandir = share/man
1192infodir = share/info
1193perfexecdir = libexec/perf-core
1194# FIXME: system's libbpf header directory, where we expect to find bpf/bpf_helpers.h, for instance
1195libbpf_include_dir = /usr/include
1196perf_examples_dir = lib/perf/examples
1197sharedir = $(prefix)/share
1198template_dir = share/perf-core/templates
1199STRACE_GROUPS_DIR = share/perf-core/strace/groups
1200htmldir = share/doc/perf-doc
1201tipdir = share/doc/perf-tip
1202srcdir = $(srctree)/tools/perf
1203ifeq ($(prefix),/usr)
1204sysconfdir = /etc
1205ETC_PERFCONFIG = $(sysconfdir)/perfconfig
1206else
1207sysconfdir = $(prefix)/etc
1208ETC_PERFCONFIG = etc/perfconfig
1209endif
1210ifndef lib
1211ifeq ($(SRCARCH)$(IS_64_BIT), x861)
1212lib = lib64
1213else
1214lib = lib
1215endif
1216endif # lib
1217libdir = $(prefix)/$(lib)
1218
1219# Shell quote (do not use $(call) to accommodate ancient setups);
1220ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
1221STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
1222DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1223bindir_SQ = $(subst ','\'',$(bindir))
1224includedir_SQ = $(subst ','\'',$(includedir))
1225mandir_SQ = $(subst ','\'',$(mandir))
1226infodir_SQ = $(subst ','\'',$(infodir))
1227perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
1228libbpf_include_dir_SQ = $(subst ','\'',$(libbpf_include_dir))
1229perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
1230template_dir_SQ = $(subst ','\'',$(template_dir))
1231htmldir_SQ = $(subst ','\'',$(htmldir))
1232tipdir_SQ = $(subst ','\'',$(tipdir))
1233prefix_SQ = $(subst ','\'',$(prefix))
1234sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
1235libdir_SQ = $(subst ','\'',$(libdir))
1236srcdir_SQ = $(subst ','\'',$(srcdir))
1237
1238ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1239perfexec_instdir = $(perfexecdir)
1240perf_include_instdir = $(libbpf_include_dir)
1241perf_examples_instdir = $(perf_examples_dir)
1242STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
1243tip_instdir = $(tipdir)
1244else
1245perfexec_instdir = $(prefix)/$(perfexecdir)
1246perf_include_instdir = $(prefix)/$(libbpf_include_dir)
1247perf_examples_instdir = $(prefix)/$(perf_examples_dir)
1248STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
1249tip_instdir = $(prefix)/$(tipdir)
1250endif
1251perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1252perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
1253perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
1254STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
1255tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
1256
1257export perfexec_instdir_SQ
1258
1259print_var = $(eval $(print_var_code)) $(info $(MSG))
1260define print_var_code
1261    MSG = $(shell printf '...%40s: %s' $(1) $($(1)))
1262endef
1263
1264ifeq ($(feature_display),1)
1265  $(call feature_display_entries)
1266endif
1267
1268ifeq ($(VF),1)
1269  # Display EXTRA features which are detected manualy
1270  # from here with feature_check call and thus cannot
1271  # be partof global state output.
1272  $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),) $(info $(MSG)))
1273  $(call print_var,prefix)
1274  $(call print_var,bindir)
1275  $(call print_var,libdir)
1276  $(call print_var,sysconfdir)
1277  $(call print_var,LIBUNWIND_DIR)
1278  $(call print_var,LIBDW_DIR)
1279  $(call print_var,JDIR)
1280
1281  ifeq ($(dwarf-post-unwind),1)
1282    $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) $(info $(MSG))
1283  endif
1284endif
1285
1286$(info )
1287
1288$(call detected_var,bindir_SQ)
1289$(call detected_var,PYTHON_WORD)
1290ifneq ($(OUTPUT),)
1291$(call detected_var,OUTPUT)
1292endif
1293$(call detected_var,htmldir_SQ)
1294$(call detected_var,infodir_SQ)
1295$(call detected_var,mandir_SQ)
1296$(call detected_var,ETC_PERFCONFIG_SQ)
1297$(call detected_var,STRACE_GROUPS_DIR_SQ)
1298$(call detected_var,prefix_SQ)
1299$(call detected_var,perfexecdir_SQ)
1300$(call detected_var,libbpf_include_dir_SQ)
1301$(call detected_var,perf_examples_dir_SQ)
1302$(call detected_var,tipdir_SQ)
1303$(call detected_var,srcdir_SQ)
1304$(call detected_var,LIBDIR)
1305$(call detected_var,GTK_CFLAGS)
1306$(call detected_var,PERL_EMBED_CCOPTS)
1307$(call detected_var,PYTHON_EMBED_CCOPTS)
1308ifneq ($(BISON_FILE_PREFIX_MAP),)
1309$(call detected_var,BISON_FILE_PREFIX_MAP)
1310endif
1311
1312# re-generate FEATURE-DUMP as we may have called feature_check, found out
1313# extra libraries to add to LDFLAGS of some other test and then redo those
1314# tests.
1315$(shell rm -f $(FEATURE_DUMP_FILENAME))
1316$(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
1317