Makefile.perf 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. include ../scripts/Makefile.include
  2. # The default target of this Makefile is...
  3. all:
  4. include ../scripts/utilities.mak
  5. # Define V to have a more verbose compile.
  6. #
  7. # Define VF to have a more verbose feature check output.
  8. #
  9. # Define O to save output files in a separate directory.
  10. #
  11. # Define ARCH as name of target architecture if you want cross-builds.
  12. #
  13. # Define CROSS_COMPILE as prefix name of compiler if you want cross-builds.
  14. #
  15. # Define NO_LIBPERL to disable perl script extension.
  16. #
  17. # Define NO_LIBPYTHON to disable python script extension.
  18. #
  19. # Define PYTHON to point to the python binary if the default
  20. # `python' is not correct; for example: PYTHON=python2
  21. #
  22. # Define PYTHON_CONFIG to point to the python-config binary if
  23. # the default `$(PYTHON)-config' is not correct.
  24. #
  25. # Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8
  26. #
  27. # Define DOCBOOK_XSL_172 if you want to format man pages with DocBook XSL v1.72.
  28. #
  29. # Define LDFLAGS=-static to build a static binary.
  30. #
  31. # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds.
  32. #
  33. # Define NO_DWARF if you do not want debug-info analysis feature at all.
  34. #
  35. # Define WERROR=0 to disable treating any warnings as errors.
  36. #
  37. # Define NO_NEWT if you do not want TUI support. (deprecated)
  38. #
  39. # Define NO_SLANG if you do not want TUI support.
  40. #
  41. # Define NO_GTK2 if you do not want GTK+ GUI support.
  42. #
  43. # Define NO_DEMANGLE if you do not want C++ symbol demangling.
  44. #
  45. # Define NO_LIBELF if you do not want libelf dependency (e.g. cross-builds)
  46. #
  47. # Define NO_LIBUNWIND if you do not want libunwind dependency for dwarf
  48. # backtrace post unwind.
  49. #
  50. # Define NO_BACKTRACE if you do not want stack backtrace debug feature
  51. #
  52. # Define NO_LIBNUMA if you do not want numa perf benchmark
  53. #
  54. # Define NO_LIBAUDIT if you do not want libaudit support
  55. #
  56. # Define NO_LIBBIONIC if you do not want bionic support
  57. #
  58. # Define NO_LIBCRYPTO if you do not want libcrypto (openssl) support
  59. # used for generating build-ids for ELFs generated by jitdump.
  60. #
  61. # Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support
  62. # for dwarf backtrace post unwind.
  63. #
  64. # Define NO_PERF_READ_VDSO32 if you do not want to build perf-read-vdso32
  65. # for reading the 32-bit compatibility VDSO in 64-bit mode
  66. #
  67. # Define NO_PERF_READ_VDSOX32 if you do not want to build perf-read-vdsox32
  68. # for reading the x32 mode 32-bit compatibility VDSO in 64-bit mode
  69. #
  70. # Define NO_ZLIB if you do not want to support compressed kernel modules
  71. #
  72. # Define LIBBABELTRACE if you DO want libbabeltrace support
  73. # for CTF data format.
  74. #
  75. # Define NO_LZMA if you do not want to support compressed (xz) kernel modules
  76. #
  77. # Define NO_AUXTRACE if you do not want AUX area tracing support
  78. #
  79. # Define NO_LIBBPF if you do not want BPF support
  80. #
  81. # Define NO_SDT if you do not want to define SDT event in perf tools,
  82. # note that it doesn't disable SDT scanning support.
  83. #
  84. # Define FEATURES_DUMP to provide features detection dump file
  85. # and bypass the feature detection
  86. # As per kernel Makefile, avoid funny character set dependencies
  87. unexport LC_ALL
  88. LC_COLLATE=C
  89. LC_NUMERIC=C
  90. export LC_COLLATE LC_NUMERIC
  91. ifeq ($(srctree),)
  92. srctree := $(patsubst %/,%,$(dir $(shell pwd)))
  93. srctree := $(patsubst %/,%,$(dir $(srctree)))
  94. #$(info Determined 'srctree' to be $(srctree))
  95. endif
  96. ifneq ($(objtree),)
  97. #$(info Determined 'objtree' to be $(objtree))
  98. endif
  99. ifneq ($(OUTPUT),)
  100. #$(info Determined 'OUTPUT' to be $(OUTPUT))
  101. # Adding $(OUTPUT) as a directory to look for source files,
  102. # because use generated output files as sources dependency
  103. # for flex/bison parsers.
  104. VPATH += $(OUTPUT)
  105. export VPATH
  106. endif
  107. ifeq ($(V),1)
  108. Q =
  109. else
  110. Q = @
  111. endif
  112. # Do not use make's built-in rules
  113. # (this improves performance and avoids hard-to-debug behaviour);
  114. MAKEFLAGS += -r
  115. $(OUTPUT)PERF-VERSION-FILE: ../../.git/HEAD
  116. $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
  117. $(Q)touch $(OUTPUT)PERF-VERSION-FILE
  118. # Makefiles suck: This macro sets a default value of $(2) for the
  119. # variable named by $(1), unless the variable has been set by
  120. # environment or command line. This is necessary for CC and AR
  121. # because make sets default values, so the simpler ?= approach
  122. # won't work as expected.
  123. define allow-override
  124. $(if $(or $(findstring environment,$(origin $(1))),\
  125. $(findstring command line,$(origin $(1)))),,\
  126. $(eval $(1) = $(2)))
  127. endef
  128. # Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix.
  129. $(call allow-override,CC,$(CROSS_COMPILE)gcc)
  130. $(call allow-override,AR,$(CROSS_COMPILE)ar)
  131. $(call allow-override,LD,$(CROSS_COMPILE)ld)
  132. LD += $(EXTRA_LDFLAGS)
  133. PKG_CONFIG = $(CROSS_COMPILE)pkg-config
  134. RM = rm -f
  135. LN = ln -f
  136. MKDIR = mkdir
  137. FIND = find
  138. INSTALL = install
  139. FLEX = flex
  140. BISON = bison
  141. STRIP = strip
  142. AWK = awk
  143. LIB_DIR = $(srctree)/tools/lib/api/
  144. TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
  145. BPF_DIR = $(srctree)/tools/lib/bpf/
  146. SUBCMD_DIR = $(srctree)/tools/lib/subcmd/
  147. # include Makefile.config by default and rule out
  148. # non-config cases
  149. config := 1
  150. NON_CONFIG_TARGETS := clean TAGS tags cscope help
  151. ifdef MAKECMDGOALS
  152. ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
  153. config := 0
  154. endif
  155. endif
  156. # Set FEATURE_TESTS to 'all' so all possible feature checkers are executed.
  157. # Without this setting the output feature dump file misses some features, for
  158. # example, liberty. Select all checkers so we won't get an incomplete feature
  159. # dump file.
  160. ifeq ($(config),1)
  161. ifdef MAKECMDGOALS
  162. ifeq ($(filter feature-dump,$(MAKECMDGOALS)),feature-dump)
  163. FEATURE_TESTS := all
  164. endif
  165. endif
  166. include Makefile.config
  167. endif
  168. ifeq ($(config),0)
  169. include $(srctree)/tools/scripts/Makefile.arch
  170. -include arch/$(ARCH)/Makefile
  171. endif
  172. # The FEATURE_DUMP_EXPORT holds location of the actual
  173. # FEATURE_DUMP file to be used to bypass feature detection
  174. # (for bpf or any other subproject)
  175. ifeq ($(FEATURES_DUMP),)
  176. FEATURE_DUMP_EXPORT := $(realpath $(OUTPUT)FEATURE-DUMP)
  177. else
  178. FEATURE_DUMP_EXPORT := $(FEATURES_DUMP)
  179. endif
  180. export prefix bindir sharedir sysconfdir DESTDIR
  181. # sparse is architecture-neutral, which means that we need to tell it
  182. # explicitly what architecture to check for. Fix this up for yours..
  183. SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
  184. # Guard against environment variables
  185. PYRF_OBJS =
  186. SCRIPT_SH =
  187. SCRIPT_SH += perf-archive.sh
  188. SCRIPT_SH += perf-with-kcore.sh
  189. grep-libs = $(filter -l%,$(1))
  190. strip-libs = $(filter-out -l%,$(1))
  191. ifneq ($(OUTPUT),)
  192. TE_PATH=$(OUTPUT)
  193. BPF_PATH=$(OUTPUT)
  194. SUBCMD_PATH=$(OUTPUT)
  195. ifneq ($(subdir),)
  196. API_PATH=$(OUTPUT)/../lib/api/
  197. else
  198. API_PATH=$(OUTPUT)
  199. endif
  200. else
  201. TE_PATH=$(TRACE_EVENT_DIR)
  202. API_PATH=$(LIB_DIR)
  203. BPF_PATH=$(BPF_DIR)
  204. SUBCMD_PATH=$(SUBCMD_DIR)
  205. endif
  206. LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
  207. export LIBTRACEEVENT
  208. LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list
  209. LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
  210. LIBAPI = $(API_PATH)libapi.a
  211. export LIBAPI
  212. LIBBPF = $(BPF_PATH)libbpf.a
  213. LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a
  214. # python extension build directories
  215. PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
  216. PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
  217. PYTHON_EXTBUILD_TMP := $(PYTHON_EXTBUILD)tmp/
  218. export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP
  219. python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so
  220. PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
  221. PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py $(LIBTRACEEVENT) $(LIBAPI)
  222. $(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) $(LIBTRACEEVENT_DYNAMIC_LIST)
  223. $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \
  224. CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS)' \
  225. $(PYTHON_WORD) util/setup.py \
  226. --quiet build_ext; \
  227. mkdir -p $(OUTPUT)python && \
  228. cp $(PYTHON_EXTBUILD_LIB)perf.so $(OUTPUT)python/
  229. #
  230. # No Perl scripts right now:
  231. #
  232. SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH))
  233. PROGRAMS += $(OUTPUT)perf
  234. ifndef NO_PERF_READ_VDSO32
  235. PROGRAMS += $(OUTPUT)perf-read-vdso32
  236. endif
  237. ifndef NO_PERF_READ_VDSOX32
  238. PROGRAMS += $(OUTPUT)perf-read-vdsox32
  239. endif
  240. # what 'all' will build and 'install' will install, in perfexecdir
  241. ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
  242. # what 'all' will build but not install in perfexecdir
  243. OTHER_PROGRAMS = $(OUTPUT)perf
  244. # Set paths to tools early so that they can be used for version tests.
  245. ifndef SHELL_PATH
  246. SHELL_PATH = /bin/sh
  247. endif
  248. ifndef PERL_PATH
  249. PERL_PATH = /usr/bin/perl
  250. endif
  251. export PERL_PATH
  252. LIB_FILE=$(OUTPUT)libperf.a
  253. PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD)
  254. ifndef NO_LIBBPF
  255. PERFLIBS += $(LIBBPF)
  256. endif
  257. # We choose to avoid "if .. else if .. else .. endif endif"
  258. # because maintaining the nesting to match is a pain. If
  259. # we had "elif" things would have been much nicer...
  260. ifneq ($(OUTPUT),)
  261. CFLAGS += -I$(OUTPUT)
  262. endif
  263. ifndef NO_GTK2
  264. ALL_PROGRAMS += $(OUTPUT)libperf-gtk.so
  265. GTK_IN := $(OUTPUT)gtk-in.o
  266. install-gtk: $(OUTPUT)libperf-gtk.so
  267. $(call QUIET_INSTALL, 'GTK UI') \
  268. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(libdir_SQ)'; \
  269. $(INSTALL) $(OUTPUT)libperf-gtk.so '$(DESTDIR_SQ)$(libdir_SQ)'
  270. endif
  271. ifdef ASCIIDOC8
  272. export ASCIIDOC8
  273. endif
  274. LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
  275. export INSTALL SHELL_PATH
  276. ### Build rules
  277. SHELL = $(SHELL_PATH)
  278. all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS)
  279. please_set_SHELL_PATH_to_a_more_modern_shell:
  280. $(Q)$$(:)
  281. shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
  282. strip: $(PROGRAMS) $(OUTPUT)perf
  283. $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf
  284. PERF_IN := $(OUTPUT)perf-in.o
  285. export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK
  286. include $(srctree)/tools/build/Makefile.include
  287. $(PERF_IN): prepare FORCE
  288. @(test -f ../../include/uapi/linux/perf_event.h && ( \
  289. (diff -B ../include/uapi/linux/perf_event.h ../../include/uapi/linux/perf_event.h >/dev/null) \
  290. || echo "Warning: tools/include/uapi/linux/perf_event.h differs from kernel" >&2 )) || true
  291. @(test -f ../../include/linux/hash.h && ( \
  292. (diff -B ../include/linux/hash.h ../../include/linux/hash.h >/dev/null) \
  293. || echo "Warning: tools/include/linux/hash.h differs from kernel" >&2 )) || true
  294. @(test -f ../../include/uapi/linux/hw_breakpoint.h && ( \
  295. (diff -B ../include/uapi/linux/hw_breakpoint.h ../../include/uapi/linux/hw_breakpoint.h >/dev/null) \
  296. || echo "Warning: tools/include/uapi/linux/hw_breakpoint.h differs from kernel" >&2 )) || true
  297. @(test -f ../../arch/x86/include/asm/disabled-features.h && ( \
  298. (diff -B ../arch/x86/include/asm/disabled-features.h ../../arch/x86/include/asm/disabled-features.h >/dev/null) \
  299. || echo "Warning: tools/arch/x86/include/asm/disabled-features.h differs from kernel" >&2 )) || true
  300. @(test -f ../../arch/x86/include/asm/required-features.h && ( \
  301. (diff -B ../arch/x86/include/asm/required-features.h ../../arch/x86/include/asm/required-features.h >/dev/null) \
  302. || echo "Warning: tools/arch/x86/include/asm/required-features.h differs from kernel" >&2 )) || true
  303. @(test -f ../../arch/x86/include/asm/cpufeatures.h && ( \
  304. (diff -B ../arch/x86/include/asm/cpufeatures.h ../../arch/x86/include/asm/cpufeatures.h >/dev/null) \
  305. || echo "Warning: tools/arch/x86/include/asm/cpufeatures.h differs from kernel" >&2 )) || true
  306. @(test -f ../../arch/x86/lib/memcpy_64.S && ( \
  307. (diff -B ../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memcpy_64.S >/dev/null) \
  308. || echo "Warning: tools/arch/x86/lib/memcpy_64.S differs from kernel" >&2 )) || true
  309. @(test -f ../../arch/x86/lib/memset_64.S && ( \
  310. (diff -B ../arch/x86/lib/memset_64.S ../../arch/x86/lib/memset_64.S >/dev/null) \
  311. || echo "Warning: tools/arch/x86/lib/memset_64.S differs from kernel" >&2 )) || true
  312. @(test -f ../../arch/arm/include/uapi/asm/perf_regs.h && ( \
  313. (diff -B ../arch/arm/include/uapi/asm/perf_regs.h ../../arch/arm/include/uapi/asm/perf_regs.h >/dev/null) \
  314. || echo "Warning: tools/arch/arm/include/uapi/asm/perf_regs.h differs from kernel" >&2 )) || true
  315. @(test -f ../../arch/arm64/include/uapi/asm/perf_regs.h && ( \
  316. (diff -B ../arch/arm64/include/uapi/asm/perf_regs.h ../../arch/arm64/include/uapi/asm/perf_regs.h >/dev/null) \
  317. || echo "Warning: tools/arch/arm64/include/uapi/asm/perf_regs.h differs from kernel" >&2 )) || true
  318. @(test -f ../../arch/powerpc/include/uapi/asm/perf_regs.h && ( \
  319. (diff -B ../arch/powerpc/include/uapi/asm/perf_regs.h ../../arch/powerpc/include/uapi/asm/perf_regs.h >/dev/null) \
  320. || echo "Warning: tools/arch/powerpc/include/uapi/asm/perf_regs.h differs from kernel" >&2 )) || true
  321. @(test -f ../../arch/x86/include/uapi/asm/perf_regs.h && ( \
  322. (diff -B ../arch/x86/include/uapi/asm/perf_regs.h ../../arch/x86/include/uapi/asm/perf_regs.h >/dev/null) \
  323. || echo "Warning: tools/arch/x86/include/uapi/asm/perf_regs.h differs from kernel" >&2 )) || true
  324. @(test -f ../../arch/x86/include/uapi/asm/kvm.h && ( \
  325. (diff -B ../arch/x86/include/uapi/asm/kvm.h ../../arch/x86/include/uapi/asm/kvm.h >/dev/null) \
  326. || echo "Warning: tools/arch/x86/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
  327. @(test -f ../../arch/x86/include/uapi/asm/kvm_perf.h && ( \
  328. (diff -B ../arch/x86/include/uapi/asm/kvm_perf.h ../../arch/x86/include/uapi/asm/kvm_perf.h >/dev/null) \
  329. || echo "Warning: tools/arch/x86/include/uapi/asm/kvm_perf.h differs from kernel" >&2 )) || true
  330. @(test -f ../../arch/x86/include/uapi/asm/svm.h && ( \
  331. (diff -B ../arch/x86/include/uapi/asm/svm.h ../../arch/x86/include/uapi/asm/svm.h >/dev/null) \
  332. || echo "Warning: tools/arch/x86/include/uapi/asm/svm.h differs from kernel" >&2 )) || true
  333. @(test -f ../../arch/x86/include/uapi/asm/vmx.h && ( \
  334. (diff -B ../arch/x86/include/uapi/asm/vmx.h ../../arch/x86/include/uapi/asm/vmx.h >/dev/null) \
  335. || echo "Warning: tools/arch/x86/include/uapi/asm/vmx.h differs from kernel" >&2 )) || true
  336. @(test -f ../../arch/powerpc/include/uapi/asm/kvm.h && ( \
  337. (diff -B ../arch/powerpc/include/uapi/asm/kvm.h ../../arch/powerpc/include/uapi/asm/kvm.h >/dev/null) \
  338. || echo "Warning: tools/arch/powerpc/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
  339. @(test -f ../../arch/s390/include/uapi/asm/kvm.h && ( \
  340. (diff -B ../arch/s390/include/uapi/asm/kvm.h ../../arch/s390/include/uapi/asm/kvm.h >/dev/null) \
  341. || echo "Warning: tools/arch/s390/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
  342. @(test -f ../../arch/s390/include/uapi/asm/kvm_perf.h && ( \
  343. (diff -B ../arch/s390/include/uapi/asm/kvm_perf.h ../../arch/s390/include/uapi/asm/kvm_perf.h >/dev/null) \
  344. || echo "Warning: tools/arch/s390/include/uapi/asm/kvm_perf.h differs from kernel" >&2 )) || true
  345. @(test -f ../../arch/s390/include/uapi/asm/sie.h && ( \
  346. (diff -B ../arch/s390/include/uapi/asm/sie.h ../../arch/s390/include/uapi/asm/sie.h >/dev/null) \
  347. || echo "Warning: tools/arch/s390/include/uapi/asm/sie.h differs from kernel" >&2 )) || true
  348. @(test -f ../../arch/arm/include/uapi/asm/kvm.h && ( \
  349. (diff -B ../arch/arm/include/uapi/asm/kvm.h ../../arch/arm/include/uapi/asm/kvm.h >/dev/null) \
  350. || echo "Warning: tools/arch/arm/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
  351. @(test -f ../../arch/arm64/include/uapi/asm/kvm.h && ( \
  352. (diff -B ../arch/arm64/include/uapi/asm/kvm.h ../../arch/arm64/include/uapi/asm/kvm.h >/dev/null) \
  353. || echo "Warning: tools/arch/arm64/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
  354. @(test -f ../../include/asm-generic/bitops/arch_hweight.h && ( \
  355. (diff -B ../include/asm-generic/bitops/arch_hweight.h ../../include/asm-generic/bitops/arch_hweight.h >/dev/null) \
  356. || echo "Warning: tools/include/asm-generic/bitops/arch_hweight.h differs from kernel" >&2 )) || true
  357. @(test -f ../../include/asm-generic/bitops/const_hweight.h && ( \
  358. (diff -B ../include/asm-generic/bitops/const_hweight.h ../../include/asm-generic/bitops/const_hweight.h >/dev/null) \
  359. || echo "Warning: tools/include/asm-generic/bitops/const_hweight.h differs from kernel" >&2 )) || true
  360. @(test -f ../../include/asm-generic/bitops/__fls.h && ( \
  361. (diff -B ../include/asm-generic/bitops/__fls.h ../../include/asm-generic/bitops/__fls.h >/dev/null) \
  362. || echo "Warning: tools/include/asm-generic/bitops/__fls.h differs from kernel" >&2 )) || true
  363. @(test -f ../../include/asm-generic/bitops/fls.h && ( \
  364. (diff -B ../include/asm-generic/bitops/fls.h ../../include/asm-generic/bitops/fls.h >/dev/null) \
  365. || echo "Warning: tools/include/asm-generic/bitops/fls.h differs from kernel" >&2 )) || true
  366. @(test -f ../../include/asm-generic/bitops/fls64.h && ( \
  367. (diff -B ../include/asm-generic/bitops/fls64.h ../../include/asm-generic/bitops/fls64.h >/dev/null) \
  368. || echo "Warning: tools/include/asm-generic/bitops/fls64.h differs from kernel" >&2 )) || true
  369. $(Q)$(MAKE) $(build)=perf
  370. $(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST)
  371. $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS) \
  372. $(PERF_IN) $(LIBS) -o $@
  373. $(GTK_IN): fixdep FORCE
  374. $(Q)$(MAKE) $(build)=gtk
  375. $(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS)
  376. $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS)
  377. $(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt
  378. $(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt)
  379. $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@
  380. $(SCRIPTS) : % : %.sh
  381. $(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@'
  382. # These can record PERF_VERSION
  383. perf.spec $(SCRIPTS) \
  384. : $(OUTPUT)PERF-VERSION-FILE
  385. .SUFFIXES:
  386. #
  387. # If a target does not match any of the later rules then prefix it by $(OUTPUT)
  388. # This makes targets like 'make O=/tmp/perf perf.o' work in a natural way.
  389. #
  390. ifneq ($(OUTPUT),)
  391. %.o: $(OUTPUT)%.o
  392. @echo " # Redirected target $@ => $(OUTPUT)$@"
  393. util/%.o: $(OUTPUT)util/%.o
  394. @echo " # Redirected target $@ => $(OUTPUT)$@"
  395. bench/%.o: $(OUTPUT)bench/%.o
  396. @echo " # Redirected target $@ => $(OUTPUT)$@"
  397. tests/%.o: $(OUTPUT)tests/%.o
  398. @echo " # Redirected target $@ => $(OUTPUT)$@"
  399. endif
  400. # These two need to be here so that when O= is not used they take precedence
  401. # over the general rule for .o
  402. # get relative building directory (to $(OUTPUT))
  403. # and '.' if it's $(OUTPUT) itself
  404. __build-dir = $(subst $(OUTPUT),,$(dir $@))
  405. build-dir = $(if $(__build-dir),$(__build-dir),.)
  406. prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h fixdep archheaders
  407. $(OUTPUT)%.o: %.c prepare FORCE
  408. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  409. $(OUTPUT)%.i: %.c prepare FORCE
  410. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  411. $(OUTPUT)%.s: %.c prepare FORCE
  412. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  413. $(OUTPUT)%-bison.o: %.c prepare FORCE
  414. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  415. $(OUTPUT)%-flex.o: %.c prepare FORCE
  416. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  417. $(OUTPUT)%.o: %.S prepare FORCE
  418. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  419. $(OUTPUT)%.i: %.S prepare FORCE
  420. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  421. $(OUTPUT)perf-%: %.o $(PERFLIBS)
  422. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)
  423. ifndef NO_PERF_READ_VDSO32
  424. $(OUTPUT)perf-read-vdso32: perf-read-vdso.c util/find-vdso-map.c
  425. $(QUIET_CC)$(CC) -m32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c
  426. endif
  427. ifndef NO_PERF_READ_VDSOX32
  428. $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-vdso-map.c
  429. $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c
  430. endif
  431. $(patsubst perf-%,%.o,$(PROGRAMS)): $(wildcard */*.h)
  432. LIBPERF_IN := $(OUTPUT)libperf-in.o
  433. $(LIBPERF_IN): prepare fixdep FORCE
  434. $(Q)$(MAKE) $(build)=libperf
  435. $(LIB_FILE): $(LIBPERF_IN)
  436. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN) $(LIB_OBJS)
  437. LIBTRACEEVENT_FLAGS += plugin_dir=$(plugindir_SQ)
  438. $(LIBTRACEEVENT): fixdep FORCE
  439. $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent.a
  440. libtraceevent_plugins: fixdep FORCE
  441. $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) plugins
  442. $(LIBTRACEEVENT_DYNAMIC_LIST): libtraceevent_plugins
  443. $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent-dynamic-list
  444. $(LIBTRACEEVENT)-clean:
  445. $(call QUIET_CLEAN, libtraceevent)
  446. $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) O=$(OUTPUT) clean >/dev/null
  447. install-traceevent-plugins: libtraceevent_plugins
  448. $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) install_plugins
  449. $(LIBAPI): fixdep FORCE
  450. $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
  451. $(LIBAPI)-clean:
  452. $(call QUIET_CLEAN, libapi)
  453. $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
  454. $(LIBBPF): fixdep FORCE
  455. $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) $(OUTPUT)libbpf.a FEATURES_DUMP=$(FEATURE_DUMP_EXPORT)
  456. $(LIBBPF)-clean:
  457. $(call QUIET_CLEAN, libbpf)
  458. $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
  459. $(LIBSUBCMD): fixdep FORCE
  460. $(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) $(OUTPUT)libsubcmd.a
  461. $(LIBSUBCMD)-clean:
  462. $(call QUIET_CLEAN, libsubcmd)
  463. $(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) clean
  464. help:
  465. @echo 'Perf make targets:'
  466. @echo ' doc - make *all* documentation (see below)'
  467. @echo ' man - make manpage documentation (access with man <foo>)'
  468. @echo ' html - make html documentation'
  469. @echo ' info - make GNU info documentation (access with info <foo>)'
  470. @echo ' pdf - make pdf documentation'
  471. @echo ' TAGS - use etags to make tag information for source browsing'
  472. @echo ' tags - use ctags to make tag information for source browsing'
  473. @echo ' cscope - use cscope to make interactive browsing database'
  474. @echo ''
  475. @echo 'Perf install targets:'
  476. @echo ' NOTE: documentation build requires asciidoc, xmlto packages to be installed'
  477. @echo ' HINT: use "prefix" or "DESTDIR" to install to a particular'
  478. @echo ' path like "make prefix=/usr/local install install-doc"'
  479. @echo ' install - install compiled binaries'
  480. @echo ' install-doc - install *all* documentation'
  481. @echo ' install-man - install manpage documentation'
  482. @echo ' install-html - install html documentation'
  483. @echo ' install-info - install GNU info documentation'
  484. @echo ' install-pdf - install pdf documentation'
  485. @echo ''
  486. @echo ' quick-install-doc - alias for quick-install-man'
  487. @echo ' quick-install-man - install the documentation quickly'
  488. @echo ' quick-install-html - install the html documentation quickly'
  489. @echo ''
  490. @echo 'Perf maintainer targets:'
  491. @echo ' clean - clean all binary objects and build output'
  492. DOC_TARGETS := doc man html info pdf
  493. INSTALL_DOC_TARGETS := $(patsubst %,install-%,$(DOC_TARGETS)) try-install-man
  494. INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html
  495. # 'make doc' should call 'make -C Documentation all'
  496. $(DOC_TARGETS):
  497. $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all)
  498. TAG_FOLDERS= . ../lib ../include
  499. TAG_FILES= ../../include/uapi/linux/perf_event.h
  500. TAGS:
  501. $(QUIET_GEN)$(RM) TAGS; \
  502. $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs etags -a $(TAG_FILES)
  503. tags:
  504. $(QUIET_GEN)$(RM) tags; \
  505. $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs ctags -a $(TAG_FILES)
  506. cscope:
  507. $(QUIET_GEN)$(RM) cscope*; \
  508. $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs cscope -b $(TAG_FILES)
  509. ### Testing rules
  510. # GNU make supports exporting all variables by "export" without parameters.
  511. # However, the environment gets quite big, and some programs have problems
  512. # with that.
  513. check: $(OUTPUT)common-cmds.h
  514. if sparse; \
  515. then \
  516. for i in *.c */*.c; \
  517. do \
  518. sparse $(CFLAGS) $(SPARSE_FLAGS) $$i || exit; \
  519. done; \
  520. else \
  521. exit 1; \
  522. fi
  523. ### Installation rules
  524. install-gtk:
  525. install-tools: all install-gtk
  526. $(call QUIET_INSTALL, binaries) \
  527. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'; \
  528. $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'; \
  529. $(LN) '$(DESTDIR_SQ)$(bindir_SQ)/perf' '$(DESTDIR_SQ)$(bindir_SQ)/trace'
  530. ifndef NO_PERF_READ_VDSO32
  531. $(call QUIET_INSTALL, perf-read-vdso32) \
  532. $(INSTALL) $(OUTPUT)perf-read-vdso32 '$(DESTDIR_SQ)$(bindir_SQ)';
  533. endif
  534. ifndef NO_PERF_READ_VDSOX32
  535. $(call QUIET_INSTALL, perf-read-vdsox32) \
  536. $(INSTALL) $(OUTPUT)perf-read-vdsox32 '$(DESTDIR_SQ)$(bindir_SQ)';
  537. endif
  538. $(call QUIET_INSTALL, libexec) \
  539. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
  540. $(call QUIET_INSTALL, perf-archive) \
  541. $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
  542. $(call QUIET_INSTALL, perf-with-kcore) \
  543. $(INSTALL) $(OUTPUT)perf-with-kcore -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
  544. ifndef NO_LIBAUDIT
  545. $(call QUIET_INSTALL, strace/groups) \
  546. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(STRACE_GROUPS_INSTDIR_SQ)'; \
  547. $(INSTALL) trace/strace/groups/* -t '$(DESTDIR_SQ)$(STRACE_GROUPS_INSTDIR_SQ)'
  548. endif
  549. ifndef NO_LIBPERL
  550. $(call QUIET_INSTALL, perl-scripts) \
  551. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'; \
  552. $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'; \
  553. $(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'; \
  554. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'; \
  555. $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
  556. endif
  557. ifndef NO_LIBPYTHON
  558. $(call QUIET_INSTALL, python-scripts) \
  559. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'; \
  560. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'; \
  561. $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'; \
  562. $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \
  563. $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
  564. endif
  565. $(call QUIET_INSTALL, perf_completion-script) \
  566. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \
  567. $(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'
  568. $(call QUIET_INSTALL, perf-tip) \
  569. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(tip_instdir_SQ)'; \
  570. $(INSTALL) Documentation/tips.txt -t '$(DESTDIR_SQ)$(tip_instdir_SQ)'
  571. install-tests: all install-gtk
  572. $(call QUIET_INSTALL, tests) \
  573. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
  574. $(INSTALL) tests/attr.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
  575. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \
  576. $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'
  577. install-bin: install-tools install-tests
  578. install: install-bin try-install-man install-traceevent-plugins
  579. install-python_ext:
  580. $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'
  581. # 'make install-doc' should call 'make -C Documentation install'
  582. $(INSTALL_DOC_TARGETS):
  583. $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:-doc=)
  584. ### Cleaning rules
  585. #
  586. # This is here, not in Makefile.config, because Makefile.config does
  587. # not get included for the clean target:
  588. #
  589. config-clean:
  590. $(call QUIET_CLEAN, config)
  591. $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null
  592. clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean
  593. $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
  594. $(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
  595. $(Q)$(RM) $(OUTPUT).config-detected
  596. $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32
  597. $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
  598. $(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \
  599. $(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c
  600. $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
  601. $(python-clean)
  602. #
  603. # To provide FEATURE-DUMP into $(FEATURE_DUMP_COPY)
  604. # file if defined, with no further action.
  605. feature-dump:
  606. ifdef FEATURE_DUMP_COPY
  607. @cp $(OUTPUT)FEATURE-DUMP $(FEATURE_DUMP_COPY)
  608. @echo "FEATURE-DUMP file copied into $(FEATURE_DUMP_COPY)"
  609. else
  610. @echo "FEATURE-DUMP file available in $(OUTPUT)FEATURE-DUMP"
  611. endif
  612. #
  613. # Trick: if ../../.git does not exist - we are building out of tree for example,
  614. # then force version regeneration:
  615. #
  616. ifeq ($(wildcard ../../.git/HEAD),)
  617. GIT-HEAD-PHONY = ../../.git/HEAD
  618. else
  619. GIT-HEAD-PHONY =
  620. endif
  621. FORCE:
  622. .PHONY: all install clean config-clean strip install-gtk
  623. .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
  624. .PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope FORCE prepare
  625. .PHONY: libtraceevent_plugins archheaders