Makefile 14 KB

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