Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. # Additional ARCH settings for x86
  9. ifeq ($(ARCH),i386)
  10. override ARCH := x86
  11. NO_PERF_REGS := 0
  12. LIBUNWIND_LIBS = -lunwind -lunwind-x86
  13. endif
  14. ifeq ($(ARCH),x86_64)
  15. override ARCH := x86
  16. IS_X86_64 := 0
  17. ifeq (, $(findstring m32,$(EXTRA_CFLAGS)))
  18. IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1)
  19. endif
  20. ifeq (${IS_X86_64}, 1)
  21. RAW_ARCH := x86_64
  22. ARCH_CFLAGS := -DARCH_X86_64
  23. ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
  24. endif
  25. NO_PERF_REGS := 0
  26. LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
  27. endif
  28. ifeq ($(NO_PERF_REGS),0)
  29. BASIC_CFLAGS += -DHAVE_PERF_REGS
  30. endif
  31. -include config/feature-tests.mak
  32. ifeq ($(call get-executable,$(FLEX)),)
  33. dummy := $(error Error: $(FLEX) is missing on this system, please install it)
  34. endif
  35. ifeq ($(call get-executable,$(BISON)),)
  36. dummy := $(error Error: $(BISON) is missing on this system, please install it)
  37. endif
  38. # Treat warnings as errors unless directed not to
  39. ifneq ($(WERROR),0)
  40. CFLAGS_WERROR := -Werror
  41. endif
  42. ifeq ("$(origin DEBUG)", "command line")
  43. PERF_DEBUG = $(DEBUG)
  44. endif
  45. ifndef PERF_DEBUG
  46. CFLAGS_OPTIMIZE = -O6
  47. endif
  48. ifdef PARSER_DEBUG
  49. PARSER_DEBUG_BISON := -t
  50. PARSER_DEBUG_FLEX := -d
  51. PARSER_DEBUG_CFLAGS := -DPARSER_DEBUG
  52. endif
  53. CFLAGS = -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) $(PARSER_DEBUG_CFLAGS)
  54. EXTLIBS = -lpthread -lrt -lelf -lm
  55. ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
  56. ALL_LDFLAGS = $(LDFLAGS)
  57. ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y)
  58. CFLAGS := $(CFLAGS) -fstack-protector-all
  59. endif
  60. ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wstack-protector,-Wstack-protector),y)
  61. CFLAGS := $(CFLAGS) -Wstack-protector
  62. endif
  63. ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wvolatile-register-var,-Wvolatile-register-var),y)
  64. CFLAGS := $(CFLAGS) -Wvolatile-register-var
  65. endif
  66. ifndef PERF_DEBUG
  67. ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -D_FORTIFY_SOURCE=2,-D_FORTIFY_SOURCE=2),y)
  68. CFLAGS := $(CFLAGS) -D_FORTIFY_SOURCE=2
  69. endif
  70. endif
  71. BASIC_CFLAGS += \
  72. -Iutil/include \
  73. -Iarch/$(ARCH)/include \
  74. $(if $(objtree),-I$(objtree)/arch/$(ARCH)/include/generated/uapi) \
  75. -I$(srctree)/arch/$(ARCH)/include/uapi \
  76. -I$(srctree)/arch/$(ARCH)/include \
  77. $(if $(objtree),-I$(objtree)/include/generated/uapi) \
  78. -I$(srctree)/include/uapi \
  79. -I$(srctree)/include \
  80. -I$(OUTPUT)util \
  81. -Iutil \
  82. -I. \
  83. -I$(TRACE_EVENT_DIR) \
  84. -I../lib/ \
  85. -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
  86. BASIC_LDFLAGS =
  87. ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
  88. BIONIC := 1
  89. EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
  90. EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
  91. BASIC_CFLAGS += -I.
  92. endif
  93. ifdef NO_LIBELF
  94. NO_DWARF := 1
  95. NO_DEMANGLE := 1
  96. NO_LIBUNWIND := 1
  97. else
  98. FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
  99. ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF),libelf),y)
  100. FLAGS_GLIBC=$(ALL_CFLAGS) $(ALL_LDFLAGS)
  101. ifeq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC),glibc),y)
  102. LIBC_SUPPORT := 1
  103. endif
  104. ifeq ($(BIONIC),1)
  105. LIBC_SUPPORT := 1
  106. endif
  107. ifeq ($(LIBC_SUPPORT),1)
  108. msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
  109. NO_LIBELF := 1
  110. NO_DWARF := 1
  111. NO_DEMANGLE := 1
  112. else
  113. msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
  114. endif
  115. else
  116. # for linking with debug library, run like:
  117. # make DEBUG=1 LIBDW_DIR=/opt/libdw/
  118. ifdef LIBDW_DIR
  119. LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
  120. LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
  121. endif
  122. FLAGS_DWARF=$(ALL_CFLAGS) $(LIBDW_CFLAGS) -ldw -lelf $(LIBDW_LDFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
  123. ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF),libdw),y)
  124. 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);
  125. NO_DWARF := 1
  126. endif # Dwarf support
  127. endif # SOURCE_LIBELF
  128. endif # NO_LIBELF
  129. ifndef NO_LIBELF
  130. BASIC_CFLAGS += -DLIBELF_SUPPORT
  131. FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
  132. ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_LIBELF),-DLIBELF_MMAP),y)
  133. BASIC_CFLAGS += -DLIBELF_MMAP
  134. endif
  135. # include ARCH specific config
  136. -include arch/$(ARCH)/Makefile
  137. ifndef NO_DWARF
  138. ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
  139. msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
  140. NO_DWARF := 1
  141. else
  142. BASIC_CFLAGS := -DDWARF_SUPPORT $(LIBDW_CFLAGS) $(BASIC_CFLAGS)
  143. BASIC_LDFLAGS := $(LIBDW_LDFLAGS) $(BASIC_LDFLAGS)
  144. EXTLIBS += -lelf -ldw
  145. endif # PERF_HAVE_DWARF_REGS
  146. endif # NO_DWARF
  147. endif # NO_LIBELF
  148. # There's only x86 (both 32 and 64) support for CFI unwind so far
  149. ifneq ($(ARCH),x86)
  150. NO_LIBUNWIND := 1
  151. endif
  152. ifndef NO_LIBUNWIND
  153. # for linking with debug library, run like:
  154. # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
  155. ifdef LIBUNWIND_DIR
  156. LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
  157. LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
  158. endif
  159. FLAGS_UNWIND=$(LIBUNWIND_CFLAGS) $(ALL_CFLAGS) $(LIBUNWIND_LDFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(LIBUNWIND_LIBS)
  160. ifneq ($(call try-cc,$(SOURCE_LIBUNWIND),$(FLAGS_UNWIND),libunwind),y)
  161. msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
  162. NO_LIBUNWIND := 1
  163. endif # Libunwind support
  164. endif # NO_LIBUNWIND
  165. ifndef NO_LIBUNWIND
  166. BASIC_CFLAGS += -DLIBUNWIND_SUPPORT
  167. EXTLIBS += $(LIBUNWIND_LIBS)
  168. BASIC_CFLAGS := $(LIBUNWIND_CFLAGS) $(BASIC_CFLAGS)
  169. BASIC_LDFLAGS := $(LIBUNWIND_LDFLAGS) $(BASIC_LDFLAGS)
  170. endif # NO_LIBUNWIND
  171. ifndef NO_LIBAUDIT
  172. FLAGS_LIBAUDIT = $(ALL_CFLAGS) $(ALL_LDFLAGS) -laudit
  173. ifneq ($(call try-cc,$(SOURCE_LIBAUDIT),$(FLAGS_LIBAUDIT),libaudit),y)
  174. msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
  175. NO_LIBAUDIT := 1
  176. else
  177. BASIC_CFLAGS += -DLIBAUDIT_SUPPORT
  178. EXTLIBS += -laudit
  179. endif
  180. endif
  181. ifdef NO_NEWT
  182. NO_SLANG=1
  183. endif
  184. ifndef NO_SLANG
  185. FLAGS_SLANG=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -I/usr/include/slang -lslang
  186. ifneq ($(call try-cc,$(SOURCE_SLANG),$(FLAGS_SLANG),libslang),y)
  187. msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
  188. NO_SLANG := 1
  189. else
  190. # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
  191. BASIC_CFLAGS += -I/usr/include/slang
  192. BASIC_CFLAGS += -DSLANG_SUPPORT
  193. EXTLIBS += -lslang
  194. endif
  195. endif
  196. ifndef NO_GTK2
  197. FLAGS_GTK2=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
  198. ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2),gtk2),y)
  199. msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
  200. NO_GTK2 := 1
  201. else
  202. ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2),-DHAVE_GTK_INFO_BAR),y)
  203. BASIC_CFLAGS += -DHAVE_GTK_INFO_BAR
  204. endif
  205. BASIC_CFLAGS += -DGTK2_SUPPORT
  206. BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
  207. EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
  208. endif
  209. endif
  210. grep-libs = $(filter -l%,$(1))
  211. strip-libs = $(filter-out -l%,$(1))
  212. ifdef NO_LIBPERL
  213. BASIC_CFLAGS += -DNO_LIBPERL
  214. else
  215. PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
  216. PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
  217. PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
  218. PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
  219. FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
  220. ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED),perl),y)
  221. BASIC_CFLAGS += -DNO_LIBPERL
  222. NO_LIBPERL := 1
  223. else
  224. ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS)
  225. EXTLIBS += $(PERL_EMBED_LIBADD)
  226. endif
  227. endif
  228. disable-python = $(eval $(disable-python_code))
  229. define disable-python_code
  230. BASIC_CFLAGS += -DNO_LIBPYTHON
  231. $(if $(1),$(warning No $(1) was found))
  232. $(warning Python support will not be built)
  233. NO_LIBPYTHON := 1
  234. endef
  235. override PYTHON := \
  236. $(call get-executable-or-default,PYTHON,python)
  237. ifndef PYTHON
  238. $(call disable-python,python interpreter)
  239. else
  240. PYTHON_WORD := $(call shell-wordify,$(PYTHON))
  241. ifdef NO_LIBPYTHON
  242. $(call disable-python)
  243. else
  244. override PYTHON_CONFIG := \
  245. $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
  246. ifndef PYTHON_CONFIG
  247. $(call disable-python,python-config tool)
  248. else
  249. PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
  250. PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
  251. PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
  252. PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
  253. PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
  254. FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
  255. ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED),python),y)
  256. $(call disable-python,Python.h (for Python 2.x))
  257. else
  258. ifneq ($(call try-cc,$(SOURCE_PYTHON_VERSION),$(FLAGS_PYTHON_EMBED),python version),y)
  259. $(warning Python 3 is not yet supported; please set)
  260. $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
  261. $(warning If you also have Python 2 installed, then)
  262. $(warning try something like:)
  263. $(warning $(and ,))
  264. $(warning $(and ,) make PYTHON=python2)
  265. $(warning $(and ,))
  266. $(warning Otherwise, disable Python support entirely:)
  267. $(warning $(and ,))
  268. $(warning $(and ,) make NO_LIBPYTHON=1)
  269. $(warning $(and ,))
  270. $(error $(and ,))
  271. else
  272. ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
  273. EXTLIBS += $(PYTHON_EMBED_LIBADD)
  274. LANG_BINDINGS += $(OUTPUT)python/perf.so
  275. endif
  276. endif
  277. endif
  278. endif
  279. endif
  280. ifdef NO_DEMANGLE
  281. BASIC_CFLAGS += -DNO_DEMANGLE
  282. else
  283. ifdef HAVE_CPLUS_DEMANGLE
  284. EXTLIBS += -liberty
  285. BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
  286. else
  287. FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -lbfd
  288. has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD),libbfd)
  289. ifeq ($(has_bfd),y)
  290. EXTLIBS += -lbfd
  291. else
  292. FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
  293. has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY),liberty)
  294. ifeq ($(has_bfd_iberty),y)
  295. EXTLIBS += -lbfd -liberty
  296. else
  297. FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
  298. has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z),libz)
  299. ifeq ($(has_bfd_iberty_z),y)
  300. EXTLIBS += -lbfd -liberty -lz
  301. else
  302. FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty
  303. has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE),demangle)
  304. ifeq ($(has_cplus_demangle),y)
  305. EXTLIBS += -liberty
  306. BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
  307. else
  308. msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
  309. BASIC_CFLAGS += -DNO_DEMANGLE
  310. endif
  311. endif
  312. endif
  313. endif
  314. endif
  315. endif
  316. ifndef NO_STRLCPY
  317. ifeq ($(call try-cc,$(SOURCE_STRLCPY),,-DHAVE_STRLCPY),y)
  318. BASIC_CFLAGS += -DHAVE_STRLCPY
  319. endif
  320. endif
  321. ifndef NO_ON_EXIT
  322. ifeq ($(call try-cc,$(SOURCE_ON_EXIT),,-DHAVE_ON_EXIT),y)
  323. BASIC_CFLAGS += -DHAVE_ON_EXIT
  324. endif
  325. endif
  326. ifndef NO_BACKTRACE
  327. ifeq ($(call try-cc,$(SOURCE_BACKTRACE),,-DBACKTRACE_SUPPORT),y)
  328. BASIC_CFLAGS += -DBACKTRACE_SUPPORT
  329. endif
  330. endif
  331. ifndef NO_LIBNUMA
  332. FLAGS_LIBNUMA = $(ALL_CFLAGS) $(ALL_LDFLAGS) -lnuma
  333. ifneq ($(call try-cc,$(SOURCE_LIBNUMA),$(FLAGS_LIBNUMA),libnuma),y)
  334. msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
  335. NO_LIBNUMA := 1
  336. else
  337. BASIC_CFLAGS += -DLIBNUMA_SUPPORT
  338. EXTLIBS += -lnuma
  339. endif
  340. endif