Makefile 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. ifeq ("$(origin O)", "command line")
  2. OUTPUT := $(O)/
  3. endif
  4. # The default target of this Makefile is...
  5. all:
  6. ifneq ($(OUTPUT),)
  7. # check that the output directory actually exists
  8. OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
  9. $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
  10. endif
  11. # Define V to have a more verbose compile.
  12. #
  13. # Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8
  14. #
  15. # Define DOCBOOK_XSL_172 if you want to format man pages with DocBook XSL v1.72.
  16. #
  17. # Define LDFLAGS=-static to build a static binary.
  18. #
  19. # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds.
  20. #
  21. # Define NO_DWARF if you do not want debug-info analysis feature at all.
  22. $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE
  23. @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
  24. -include $(OUTPUT)PERF-VERSION-FILE
  25. uname_M := $(shell uname -m 2>/dev/null || echo not)
  26. ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
  27. -e s/arm.*/arm/ -e s/sa110/arm/ \
  28. -e s/s390x/s390/ -e s/parisc64/parisc/ \
  29. -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
  30. -e s/sh[234].*/sh/ )
  31. CC = $(CROSS_COMPILE)gcc
  32. AR = $(CROSS_COMPILE)ar
  33. # Additional ARCH settings for x86
  34. ifeq ($(ARCH),i386)
  35. ARCH := x86
  36. endif
  37. ifeq ($(ARCH),x86_64)
  38. ARCH := x86
  39. IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -xc - | tail -n 1)
  40. ifeq (${IS_X86_64}, 1)
  41. RAW_ARCH := x86_64
  42. ARCH_CFLAGS := -DARCH_X86_64
  43. ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S
  44. endif
  45. endif
  46. #
  47. # Include saner warnings here, which can catch bugs:
  48. #
  49. EXTRA_WARNINGS := -Wformat
  50. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security
  51. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k
  52. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow
  53. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Winit-self
  54. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wpacked
  55. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wredundant-decls
  56. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-aliasing=3
  57. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-default
  58. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-enum
  59. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wno-system-headers
  60. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wundef
  61. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wwrite-strings
  62. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wbad-function-cast
  63. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-declarations
  64. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-prototypes
  65. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wnested-externs
  66. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition
  67. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes
  68. EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement
  69. ifeq ("$(origin DEBUG)", "command line")
  70. PERF_DEBUG = $(DEBUG)
  71. endif
  72. ifndef PERF_DEBUG
  73. CFLAGS_OPTIMIZE = -O6
  74. endif
  75. CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
  76. EXTLIBS = -lpthread -lrt -lelf -lm
  77. ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
  78. ALL_LDFLAGS = $(LDFLAGS)
  79. STRIP ?= strip
  80. # Among the variables below, these:
  81. # perfexecdir
  82. # template_dir
  83. # mandir
  84. # infodir
  85. # htmldir
  86. # ETC_PERFCONFIG (but not sysconfdir)
  87. # can be specified as a relative path some/where/else;
  88. # this is interpreted as relative to $(prefix) and "perf" at
  89. # runtime figures out where they are based on the path to the executable.
  90. # This can help installing the suite in a relocatable way.
  91. # Make the path relative to DESTDIR, not to prefix
  92. ifndef DESTDIR
  93. prefix = $(HOME)
  94. endif
  95. bindir_relative = bin
  96. bindir = $(prefix)/$(bindir_relative)
  97. mandir = share/man
  98. infodir = share/info
  99. perfexecdir = libexec/perf-core
  100. sharedir = $(prefix)/share
  101. template_dir = share/perf-core/templates
  102. htmldir = share/doc/perf-doc
  103. ifeq ($(prefix),/usr)
  104. sysconfdir = /etc
  105. ETC_PERFCONFIG = $(sysconfdir)/perfconfig
  106. else
  107. sysconfdir = $(prefix)/etc
  108. ETC_PERFCONFIG = etc/perfconfig
  109. endif
  110. lib = lib
  111. export prefix bindir sharedir sysconfdir
  112. RM = rm -f
  113. MKDIR = mkdir
  114. FIND = find
  115. INSTALL = install
  116. # sparse is architecture-neutral, which means that we need to tell it
  117. # explicitly what architecture to check for. Fix this up for yours..
  118. SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
  119. -include feature-tests.mak
  120. ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y)
  121. CFLAGS := $(CFLAGS) -fstack-protector-all
  122. endif
  123. ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wstack-protector),y)
  124. CFLAGS := $(CFLAGS) -Wstack-protector
  125. endif
  126. ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wvolatile-register-var),y)
  127. CFLAGS := $(CFLAGS) -Wvolatile-register-var
  128. endif
  129. ### --- END CONFIGURATION SECTION ---
  130. # Those must not be GNU-specific; they are shared with perl/ which may
  131. # be built by a different compiler. (Note that this is an artifact now
  132. # but it still might be nice to keep that distinction.)
  133. BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include
  134. BASIC_LDFLAGS =
  135. # Guard against environment variables
  136. BUILTIN_OBJS =
  137. LIB_H =
  138. LIB_OBJS =
  139. PYRF_OBJS =
  140. SCRIPT_SH =
  141. SCRIPT_SH += perf-archive.sh
  142. grep-libs = $(filter -l%,$(1))
  143. strip-libs = $(filter-out -l%,$(1))
  144. $(OUTPUT)python/perf.so: $(PYRF_OBJS)
  145. $(QUIET_GEN)( \
  146. export CFLAGS="$(BASIC_CFLAGS)"; \
  147. python util/setup.py --quiet build_ext --build-lib='$(OUTPUT)python' \
  148. --build-temp='$(OUTPUT)python/temp' \
  149. )
  150. #
  151. # No Perl scripts right now:
  152. #
  153. SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH))
  154. #
  155. # Single 'perf' binary right now:
  156. #
  157. PROGRAMS += $(OUTPUT)perf
  158. LANG_BINDINGS =
  159. # what 'all' will build and 'install' will install, in perfexecdir
  160. ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
  161. # what 'all' will build but not install in perfexecdir
  162. OTHER_PROGRAMS = $(OUTPUT)perf
  163. # Set paths to tools early so that they can be used for version tests.
  164. ifndef SHELL_PATH
  165. SHELL_PATH = /bin/sh
  166. endif
  167. ifndef PERL_PATH
  168. PERL_PATH = /usr/bin/perl
  169. endif
  170. export PERL_PATH
  171. LIB_FILE=$(OUTPUT)libperf.a
  172. LIB_H += ../../include/linux/perf_event.h
  173. LIB_H += ../../include/linux/rbtree.h
  174. LIB_H += ../../include/linux/list.h
  175. LIB_H += ../../include/linux/hash.h
  176. LIB_H += ../../include/linux/stringify.h
  177. LIB_H += util/include/linux/bitmap.h
  178. LIB_H += util/include/linux/bitops.h
  179. LIB_H += util/include/linux/compiler.h
  180. LIB_H += util/include/linux/ctype.h
  181. LIB_H += util/include/linux/kernel.h
  182. LIB_H += util/include/linux/list.h
  183. LIB_H += util/include/linux/module.h
  184. LIB_H += util/include/linux/poison.h
  185. LIB_H += util/include/linux/prefetch.h
  186. LIB_H += util/include/linux/rbtree.h
  187. LIB_H += util/include/linux/string.h
  188. LIB_H += util/include/linux/types.h
  189. LIB_H += util/include/linux/linkage.h
  190. LIB_H += util/include/asm/asm-offsets.h
  191. LIB_H += util/include/asm/bug.h
  192. LIB_H += util/include/asm/byteorder.h
  193. LIB_H += util/include/asm/hweight.h
  194. LIB_H += util/include/asm/swab.h
  195. LIB_H += util/include/asm/system.h
  196. LIB_H += util/include/asm/uaccess.h
  197. LIB_H += util/include/dwarf-regs.h
  198. LIB_H += util/include/asm/dwarf2.h
  199. LIB_H += util/include/asm/cpufeature.h
  200. LIB_H += perf.h
  201. LIB_H += util/annotate.h
  202. LIB_H += util/cache.h
  203. LIB_H += util/callchain.h
  204. LIB_H += util/build-id.h
  205. LIB_H += util/debug.h
  206. LIB_H += util/debugfs.h
  207. LIB_H += util/event.h
  208. LIB_H += util/evsel.h
  209. LIB_H += util/evlist.h
  210. LIB_H += util/exec_cmd.h
  211. LIB_H += util/types.h
  212. LIB_H += util/levenshtein.h
  213. LIB_H += util/map.h
  214. LIB_H += util/parse-options.h
  215. LIB_H += util/parse-events.h
  216. LIB_H += util/quote.h
  217. LIB_H += util/util.h
  218. LIB_H += util/xyarray.h
  219. LIB_H += util/header.h
  220. LIB_H += util/help.h
  221. LIB_H += util/session.h
  222. LIB_H += util/strbuf.h
  223. LIB_H += util/strlist.h
  224. LIB_H += util/strfilter.h
  225. LIB_H += util/svghelper.h
  226. LIB_H += util/run-command.h
  227. LIB_H += util/sigchain.h
  228. LIB_H += util/symbol.h
  229. LIB_H += util/color.h
  230. LIB_H += util/values.h
  231. LIB_H += util/sort.h
  232. LIB_H += util/hist.h
  233. LIB_H += util/thread.h
  234. LIB_H += util/thread_map.h
  235. LIB_H += util/trace-event.h
  236. LIB_H += util/probe-finder.h
  237. LIB_H += util/probe-event.h
  238. LIB_H += util/pstack.h
  239. LIB_H += util/cpumap.h
  240. LIB_H += util/top.h
  241. LIB_H += $(ARCH_INCLUDE)
  242. LIB_H += util/cgroup.h
  243. LIB_OBJS += $(OUTPUT)util/abspath.o
  244. LIB_OBJS += $(OUTPUT)util/alias.o
  245. LIB_OBJS += $(OUTPUT)util/annotate.o
  246. LIB_OBJS += $(OUTPUT)util/build-id.o
  247. LIB_OBJS += $(OUTPUT)util/config.o
  248. LIB_OBJS += $(OUTPUT)util/ctype.o
  249. LIB_OBJS += $(OUTPUT)util/debugfs.o
  250. LIB_OBJS += $(OUTPUT)util/environment.o
  251. LIB_OBJS += $(OUTPUT)util/event.o
  252. LIB_OBJS += $(OUTPUT)util/evlist.o
  253. LIB_OBJS += $(OUTPUT)util/evsel.o
  254. LIB_OBJS += $(OUTPUT)util/exec_cmd.o
  255. LIB_OBJS += $(OUTPUT)util/help.o
  256. LIB_OBJS += $(OUTPUT)util/levenshtein.o
  257. LIB_OBJS += $(OUTPUT)util/parse-options.o
  258. LIB_OBJS += $(OUTPUT)util/parse-events.o
  259. LIB_OBJS += $(OUTPUT)util/path.o
  260. LIB_OBJS += $(OUTPUT)util/rbtree.o
  261. LIB_OBJS += $(OUTPUT)util/bitmap.o
  262. LIB_OBJS += $(OUTPUT)util/hweight.o
  263. LIB_OBJS += $(OUTPUT)util/run-command.o
  264. LIB_OBJS += $(OUTPUT)util/quote.o
  265. LIB_OBJS += $(OUTPUT)util/strbuf.o
  266. LIB_OBJS += $(OUTPUT)util/string.o
  267. LIB_OBJS += $(OUTPUT)util/strlist.o
  268. LIB_OBJS += $(OUTPUT)util/strfilter.o
  269. LIB_OBJS += $(OUTPUT)util/top.o
  270. LIB_OBJS += $(OUTPUT)util/usage.o
  271. LIB_OBJS += $(OUTPUT)util/wrapper.o
  272. LIB_OBJS += $(OUTPUT)util/sigchain.o
  273. LIB_OBJS += $(OUTPUT)util/symbol.o
  274. LIB_OBJS += $(OUTPUT)util/color.o
  275. LIB_OBJS += $(OUTPUT)util/pager.o
  276. LIB_OBJS += $(OUTPUT)util/header.o
  277. LIB_OBJS += $(OUTPUT)util/callchain.o
  278. LIB_OBJS += $(OUTPUT)util/values.o
  279. LIB_OBJS += $(OUTPUT)util/debug.o
  280. LIB_OBJS += $(OUTPUT)util/map.o
  281. LIB_OBJS += $(OUTPUT)util/pstack.o
  282. LIB_OBJS += $(OUTPUT)util/session.o
  283. LIB_OBJS += $(OUTPUT)util/thread.o
  284. LIB_OBJS += $(OUTPUT)util/thread_map.o
  285. LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
  286. LIB_OBJS += $(OUTPUT)util/trace-event-read.o
  287. LIB_OBJS += $(OUTPUT)util/trace-event-info.o
  288. LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
  289. LIB_OBJS += $(OUTPUT)util/svghelper.o
  290. LIB_OBJS += $(OUTPUT)util/sort.o
  291. LIB_OBJS += $(OUTPUT)util/hist.o
  292. LIB_OBJS += $(OUTPUT)util/probe-event.o
  293. LIB_OBJS += $(OUTPUT)util/util.o
  294. LIB_OBJS += $(OUTPUT)util/xyarray.o
  295. LIB_OBJS += $(OUTPUT)util/cpumap.o
  296. LIB_OBJS += $(OUTPUT)util/cgroup.o
  297. BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
  298. BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
  299. # Benchmark modules
  300. BUILTIN_OBJS += $(OUTPUT)bench/sched-messaging.o
  301. BUILTIN_OBJS += $(OUTPUT)bench/sched-pipe.o
  302. ifeq ($(RAW_ARCH),x86_64)
  303. BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy-x86-64-asm.o
  304. endif
  305. BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
  306. BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
  307. BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
  308. BUILTIN_OBJS += $(OUTPUT)builtin-help.o
  309. BUILTIN_OBJS += $(OUTPUT)builtin-sched.o
  310. BUILTIN_OBJS += $(OUTPUT)builtin-buildid-list.o
  311. BUILTIN_OBJS += $(OUTPUT)builtin-buildid-cache.o
  312. BUILTIN_OBJS += $(OUTPUT)builtin-list.o
  313. BUILTIN_OBJS += $(OUTPUT)builtin-record.o
  314. BUILTIN_OBJS += $(OUTPUT)builtin-report.o
  315. BUILTIN_OBJS += $(OUTPUT)builtin-stat.o
  316. BUILTIN_OBJS += $(OUTPUT)builtin-timechart.o
  317. BUILTIN_OBJS += $(OUTPUT)builtin-top.o
  318. BUILTIN_OBJS += $(OUTPUT)builtin-script.o
  319. BUILTIN_OBJS += $(OUTPUT)builtin-probe.o
  320. BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o
  321. BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
  322. BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
  323. BUILTIN_OBJS += $(OUTPUT)builtin-test.o
  324. BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
  325. PERFLIBS = $(LIB_FILE)
  326. # Files needed for the python binding, perf.so
  327. # pyrf is just an internal name needed for all those wrappers.
  328. # This has to be in sync with what is in the 'sources' variable in
  329. # tools/perf/util/setup.py
  330. PYRF_OBJS += $(OUTPUT)util/cpumap.o
  331. PYRF_OBJS += $(OUTPUT)util/ctype.o
  332. PYRF_OBJS += $(OUTPUT)util/evlist.o
  333. PYRF_OBJS += $(OUTPUT)util/evsel.o
  334. PYRF_OBJS += $(OUTPUT)util/python.o
  335. PYRF_OBJS += $(OUTPUT)util/thread_map.o
  336. PYRF_OBJS += $(OUTPUT)util/util.o
  337. PYRF_OBJS += $(OUTPUT)util/xyarray.o
  338. #
  339. # Platform specific tweaks
  340. #
  341. # We choose to avoid "if .. else if .. else .. endif endif"
  342. # because maintaining the nesting to match is a pain. If
  343. # we had "elif" things would have been much nicer...
  344. -include config.mak.autogen
  345. -include config.mak
  346. ifndef NO_DWARF
  347. FLAGS_DWARF=$(ALL_CFLAGS) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
  348. ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
  349. 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);
  350. NO_DWARF := 1
  351. endif # Dwarf support
  352. endif # NO_DWARF
  353. -include arch/$(ARCH)/Makefile
  354. ifneq ($(OUTPUT),)
  355. BASIC_CFLAGS += -I$(OUTPUT)
  356. endif
  357. FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
  358. ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF)),y)
  359. FLAGS_GLIBC=$(ALL_CFLAGS) $(ALL_LDFLAGS)
  360. ifneq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC)),y)
  361. msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
  362. else
  363. msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel);
  364. endif
  365. endif
  366. ifneq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_COMMON)),y)
  367. BASIC_CFLAGS += -DLIBELF_NO_MMAP
  368. endif
  369. ifndef NO_DWARF
  370. ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
  371. msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
  372. else
  373. BASIC_CFLAGS += -DDWARF_SUPPORT
  374. EXTLIBS += -lelf -ldw
  375. LIB_OBJS += $(OUTPUT)util/probe-finder.o
  376. endif # PERF_HAVE_DWARF_REGS
  377. endif # NO_DWARF
  378. ifdef NO_NEWT
  379. BASIC_CFLAGS += -DNO_NEWT_SUPPORT
  380. else
  381. FLAGS_NEWT=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lnewt
  382. ifneq ($(call try-cc,$(SOURCE_NEWT),$(FLAGS_NEWT)),y)
  383. msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev);
  384. BASIC_CFLAGS += -DNO_NEWT_SUPPORT
  385. else
  386. # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
  387. BASIC_CFLAGS += -I/usr/include/slang
  388. EXTLIBS += -lnewt -lslang
  389. LIB_OBJS += $(OUTPUT)util/ui/setup.o
  390. LIB_OBJS += $(OUTPUT)util/ui/browser.o
  391. LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o
  392. LIB_OBJS += $(OUTPUT)util/ui/browsers/hists.o
  393. LIB_OBJS += $(OUTPUT)util/ui/browsers/map.o
  394. LIB_OBJS += $(OUTPUT)util/ui/browsers/top.o
  395. LIB_OBJS += $(OUTPUT)util/ui/helpline.o
  396. LIB_OBJS += $(OUTPUT)util/ui/progress.o
  397. LIB_OBJS += $(OUTPUT)util/ui/util.o
  398. LIB_H += util/ui/browser.h
  399. LIB_H += util/ui/browsers/map.h
  400. LIB_H += util/ui/helpline.h
  401. LIB_H += util/ui/libslang.h
  402. LIB_H += util/ui/progress.h
  403. LIB_H += util/ui/util.h
  404. LIB_H += util/ui/ui.h
  405. endif
  406. endif
  407. ifdef NO_LIBPERL
  408. BASIC_CFLAGS += -DNO_LIBPERL
  409. else
  410. PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
  411. PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
  412. PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
  413. PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
  414. FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
  415. ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y)
  416. BASIC_CFLAGS += -DNO_LIBPERL
  417. else
  418. ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS)
  419. EXTLIBS += $(PERL_EMBED_LIBADD)
  420. LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
  421. LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
  422. endif
  423. endif
  424. ifdef NO_LIBPYTHON
  425. BASIC_CFLAGS += -DNO_LIBPYTHON
  426. else
  427. PYTHON_EMBED_LDOPTS = $(shell python-config --ldflags 2>/dev/null)
  428. PYTHON_EMBED_LDFLAGS = $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
  429. PYTHON_EMBED_LIBADD = $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
  430. PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
  431. FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
  432. ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
  433. msg := $(warning No Python.h found, install python-dev[el] to have python support in 'perf script' and to build the python bindings)
  434. BASIC_CFLAGS += -DNO_LIBPYTHON
  435. else
  436. ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
  437. EXTLIBS += $(PYTHON_EMBED_LIBADD)
  438. LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
  439. LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
  440. LANG_BINDINGS += $(OUTPUT)python/perf.so
  441. endif
  442. endif
  443. ifdef NO_DEMANGLE
  444. BASIC_CFLAGS += -DNO_DEMANGLE
  445. else
  446. ifdef HAVE_CPLUS_DEMANGLE
  447. EXTLIBS += -liberty
  448. BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
  449. else
  450. FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd
  451. has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
  452. ifeq ($(has_bfd),y)
  453. EXTLIBS += -lbfd
  454. else
  455. FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
  456. has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY))
  457. ifeq ($(has_bfd_iberty),y)
  458. EXTLIBS += -lbfd -liberty
  459. else
  460. FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
  461. has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z))
  462. ifeq ($(has_bfd_iberty_z),y)
  463. EXTLIBS += -lbfd -liberty -lz
  464. else
  465. FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty
  466. has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE))
  467. ifeq ($(has_cplus_demangle),y)
  468. EXTLIBS += -liberty
  469. BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
  470. else
  471. msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
  472. BASIC_CFLAGS += -DNO_DEMANGLE
  473. endif
  474. endif
  475. endif
  476. endif
  477. endif
  478. endif
  479. ifdef NO_STRLCPY
  480. BASIC_CFLAGS += -DNO_STRLCPY
  481. else
  482. ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y)
  483. BASIC_CFLAGS += -DNO_STRLCPY
  484. endif
  485. endif
  486. ifneq ($(findstring $(MAKEFLAGS),s),s)
  487. ifndef V
  488. QUIET_CC = @echo ' ' CC $@;
  489. QUIET_AR = @echo ' ' AR $@;
  490. QUIET_LINK = @echo ' ' LINK $@;
  491. QUIET_MKDIR = @echo ' ' MKDIR $@;
  492. QUIET_GEN = @echo ' ' GEN $@;
  493. endif
  494. endif
  495. ifdef ASCIIDOC8
  496. export ASCIIDOC8
  497. endif
  498. # Shell quote (do not use $(call) to accommodate ancient setups);
  499. ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
  500. DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
  501. bindir_SQ = $(subst ','\'',$(bindir))
  502. bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
  503. mandir_SQ = $(subst ','\'',$(mandir))
  504. infodir_SQ = $(subst ','\'',$(infodir))
  505. perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
  506. template_dir_SQ = $(subst ','\'',$(template_dir))
  507. htmldir_SQ = $(subst ','\'',$(htmldir))
  508. prefix_SQ = $(subst ','\'',$(prefix))
  509. SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
  510. LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive $(EXTLIBS)
  511. ALL_CFLAGS += $(BASIC_CFLAGS)
  512. ALL_CFLAGS += $(ARCH_CFLAGS)
  513. ALL_LDFLAGS += $(BASIC_LDFLAGS)
  514. export INSTALL SHELL_PATH
  515. ### Build rules
  516. SHELL = $(SHELL_PATH)
  517. all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS)
  518. please_set_SHELL_PATH_to_a_more_modern_shell:
  519. @$$(:)
  520. shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
  521. strip: $(PROGRAMS) $(OUTPUT)perf
  522. $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf
  523. $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
  524. $(QUIET_CC)$(CC) -DPERF_VERSION='"$(PERF_VERSION)"' \
  525. '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
  526. $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
  527. $(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
  528. $(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
  529. $(BUILTIN_OBJS) $(LIBS) -o $@
  530. $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
  531. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
  532. '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
  533. '-DPERF_MAN_PATH="$(mandir_SQ)"' \
  534. '-DPERF_INFO_PATH="$(infodir_SQ)"' $<
  535. $(OUTPUT)builtin-timechart.o: builtin-timechart.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
  536. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
  537. '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
  538. '-DPERF_MAN_PATH="$(mandir_SQ)"' \
  539. '-DPERF_INFO_PATH="$(infodir_SQ)"' $<
  540. $(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt
  541. $(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt)
  542. $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@
  543. $(SCRIPTS) : % : %.sh
  544. $(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@'
  545. # These can record PERF_VERSION
  546. $(OUTPUT)perf.o perf.spec \
  547. $(SCRIPTS) \
  548. : $(OUTPUT)PERF-VERSION-FILE
  549. $(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS
  550. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
  551. $(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
  552. $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
  553. $(OUTPUT)%.o: %.S
  554. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
  555. $(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS
  556. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
  557. '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \
  558. '-DBINDIR="$(bindir_relative_SQ)"' \
  559. '-DPREFIX="$(prefix_SQ)"' \
  560. $<
  561. $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
  562. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
  563. $(OUTPUT)util/ui/browser.o: util/ui/browser.c $(OUTPUT)PERF-CFLAGS
  564. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
  565. $(OUTPUT)util/ui/browsers/annotate.o: util/ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS
  566. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
  567. $(OUTPUT)util/ui/browsers/top.o: util/ui/browsers/top.c $(OUTPUT)PERF-CFLAGS
  568. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
  569. $(OUTPUT)util/ui/browsers/hists.o: util/ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS
  570. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
  571. $(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
  572. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
  573. $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
  574. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
  575. $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
  576. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
  577. $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
  578. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
  579. $(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c $(OUTPUT)PERF-CFLAGS
  580. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
  581. $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
  582. $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
  583. $(OUTPUT)perf-%: %.o $(PERFLIBS)
  584. $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
  585. $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
  586. $(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
  587. # we compile into subdirectories. if the target directory is not the source directory, they might not exists. So
  588. # we depend the various files onto their directories.
  589. DIRECTORY_DEPS = $(LIB_OBJS) $(BUILTIN_OBJS) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h
  590. $(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
  591. # In the second step, we make a rule to actually create these directories
  592. $(sort $(dir $(DIRECTORY_DEPS))):
  593. $(QUIET_MKDIR)$(MKDIR) -p $@ 2>/dev/null
  594. $(LIB_FILE): $(LIB_OBJS)
  595. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
  596. help:
  597. @echo 'Perf make targets:'
  598. @echo ' doc - make *all* documentation (see below)'
  599. @echo ' man - make manpage documentation (access with man <foo>)'
  600. @echo ' html - make html documentation'
  601. @echo ' info - make GNU info documentation (access with info <foo>)'
  602. @echo ' pdf - make pdf documentation'
  603. @echo ' TAGS - use etags to make tag information for source browsing'
  604. @echo ' tags - use ctags to make tag information for source browsing'
  605. @echo ' cscope - use cscope to make interactive browsing database'
  606. @echo ''
  607. @echo 'Perf install targets:'
  608. @echo ' NOTE: documentation build requires asciidoc, xmlto packages to be installed'
  609. @echo ' HINT: use "make prefix=<path> <install target>" to install to a particular'
  610. @echo ' path like make prefix=/usr/local install install-doc'
  611. @echo ' install - install compiled binaries'
  612. @echo ' install-doc - install *all* documentation'
  613. @echo ' install-man - install manpage documentation'
  614. @echo ' install-html - install html documentation'
  615. @echo ' install-info - install GNU info documentation'
  616. @echo ' install-pdf - install pdf documentation'
  617. @echo ''
  618. @echo ' quick-install-doc - alias for quick-install-man'
  619. @echo ' quick-install-man - install the documentation quickly'
  620. @echo ' quick-install-html - install the html documentation quickly'
  621. @echo ''
  622. @echo 'Perf maintainer targets:'
  623. @echo ' distclean - alias to clean'
  624. @echo ' clean - clean all binary objects and build output'
  625. doc:
  626. $(MAKE) -C Documentation all
  627. man:
  628. $(MAKE) -C Documentation man
  629. html:
  630. $(MAKE) -C Documentation html
  631. info:
  632. $(MAKE) -C Documentation info
  633. pdf:
  634. $(MAKE) -C Documentation pdf
  635. TAGS:
  636. $(RM) TAGS
  637. $(FIND) . -name '*.[hcS]' -print | xargs etags -a
  638. tags:
  639. $(RM) tags
  640. $(FIND) . -name '*.[hcS]' -print | xargs ctags -a
  641. cscope:
  642. $(RM) cscope*
  643. $(FIND) . -name '*.[hcS]' -print | xargs cscope -b
  644. ### Detect prefix changes
  645. TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
  646. $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
  647. $(OUTPUT)PERF-CFLAGS: .FORCE-PERF-CFLAGS
  648. @FLAGS='$(TRACK_CFLAGS)'; \
  649. if test x"$$FLAGS" != x"`cat $(OUTPUT)PERF-CFLAGS 2>/dev/null`" ; then \
  650. echo 1>&2 " * new build flags or prefix"; \
  651. echo "$$FLAGS" >$(OUTPUT)PERF-CFLAGS; \
  652. fi
  653. ### Testing rules
  654. # GNU make supports exporting all variables by "export" without parameters.
  655. # However, the environment gets quite big, and some programs have problems
  656. # with that.
  657. check: $(OUTPUT)common-cmds.h
  658. if sparse; \
  659. then \
  660. for i in *.c */*.c; \
  661. do \
  662. sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; \
  663. done; \
  664. else \
  665. exit 1; \
  666. fi
  667. ### Installation rules
  668. ifneq ($(filter /%,$(firstword $(perfexecdir))),)
  669. perfexec_instdir = $(perfexecdir)
  670. else
  671. perfexec_instdir = $(prefix)/$(perfexecdir)
  672. endif
  673. perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
  674. install: all
  675. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
  676. $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'
  677. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
  678. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
  679. $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
  680. $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
  681. $(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'
  682. $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
  683. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
  684. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
  685. $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
  686. $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'
  687. $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
  688. install-doc:
  689. $(MAKE) -C Documentation install
  690. install-man:
  691. $(MAKE) -C Documentation install-man
  692. install-html:
  693. $(MAKE) -C Documentation install-html
  694. install-info:
  695. $(MAKE) -C Documentation install-info
  696. install-pdf:
  697. $(MAKE) -C Documentation install-pdf
  698. quick-install-doc:
  699. $(MAKE) -C Documentation quick-install
  700. quick-install-man:
  701. $(MAKE) -C Documentation quick-install-man
  702. quick-install-html:
  703. $(MAKE) -C Documentation quick-install-html
  704. ### Cleaning rules
  705. clean:
  706. $(RM) $(OUTPUT){*.o,*/*.o,*/*/*.o,*/*/*/*.o,$(LIB_FILE),perf-archive}
  707. $(RM) $(ALL_PROGRAMS) perf
  708. $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope*
  709. $(MAKE) -C Documentation/ clean
  710. $(RM) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS
  711. @python util/setup.py clean --build-lib='$(OUTPUT)python' \
  712. --build-temp='$(OUTPUT)python/temp'
  713. .PHONY: all install clean strip
  714. .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
  715. .PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope .FORCE-PERF-CFLAGS