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