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