Makefile 13 KB

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