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