Back to home page

LXR

 
 

    


0001 
0002 ifeq ($(src-perf),)
0003 src-perf := $(srctree)/tools/perf
0004 endif
0005 
0006 ifeq ($(obj-perf),)
0007 obj-perf := $(OUTPUT)
0008 endif
0009 
0010 ifneq ($(obj-perf),)
0011 obj-perf := $(abspath $(obj-perf))/
0012 endif
0013 
0014 $(shell printf "" > $(OUTPUT).config-detected)
0015 detected     = $(shell echo "$(1)=y"       >> $(OUTPUT).config-detected)
0016 detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
0017 
0018 CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
0019 
0020 include $(srctree)/tools/scripts/Makefile.arch
0021 
0022 $(call detected_var,ARCH)
0023 
0024 NO_PERF_REGS := 1
0025 
0026 # Additional ARCH settings for ppc
0027 ifeq ($(ARCH),powerpc)
0028   NO_PERF_REGS := 0
0029   LIBUNWIND_LIBS := -lunwind -lunwind-ppc64
0030 endif
0031 
0032 # Additional ARCH settings for x86
0033 ifeq ($(ARCH),x86)
0034   $(call detected,CONFIG_X86)
0035   ifeq (${IS_64_BIT}, 1)
0036     CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT -DHAVE_SYSCALL_TABLE -I$(OUTPUT)arch/x86/include/generated
0037     ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
0038     LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
0039     $(call detected,CONFIG_X86_64)
0040   else
0041     LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind
0042   endif
0043   NO_PERF_REGS := 0
0044 endif
0045 
0046 ifeq ($(ARCH),arm)
0047   NO_PERF_REGS := 0
0048   LIBUNWIND_LIBS = -lunwind -lunwind-arm
0049 endif
0050 
0051 ifeq ($(ARCH),arm64)
0052   NO_PERF_REGS := 0
0053   LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
0054 endif
0055 
0056 ifeq ($(NO_PERF_REGS),0)
0057   $(call detected,CONFIG_PERF_REGS)
0058 endif
0059 
0060 # So far there's only x86 and arm libdw unwind support merged in perf.
0061 # Disable it on all other architectures in case libdw unwind
0062 # support is detected in system. Add supported architectures
0063 # to the check.
0064 ifneq ($(ARCH),$(filter $(ARCH),x86 arm))
0065   NO_LIBDW_DWARF_UNWIND := 1
0066 endif
0067 
0068 ifeq ($(LIBUNWIND_LIBS),)
0069   NO_LIBUNWIND := 1
0070 endif
0071 #
0072 # For linking with debug library, run like:
0073 #
0074 #   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
0075 #
0076 
0077 libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
0078 define libunwind_arch_set_flags_code
0079   FEATURE_CHECK_CFLAGS-libunwind-$(1)  = -I$(LIBUNWIND_DIR)/include
0080   FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib 
0081 endef
0082 
0083 ifdef LIBUNWIND_DIR
0084   LIBUNWIND_CFLAGS  = -I$(LIBUNWIND_DIR)/include
0085   LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib 
0086   LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
0087   $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
0088 endif
0089 
0090 # Set per-feature check compilation flags
0091 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
0092 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
0093 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
0094 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
0095 
0096 ifeq ($(NO_PERF_REGS),0)
0097   CFLAGS += -DHAVE_PERF_REGS_SUPPORT
0098 endif
0099 
0100 # for linking with debug library, run like:
0101 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
0102 ifdef LIBDW_DIR
0103   LIBDW_CFLAGS  := -I$(LIBDW_DIR)/include
0104   LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib 
0105 endif
0106 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
0107 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) -ldw
0108 
0109 # for linking with debug library, run like:
0110 # make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
0111 ifdef LIBBABELTRACE_DIR
0112   LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
0113   LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib 
0114 endif
0115 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
0116 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
0117 
0118 FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(ARCH)/include/uapi -I$(srctree)/tools/include/uapi 
0119 # include ARCH specific config
0120 -include $(src-perf)/arch/$(ARCH)/Makefile
0121 
0122 ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
0123   CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
0124 endif
0125 
0126 include $(srctree)/tools/scripts/utilities.mak
0127 
0128 ifeq ($(call get-executable,$(FLEX)),)
0129   dummy := $(error Error: $(FLEX) is missing on this system, please install it)
0130 endif
0131 
0132 ifeq ($(call get-executable,$(BISON)),)
0133   dummy := $(error Error: $(BISON) is missing on this system, please install it)
0134 endif
0135 
0136 # Treat warnings as errors unless directed not to
0137 ifneq ($(WERROR),0)
0138   CFLAGS += -Werror
0139   CXXFLAGS += -Werror
0140 endif
0141 
0142 ifndef DEBUG
0143   DEBUG := 0
0144 endif
0145 
0146 ifeq ($(DEBUG),0)
0147   CFLAGS += -O6
0148 endif
0149 
0150 ifdef PARSER_DEBUG
0151   PARSER_DEBUG_BISON := -t
0152   PARSER_DEBUG_FLEX  := -d
0153   CFLAGS             += -DPARSER_DEBUG
0154   $(call detected_var,PARSER_DEBUG_BISON)
0155   $(call detected_var,PARSER_DEBUG_FLEX)
0156 endif
0157 
0158 # Try different combinations to accommodate systems that only have
0159 # python[2][-config] in weird combinations but always preferring
0160 # python2 and python2-config as per pep-0394. If we catch a
0161 # python[-config] in version 3, the version check will kill it.
0162 PYTHON2 := $(if $(call get-executable,python2),python2,python)
0163 override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2))
0164 PYTHON2_CONFIG := \
0165   $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config)
0166 override PYTHON_CONFIG := \
0167   $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
0168 
0169 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
0170 
0171 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
0172 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
0173 
0174 FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
0175 FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
0176 FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
0177 FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
0178 
0179 CFLAGS += -fno-omit-frame-pointer
0180 CFLAGS += -ggdb3
0181 CFLAGS += -funwind-tables
0182 CFLAGS += -Wall
0183 CFLAGS += -Wextra
0184 CFLAGS += -std=gnu99
0185 
0186 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
0187 CXXFLAGS += -Wall
0188 CXXFLAGS += -fno-omit-frame-pointer
0189 CXXFLAGS += -ggdb3
0190 CXXFLAGS += -funwind-tables
0191 CXXFLAGS += -Wno-strict-aliasing
0192 
0193 # Enforce a non-executable stack, as we may regress (again) in the future by
0194 # adding assembler files missing the .GNU-stack linker note.
0195 LDFLAGS += -Wl,-z,noexecstack
0196 
0197 EXTLIBS = -lpthread -lrt -lm -ldl
0198 
0199 ifeq ($(FEATURES_DUMP),)
0200 include $(srctree)/tools/build/Makefile.feature
0201 else
0202 include $(FEATURES_DUMP)
0203 endif
0204 
0205 ifeq ($(feature-stackprotector-all), 1)
0206   CFLAGS += -fstack-protector-all
0207 endif
0208 
0209 ifeq ($(DEBUG),0)
0210   ifeq ($(feature-fortify-source), 1)
0211     CFLAGS += -D_FORTIFY_SOURCE=2
0212   endif
0213 endif
0214 
0215 INC_FLAGS += -I$(src-perf)/util/include
0216 INC_FLAGS += -I$(src-perf)/arch/$(ARCH)/include 
0217 INC_FLAGS += -I$(srctree)/tools/include/uapi
0218 INC_FLAGS += -I$(srctree)/tools/include/
0219 INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/uapi
0220 INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/
0221 INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/
0222 
0223 # $(obj-perf)      for generated common-cmds.h
0224 # $(obj-perf)/util for generated bison/flex headers
0225 ifneq ($(OUTPUT),)
0226 INC_FLAGS += -I$(obj-perf)/util
0227 INC_FLAGS += -I$(obj-perf)
0228 endif
0229 
0230 INC_FLAGS += -I$(src-perf)/util
0231 INC_FLAGS += -I$(src-perf)
0232 INC_FLAGS += -I$(srctree)/tools/lib/
0233 
0234 CFLAGS   += $(INC_FLAGS)
0235 CXXFLAGS += $(INC_FLAGS)
0236 
0237 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
0238 
0239 ifeq ($(feature-sync-compare-and-swap), 1)
0240   CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
0241 endif
0242 
0243 ifeq ($(feature-pthread-attr-setaffinity-np), 1)
0244   CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
0245 endif
0246 
0247 ifndef NO_BIONIC
0248   $(call feature_check,bionic)
0249   ifeq ($(feature-bionic), 1)
0250     BIONIC := 1
0251     EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
0252     EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
0253   endif
0254 endif
0255 
0256 ifdef NO_LIBELF
0257   NO_DWARF := 1
0258   NO_DEMANGLE := 1
0259   NO_LIBUNWIND := 1
0260   NO_LIBDW_DWARF_UNWIND := 1
0261   NO_LIBBPF := 1
0262 else
0263   ifeq ($(feature-libelf), 0)
0264     ifeq ($(feature-glibc), 1)
0265       LIBC_SUPPORT := 1
0266     endif
0267     ifeq ($(BIONIC),1)
0268       LIBC_SUPPORT := 1
0269     endif
0270     ifeq ($(LIBC_SUPPORT),1)
0271       msg := $(warning No libelf found, disables 'probe' tool and BPF support in 'perf record', please install libelf-dev, libelf-devel or elfutils-libelf-devel);
0272 
0273       NO_LIBELF := 1
0274       NO_DWARF := 1
0275       NO_DEMANGLE := 1
0276       NO_LIBUNWIND := 1
0277       NO_LIBDW_DWARF_UNWIND := 1
0278       NO_LIBBPF := 1
0279     else
0280       ifneq ($(filter s% -static%,$(LDFLAGS),),)
0281         msg := $(error No static glibc found, please install glibc-static);
0282       else
0283         msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
0284       endif
0285     endif
0286   else
0287     ifndef NO_LIBDW_DWARF_UNWIND
0288       ifneq ($(feature-libdw-dwarf-unwind),1)
0289         NO_LIBDW_DWARF_UNWIND := 1
0290         msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
0291       endif
0292     endif
0293     ifneq ($(feature-dwarf), 1)
0294       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);
0295       NO_DWARF := 1
0296     else
0297       ifneq ($(feature-dwarf_getlocations), 1)
0298         msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157);
0299       else
0300         CFLAGS += -DHAVE_DWARF_GETLOCATIONS
0301       endif # dwarf_getlocations
0302     endif # Dwarf support
0303   endif # libelf support
0304 endif # NO_LIBELF
0305 
0306 ifdef NO_DWARF
0307   NO_LIBDW_DWARF_UNWIND := 1
0308 endif
0309 
0310 ifndef NO_LIBELF
0311   CFLAGS += -DHAVE_LIBELF_SUPPORT
0312   EXTLIBS += -lelf
0313   $(call detected,CONFIG_LIBELF)
0314 
0315   ifeq ($(feature-libelf-mmap), 1)
0316     CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
0317   endif
0318 
0319   ifeq ($(feature-libelf-getphdrnum), 1)
0320     CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
0321   endif
0322 
0323   ifeq ($(feature-libelf-gelf_getnote), 1)
0324     CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
0325   else
0326     msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
0327   endif
0328 
0329   ifeq ($(feature-libelf-getshdrstrndx), 1)
0330     CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
0331   endif
0332 
0333   ifndef NO_DWARF
0334     ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
0335       msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
0336       NO_DWARF := 1
0337     else
0338       CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
0339       LDFLAGS += $(LIBDW_LDFLAGS)
0340       DWARFLIBS := -ldw
0341       ifeq ($(findstring -static,${LDFLAGS}),-static)
0342         DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
0343       endif
0344       EXTLIBS += ${DWARFLIBS}
0345       $(call detected,CONFIG_DWARF)
0346     endif # PERF_HAVE_DWARF_REGS
0347   endif # NO_DWARF
0348 
0349   ifndef NO_LIBBPF
0350     ifeq ($(feature-bpf), 1)
0351       CFLAGS += -DHAVE_LIBBPF_SUPPORT
0352       $(call detected,CONFIG_LIBBPF)
0353     endif
0354 
0355     ifndef NO_DWARF
0356       ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
0357         CFLAGS += -DHAVE_BPF_PROLOGUE
0358         $(call detected,CONFIG_BPF_PROLOGUE)
0359       else
0360         msg := $(warning BPF prologue is not supported by architecture $(ARCH), missing regs_query_register_offset());
0361       endif
0362     else
0363       msg := $(warning DWARF support is off, BPF prologue is disabled);
0364     endif
0365 
0366   endif # NO_LIBBPF
0367 endif # NO_LIBELF
0368 
0369 ifndef NO_SDT
0370   ifneq ($(feature-sdt), 1)
0371     msg := $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev);
0372     NO_SDT := 1;
0373   else
0374     CFLAGS += -DHAVE_SDT_EVENT
0375     $(call detected,CONFIG_SDT_EVENT)
0376   endif
0377 endif
0378 
0379 ifdef PERF_HAVE_JITDUMP
0380   ifndef NO_LIBELF
0381     $(call detected,CONFIG_JITDUMP)
0382     CFLAGS += -DHAVE_JITDUMP
0383   endif
0384 endif
0385 
0386 ifeq ($(ARCH),powerpc)
0387   ifndef NO_DWARF
0388     CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
0389   endif
0390 endif
0391 
0392 ifndef NO_LIBUNWIND
0393   have_libunwind :=
0394 
0395   ifeq ($(feature-libunwind-x86), 1)
0396     $(call detected,CONFIG_LIBUNWIND_X86)
0397     CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
0398     LDFLAGS += -lunwind-x86
0399     EXTLIBS_LIBUNWIND += -lunwind-x86
0400     have_libunwind = 1
0401   endif
0402 
0403   ifeq ($(feature-libunwind-aarch64), 1)
0404     $(call detected,CONFIG_LIBUNWIND_AARCH64)
0405     CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
0406     LDFLAGS += -lunwind-aarch64
0407     EXTLIBS_LIBUNWIND += -lunwind-aarch64
0408     have_libunwind = 1
0409     $(call feature_check,libunwind-debug-frame-aarch64)
0410     ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
0411       msg := $(warning No debug_frame support found in libunwind-aarch64);
0412       CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
0413     endif
0414   endif
0415 
0416   ifneq ($(feature-libunwind), 1)
0417     msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
0418     NO_LOCAL_LIBUNWIND := 1
0419   else
0420     have_libunwind := 1
0421     $(call detected,CONFIG_LOCAL_LIBUNWIND)
0422   endif
0423 
0424   ifneq ($(have_libunwind), 1)
0425     NO_LIBUNWIND := 1
0426   endif
0427 else
0428   NO_LOCAL_LIBUNWIND := 1
0429 endif
0430 
0431 ifndef NO_LIBBPF
0432   ifneq ($(feature-bpf), 1)
0433     msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
0434     NO_LIBBPF := 1
0435   endif
0436 endif
0437 
0438 dwarf-post-unwind := 1
0439 dwarf-post-unwind-text := BUG
0440 
0441 # setup DWARF post unwinder
0442 ifdef NO_LIBUNWIND
0443   ifdef NO_LIBDW_DWARF_UNWIND
0444     msg := $(warning Disabling post unwind, no support found.);
0445     dwarf-post-unwind := 0
0446   else
0447     dwarf-post-unwind-text := libdw
0448     $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
0449   endif
0450 else
0451   dwarf-post-unwind-text := libunwind
0452   $(call detected,CONFIG_LIBUNWIND)
0453   # Enable libunwind support by default.
0454   ifndef NO_LIBDW_DWARF_UNWIND
0455     NO_LIBDW_DWARF_UNWIND := 1
0456   endif
0457 endif
0458 
0459 ifeq ($(dwarf-post-unwind),1)
0460   CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
0461   $(call detected,CONFIG_DWARF_UNWIND)
0462 else
0463   NO_DWARF_UNWIND := 1
0464 endif
0465 
0466 ifndef NO_LOCAL_LIBUNWIND
0467   ifeq ($(ARCH),$(filter $(ARCH),arm arm64))
0468     $(call feature_check,libunwind-debug-frame)
0469     ifneq ($(feature-libunwind-debug-frame), 1)
0470       msg := $(warning No debug_frame support found in libunwind);
0471       CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
0472     endif
0473   else
0474     # non-ARM has no dwarf_find_debug_frame() function:
0475     CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
0476   endif
0477   EXTLIBS += $(LIBUNWIND_LIBS)
0478   LDFLAGS += $(LIBUNWIND_LIBS)
0479 endif
0480 
0481 ifndef NO_LIBUNWIND
0482   CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
0483   CFLAGS  += $(LIBUNWIND_CFLAGS)
0484   LDFLAGS += $(LIBUNWIND_LDFLAGS)
0485   EXTLIBS += $(EXTLIBS_LIBUNWIND)
0486 endif
0487 
0488 ifndef NO_LIBAUDIT
0489   ifneq ($(feature-libaudit), 1)
0490     msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
0491     NO_LIBAUDIT := 1
0492   else
0493     CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
0494     EXTLIBS += -laudit
0495     $(call detected,CONFIG_AUDIT)
0496   endif
0497 endif
0498 
0499 ifndef NO_LIBCRYPTO
0500   ifneq ($(feature-libcrypto), 1)
0501     msg := $(warning No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev);
0502     NO_LIBCRYPTO := 1
0503   else
0504     CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
0505     EXTLIBS += -lcrypto
0506     $(call detected,CONFIG_CRYPTO)
0507   endif
0508 endif
0509 
0510 ifdef NO_NEWT
0511   NO_SLANG=1
0512 endif
0513 
0514 ifndef NO_SLANG
0515   ifneq ($(feature-libslang), 1)
0516     msg := $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev);
0517     NO_SLANG := 1
0518   else
0519     # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
0520     CFLAGS += -I/usr/include/slang
0521     CFLAGS += -DHAVE_SLANG_SUPPORT
0522     EXTLIBS += -lslang
0523     $(call detected,CONFIG_SLANG)
0524   endif
0525 endif
0526 
0527 ifndef NO_GTK2
0528   FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
0529   ifneq ($(feature-gtk2), 1)
0530     msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
0531     NO_GTK2 := 1
0532   else
0533     ifeq ($(feature-gtk2-infobar), 1)
0534       GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
0535     endif
0536     CFLAGS += -DHAVE_GTK2_SUPPORT
0537     GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
0538     GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
0539     EXTLIBS += -ldl
0540   endif
0541 endif
0542 
0543 grep-libs  = $(filter -l%,$(1))
0544 strip-libs = $(filter-out -l%,$(1))
0545 
0546 ifdef NO_LIBPERL
0547   CFLAGS += -DNO_LIBPERL
0548 else
0549   PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
0550   PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
0551   PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
0552   PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
0553   FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
0554 
0555   ifneq ($(feature-libperl), 1)
0556     CFLAGS += -DNO_LIBPERL
0557     NO_LIBPERL := 1
0558     msg := $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev);
0559   else
0560     LDFLAGS += $(PERL_EMBED_LDFLAGS)
0561     EXTLIBS += $(PERL_EMBED_LIBADD)
0562     $(call detected,CONFIG_LIBPERL)
0563   endif
0564 endif
0565 
0566 ifeq ($(feature-timerfd), 1)
0567   CFLAGS += -DHAVE_TIMERFD_SUPPORT
0568 else
0569   msg := $(warning No timerfd support. Disables 'perf kvm stat live');
0570 endif
0571 
0572 disable-python = $(eval $(disable-python_code))
0573 define disable-python_code
0574   CFLAGS += -DNO_LIBPYTHON
0575   $(warning $1)
0576   NO_LIBPYTHON := 1
0577 endef
0578 
0579 ifdef NO_LIBPYTHON
0580   $(call disable-python,Python support disabled by user)
0581 else
0582 
0583   ifndef PYTHON
0584     $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
0585   else
0586     PYTHON_WORD := $(call shell-wordify,$(PYTHON))
0587 
0588     ifndef PYTHON_CONFIG
0589       $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
0590     else
0591 
0592       PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
0593 
0594       PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
0595       PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
0596       PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
0597       PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
0598       FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
0599 
0600       ifneq ($(feature-libpython), 1)
0601         $(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
0602       else
0603 
0604         ifneq ($(feature-libpython-version), 1)
0605           $(warning Python 3 is not yet supported; please set)
0606           $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
0607           $(warning If you also have Python 2 installed, then)
0608           $(warning try something like:)
0609           $(warning $(and ,))
0610           $(warning $(and ,)  make PYTHON=python2)
0611           $(warning $(and ,))
0612           $(warning Otherwise, disable Python support entirely:)
0613           $(warning $(and ,))
0614           $(warning $(and ,)  make NO_LIBPYTHON=1)
0615           $(warning $(and ,))
0616           $(error   $(and ,))
0617         else
0618           LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
0619           EXTLIBS += $(PYTHON_EMBED_LIBADD)
0620           LANG_BINDINGS += $(obj-perf)python/perf.so
0621           $(call detected,CONFIG_LIBPYTHON)
0622         endif
0623       endif
0624     endif
0625   endif
0626 endif
0627 
0628 ifeq ($(feature-libbfd), 1)
0629   EXTLIBS += -lbfd
0630 
0631   # call all detections now so we get correct
0632   # status in VF output
0633   $(call feature_check,liberty)
0634   $(call feature_check,liberty-z)
0635   $(call feature_check,cplus-demangle)
0636 
0637   ifeq ($(feature-liberty), 1)
0638     EXTLIBS += -liberty
0639   else
0640     ifeq ($(feature-liberty-z), 1)
0641       EXTLIBS += -liberty -lz
0642     endif
0643   endif
0644 endif
0645 
0646 ifdef NO_DEMANGLE
0647   CFLAGS += -DNO_DEMANGLE
0648 else
0649   ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
0650     EXTLIBS += -liberty
0651     CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
0652   else
0653     ifneq ($(feature-libbfd), 1)
0654       ifneq ($(feature-liberty), 1)
0655         ifneq ($(feature-liberty-z), 1)
0656           # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
0657           # or any of 'bfd iberty z' trinity
0658           ifeq ($(feature-cplus-demangle), 1)
0659             EXTLIBS += -liberty
0660             CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
0661           else
0662             msg := $(warning No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling)
0663             CFLAGS += -DNO_DEMANGLE
0664           endif
0665         endif
0666       endif
0667     endif
0668   endif
0669 endif
0670 
0671 ifneq ($(filter -lbfd,$(EXTLIBS)),)
0672   CFLAGS += -DHAVE_LIBBFD_SUPPORT
0673 endif
0674 
0675 ifndef NO_ZLIB
0676   ifeq ($(feature-zlib), 1)
0677     CFLAGS += -DHAVE_ZLIB_SUPPORT
0678     EXTLIBS += -lz
0679     $(call detected,CONFIG_ZLIB)
0680   else
0681     NO_ZLIB := 1
0682   endif
0683 endif
0684 
0685 ifndef NO_LZMA
0686   ifeq ($(feature-lzma), 1)
0687     CFLAGS += -DHAVE_LZMA_SUPPORT
0688     EXTLIBS += -llzma
0689     $(call detected,CONFIG_LZMA)
0690   else
0691     msg := $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev);
0692     NO_LZMA := 1
0693   endif
0694 endif
0695 
0696 ifndef NO_BACKTRACE
0697   ifeq ($(feature-backtrace), 1)
0698     CFLAGS += -DHAVE_BACKTRACE_SUPPORT
0699   endif
0700 endif
0701 
0702 ifndef NO_LIBNUMA
0703   ifeq ($(feature-libnuma), 0)
0704     msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
0705     NO_LIBNUMA := 1
0706   else
0707     ifeq ($(feature-numa_num_possible_cpus), 0)
0708       msg := $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8);
0709       NO_LIBNUMA := 1
0710     else
0711       CFLAGS += -DHAVE_LIBNUMA_SUPPORT
0712       EXTLIBS += -lnuma
0713       $(call detected,CONFIG_NUMA)
0714     endif
0715   endif
0716 endif
0717 
0718 ifdef HAVE_KVM_STAT_SUPPORT
0719     CFLAGS += -DHAVE_KVM_STAT_SUPPORT
0720 endif
0721 
0722 ifeq (${IS_64_BIT}, 1)
0723   ifndef NO_PERF_READ_VDSO32
0724     $(call feature_check,compile-32)
0725     ifeq ($(feature-compile-32), 1)
0726       CFLAGS += -DHAVE_PERF_READ_VDSO32
0727     else
0728       NO_PERF_READ_VDSO32 := 1
0729     endif
0730   endif
0731   ifneq ($(ARCH), x86)
0732     NO_PERF_READ_VDSOX32 := 1
0733   endif
0734   ifndef NO_PERF_READ_VDSOX32
0735     $(call feature_check,compile-x32)
0736     ifeq ($(feature-compile-x32), 1)
0737       CFLAGS += -DHAVE_PERF_READ_VDSOX32
0738     else
0739       NO_PERF_READ_VDSOX32 := 1
0740     endif
0741   endif
0742 else
0743   NO_PERF_READ_VDSO32 := 1
0744   NO_PERF_READ_VDSOX32 := 1
0745 endif
0746 
0747 ifdef LIBBABELTRACE
0748   $(call feature_check,libbabeltrace)
0749   ifeq ($(feature-libbabeltrace), 1)
0750     CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
0751     LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
0752     EXTLIBS += -lbabeltrace-ctf
0753     $(call detected,CONFIG_LIBBABELTRACE)
0754   else
0755     msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev);
0756   endif
0757 endif
0758 
0759 ifndef NO_AUXTRACE
0760   ifeq ($(ARCH),x86)
0761     ifeq ($(feature-get_cpuid), 0)
0762       msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc);
0763       NO_AUXTRACE := 1
0764     endif
0765   endif
0766   ifndef NO_AUXTRACE
0767     $(call detected,CONFIG_AUXTRACE)
0768     CFLAGS += -DHAVE_AUXTRACE_SUPPORT
0769   endif
0770 endif
0771 
0772 ifndef NO_JVMTI
0773   ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
0774     JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
0775   else
0776     ifneq (,$(wildcard /usr/sbin/alternatives))
0777       JDIR=$(shell alternatives --display java | tail -1 | cut -d' ' -f 5 | sed 's%/jre/bin/java.%%g')
0778     endif
0779   endif
0780   ifndef JDIR
0781     $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
0782     NO_JVMTI := 1
0783   endif
0784 endif
0785 
0786 ifndef NO_JVMTI
0787   FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
0788   $(call feature_check,jvmti)
0789   ifeq ($(feature-jvmti), 1)
0790     $(call detected_var,JDIR)
0791   else
0792     $(warning No openjdk development package found, please install JDK package)
0793     NO_JVMTI := 1
0794   endif
0795 endif
0796 
0797 USE_CXX = 0
0798 USE_CLANGLLVM = 0
0799 ifdef LIBCLANGLLVM
0800   $(call feature_check,cxx)
0801   ifneq ($(feature-cxx), 1)
0802     msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
0803   else
0804     $(call feature_check,llvm)
0805     $(call feature_check,llvm-version)
0806     ifneq ($(feature-llvm), 1)
0807       msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
0808     else
0809       $(call feature_check,clang)
0810       ifneq ($(feature-clang), 1)
0811         msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
0812       else
0813         CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
0814         CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
0815         $(call detected,CONFIG_CXX)
0816         $(call detected,CONFIG_CLANGLLVM)
0817         USE_CXX = 1
0818         USE_LLVM = 1
0819         USE_CLANG = 1
0820         ifneq ($(feature-llvm-version),1)
0821           msg := $(warning This version of LLVM is not tested. May cause build errors)
0822         endif
0823       endif
0824     endif
0825   endif
0826 endif
0827 
0828 # Among the variables below, these:
0829 #   perfexecdir
0830 #   template_dir
0831 #   mandir
0832 #   infodir
0833 #   htmldir
0834 #   ETC_PERFCONFIG (but not sysconfdir)
0835 # can be specified as a relative path some/where/else;
0836 # this is interpreted as relative to $(prefix) and "perf" at
0837 # runtime figures out where they are based on the path to the executable.
0838 # This can help installing the suite in a relocatable way.
0839 
0840 # Make the path relative to DESTDIR, not to prefix
0841 ifndef DESTDIR
0842 prefix ?= $(HOME)
0843 endif
0844 bindir_relative = bin
0845 bindir = $(abspath $(prefix)/$(bindir_relative))
0846 mandir = share/man
0847 infodir = share/info
0848 perfexecdir = libexec/perf-core
0849 sharedir = $(prefix)/share
0850 template_dir = share/perf-core/templates
0851 STRACE_GROUPS_DIR = share/perf-core/strace/groups
0852 htmldir = share/doc/perf-doc
0853 tipdir = share/doc/perf-tip
0854 srcdir = $(srctree)/tools/perf
0855 ifeq ($(prefix),/usr)
0856 sysconfdir = /etc
0857 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
0858 else
0859 sysconfdir = $(prefix)/etc
0860 ETC_PERFCONFIG = etc/perfconfig
0861 endif
0862 ifndef lib
0863 ifeq ($(ARCH)$(IS_64_BIT), x861)
0864 lib = lib64
0865 else
0866 lib = lib
0867 endif
0868 endif # lib
0869 libdir = $(prefix)/$(lib)
0870 
0871 # Shell quote (do not use $(call) to accommodate ancient setups);
0872 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
0873 STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
0874 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
0875 bindir_SQ = $(subst ','\'',$(bindir))
0876 mandir_SQ = $(subst ','\'',$(mandir))
0877 infodir_SQ = $(subst ','\'',$(infodir))
0878 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
0879 template_dir_SQ = $(subst ','\'',$(template_dir))
0880 htmldir_SQ = $(subst ','\'',$(htmldir))
0881 tipdir_SQ = $(subst ','\'',$(tipdir))
0882 prefix_SQ = $(subst ','\'',$(prefix))
0883 sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
0884 libdir_SQ = $(subst ','\'',$(libdir))
0885 srcdir_SQ = $(subst ','\'',$(srcdir))
0886 
0887 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
0888 perfexec_instdir = $(perfexecdir)
0889 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
0890 tip_instdir = $(tipdir)
0891 else
0892 perfexec_instdir = $(prefix)/$(perfexecdir)
0893 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
0894 tip_instdir = $(prefix)/$(tipdir)
0895 endif
0896 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
0897 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
0898 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
0899 
0900 # If we install to $(HOME) we keep the traceevent default:
0901 # $(HOME)/.traceevent/plugins
0902 # Otherwise we install plugins into the global $(libdir).
0903 ifdef DESTDIR
0904 plugindir=$(libdir)/traceevent/plugins
0905 plugindir_SQ= $(subst ','\'',$(plugindir))
0906 endif
0907 
0908 print_var = $(eval $(print_var_code)) $(info $(MSG))
0909 define print_var_code
0910     MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
0911 endef
0912 
0913 ifeq ($(VF),1)
0914   $(call print_var,prefix)
0915   $(call print_var,bindir)
0916   $(call print_var,libdir)
0917   $(call print_var,sysconfdir)
0918   $(call print_var,LIBUNWIND_DIR)
0919   $(call print_var,LIBDW_DIR)
0920   $(call print_var,JDIR)
0921 
0922   ifeq ($(dwarf-post-unwind),1)
0923     $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
0924   endif
0925   $(info )
0926 endif
0927 
0928 $(call detected_var,bindir_SQ)
0929 $(call detected_var,PYTHON_WORD)
0930 ifneq ($(OUTPUT),)
0931 $(call detected_var,OUTPUT)
0932 endif
0933 $(call detected_var,htmldir_SQ)
0934 $(call detected_var,infodir_SQ)
0935 $(call detected_var,mandir_SQ)
0936 $(call detected_var,ETC_PERFCONFIG_SQ)
0937 $(call detected_var,STRACE_GROUPS_DIR_SQ)
0938 $(call detected_var,prefix_SQ)
0939 $(call detected_var,perfexecdir_SQ)
0940 $(call detected_var,tipdir_SQ)
0941 $(call detected_var,srcdir_SQ)
0942 $(call detected_var,LIBDIR)
0943 $(call detected_var,GTK_CFLAGS)
0944 $(call detected_var,PERL_EMBED_CCOPTS)
0945 $(call detected_var,PYTHON_EMBED_CCOPTS)