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