Makefile 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. ifeq ($(src-perf),)
  2. src-perf := $(srctree)/tools/perf
  3. endif
  4. ifeq ($(obj-perf),)
  5. obj-perf := $(OUTPUT)
  6. endif
  7. ifneq ($(obj-perf),)
  8. obj-perf := $(abspath $(obj-perf))/
  9. endif
  10. LIB_INCLUDE := $(srctree)/tools/lib/
  11. CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
  12. include $(src-perf)/config/Makefile.arch
  13. NO_PERF_REGS := 1
  14. # Additional ARCH settings for x86
  15. ifeq ($(ARCH),x86)
  16. ifeq (${IS_X86_64}, 1)
  17. CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
  18. ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
  19. LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
  20. else
  21. LIBUNWIND_LIBS = -lunwind -lunwind-x86
  22. endif
  23. NO_PERF_REGS := 0
  24. endif
  25. ifeq ($(ARCH),arm)
  26. NO_PERF_REGS := 0
  27. LIBUNWIND_LIBS = -lunwind -lunwind-arm
  28. endif
  29. ifeq ($(ARCH),arm64)
  30. NO_PERF_REGS := 0
  31. LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
  32. endif
  33. # So far there's only x86 and arm libdw unwind support merged in perf.
  34. # Disable it on all other architectures in case libdw unwind
  35. # support is detected in system. Add supported architectures
  36. # to the check.
  37. ifneq ($(ARCH),$(filter $(ARCH),x86 arm))
  38. NO_LIBDW_DWARF_UNWIND := 1
  39. endif
  40. ifeq ($(LIBUNWIND_LIBS),)
  41. NO_LIBUNWIND := 1
  42. else
  43. #
  44. # For linking with debug library, run like:
  45. #
  46. # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
  47. #
  48. ifdef LIBUNWIND_DIR
  49. LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include
  50. LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
  51. endif
  52. LIBUNWIND_LDFLAGS += $(LIBUNWIND_LIBS)
  53. # Set per-feature check compilation flags
  54. FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
  55. FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS)
  56. FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
  57. FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS)
  58. endif
  59. ifeq ($(NO_PERF_REGS),0)
  60. CFLAGS += -DHAVE_PERF_REGS_SUPPORT
  61. endif
  62. ifndef NO_LIBELF
  63. # for linking with debug library, run like:
  64. # make DEBUG=1 LIBDW_DIR=/opt/libdw/
  65. ifdef LIBDW_DIR
  66. LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
  67. LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
  68. endif
  69. FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
  70. FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) -ldw
  71. endif
  72. # include ARCH specific config
  73. -include $(src-perf)/arch/$(ARCH)/Makefile
  74. include $(src-perf)/config/utilities.mak
  75. ifeq ($(call get-executable,$(FLEX)),)
  76. dummy := $(error Error: $(FLEX) is missing on this system, please install it)
  77. endif
  78. ifeq ($(call get-executable,$(BISON)),)
  79. dummy := $(error Error: $(BISON) is missing on this system, please install it)
  80. endif
  81. # Treat warnings as errors unless directed not to
  82. ifneq ($(WERROR),0)
  83. CFLAGS += -Werror
  84. endif
  85. ifndef DEBUG
  86. DEBUG := 0
  87. endif
  88. ifeq ($(DEBUG),0)
  89. CFLAGS += -O6
  90. endif
  91. ifdef PARSER_DEBUG
  92. PARSER_DEBUG_BISON := -t
  93. PARSER_DEBUG_FLEX := -d
  94. CFLAGS += -DPARSER_DEBUG
  95. endif
  96. ifndef NO_LIBPYTHON
  97. # Try different combinations to accommodate systems that only have
  98. # python[2][-config] in weird combinations but always preferring
  99. # python2 and python2-config as per pep-0394. If we catch a
  100. # python[-config] in version 3, the version check will kill it.
  101. PYTHON2 := $(if $(call get-executable,python2),python2,python)
  102. override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2))
  103. PYTHON2_CONFIG := \
  104. $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config)
  105. override PYTHON_CONFIG := \
  106. $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
  107. PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
  108. PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
  109. PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
  110. FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
  111. FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
  112. FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
  113. FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
  114. endif
  115. CFLAGS += -fno-omit-frame-pointer
  116. CFLAGS += -ggdb3
  117. CFLAGS += -funwind-tables
  118. CFLAGS += -Wall
  119. CFLAGS += -Wextra
  120. CFLAGS += -std=gnu99
  121. # Enforce a non-executable stack, as we may regress (again) in the future by
  122. # adding assembler files missing the .GNU-stack linker note.
  123. LDFLAGS += -Wl,-z,noexecstack
  124. EXTLIBS = -lelf -lpthread -lrt -lm -ldl
  125. ifneq ($(OUTPUT),)
  126. OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
  127. $(shell mkdir -p $(OUTPUT_FEATURES))
  128. endif
  129. feature_check = $(eval $(feature_check_code))
  130. define feature_check_code
  131. feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C config/feature-checks test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
  132. endef
  133. feature_set = $(eval $(feature_set_code))
  134. define feature_set_code
  135. feature-$(1) := 1
  136. endef
  137. #
  138. # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
  139. #
  140. #
  141. # Note that this is not a complete list of all feature tests, just
  142. # those that are typically built on a fully configured system.
  143. #
  144. # [ Feature tests not mentioned here have to be built explicitly in
  145. # the rule that uses them - an example for that is the 'bionic'
  146. # feature check. ]
  147. #
  148. CORE_FEATURE_TESTS = \
  149. backtrace \
  150. dwarf \
  151. fortify-source \
  152. sync-compare-and-swap \
  153. glibc \
  154. gtk2 \
  155. gtk2-infobar \
  156. libaudit \
  157. libbfd \
  158. libelf \
  159. libelf-getphdrnum \
  160. libelf-mmap \
  161. libnuma \
  162. libperl \
  163. libpython \
  164. libpython-version \
  165. libslang \
  166. libunwind \
  167. stackprotector-all \
  168. timerfd \
  169. libdw-dwarf-unwind
  170. LIB_FEATURE_TESTS = \
  171. dwarf \
  172. glibc \
  173. gtk2 \
  174. libaudit \
  175. libbfd \
  176. libelf \
  177. libnuma \
  178. libperl \
  179. libpython \
  180. libslang \
  181. libunwind \
  182. libdw-dwarf-unwind
  183. VF_FEATURE_TESTS = \
  184. backtrace \
  185. fortify-source \
  186. sync-compare-and-swap \
  187. gtk2-infobar \
  188. libelf-getphdrnum \
  189. libelf-mmap \
  190. libpython-version \
  191. stackprotector-all \
  192. timerfd \
  193. libunwind-debug-frame \
  194. bionic \
  195. liberty \
  196. liberty-z \
  197. cplus-demangle
  198. # Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features.
  199. # If in the future we need per-feature checks/flags for features not
  200. # mentioned in this list we need to refactor this ;-).
  201. set_test_all_flags = $(eval $(set_test_all_flags_code))
  202. define set_test_all_flags_code
  203. FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1))
  204. FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
  205. endef
  206. $(foreach feat,$(CORE_FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
  207. #
  208. # Special fast-path for the 'all features are available' case:
  209. #
  210. $(call feature_check,all,$(MSG))
  211. #
  212. # Just in case the build freshly failed, make sure we print the
  213. # feature matrix:
  214. #
  215. ifeq ($(feature-all), 1)
  216. #
  217. # test-all.c passed - just set all the core feature flags to 1:
  218. #
  219. $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
  220. else
  221. $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(addsuffix .bin,$(CORE_FEATURE_TESTS)) >/dev/null 2>&1)
  222. $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
  223. endif
  224. ifeq ($(feature-stackprotector-all), 1)
  225. CFLAGS += -fstack-protector-all
  226. endif
  227. ifeq ($(DEBUG),0)
  228. ifeq ($(feature-fortify-source), 1)
  229. CFLAGS += -D_FORTIFY_SOURCE=2
  230. endif
  231. endif
  232. CFLAGS += -I$(src-perf)/util/include
  233. CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
  234. CFLAGS += -I$(srctree)/tools/include/
  235. CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
  236. CFLAGS += -I$(srctree)/arch/$(ARCH)/include
  237. CFLAGS += -I$(srctree)/include/uapi
  238. CFLAGS += -I$(srctree)/include
  239. # $(obj-perf) for generated common-cmds.h
  240. # $(obj-perf)/util for generated bison/flex headers
  241. ifneq ($(OUTPUT),)
  242. CFLAGS += -I$(obj-perf)/util
  243. CFLAGS += -I$(obj-perf)
  244. endif
  245. CFLAGS += -I$(src-perf)/util
  246. CFLAGS += -I$(src-perf)
  247. CFLAGS += -I$(LIB_INCLUDE)
  248. CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
  249. ifeq ($(feature-sync-compare-and-swap), 1)
  250. CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
  251. endif
  252. ifndef NO_BIONIC
  253. $(call feature_check,bionic)
  254. ifeq ($(feature-bionic), 1)
  255. BIONIC := 1
  256. EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
  257. EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
  258. endif
  259. endif
  260. ifdef NO_LIBELF
  261. NO_DWARF := 1
  262. NO_DEMANGLE := 1
  263. NO_LIBUNWIND := 1
  264. NO_LIBDW_DWARF_UNWIND := 1
  265. else
  266. ifeq ($(feature-libelf), 0)
  267. ifeq ($(feature-glibc), 1)
  268. LIBC_SUPPORT := 1
  269. endif
  270. ifeq ($(BIONIC),1)
  271. LIBC_SUPPORT := 1
  272. endif
  273. ifeq ($(LIBC_SUPPORT),1)
  274. msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
  275. NO_LIBELF := 1
  276. NO_DWARF := 1
  277. NO_DEMANGLE := 1
  278. NO_LIBUNWIND := 1
  279. NO_LIBDW_DWARF_UNWIND := 1
  280. else
  281. ifneq ($(filter s% -static%,$(LDFLAGS),),)
  282. msg := $(error No static glibc found, please install glibc-static);
  283. else
  284. msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
  285. endif
  286. endif
  287. else
  288. ifndef NO_LIBDW_DWARF_UNWIND
  289. ifneq ($(feature-libdw-dwarf-unwind),1)
  290. NO_LIBDW_DWARF_UNWIND := 1
  291. msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
  292. endif
  293. endif
  294. ifneq ($(feature-dwarf), 1)
  295. 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);
  296. NO_DWARF := 1
  297. endif # Dwarf support
  298. endif # libelf support
  299. endif # NO_LIBELF
  300. ifndef NO_LIBELF
  301. CFLAGS += -DHAVE_LIBELF_SUPPORT
  302. ifeq ($(feature-libelf-mmap), 1)
  303. CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
  304. endif
  305. ifeq ($(feature-libelf-getphdrnum), 1)
  306. CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
  307. endif
  308. # include ARCH specific config
  309. -include $(src-perf)/arch/$(ARCH)/Makefile
  310. ifndef NO_DWARF
  311. ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
  312. msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
  313. NO_DWARF := 1
  314. else
  315. CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
  316. LDFLAGS += $(LIBDW_LDFLAGS)
  317. EXTLIBS += -lelf -ldw
  318. endif # PERF_HAVE_DWARF_REGS
  319. endif # NO_DWARF
  320. endif # NO_LIBELF
  321. ifeq ($(ARCH),powerpc)
  322. ifndef NO_DWARF
  323. CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
  324. endif
  325. endif
  326. ifndef NO_LIBUNWIND
  327. ifneq ($(feature-libunwind), 1)
  328. msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
  329. NO_LIBUNWIND := 1
  330. endif
  331. endif
  332. dwarf-post-unwind := 1
  333. dwarf-post-unwind-text := BUG
  334. # setup DWARF post unwinder
  335. ifdef NO_LIBUNWIND
  336. ifdef NO_LIBDW_DWARF_UNWIND
  337. msg := $(warning Disabling post unwind, no support found.);
  338. dwarf-post-unwind := 0
  339. else
  340. dwarf-post-unwind-text := libdw
  341. endif
  342. else
  343. dwarf-post-unwind-text := libunwind
  344. # Enable libunwind support by default.
  345. ifndef NO_LIBDW_DWARF_UNWIND
  346. NO_LIBDW_DWARF_UNWIND := 1
  347. endif
  348. endif
  349. ifeq ($(dwarf-post-unwind),1)
  350. CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
  351. else
  352. NO_DWARF_UNWIND := 1
  353. endif
  354. ifndef NO_LIBUNWIND
  355. ifeq ($(ARCH),$(filter $(ARCH),arm arm64))
  356. $(call feature_check,libunwind-debug-frame)
  357. ifneq ($(feature-libunwind-debug-frame), 1)
  358. msg := $(warning No debug_frame support found in libunwind);
  359. CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
  360. endif
  361. else
  362. # non-ARM has no dwarf_find_debug_frame() function:
  363. CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
  364. endif
  365. CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
  366. EXTLIBS += $(LIBUNWIND_LIBS)
  367. CFLAGS += $(LIBUNWIND_CFLAGS)
  368. LDFLAGS += $(LIBUNWIND_LDFLAGS)
  369. endif
  370. ifndef NO_LIBAUDIT
  371. ifneq ($(feature-libaudit), 1)
  372. msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
  373. NO_LIBAUDIT := 1
  374. else
  375. CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
  376. EXTLIBS += -laudit
  377. endif
  378. endif
  379. ifdef NO_NEWT
  380. NO_SLANG=1
  381. endif
  382. ifndef NO_SLANG
  383. ifneq ($(feature-libslang), 1)
  384. msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
  385. NO_SLANG := 1
  386. else
  387. # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
  388. CFLAGS += -I/usr/include/slang
  389. CFLAGS += -DHAVE_SLANG_SUPPORT
  390. EXTLIBS += -lslang
  391. endif
  392. endif
  393. ifndef NO_GTK2
  394. FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
  395. ifneq ($(feature-gtk2), 1)
  396. msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
  397. NO_GTK2 := 1
  398. else
  399. ifeq ($(feature-gtk2-infobar), 1)
  400. GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
  401. endif
  402. CFLAGS += -DHAVE_GTK2_SUPPORT
  403. GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
  404. GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
  405. EXTLIBS += -ldl
  406. endif
  407. endif
  408. grep-libs = $(filter -l%,$(1))
  409. strip-libs = $(filter-out -l%,$(1))
  410. ifdef NO_LIBPERL
  411. CFLAGS += -DNO_LIBPERL
  412. else
  413. PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
  414. PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
  415. PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
  416. PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
  417. FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
  418. ifneq ($(feature-libperl), 1)
  419. CFLAGS += -DNO_LIBPERL
  420. NO_LIBPERL := 1
  421. msg := $(warning Missing perl devel files. Disabling perl scripting support, consider installing perl-ExtUtils-Embed);
  422. else
  423. LDFLAGS += $(PERL_EMBED_LDFLAGS)
  424. EXTLIBS += $(PERL_EMBED_LIBADD)
  425. endif
  426. endif
  427. ifeq ($(feature-timerfd), 1)
  428. CFLAGS += -DHAVE_TIMERFD_SUPPORT
  429. else
  430. msg := $(warning No timerfd support. Disables 'perf kvm stat live');
  431. endif
  432. disable-python = $(eval $(disable-python_code))
  433. define disable-python_code
  434. CFLAGS += -DNO_LIBPYTHON
  435. $(if $(1),$(warning No $(1) was found))
  436. $(warning Python support will not be built)
  437. NO_LIBPYTHON := 1
  438. endef
  439. ifdef NO_LIBPYTHON
  440. $(call disable-python)
  441. else
  442. ifndef PYTHON
  443. $(call disable-python,python interpreter)
  444. else
  445. PYTHON_WORD := $(call shell-wordify,$(PYTHON))
  446. ifndef PYTHON_CONFIG
  447. $(call disable-python,python-config tool)
  448. else
  449. PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
  450. PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
  451. PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
  452. PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
  453. PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
  454. FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
  455. ifneq ($(feature-libpython), 1)
  456. $(call disable-python,Python.h (for Python 2.x))
  457. else
  458. ifneq ($(feature-libpython-version), 1)
  459. $(warning Python 3 is not yet supported; please set)
  460. $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
  461. $(warning If you also have Python 2 installed, then)
  462. $(warning try something like:)
  463. $(warning $(and ,))
  464. $(warning $(and ,) make PYTHON=python2)
  465. $(warning $(and ,))
  466. $(warning Otherwise, disable Python support entirely:)
  467. $(warning $(and ,))
  468. $(warning $(and ,) make NO_LIBPYTHON=1)
  469. $(warning $(and ,))
  470. $(error $(and ,))
  471. else
  472. LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
  473. EXTLIBS += $(PYTHON_EMBED_LIBADD)
  474. LANG_BINDINGS += $(obj-perf)python/perf.so
  475. endif
  476. endif
  477. endif
  478. endif
  479. endif
  480. ifeq ($(feature-libbfd), 1)
  481. EXTLIBS += -lbfd
  482. # call all detections now so we get correct
  483. # status in VF output
  484. $(call feature_check,liberty)
  485. $(call feature_check,liberty-z)
  486. $(call feature_check,cplus-demangle)
  487. ifeq ($(feature-liberty), 1)
  488. EXTLIBS += -liberty
  489. else
  490. ifeq ($(feature-liberty-z), 1)
  491. EXTLIBS += -liberty -lz
  492. endif
  493. endif
  494. endif
  495. ifdef NO_DEMANGLE
  496. CFLAGS += -DNO_DEMANGLE
  497. else
  498. ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
  499. EXTLIBS += -liberty
  500. CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
  501. else
  502. ifneq ($(feature-libbfd), 1)
  503. ifneq ($(feature-liberty), 1)
  504. ifneq ($(feature-liberty-z), 1)
  505. # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
  506. # or any of 'bfd iberty z' trinity
  507. ifeq ($(feature-cplus-demangle), 1)
  508. EXTLIBS += -liberty
  509. CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
  510. else
  511. msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
  512. CFLAGS += -DNO_DEMANGLE
  513. endif
  514. endif
  515. endif
  516. endif
  517. endif
  518. endif
  519. ifneq ($(filter -lbfd,$(EXTLIBS)),)
  520. CFLAGS += -DHAVE_LIBBFD_SUPPORT
  521. endif
  522. ifndef NO_BACKTRACE
  523. ifeq ($(feature-backtrace), 1)
  524. CFLAGS += -DHAVE_BACKTRACE_SUPPORT
  525. endif
  526. endif
  527. ifndef NO_LIBNUMA
  528. ifeq ($(feature-libnuma), 0)
  529. msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
  530. NO_LIBNUMA := 1
  531. else
  532. CFLAGS += -DHAVE_LIBNUMA_SUPPORT
  533. EXTLIBS += -lnuma
  534. endif
  535. endif
  536. ifdef HAVE_KVM_STAT_SUPPORT
  537. CFLAGS += -DHAVE_KVM_STAT_SUPPORT
  538. endif
  539. # Among the variables below, these:
  540. # perfexecdir
  541. # template_dir
  542. # mandir
  543. # infodir
  544. # htmldir
  545. # ETC_PERFCONFIG (but not sysconfdir)
  546. # can be specified as a relative path some/where/else;
  547. # this is interpreted as relative to $(prefix) and "perf" at
  548. # runtime figures out where they are based on the path to the executable.
  549. # This can help installing the suite in a relocatable way.
  550. # Make the path relative to DESTDIR, not to prefix
  551. ifndef DESTDIR
  552. prefix ?= $(HOME)
  553. endif
  554. bindir_relative = bin
  555. bindir = $(prefix)/$(bindir_relative)
  556. mandir = share/man
  557. infodir = share/info
  558. perfexecdir = libexec/perf-core
  559. sharedir = $(prefix)/share
  560. template_dir = share/perf-core/templates
  561. htmldir = share/doc/perf-doc
  562. ifeq ($(prefix),/usr)
  563. sysconfdir = /etc
  564. ETC_PERFCONFIG = $(sysconfdir)/perfconfig
  565. else
  566. sysconfdir = $(prefix)/etc
  567. ETC_PERFCONFIG = etc/perfconfig
  568. endif
  569. ifndef lib
  570. ifeq ($(IS_X86_64),1)
  571. lib = lib64
  572. else
  573. lib = lib
  574. endif
  575. endif # lib
  576. libdir = $(prefix)/$(lib)
  577. # Shell quote (do not use $(call) to accommodate ancient setups);
  578. ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
  579. DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
  580. bindir_SQ = $(subst ','\'',$(bindir))
  581. mandir_SQ = $(subst ','\'',$(mandir))
  582. infodir_SQ = $(subst ','\'',$(infodir))
  583. perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
  584. template_dir_SQ = $(subst ','\'',$(template_dir))
  585. htmldir_SQ = $(subst ','\'',$(htmldir))
  586. prefix_SQ = $(subst ','\'',$(prefix))
  587. sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
  588. libdir_SQ = $(subst ','\'',$(libdir))
  589. ifneq ($(filter /%,$(firstword $(perfexecdir))),)
  590. perfexec_instdir = $(perfexecdir)
  591. else
  592. perfexec_instdir = $(prefix)/$(perfexecdir)
  593. endif
  594. perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
  595. # If we install to $(HOME) we keep the traceevent default:
  596. # $(HOME)/.traceevent/plugins
  597. # Otherwise we install plugins into the global $(libdir).
  598. ifdef DESTDIR
  599. plugindir=$(libdir)/traceevent/plugins
  600. plugindir_SQ= $(subst ','\'',$(plugindir))
  601. endif
  602. #
  603. # Print the result of the feature test:
  604. #
  605. feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
  606. define feature_print_status_code
  607. ifeq ($(feature-$(1)), 1)
  608. MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
  609. else
  610. MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
  611. endif
  612. endef
  613. feature_print_var = $(eval $(feature_print_var_code)) $(info $(MSG))
  614. define feature_print_var_code
  615. MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
  616. endef
  617. feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
  618. define feature_print_text_code
  619. MSG = $(shell printf '...%30s: %s' $(1) $(2))
  620. endef
  621. PERF_FEATURES := $(foreach feat,$(LIB_FEATURE_TESTS),feature-$(feat)($(feature-$(feat))))
  622. PERF_FEATURES_FILE := $(shell touch $(OUTPUT)PERF-FEATURES; cat $(OUTPUT)PERF-FEATURES)
  623. ifeq ($(dwarf-post-unwind),1)
  624. PERF_FEATURES += dwarf-post-unwind($(dwarf-post-unwind-text))
  625. endif
  626. # The $(display_lib) controls the default detection message
  627. # output. It's set if:
  628. # - detected features differes from stored features from
  629. # last build (in PERF-FEATURES file)
  630. # - one of the $(LIB_FEATURE_TESTS) is not detected
  631. # - VF is enabled
  632. ifneq ("$(PERF_FEATURES)","$(PERF_FEATURES_FILE)")
  633. $(shell echo "$(PERF_FEATURES)" > $(OUTPUT)PERF-FEATURES)
  634. display_lib := 1
  635. endif
  636. feature_check = $(eval $(feature_check_code))
  637. define feature_check_code
  638. ifneq ($(feature-$(1)), 1)
  639. display_lib := 1
  640. endif
  641. endef
  642. $(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_check,$(feat)))
  643. ifeq ($(VF),1)
  644. display_lib := 1
  645. display_vf := 1
  646. endif
  647. ifeq ($(display_lib),1)
  648. $(info )
  649. $(info Auto-detecting system features:)
  650. $(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_print_status,$(feat),))
  651. ifeq ($(dwarf-post-unwind),1)
  652. $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
  653. endif
  654. endif
  655. ifeq ($(display_vf),1)
  656. $(foreach feat,$(VF_FEATURE_TESTS),$(call feature_print_status,$(feat),))
  657. $(info )
  658. $(call feature_print_var,prefix)
  659. $(call feature_print_var,bindir)
  660. $(call feature_print_var,libdir)
  661. $(call feature_print_var,sysconfdir)
  662. $(call feature_print_var,LIBUNWIND_DIR)
  663. $(call feature_print_var,LIBDW_DIR)
  664. endif
  665. ifeq ($(display_lib),1)
  666. $(info )
  667. endif