Makefile 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. uname_M := $(shell uname -m 2>/dev/null || echo not)
  2. ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
  3. -e s/arm.*/arm/ -e s/sa110/arm/ \
  4. -e s/s390x/s390/ -e s/parisc64/parisc/ \
  5. -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
  6. -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
  7. NO_PERF_REGS := 1
  8. CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
  9. # Additional ARCH settings for x86
  10. ifeq ($(ARCH),i386)
  11. override ARCH := x86
  12. NO_PERF_REGS := 0
  13. LIBUNWIND_LIBS = -lunwind -lunwind-x86
  14. endif
  15. ifeq ($(ARCH),x86_64)
  16. override ARCH := x86
  17. IS_X86_64 := 0
  18. ifeq (, $(findstring m32,$(CFLAGS)))
  19. IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1)
  20. endif
  21. ifeq (${IS_X86_64}, 1)
  22. RAW_ARCH := x86_64
  23. CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
  24. ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
  25. endif
  26. NO_PERF_REGS := 0
  27. LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
  28. endif
  29. ifeq ($(NO_PERF_REGS),0)
  30. CFLAGS += -DHAVE_PERF_REGS_SUPPORT
  31. endif
  32. ifeq ($(src-perf),)
  33. src-perf := $(srctree)/tools/perf
  34. endif
  35. ifeq ($(obj-perf),)
  36. obj-perf := $(OUTPUT)
  37. endif
  38. ifneq ($(obj-perf),)
  39. obj-perf := $(abspath $(obj-perf))/
  40. endif
  41. LIB_INCLUDE := $(srctree)/tools/lib/
  42. # include ARCH specific config
  43. -include $(src-perf)/arch/$(ARCH)/Makefile
  44. include $(src-perf)/config/utilities.mak
  45. ifeq ($(call get-executable,$(FLEX)),)
  46. dummy := $(error Error: $(FLEX) is missing on this system, please install it)
  47. endif
  48. ifeq ($(call get-executable,$(BISON)),)
  49. dummy := $(error Error: $(BISON) is missing on this system, please install it)
  50. endif
  51. # Treat warnings as errors unless directed not to
  52. ifneq ($(WERROR),0)
  53. CFLAGS += -Werror
  54. endif
  55. ifeq ("$(origin DEBUG)", "command line")
  56. PERF_DEBUG = $(DEBUG)
  57. endif
  58. ifndef PERF_DEBUG
  59. CFLAGS += -O6
  60. endif
  61. ifdef PARSER_DEBUG
  62. PARSER_DEBUG_BISON := -t
  63. PARSER_DEBUG_FLEX := -d
  64. CFLAGS += -DPARSER_DEBUG
  65. endif
  66. CFLAGS += -fno-omit-frame-pointer
  67. CFLAGS += -ggdb3
  68. CFLAGS += -funwind-tables
  69. CFLAGS += -Wall
  70. CFLAGS += -Wextra
  71. CFLAGS += -std=gnu99
  72. EXTLIBS = -lelf -lpthread -lrt -lm -ldl
  73. feature_check = $(eval $(feature_check_code))
  74. define feature_check_code
  75. feature-$(1) := $(shell $(MAKE) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
  76. endef
  77. feature_set = $(eval $(feature_set_code))
  78. define feature_set_code
  79. feature-$(1) := 1
  80. endef
  81. #
  82. # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
  83. #
  84. #
  85. # Note that this is not a complete list of all feature tests, just
  86. # those that are typically built on a fully configured system.
  87. #
  88. # [ Feature tests not mentioned here have to be built explicitly in
  89. # the rule that uses them - an example for that is the 'bionic'
  90. # feature check. ]
  91. #
  92. CORE_FEATURE_TESTS = \
  93. backtrace \
  94. dwarf \
  95. fortify-source \
  96. glibc \
  97. gtk2 \
  98. gtk2-infobar \
  99. libaudit \
  100. libbfd \
  101. libelf \
  102. libelf-getphdrnum \
  103. libelf-mmap \
  104. libnuma \
  105. libperl \
  106. libpython \
  107. libpython-version \
  108. libslang \
  109. libunwind \
  110. on-exit \
  111. stackprotector \
  112. stackprotector-all \
  113. volatile-register-var
  114. #
  115. # So here we detect whether test-all was rebuilt, to be able
  116. # to skip the print-out of the long features list if the file
  117. # existed before and after it was built:
  118. #
  119. ifeq ($(wildcard config/feature-checks/test-all),)
  120. test-all-failed := 1
  121. else
  122. test-all-failed := 0
  123. endif
  124. #
  125. # Special fast-path for the 'all features are available' case:
  126. #
  127. $(call feature_check,all,$(MSG))
  128. #
  129. # Just in case the build freshly failed, make sure we print the
  130. # feature matrix:
  131. #
  132. ifeq ($(feature-all), 0)
  133. test-all-failed := 1
  134. endif
  135. ifeq ($(test-all-failed),1)
  136. $(info )
  137. $(info Auto-detecting system features:)
  138. endif
  139. ifeq ($(feature-all), 1)
  140. #
  141. # test-all.c passed - just set all the core feature flags to 1:
  142. #
  143. $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
  144. else
  145. $(shell $(MAKE) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
  146. $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
  147. endif
  148. #
  149. # Print the result of the feature test:
  150. #
  151. feature_print = $(eval $(feature_print_code))
  152. define feature_print_code
  153. ifeq ($(feature-$(1)), 1)
  154. MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
  155. else
  156. MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
  157. endif
  158. $(info $(MSG))
  159. endef
  160. #
  161. # Only print out our features if we rebuilt the testcases or if a test failed:
  162. #
  163. ifeq ($(test-all-failed), 1)
  164. $(foreach feat,$(CORE_FEATURE_TESTS) DUMMY,$(call feature_print,$(feat)))
  165. $(info )
  166. endif
  167. ifeq ($(feature-stackprotector-all), 1)
  168. CFLAGS += -fstack-protector-all
  169. endif
  170. ifeq ($(feature-stackprotector), 1)
  171. CFLAGS += -Wstack-protector
  172. endif
  173. ifeq ($(feature-volatile-register-var), 1)
  174. CFLAGS += -Wvolatile-register-var
  175. endif
  176. ifndef PERF_DEBUG
  177. ifeq ($(feature-fortify-source), 1)
  178. CFLAGS += -D_FORTIFY_SOURCE=2
  179. endif
  180. endif
  181. CFLAGS += -I$(src-perf)/util/include
  182. CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
  183. CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
  184. CFLAGS += -I$(srctree)/arch/$(ARCH)/include
  185. CFLAGS += -I$(srctree)/include/uapi
  186. CFLAGS += -I$(srctree)/include
  187. # $(obj-perf) for generated common-cmds.h
  188. # $(obj-perf)/util for generated bison/flex headers
  189. ifneq ($(OUTPUT),)
  190. CFLAGS += -I$(obj-perf)/util
  191. CFLAGS += -I$(obj-perf)
  192. endif
  193. CFLAGS += -I$(src-perf)/util
  194. CFLAGS += -I$(src-perf)
  195. CFLAGS += -I$(LIB_INCLUDE)
  196. CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
  197. ifndef NO_BIONIC
  198. $(feature_check,bionic)
  199. ifeq ($(feature-bionic), 1)
  200. BIONIC := 1
  201. EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
  202. EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
  203. endif
  204. endif
  205. ifdef NO_LIBELF
  206. NO_DWARF := 1
  207. NO_DEMANGLE := 1
  208. NO_LIBUNWIND := 1
  209. else
  210. ifeq ($(feature-libelf), 0)
  211. ifeq ($(feature-glibc), 1)
  212. LIBC_SUPPORT := 1
  213. endif
  214. ifeq ($(BIONIC),1)
  215. LIBC_SUPPORT := 1
  216. endif
  217. ifeq ($(LIBC_SUPPORT),1)
  218. msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
  219. NO_LIBELF := 1
  220. NO_DWARF := 1
  221. NO_DEMANGLE := 1
  222. else
  223. msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
  224. endif
  225. else
  226. # for linking with debug library, run like:
  227. # make DEBUG=1 LIBDW_DIR=/opt/libdw/
  228. ifdef LIBDW_DIR
  229. LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
  230. LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
  231. endif
  232. ifneq ($(feature-dwarf), 1)
  233. 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);
  234. NO_DWARF := 1
  235. endif # Dwarf support
  236. endif # libelf support
  237. endif # NO_LIBELF
  238. ifndef NO_LIBELF
  239. CFLAGS += -DHAVE_LIBELF_SUPPORT
  240. FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
  241. ifeq ($(feature-libelf-mmap), 1)
  242. CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
  243. endif
  244. ifeq ($(feature-libelf-getphdrnum), 1)
  245. CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
  246. endif
  247. # include ARCH specific config
  248. -include $(src-perf)/arch/$(ARCH)/Makefile
  249. ifndef NO_DWARF
  250. ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
  251. msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
  252. NO_DWARF := 1
  253. else
  254. CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
  255. LDFLAGS += $(LIBDW_LDFLAGS)
  256. EXTLIBS += -lelf -ldw
  257. endif # PERF_HAVE_DWARF_REGS
  258. endif # NO_DWARF
  259. endif # NO_LIBELF
  260. ifndef NO_LIBELF
  261. CFLAGS += -DHAVE_LIBELF_SUPPORT
  262. ifeq ($(feature-libelf-mmap), 1)
  263. CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
  264. endif
  265. endif # NO_LIBELF
  266. # There's only x86 (both 32 and 64) support for CFI unwind so far
  267. ifneq ($(ARCH),x86)
  268. NO_LIBUNWIND := 1
  269. endif
  270. ifndef NO_LIBUNWIND
  271. #
  272. # For linking with debug library, run like:
  273. #
  274. # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
  275. #
  276. ifdef LIBUNWIND_DIR
  277. LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
  278. LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
  279. endif
  280. ifneq ($(feature-libunwind), 1)
  281. msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
  282. NO_LIBUNWIND := 1
  283. endif
  284. endif
  285. ifndef NO_LIBUNWIND
  286. CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
  287. EXTLIBS += $(LIBUNWIND_LIBS)
  288. CFLAGS += $(LIBUNWIND_CFLAGS)
  289. LDFLAGS += $(LIBUNWIND_LDFLAGS)
  290. endif
  291. ifndef NO_LIBAUDIT
  292. ifneq ($(feature-libaudit), 1)
  293. msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
  294. NO_LIBAUDIT := 1
  295. else
  296. CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
  297. EXTLIBS += -laudit
  298. endif
  299. endif
  300. ifdef NO_NEWT
  301. NO_SLANG=1
  302. endif
  303. ifndef NO_SLANG
  304. ifneq ($(feature-libslang), 1)
  305. msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
  306. NO_SLANG := 1
  307. else
  308. # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
  309. CFLAGS += -I/usr/include/slang
  310. CFLAGS += -DHAVE_SLANG_SUPPORT
  311. EXTLIBS += -lslang
  312. endif
  313. endif
  314. ifndef NO_GTK2
  315. FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
  316. ifneq ($(feature-gtk2), 1)
  317. msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
  318. NO_GTK2 := 1
  319. else
  320. ifeq ($(feature-gtk2-infobar), 1)
  321. CFLAGS += -DHAVE_GTK_INFO_BAR_SUPPORT
  322. endif
  323. CFLAGS += -DHAVE_GTK2_SUPPORT
  324. CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
  325. EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
  326. endif
  327. endif
  328. grep-libs = $(filter -l%,$(1))
  329. strip-libs = $(filter-out -l%,$(1))
  330. ifdef NO_LIBPERL
  331. CFLAGS += -DNO_LIBPERL
  332. else
  333. PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
  334. PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
  335. PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
  336. PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
  337. FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
  338. ifneq ($(feature-libperl), 1)
  339. CFLAGS += -DNO_LIBPERL
  340. NO_LIBPERL := 1
  341. else
  342. LDFLAGS += $(PERL_EMBED_LDFLAGS)
  343. EXTLIBS += $(PERL_EMBED_LIBADD)
  344. endif
  345. endif
  346. disable-python = $(eval $(disable-python_code))
  347. define disable-python_code
  348. CFLAGS += -DNO_LIBPYTHON
  349. $(if $(1),$(warning No $(1) was found))
  350. $(warning Python support will not be built)
  351. NO_LIBPYTHON := 1
  352. endef
  353. override PYTHON := \
  354. $(call get-executable-or-default,PYTHON,python)
  355. ifndef PYTHON
  356. $(call disable-python,python interpreter)
  357. else
  358. PYTHON_WORD := $(call shell-wordify,$(PYTHON))
  359. ifdef NO_LIBPYTHON
  360. $(call disable-python)
  361. else
  362. override PYTHON_CONFIG := \
  363. $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
  364. ifndef PYTHON_CONFIG
  365. $(call disable-python,python-config tool)
  366. else
  367. PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
  368. PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
  369. PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
  370. PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
  371. PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
  372. FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
  373. ifneq ($(feature-libpython), 1)
  374. $(call disable-python,Python.h (for Python 2.x))
  375. else
  376. ifneq ($(feature-libpython-version), 1)
  377. $(warning Python 3 is not yet supported; please set)
  378. $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
  379. $(warning If you also have Python 2 installed, then)
  380. $(warning try something like:)
  381. $(warning $(and ,))
  382. $(warning $(and ,) make PYTHON=python2)
  383. $(warning $(and ,))
  384. $(warning Otherwise, disable Python support entirely:)
  385. $(warning $(and ,))
  386. $(warning $(and ,) make NO_LIBPYTHON=1)
  387. $(warning $(and ,))
  388. $(error $(and ,))
  389. else
  390. LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
  391. EXTLIBS += $(PYTHON_EMBED_LIBADD)
  392. LANG_BINDINGS += $(obj-perf)python/perf.so
  393. endif
  394. endif
  395. endif
  396. endif
  397. endif
  398. ifdef NO_DEMANGLE
  399. CFLAGS += -DNO_DEMANGLE
  400. else
  401. ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
  402. EXTLIBS += -liberty
  403. CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
  404. else
  405. ifeq ($(feature-libbfd), 1)
  406. EXTLIBS += -lbfd
  407. else
  408. $(feature_check,liberty)
  409. ifeq ($(feature-liberty), 1)
  410. EXTLIBS += -lbfd -liberty
  411. else
  412. $(feature_check,liberty-z)
  413. ifeq ($(feature-liberty-z), 1)
  414. EXTLIBS += -lbfd -liberty -lz
  415. else
  416. $(feature_check,cplus-demangle)
  417. ifeq ($(feature-cplus-demangle), 1)
  418. EXTLIBS += -liberty
  419. CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
  420. else
  421. msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
  422. CFLAGS += -DNO_DEMANGLE
  423. endif
  424. endif
  425. endif
  426. endif
  427. endif
  428. endif
  429. ifndef NO_ON_EXIT
  430. ifeq ($(feature-on-exit), 1)
  431. CFLAGS += -DHAVE_ON_EXIT_SUPPORT
  432. endif
  433. endif
  434. ifndef NO_BACKTRACE
  435. ifeq ($(feature-backtrace), 1)
  436. CFLAGS += -DHAVE_BACKTRACE_SUPPORT
  437. endif
  438. endif
  439. ifndef NO_LIBNUMA
  440. ifeq ($(feature-libnuma), 0)
  441. msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
  442. NO_LIBNUMA := 1
  443. else
  444. CFLAGS += -DHAVE_LIBNUMA_SUPPORT
  445. EXTLIBS += -lnuma
  446. endif
  447. endif
  448. # Among the variables below, these:
  449. # perfexecdir
  450. # template_dir
  451. # mandir
  452. # infodir
  453. # htmldir
  454. # ETC_PERFCONFIG (but not sysconfdir)
  455. # can be specified as a relative path some/where/else;
  456. # this is interpreted as relative to $(prefix) and "perf" at
  457. # runtime figures out where they are based on the path to the executable.
  458. # This can help installing the suite in a relocatable way.
  459. # Make the path relative to DESTDIR, not to prefix
  460. ifndef DESTDIR
  461. prefix = $(HOME)
  462. endif
  463. bindir_relative = bin
  464. bindir = $(prefix)/$(bindir_relative)
  465. mandir = share/man
  466. infodir = share/info
  467. perfexecdir = libexec/perf-core
  468. sharedir = $(prefix)/share
  469. template_dir = share/perf-core/templates
  470. htmldir = share/doc/perf-doc
  471. ifeq ($(prefix),/usr)
  472. sysconfdir = /etc
  473. ETC_PERFCONFIG = $(sysconfdir)/perfconfig
  474. else
  475. sysconfdir = $(prefix)/etc
  476. ETC_PERFCONFIG = etc/perfconfig
  477. endif
  478. lib = lib
  479. # Shell quote (do not use $(call) to accommodate ancient setups);
  480. ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
  481. DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
  482. bindir_SQ = $(subst ','\'',$(bindir))
  483. mandir_SQ = $(subst ','\'',$(mandir))
  484. infodir_SQ = $(subst ','\'',$(infodir))
  485. perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
  486. template_dir_SQ = $(subst ','\'',$(template_dir))
  487. htmldir_SQ = $(subst ','\'',$(htmldir))
  488. prefix_SQ = $(subst ','\'',$(prefix))
  489. sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
  490. ifneq ($(filter /%,$(firstword $(perfexecdir))),)
  491. perfexec_instdir = $(perfexecdir)
  492. else
  493. perfexec_instdir = $(prefix)/$(perfexecdir)
  494. endif
  495. perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))