Makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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/feature-tests.mak
  45. include $(src-perf)/config/utilities.mak
  46. ifeq ($(call get-executable,$(FLEX)),)
  47. dummy := $(error Error: $(FLEX) is missing on this system, please install it)
  48. endif
  49. ifeq ($(call get-executable,$(BISON)),)
  50. dummy := $(error Error: $(BISON) is missing on this system, please install it)
  51. endif
  52. # Treat warnings as errors unless directed not to
  53. ifneq ($(WERROR),0)
  54. CFLAGS += -Werror
  55. endif
  56. ifeq ("$(origin DEBUG)", "command line")
  57. PERF_DEBUG = $(DEBUG)
  58. endif
  59. ifndef PERF_DEBUG
  60. CFLAGS += -O6
  61. endif
  62. ifdef PARSER_DEBUG
  63. PARSER_DEBUG_BISON := -t
  64. PARSER_DEBUG_FLEX := -d
  65. CFLAGS += -DPARSER_DEBUG
  66. endif
  67. CFLAGS += -fno-omit-frame-pointer
  68. CFLAGS += -ggdb3
  69. CFLAGS += -funwind-tables
  70. CFLAGS += -Wall
  71. CFLAGS += -Wextra
  72. CFLAGS += -std=gnu99
  73. EXTLIBS = -lelf -lpthread -lrt -lm -ldl
  74. feature_check = $(eval $(feature_check_code)); $(info CHK: config/feature-checks/test-$(1))
  75. define feature_check_code
  76. feature-$(2) := $(shell make -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
  77. endef
  78. #
  79. # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
  80. #
  81. $(info Testing features:)
  82. $(shell make -i -j -C config/feature-checks >/dev/null 2>&1)
  83. $(info done)
  84. FEATURE_TESTS = \
  85. hello \
  86. stackprotector-all \
  87. stackprotector \
  88. volatile-register-var \
  89. fortify-source \
  90. bionic \
  91. libelf \
  92. glibc \
  93. dwarf \
  94. libelf-mmap \
  95. libelf-getphdrnum \
  96. libunwind \
  97. libaudit \
  98. libslang \
  99. gtk2 \
  100. gtk2-infobar \
  101. libperl \
  102. libpython \
  103. libnuma
  104. $(foreach test,$(FEATURE_TESTS),$(call feature_check,$(test),$(test)))
  105. ifeq ($(feature-stackprotector-all), 1)
  106. CFLAGS += -fstack-protector-all
  107. endif
  108. ifeq ($(feature-stackprotector), 1)
  109. CFLAGS += -Wstack-protector
  110. endif
  111. ifeq ($(feature-volatile-register-var), 1)
  112. CFLAGS += -Wvolatile-register-var
  113. endif
  114. ifndef PERF_DEBUG
  115. ifeq ($(feature-fortify-source), 1)
  116. CFLAGS += -D_FORTIFY_SOURCE=2
  117. endif
  118. endif
  119. CFLAGS += -I$(src-perf)/util/include
  120. CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
  121. CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
  122. CFLAGS += -I$(srctree)/arch/$(ARCH)/include
  123. CFLAGS += -I$(srctree)/include/uapi
  124. CFLAGS += -I$(srctree)/include
  125. # $(obj-perf) for generated common-cmds.h
  126. # $(obj-perf)/util for generated bison/flex headers
  127. ifneq ($(OUTPUT),)
  128. CFLAGS += -I$(obj-perf)/util
  129. CFLAGS += -I$(obj-perf)
  130. endif
  131. CFLAGS += -I$(src-perf)/util
  132. CFLAGS += -I$(src-perf)
  133. CFLAGS += -I$(LIB_INCLUDE)
  134. CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
  135. ifndef NO_BIONIC
  136. $(feature_check,bionic)
  137. ifeq ($(feature-bionic), 1)
  138. BIONIC := 1
  139. EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
  140. EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
  141. endif
  142. endif
  143. ifdef NO_LIBELF
  144. NO_DWARF := 1
  145. NO_DEMANGLE := 1
  146. NO_LIBUNWIND := 1
  147. else
  148. ifeq ($(feature-libelf), 0)
  149. ifeq ($(feature-glibc), 1)
  150. LIBC_SUPPORT := 1
  151. endif
  152. ifeq ($(BIONIC),1)
  153. LIBC_SUPPORT := 1
  154. endif
  155. ifeq ($(LIBC_SUPPORT),1)
  156. msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
  157. NO_LIBELF := 1
  158. NO_DWARF := 1
  159. NO_DEMANGLE := 1
  160. else
  161. msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
  162. endif
  163. else
  164. # for linking with debug library, run like:
  165. # make DEBUG=1 LIBDW_DIR=/opt/libdw/
  166. ifdef LIBDW_DIR
  167. LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
  168. LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
  169. endif
  170. ifneq ($(feature-dwarf), 1)
  171. 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);
  172. NO_DWARF := 1
  173. endif # Dwarf support
  174. endif # SOURCE_LIBELF
  175. endif # NO_LIBELF
  176. ifndef NO_LIBELF
  177. CFLAGS += -DHAVE_LIBELF_SUPPORT
  178. FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
  179. ifeq ($(feature-libelf-mmap), 1)
  180. CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
  181. endif
  182. ifeq ($(feature-libelf-getphdrnum), 1)
  183. CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
  184. endif
  185. # include ARCH specific config
  186. -include $(src-perf)/arch/$(ARCH)/Makefile
  187. ifndef NO_DWARF
  188. ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
  189. msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
  190. NO_DWARF := 1
  191. else
  192. CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
  193. LDFLAGS += $(LIBDW_LDFLAGS)
  194. EXTLIBS += -lelf -ldw
  195. endif # PERF_HAVE_DWARF_REGS
  196. endif # NO_DWARF
  197. endif # NO_LIBELF
  198. ifndef NO_LIBELF
  199. CFLAGS += -DHAVE_LIBELF_SUPPORT
  200. ifeq ($(feature-libelf-mmap), 1)
  201. CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
  202. endif
  203. endif # NO_LIBELF
  204. # There's only x86 (both 32 and 64) support for CFI unwind so far
  205. ifneq ($(ARCH),x86)
  206. NO_LIBUNWIND := 1
  207. endif
  208. ifndef NO_LIBUNWIND
  209. #
  210. # For linking with debug library, run like:
  211. #
  212. # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
  213. #
  214. ifdef LIBUNWIND_DIR
  215. LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
  216. LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
  217. endif
  218. ifneq ($(feature-libunwind), 1)
  219. msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
  220. NO_LIBUNWIND := 1
  221. endif
  222. endif
  223. ifndef NO_LIBUNWIND
  224. CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
  225. EXTLIBS += $(LIBUNWIND_LIBS)
  226. CFLAGS += $(LIBUNWIND_CFLAGS)
  227. LDFLAGS += $(LIBUNWIND_LDFLAGS)
  228. endif
  229. ifndef NO_LIBAUDIT
  230. ifneq ($(feature-libaudit), 1)
  231. msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
  232. NO_LIBAUDIT := 1
  233. else
  234. CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
  235. EXTLIBS += -laudit
  236. endif
  237. endif
  238. ifdef NO_NEWT
  239. NO_SLANG=1
  240. endif
  241. ifndef NO_SLANG
  242. ifneq ($(feature-libslang), 1)
  243. msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
  244. NO_SLANG := 1
  245. else
  246. # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
  247. CFLAGS += -I/usr/include/slang
  248. CFLAGS += -DHAVE_SLANG_SUPPORT
  249. EXTLIBS += -lslang
  250. endif
  251. endif
  252. ifndef NO_GTK2
  253. FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
  254. ifneq ($(feature-gtk2), 1)
  255. msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
  256. NO_GTK2 := 1
  257. else
  258. ifeq ($(feature-gtk2-infobar), 1)
  259. CFLAGS += -DHAVE_GTK_INFO_BAR_SUPPORT
  260. endif
  261. CFLAGS += -DHAVE_GTK2_SUPPORT
  262. CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
  263. EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
  264. endif
  265. endif
  266. grep-libs = $(filter -l%,$(1))
  267. strip-libs = $(filter-out -l%,$(1))
  268. ifdef NO_LIBPERL
  269. CFLAGS += -DNO_LIBPERL
  270. else
  271. PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
  272. PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
  273. PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
  274. PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
  275. FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
  276. ifneq ($(feature-libperl), 1)
  277. CFLAGS += -DNO_LIBPERL
  278. NO_LIBPERL := 1
  279. else
  280. LDFLAGS += $(PERL_EMBED_LDFLAGS)
  281. EXTLIBS += $(PERL_EMBED_LIBADD)
  282. endif
  283. endif
  284. disable-python = $(eval $(disable-python_code))
  285. define disable-python_code
  286. CFLAGS += -DNO_LIBPYTHON
  287. $(if $(1),$(warning No $(1) was found))
  288. $(warning Python support will not be built)
  289. NO_LIBPYTHON := 1
  290. endef
  291. override PYTHON := \
  292. $(call get-executable-or-default,PYTHON,python)
  293. ifndef PYTHON
  294. $(call disable-python,python interpreter)
  295. else
  296. PYTHON_WORD := $(call shell-wordify,$(PYTHON))
  297. ifdef NO_LIBPYTHON
  298. $(call disable-python)
  299. else
  300. override PYTHON_CONFIG := \
  301. $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
  302. ifndef PYTHON_CONFIG
  303. $(call disable-python,python-config tool)
  304. else
  305. PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
  306. PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
  307. PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
  308. PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
  309. PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
  310. FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
  311. ifneq ($(feature-libpython), 1)
  312. $(call disable-python,Python.h (for Python 2.x))
  313. else
  314. ifneq ($(call try-cc,$(SOURCE_PYTHON_VERSION),$(FLAGS_PYTHON_EMBED),python version),y)
  315. $(warning Python 3 is not yet supported; please set)
  316. $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
  317. $(warning If you also have Python 2 installed, then)
  318. $(warning try something like:)
  319. $(warning $(and ,))
  320. $(warning $(and ,) make PYTHON=python2)
  321. $(warning $(and ,))
  322. $(warning Otherwise, disable Python support entirely:)
  323. $(warning $(and ,))
  324. $(warning $(and ,) make NO_LIBPYTHON=1)
  325. $(warning $(and ,))
  326. $(error $(and ,))
  327. else
  328. LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
  329. EXTLIBS += $(PYTHON_EMBED_LIBADD)
  330. LANG_BINDINGS += $(obj-perf)python/perf.so
  331. endif
  332. endif
  333. endif
  334. endif
  335. endif
  336. ifdef NO_DEMANGLE
  337. CFLAGS += -DNO_DEMANGLE
  338. else
  339. ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
  340. EXTLIBS += -liberty
  341. CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
  342. else
  343. FLAGS_BFD=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -lbfd
  344. has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD),libbfd)
  345. ifeq ($(has_bfd),y)
  346. EXTLIBS += -lbfd
  347. else
  348. FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
  349. has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY),liberty)
  350. ifeq ($(has_bfd_iberty),y)
  351. EXTLIBS += -lbfd -liberty
  352. else
  353. FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
  354. has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z),libz)
  355. ifeq ($(has_bfd_iberty_z),y)
  356. EXTLIBS += -lbfd -liberty -lz
  357. else
  358. FLAGS_CPLUS_DEMANGLE=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -liberty
  359. has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE),demangle)
  360. ifeq ($(has_cplus_demangle),y)
  361. EXTLIBS += -liberty
  362. CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
  363. else
  364. msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
  365. CFLAGS += -DNO_DEMANGLE
  366. endif
  367. endif
  368. endif
  369. endif
  370. endif
  371. endif
  372. ifndef NO_STRLCPY
  373. ifeq ($(call try-cc,$(SOURCE_STRLCPY),,-DHAVE_STRLCPY_SUPPORT),y)
  374. CFLAGS += -DHAVE_STRLCPY_SUPPORT
  375. endif
  376. endif
  377. ifndef NO_ON_EXIT
  378. ifeq ($(call try-cc,$(SOURCE_ON_EXIT),,-DHAVE_ON_EXIT_SUPPORT),y)
  379. CFLAGS += -DHAVE_ON_EXIT_SUPPORT
  380. endif
  381. endif
  382. ifndef NO_BACKTRACE
  383. ifeq ($(call try-cc,$(SOURCE_BACKTRACE),,-DHAVE_BACKTRACE_SUPPORT),y)
  384. CFLAGS += -DHAVE_BACKTRACE_SUPPORT
  385. endif
  386. endif
  387. ifndef NO_LIBNUMA
  388. ifeq ($(feature-libnuma), 0)
  389. msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
  390. NO_LIBNUMA := 1
  391. else
  392. CFLAGS += -DHAVE_LIBNUMA_SUPPORT
  393. EXTLIBS += -lnuma
  394. endif
  395. endif
  396. # Among the variables below, these:
  397. # perfexecdir
  398. # template_dir
  399. # mandir
  400. # infodir
  401. # htmldir
  402. # ETC_PERFCONFIG (but not sysconfdir)
  403. # can be specified as a relative path some/where/else;
  404. # this is interpreted as relative to $(prefix) and "perf" at
  405. # runtime figures out where they are based on the path to the executable.
  406. # This can help installing the suite in a relocatable way.
  407. # Make the path relative to DESTDIR, not to prefix
  408. ifndef DESTDIR
  409. prefix = $(HOME)
  410. endif
  411. bindir_relative = bin
  412. bindir = $(prefix)/$(bindir_relative)
  413. mandir = share/man
  414. infodir = share/info
  415. perfexecdir = libexec/perf-core
  416. sharedir = $(prefix)/share
  417. template_dir = share/perf-core/templates
  418. htmldir = share/doc/perf-doc
  419. ifeq ($(prefix),/usr)
  420. sysconfdir = /etc
  421. ETC_PERFCONFIG = $(sysconfdir)/perfconfig
  422. else
  423. sysconfdir = $(prefix)/etc
  424. ETC_PERFCONFIG = etc/perfconfig
  425. endif
  426. lib = lib
  427. # Shell quote (do not use $(call) to accommodate ancient setups);
  428. ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
  429. DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
  430. bindir_SQ = $(subst ','\'',$(bindir))
  431. mandir_SQ = $(subst ','\'',$(mandir))
  432. infodir_SQ = $(subst ','\'',$(infodir))
  433. perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
  434. template_dir_SQ = $(subst ','\'',$(template_dir))
  435. htmldir_SQ = $(subst ','\'',$(htmldir))
  436. prefix_SQ = $(subst ','\'',$(prefix))
  437. sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
  438. ifneq ($(filter /%,$(firstword $(perfexecdir))),)
  439. perfexec_instdir = $(perfexecdir)
  440. else
  441. perfexec_instdir = $(prefix)/$(perfexecdir)
  442. endif
  443. perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))