Makefile.perf 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. include ../scripts/Makefile.include
  3. include ../scripts/Makefile.arch
  4. # The default target of this Makefile is...
  5. all:
  6. include ../scripts/utilities.mak
  7. # Define V to have a more verbose compile.
  8. #
  9. # Define VF to have a more verbose feature check output.
  10. #
  11. # Define O to save output files in a separate directory.
  12. #
  13. # Define ARCH as name of target architecture if you want cross-builds.
  14. #
  15. # Define CROSS_COMPILE as prefix name of compiler if you want cross-builds.
  16. #
  17. # Define NO_LIBPERL to disable perl script extension.
  18. #
  19. # Define NO_LIBPYTHON to disable python script extension.
  20. #
  21. # Define PYTHON to point to the python binary if the default
  22. # `python' is not correct; for example: PYTHON=python2
  23. #
  24. # Define PYTHON_CONFIG to point to the python-config binary if
  25. # the default `$(PYTHON)-config' is not correct.
  26. #
  27. # Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8
  28. #
  29. # Define DOCBOOK_XSL_172 if you want to format man pages with DocBook XSL v1.72.
  30. #
  31. # Define LDFLAGS=-static to build a static binary.
  32. #
  33. # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds.
  34. #
  35. # Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated
  36. # EXTLIBS.
  37. #
  38. # Define EXTRA_PERFLIBS to pass extra libraries to PERFLIBS.
  39. #
  40. # Define NO_DWARF if you do not want debug-info analysis feature at all.
  41. #
  42. # Define WERROR=0 to disable treating any warnings as errors.
  43. #
  44. # Define NO_SLANG if you do not want TUI support.
  45. #
  46. # Define GTK2 if you want GTK+ GUI support.
  47. #
  48. # Define NO_DEMANGLE if you do not want C++ symbol demangling.
  49. #
  50. # Define NO_LIBELF if you do not want libelf dependency (e.g. cross-builds)
  51. #
  52. # Define NO_LIBUNWIND if you do not want libunwind dependency for dwarf
  53. # backtrace post unwind.
  54. #
  55. # Define NO_BACKTRACE if you do not want stack backtrace debug feature
  56. #
  57. # Define NO_LIBNUMA if you do not want numa perf benchmark
  58. #
  59. # Define NO_LIBAUDIT if you do not want libaudit support
  60. #
  61. # Define NO_LIBBIONIC if you do not want bionic support
  62. #
  63. # Define NO_LIBCRYPTO if you do not want libcrypto (openssl) support
  64. # used for generating build-ids for ELFs generated by jitdump.
  65. #
  66. # Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support
  67. # for dwarf backtrace post unwind.
  68. #
  69. # Define NO_LIBTRACEEVENT=1 if you don't want libtraceevent to be linked,
  70. # this will remove multiple features and tools, such as 'perf trace',
  71. # that need it to read tracefs event format files, etc.
  72. #
  73. # Define NO_PERF_READ_VDSO32 if you do not want to build perf-read-vdso32
  74. # for reading the 32-bit compatibility VDSO in 64-bit mode
  75. #
  76. # Define NO_PERF_READ_VDSOX32 if you do not want to build perf-read-vdsox32
  77. # for reading the x32 mode 32-bit compatibility VDSO in 64-bit mode
  78. #
  79. # Define NO_ZLIB if you do not want to support compressed kernel modules
  80. #
  81. # Define NO_LIBBABELTRACE if you do not want libbabeltrace support
  82. # for CTF data format.
  83. #
  84. # Define NO_CAPSTONE if you do not want libcapstone support
  85. # for disasm engine.
  86. #
  87. # Define NO_LZMA if you do not want to support compressed (xz) kernel modules
  88. #
  89. # Define NO_AUXTRACE if you do not want AUX area tracing support
  90. #
  91. # Define NO_LIBBPF if you do not want BPF support
  92. #
  93. # Define NO_LIBCAP if you do not want process capabilities considered by perf
  94. #
  95. # Define NO_SDT if you do not want to define SDT event in perf tools,
  96. # note that it doesn't disable SDT scanning support.
  97. #
  98. # Define FEATURES_DUMP to provide features detection dump file
  99. # and bypass the feature detection
  100. #
  101. # Define NO_JVMTI if you do not want jvmti agent built
  102. #
  103. # Define NO_JVMTI_CMLR (debug only) if you do not want to process CMLR
  104. # data for java source lines.
  105. #
  106. # Define CORESIGHT if you DO WANT support for CoreSight trace decoding.
  107. #
  108. # Define NO_AIO if you do not want support of Posix AIO based trace
  109. # streaming for record mode. Currently Posix AIO trace streaming is
  110. # supported only when linking with glibc.
  111. #
  112. # Define NO_LIBZSTD if you do not want support of Zstandard based runtime
  113. # trace compression in record mode.
  114. #
  115. # Define TCMALLOC to enable tcmalloc heap profiling.
  116. #
  117. # Define LIBBPF_DYNAMIC to enable libbpf dynamic linking.
  118. #
  119. # Define NO_SYSCALL_TABLE=1 to disable the use of syscall id to/from name tables
  120. # generated from the kernel .tbl or unistd.h files and use, if available, libaudit
  121. # for doing the conversions to/from strings/id.
  122. #
  123. # Define NO_LIBPFM4 to disable libpfm4 events extension.
  124. #
  125. # Define NO_LIBDEBUGINFOD if you do not want support debuginfod
  126. #
  127. # Set BUILD_BPF_SKEL to 0 to override BUILD_BPF_SKEL and not build BPF skeletons
  128. #
  129. # Define BUILD_NONDISTRO to enable building an linking against libbfd and
  130. # libiberty distribution license incompatible libraries.
  131. #
  132. # Define EXTRA_TESTS to enable building extra tests useful mainly to perf
  133. # developers, such as:
  134. # x86 instruction decoder - new instructions test
  135. #
  136. # Define GEN_VMLINUX_H to generate vmlinux.h from the BTF.
  137. #
  138. # Define NO_SHELLCHECK if you do not want to run shellcheck during build
  139. # As per kernel Makefile, avoid funny character set dependencies
  140. unexport LC_ALL
  141. LC_COLLATE=C
  142. LC_NUMERIC=C
  143. export LC_COLLATE LC_NUMERIC
  144. ifeq ($(srctree),)
  145. srctree := $(patsubst %/,%,$(dir $(CURDIR)))
  146. srctree := $(patsubst %/,%,$(dir $(srctree)))
  147. #$(info Determined 'srctree' to be $(srctree))
  148. endif
  149. ifneq ($(objtree),)
  150. #$(info Determined 'objtree' to be $(objtree))
  151. endif
  152. ifneq ($(OUTPUT),)
  153. #$(info Determined 'OUTPUT' to be $(OUTPUT))
  154. # Adding $(OUTPUT) as a directory to look for source files,
  155. # because use generated output files as sources dependency
  156. # for flex/bison parsers.
  157. VPATH += $(OUTPUT)
  158. export VPATH
  159. # create symlink to the original source
  160. SOURCE := $(shell ln -sfn $(srctree)/tools/perf $(OUTPUT)/source)
  161. endif
  162. ifeq ($(V),1)
  163. Q =
  164. else
  165. Q = @
  166. endif
  167. # Do not use make's built-in rules
  168. # (this improves performance and avoids hard-to-debug behaviour);
  169. MAKEFLAGS += -r
  170. # Makefiles suck: This macro sets a default value of $(2) for the
  171. # variable named by $(1), unless the variable has been set by
  172. # environment or command line. This is necessary for CC and AR
  173. # because make sets default values, so the simpler ?= approach
  174. # won't work as expected.
  175. define allow-override
  176. $(if $(or $(findstring environment,$(origin $(1))),\
  177. $(findstring command line,$(origin $(1)))),,\
  178. $(eval $(1) = $(2)))
  179. endef
  180. LD += $(EXTRA_LDFLAGS)
  181. HOSTCC ?= gcc
  182. HOSTLD ?= ld
  183. HOSTAR ?= ar
  184. CLANG ?= clang
  185. # Some distros provide the command $(CROSS_COMPILE)pkg-config for
  186. # searching packges installed with Multiarch. Use it for cross
  187. # compilation if it is existed.
  188. ifneq (, $(shell which $(CROSS_COMPILE)pkg-config))
  189. PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
  190. else
  191. PKG_CONFIG ?= pkg-config
  192. # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR
  193. # for modified system root, is required for the cross compilation.
  194. # If these PKG_CONFIG environment variables are not set, Multiarch library
  195. # paths are used instead.
  196. ifdef CROSS_COMPILE
  197. ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),)
  198. CROSS_ARCH = $(shell $(CC) -dumpmachine)
  199. PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
  200. PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
  201. PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
  202. PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
  203. PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
  204. export PKG_CONFIG_LIBDIR
  205. $(warning Missing PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH and PKG_CONFIG_SYSROOT_DIR for cross compilation,)
  206. $(warning set PKG_CONFIG_LIBDIR for using Multiarch libs.)
  207. endif
  208. endif
  209. endif
  210. RM = rm -f
  211. LN = ln -f
  212. MKDIR = mkdir
  213. FIND = find
  214. INSTALL = install
  215. FLEX ?= flex
  216. BISON ?= bison
  217. STRIP = strip
  218. AWK = awk
  219. READELF ?= readelf
  220. # include Makefile.config by default and rule out
  221. # non-config cases
  222. config := 1
  223. NON_CONFIG_TARGETS := clean python-clean TAGS tags cscope help
  224. ifdef MAKECMDGOALS
  225. ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
  226. VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h
  227. config := 0
  228. endif
  229. endif
  230. # The fixdep build - we force fixdep tool to be built as
  231. # the first target in the separate make session not to be
  232. # disturbed by any parallel make jobs. Once fixdep is done
  233. # we issue the requested build with FIXDEP=1 variable.
  234. #
  235. # The fixdep build is disabled for $(NON_CONFIG_TARGETS)
  236. # targets, because it's not necessary.
  237. ifdef FIXDEP
  238. force_fixdep := 0
  239. else
  240. force_fixdep := $(config)
  241. endif
  242. # Runs shellcheck on perf test shell scripts
  243. ifeq ($(NO_SHELLCHECK),1)
  244. SHELLCHECK :=
  245. else
  246. SHELLCHECK := $(shell which shellcheck 2> /dev/null)
  247. endif
  248. # shellcheck is using in tools/perf/tests/Build with option -a/--check-sourced (
  249. # introduced in v0.4.7) and -S/--severity (introduced in v0.6.0). So make the
  250. # minimal shellcheck version as v0.6.0.
  251. ifneq ($(SHELLCHECK),)
  252. ifeq ($(shell expr $(shell $(SHELLCHECK) --version | grep version: | \
  253. sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \< 060), 1)
  254. SHELLCHECK :=
  255. endif
  256. endif
  257. export srctree OUTPUT RM CC CXX LD AR CFLAGS CXXFLAGS V BISON FLEX AWK
  258. export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK
  259. include $(srctree)/tools/build/Makefile.include
  260. ifeq ($(force_fixdep),1)
  261. goals := $(filter-out all sub-make, $(MAKECMDGOALS))
  262. $(goals) all: sub-make
  263. sub-make: fixdep
  264. @./check-headers.sh
  265. $(Q)$(MAKE) FIXDEP=1 -f Makefile.perf $(goals)
  266. else # force_fixdep
  267. LIBAPI_DIR = $(srctree)/tools/lib/api/
  268. LIBBPF_DIR = $(srctree)/tools/lib/bpf/
  269. LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
  270. LIBSYMBOL_DIR = $(srctree)/tools/lib/symbol/
  271. LIBPERF_DIR = $(srctree)/tools/lib/perf/
  272. DOC_DIR = $(srctree)/tools/perf/Documentation/
  273. # Set FEATURE_TESTS to 'all' so all possible feature checkers are executed.
  274. # Without this setting the output feature dump file misses some features, for
  275. # example, liberty. Select all checkers so we won't get an incomplete feature
  276. # dump file.
  277. ifeq ($(config),1)
  278. ifdef MAKECMDGOALS
  279. ifeq ($(filter feature-dump,$(MAKECMDGOALS)),feature-dump)
  280. FEATURE_TESTS := all
  281. endif
  282. endif
  283. include Makefile.config
  284. endif
  285. ifeq ($(config),0)
  286. include $(srctree)/tools/scripts/Makefile.arch
  287. -include arch/$(SRCARCH)/Makefile
  288. endif
  289. # The FEATURE_DUMP_EXPORT holds location of the actual
  290. # FEATURE_DUMP file to be used to bypass feature detection
  291. # (for bpf or any other subproject)
  292. ifeq ($(FEATURES_DUMP),)
  293. FEATURE_DUMP_EXPORT := $(realpath $(OUTPUT)FEATURE-DUMP)
  294. else
  295. FEATURE_DUMP_EXPORT := $(realpath $(FEATURES_DUMP))
  296. endif
  297. export prefix bindir sharedir sysconfdir DESTDIR
  298. # sparse is architecture-neutral, which means that we need to tell it
  299. # explicitly what architecture to check for. Fix this up for yours..
  300. SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
  301. # Guard against environment variables
  302. PYRF_OBJS =
  303. SCRIPT_SH =
  304. SCRIPT_SH += perf-archive.sh
  305. SCRIPT_SH += perf-iostat.sh
  306. grep-libs = $(filter -l%,$(1))
  307. strip-libs = $(filter-out -l%,$(1))
  308. ifneq ($(OUTPUT),)
  309. LIBAPI_OUTPUT = $(abspath $(OUTPUT))/libapi
  310. else
  311. LIBAPI_OUTPUT = $(CURDIR)/libapi
  312. endif
  313. LIBAPI_DESTDIR = $(LIBAPI_OUTPUT)
  314. LIBAPI_INCLUDE = $(LIBAPI_DESTDIR)/include
  315. LIBAPI = $(LIBAPI_OUTPUT)/libapi.a
  316. export LIBAPI
  317. CFLAGS += -I$(LIBAPI_OUTPUT)/include
  318. ifneq ($(OUTPUT),)
  319. LIBBPF_OUTPUT = $(abspath $(OUTPUT))/libbpf
  320. else
  321. LIBBPF_OUTPUT = $(CURDIR)/libbpf
  322. endif
  323. ifdef LIBBPF_STATIC
  324. LIBBPF_DESTDIR = $(LIBBPF_OUTPUT)
  325. LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
  326. LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a
  327. CFLAGS += -I$(LIBBPF_OUTPUT)/include
  328. endif
  329. ifneq ($(OUTPUT),)
  330. LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
  331. else
  332. LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
  333. endif
  334. LIBSUBCMD_DESTDIR = $(LIBSUBCMD_OUTPUT)
  335. LIBSUBCMD_INCLUDE = $(LIBSUBCMD_DESTDIR)/include
  336. LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
  337. CFLAGS += -I$(LIBSUBCMD_OUTPUT)/include
  338. ifneq ($(OUTPUT),)
  339. LIBSYMBOL_OUTPUT = $(abspath $(OUTPUT))/libsymbol
  340. else
  341. LIBSYMBOL_OUTPUT = $(CURDIR)/libsymbol
  342. endif
  343. LIBSYMBOL_DESTDIR = $(LIBSYMBOL_OUTPUT)
  344. LIBSYMBOL_INCLUDE = $(LIBSYMBOL_DESTDIR)/include
  345. LIBSYMBOL = $(LIBSYMBOL_OUTPUT)/libsymbol.a
  346. CFLAGS += -I$(LIBSYMBOL_OUTPUT)/include
  347. ifneq ($(OUTPUT),)
  348. LIBPERF_OUTPUT = $(abspath $(OUTPUT))/libperf
  349. else
  350. LIBPERF_OUTPUT = $(CURDIR)/libperf
  351. endif
  352. LIBPERF_DESTDIR = $(LIBPERF_OUTPUT)
  353. LIBPERF_INCLUDE = $(LIBPERF_DESTDIR)/include
  354. LIBPERF = $(LIBPERF_OUTPUT)/libperf.a
  355. export LIBPERF
  356. CFLAGS += -I$(LIBPERF_OUTPUT)/include
  357. # python extension build directories
  358. PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
  359. PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
  360. PYTHON_EXTBUILD_TMP := $(PYTHON_EXTBUILD)tmp/
  361. export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP
  362. python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf*.so
  363. # Use the detected configuration
  364. -include $(OUTPUT).config-detected
  365. SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH))
  366. PROGRAMS += $(OUTPUT)perf
  367. ifndef NO_PERF_READ_VDSO32
  368. PROGRAMS += $(OUTPUT)perf-read-vdso32
  369. endif
  370. ifndef NO_PERF_READ_VDSOX32
  371. PROGRAMS += $(OUTPUT)perf-read-vdsox32
  372. endif
  373. LIBJVMTI = libperf-jvmti.so
  374. ifndef NO_JVMTI
  375. PROGRAMS += $(OUTPUT)$(LIBJVMTI)
  376. endif
  377. DLFILTERS := dlfilter-test-api-v0.so dlfilter-test-api-v2.so dlfilter-show-cycles.so
  378. DLFILTERS := $(patsubst %,$(OUTPUT)dlfilters/%,$(DLFILTERS))
  379. # what 'all' will build and 'install' will install, in perfexecdir
  380. ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) $(DLFILTERS)
  381. # what 'all' will build but not install in perfexecdir
  382. OTHER_PROGRAMS = $(OUTPUT)perf
  383. # Set paths to tools early so that they can be used for version tests.
  384. ifndef SHELL_PATH
  385. SHELL_PATH = /bin/sh
  386. endif
  387. ifndef PERL_PATH
  388. PERL_PATH = /usr/bin/perl
  389. endif
  390. export PERL_PATH
  391. LIBPERF_BENCH_IN := $(OUTPUT)perf-bench-in.o
  392. LIBPERF_BENCH := $(OUTPUT)libperf-bench.a
  393. LIBPERF_TEST_IN := $(OUTPUT)perf-test-in.o
  394. LIBPERF_TEST := $(OUTPUT)libperf-test.a
  395. LIBPERF_UI_IN := $(OUTPUT)perf-ui-in.o
  396. LIBPERF_UI := $(OUTPUT)libperf-ui.a
  397. LIBPERF_UTIL_IN := $(OUTPUT)perf-util-in.o
  398. LIBPERF_UTIL := $(OUTPUT)libperf-util.a
  399. LIBPMU_EVENTS_IN := $(OUTPUT)pmu-events/pmu-events-in.o
  400. LIBPMU_EVENTS := $(OUTPUT)libpmu-events.a
  401. PERFLIBS = $(LIBAPI) $(LIBPERF) $(LIBSUBCMD) $(LIBSYMBOL)
  402. ifdef LIBBPF_STATIC
  403. PERFLIBS += $(LIBBPF)
  404. endif
  405. PERFLIBS += $(LIBPERF_BENCH) $(LIBPERF_TEST) $(LIBPERF_UI) $(LIBPERF_UTIL)
  406. PERFLIBS += $(LIBPMU_EVENTS)
  407. # We choose to avoid "if .. else if .. else .. endif endif"
  408. # because maintaining the nesting to match is a pain. If
  409. # we had "elif" things would have been much nicer...
  410. ifneq ($(OUTPUT),)
  411. CFLAGS += -I$(OUTPUT)
  412. endif
  413. ifdef GTK2
  414. ALL_PROGRAMS += $(OUTPUT)libperf-gtk.so
  415. GTK_IN := $(OUTPUT)gtk-in.o
  416. endif
  417. ifdef ASCIIDOC8
  418. export ASCIIDOC8
  419. endif
  420. EXTLIBS := $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS))
  421. LIBS = -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
  422. export INSTALL SHELL_PATH
  423. ### Build rules
  424. SHELL = $(SHELL_PATH)
  425. arm64_gen_sysreg_dir := $(srctree)/tools/arch/arm64/tools
  426. ifneq ($(OUTPUT),)
  427. arm64_gen_sysreg_outdir := $(abspath $(OUTPUT))
  428. else
  429. arm64_gen_sysreg_outdir := $(CURDIR)
  430. endif
  431. arm64-sysreg-defs: FORCE
  432. $(Q)$(MAKE) -C $(arm64_gen_sysreg_dir) O=$(arm64_gen_sysreg_outdir) \
  433. prefix= subdir=
  434. arm64-sysreg-defs-clean:
  435. $(call QUIET_CLEAN,arm64-sysreg-defs)
  436. $(Q)$(MAKE) -C $(arm64_gen_sysreg_dir) O=$(arm64_gen_sysreg_outdir) \
  437. prefix= subdir= clean > /dev/null
  438. beauty_linux_dir := $(srctree)/tools/perf/trace/beauty/include/linux/
  439. beauty_uapi_linux_dir := $(srctree)/tools/perf/trace/beauty/include/uapi/linux/
  440. beauty_uapi_sound_dir := $(srctree)/tools/perf/trace/beauty/include/uapi/sound/
  441. beauty_arch_asm_dir := $(srctree)/tools/perf/trace/beauty/arch/x86/include/asm/
  442. beauty_x86_arch_asm_uapi_dir := $(srctree)/tools/perf/trace/beauty/arch/x86/include/uapi/asm/
  443. linux_uapi_dir := $(srctree)/tools/include/uapi/linux
  444. asm_generic_uapi_dir := $(srctree)/tools/include/uapi/asm-generic
  445. arch_asm_uapi_dir := $(srctree)/tools/arch/$(SRCARCH)/include/uapi/asm/
  446. x86_arch_asm_dir := $(srctree)/tools/arch/x86/include/asm/
  447. beauty_outdir := $(OUTPUT)trace/beauty/generated
  448. beauty_ioctl_outdir := $(beauty_outdir)/ioctl
  449. # Create output directory if not already present
  450. $(shell [ -d '$(beauty_ioctl_outdir)' ] || mkdir -p '$(beauty_ioctl_outdir)')
  451. fs_at_flags_array := $(beauty_outdir)/fs_at_flags_array.c
  452. fs_at_flags_tbl := $(srctree)/tools/perf/trace/beauty/fs_at_flags.sh
  453. $(fs_at_flags_array): $(beauty_uapi_linux_dir)/fcntl.h $(fs_at_flags_tbl)
  454. $(Q)$(SHELL) '$(fs_at_flags_tbl)' $(beauty_uapi_linux_dir) > $@
  455. clone_flags_array := $(beauty_outdir)/clone_flags_array.c
  456. clone_flags_tbl := $(srctree)/tools/perf/trace/beauty/clone.sh
  457. $(clone_flags_array): $(beauty_uapi_linux_dir)/sched.h $(clone_flags_tbl)
  458. $(Q)$(SHELL) '$(clone_flags_tbl)' $(beauty_uapi_linux_dir) > $@
  459. drm_ioctl_array := $(beauty_ioctl_outdir)/drm_ioctl_array.c
  460. drm_hdr_dir := $(srctree)/tools/include/uapi/drm
  461. drm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/drm_ioctl.sh
  462. $(drm_ioctl_array): $(drm_hdr_dir)/drm.h $(drm_hdr_dir)/i915_drm.h $(drm_ioctl_tbl)
  463. $(Q)$(SHELL) '$(drm_ioctl_tbl)' $(drm_hdr_dir) > $@
  464. fadvise_advice_array := $(beauty_outdir)/fadvise_advice_array.c
  465. fadvise_advice_tbl := $(srctree)/tools/perf/trace/beauty/fadvise.sh
  466. $(fadvise_advice_array): $(linux_uapi_dir)/in.h $(fadvise_advice_tbl)
  467. $(Q)$(SHELL) '$(fadvise_advice_tbl)' $(linux_uapi_dir) > $@
  468. fsmount_arrays := $(beauty_outdir)/fsmount_arrays.c
  469. fsmount_tbls := $(srctree)/tools/perf/trace/beauty/fsmount.sh
  470. $(fsmount_arrays): $(beauty_uapi_linux_dir)/mount.h $(fsmount_tbls)
  471. $(Q)$(SHELL) '$(fsmount_tbls)' $(beauty_uapi_linux_dir) > $@
  472. fspick_arrays := $(beauty_outdir)/fspick_arrays.c
  473. fspick_tbls := $(srctree)/tools/perf/trace/beauty/fspick.sh
  474. $(fspick_arrays): $(beauty_uapi_linux_dir)/mount.h $(fspick_tbls)
  475. $(Q)$(SHELL) '$(fspick_tbls)' $(beauty_uapi_linux_dir) > $@
  476. fsconfig_arrays := $(beauty_outdir)/fsconfig_arrays.c
  477. fsconfig_tbls := $(srctree)/tools/perf/trace/beauty/fsconfig.sh
  478. $(fsconfig_arrays): $(beauty_uapi_linux_dir)/mount.h $(fsconfig_tbls)
  479. $(Q)$(SHELL) '$(fsconfig_tbls)' $(beauty_uapi_linux_dir) > $@
  480. pkey_alloc_access_rights_array := $(beauty_outdir)/pkey_alloc_access_rights_array.c
  481. asm_generic_hdr_dir := $(srctree)/tools/include/uapi/asm-generic/
  482. pkey_alloc_access_rights_tbl := $(srctree)/tools/perf/trace/beauty/pkey_alloc_access_rights.sh
  483. $(pkey_alloc_access_rights_array): $(asm_generic_hdr_dir)/mman-common.h $(pkey_alloc_access_rights_tbl)
  484. $(Q)$(SHELL) '$(pkey_alloc_access_rights_tbl)' $(asm_generic_hdr_dir) > $@
  485. sndrv_ctl_ioctl_array := $(beauty_ioctl_outdir)/sndrv_ctl_ioctl_array.c
  486. sndrv_ctl_hdr_dir := $(srctree)/tools/include/uapi/sound
  487. sndrv_ctl_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/sndrv_ctl_ioctl.sh
  488. $(sndrv_ctl_ioctl_array): $(beauty_uapi_sound_dir)/asound.h $(sndrv_ctl_ioctl_tbl)
  489. $(Q)$(SHELL) '$(sndrv_ctl_ioctl_tbl)' $(beauty_uapi_sound_dir) > $@
  490. sndrv_pcm_ioctl_array := $(beauty_ioctl_outdir)/sndrv_pcm_ioctl_array.c
  491. sndrv_pcm_hdr_dir := $(srctree)/tools/include/uapi/sound
  492. sndrv_pcm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/sndrv_pcm_ioctl.sh
  493. $(sndrv_pcm_ioctl_array): $(beauty_uapi_sound_dir)/asound.h $(sndrv_pcm_ioctl_tbl)
  494. $(Q)$(SHELL) '$(sndrv_pcm_ioctl_tbl)' $(beauty_uapi_sound_dir) > $@
  495. kcmp_type_array := $(beauty_outdir)/kcmp_type_array.c
  496. kcmp_hdr_dir := $(srctree)/tools/include/uapi/linux/
  497. kcmp_type_tbl := $(srctree)/tools/perf/trace/beauty/kcmp_type.sh
  498. $(kcmp_type_array): $(kcmp_hdr_dir)/kcmp.h $(kcmp_type_tbl)
  499. $(Q)$(SHELL) '$(kcmp_type_tbl)' $(kcmp_hdr_dir) > $@
  500. kvm_ioctl_array := $(beauty_ioctl_outdir)/kvm_ioctl_array.c
  501. kvm_hdr_dir := $(srctree)/tools/include/uapi/linux
  502. kvm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/kvm_ioctl.sh
  503. $(kvm_ioctl_array): $(kvm_hdr_dir)/kvm.h $(kvm_ioctl_tbl)
  504. $(Q)$(SHELL) '$(kvm_ioctl_tbl)' $(kvm_hdr_dir) > $@
  505. socket_arrays := $(beauty_outdir)/socket.c
  506. socket_tbl := $(srctree)/tools/perf/trace/beauty/socket.sh
  507. $(socket_arrays): $(linux_uapi_dir)/in.h $(beauty_linux_dir)/socket.h $(socket_tbl)
  508. $(Q)$(SHELL) '$(socket_tbl)' $(linux_uapi_dir) $(beauty_linux_dir) > $@
  509. sockaddr_arrays := $(beauty_outdir)/sockaddr.c
  510. sockaddr_tbl := $(srctree)/tools/perf/trace/beauty/sockaddr.sh
  511. $(sockaddr_arrays): $(beauty_linux_dir)/socket.h $(sockaddr_tbl)
  512. $(Q)$(SHELL) '$(sockaddr_tbl)' $(beauty_linux_dir) > $@
  513. vhost_virtio_ioctl_array := $(beauty_ioctl_outdir)/vhost_virtio_ioctl_array.c
  514. vhost_virtio_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/vhost_virtio_ioctl.sh
  515. $(vhost_virtio_ioctl_array): $(beauty_uapi_linux_dir)/vhost.h $(vhost_virtio_ioctl_tbl)
  516. $(Q)$(SHELL) '$(vhost_virtio_ioctl_tbl)' $(beauty_uapi_linux_dir) > $@
  517. perf_ioctl_array := $(beauty_ioctl_outdir)/perf_ioctl_array.c
  518. perf_hdr_dir := $(srctree)/tools/include/uapi/linux
  519. perf_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/perf_ioctl.sh
  520. $(perf_ioctl_array): $(perf_hdr_dir)/perf_event.h $(perf_ioctl_tbl)
  521. $(Q)$(SHELL) '$(perf_ioctl_tbl)' $(perf_hdr_dir) > $@
  522. madvise_behavior_array := $(beauty_outdir)/madvise_behavior_array.c
  523. madvise_hdr_dir := $(srctree)/tools/include/uapi/asm-generic/
  524. madvise_behavior_tbl := $(srctree)/tools/perf/trace/beauty/madvise_behavior.sh
  525. $(madvise_behavior_array): $(madvise_hdr_dir)/mman-common.h $(madvise_behavior_tbl)
  526. $(Q)$(SHELL) '$(madvise_behavior_tbl)' $(madvise_hdr_dir) > $@
  527. mmap_flags_array := $(beauty_outdir)/mmap_flags_array.c
  528. mmap_flags_tbl := $(srctree)/tools/perf/trace/beauty/mmap_flags.sh
  529. $(mmap_flags_array): $(linux_uapi_dir)/mman.h $(asm_generic_uapi_dir)/mman.h $(asm_generic_uapi_dir)/mman-common.h $(mmap_flags_tbl)
  530. $(Q)$(SHELL) '$(mmap_flags_tbl)' $(linux_uapi_dir) $(asm_generic_uapi_dir) $(arch_asm_uapi_dir) > $@
  531. mremap_flags_array := $(beauty_outdir)/mremap_flags_array.c
  532. mremap_flags_tbl := $(srctree)/tools/perf/trace/beauty/mremap_flags.sh
  533. $(mremap_flags_array): $(linux_uapi_dir)/mman.h $(mremap_flags_tbl)
  534. $(Q)$(SHELL) '$(mremap_flags_tbl)' $(linux_uapi_dir) > $@
  535. mount_flags_array := $(beauty_outdir)/mount_flags_array.c
  536. mount_flags_tbl := $(srctree)/tools/perf/trace/beauty/mount_flags.sh
  537. $(mount_flags_array): $(beauty_uapi_linux_dir)/mount.h $(mount_flags_tbl)
  538. $(Q)$(SHELL) '$(mount_flags_tbl)' $(beauty_uapi_linux_dir) > $@
  539. move_mount_flags_array := $(beauty_outdir)/move_mount_flags_array.c
  540. move_mount_flags_tbl := $(srctree)/tools/perf/trace/beauty/move_mount_flags.sh
  541. $(move_mount_flags_array): $(beauty_uapi_linux_dir)/mount.h $(move_mount_flags_tbl)
  542. $(Q)$(SHELL) '$(move_mount_flags_tbl)' $(beauty_uapi_linux_dir) > $@
  543. mmap_prot_array := $(beauty_outdir)/mmap_prot_array.c
  544. mmap_prot_tbl := $(srctree)/tools/perf/trace/beauty/mmap_prot.sh
  545. $(mmap_prot_array): $(asm_generic_uapi_dir)/mman.h $(asm_generic_uapi_dir)/mman-common.h $(mmap_prot_tbl)
  546. $(Q)$(SHELL) '$(mmap_prot_tbl)' $(asm_generic_uapi_dir) $(arch_asm_uapi_dir) > $@
  547. prctl_option_array := $(beauty_outdir)/prctl_option_array.c
  548. prctl_option_tbl := $(srctree)/tools/perf/trace/beauty/prctl_option.sh
  549. $(prctl_option_array): $(beauty_uapi_linux_dir)/prctl.h $(prctl_option_tbl)
  550. $(Q)$(SHELL) '$(prctl_option_tbl)' $(beauty_uapi_linux_dir) > $@
  551. usbdevfs_ioctl_array := $(beauty_ioctl_outdir)/usbdevfs_ioctl_array.c
  552. usbdevfs_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/usbdevfs_ioctl.sh
  553. $(usbdevfs_ioctl_array): $(beauty_uapi_linux_dir)/usbdevice_fs.h $(usbdevfs_ioctl_tbl)
  554. $(Q)$(SHELL) '$(usbdevfs_ioctl_tbl)' $(beauty_uapi_linux_dir) > $@
  555. x86_arch_prctl_code_array := $(beauty_outdir)/x86_arch_prctl_code_array.c
  556. x86_arch_prctl_code_tbl := $(srctree)/tools/perf/trace/beauty/x86_arch_prctl.sh
  557. $(x86_arch_prctl_code_array): $(beauty_x86_arch_asm_uapi_dir)/prctl.h $(x86_arch_prctl_code_tbl)
  558. $(Q)$(SHELL) '$(x86_arch_prctl_code_tbl)' $(beauty_x86_arch_asm_uapi_dir) > $@
  559. x86_arch_irq_vectors_array := $(beauty_outdir)/x86_arch_irq_vectors_array.c
  560. x86_arch_irq_vectors_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_irq_vectors.sh
  561. $(x86_arch_irq_vectors_array): $(beauty_arch_asm_dir)/irq_vectors.h $(x86_arch_irq_vectors_tbl)
  562. $(Q)$(SHELL) '$(x86_arch_irq_vectors_tbl)' $(beauty_arch_asm_dir) > $@
  563. x86_arch_MSRs_array := $(beauty_outdir)/x86_arch_MSRs_array.c
  564. x86_arch_MSRs_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_msr.sh
  565. $(x86_arch_MSRs_array): $(x86_arch_asm_dir)/msr-index.h $(x86_arch_MSRs_tbl)
  566. $(Q)$(SHELL) '$(x86_arch_MSRs_tbl)' $(x86_arch_asm_dir) > $@
  567. rename_flags_array := $(beauty_outdir)/rename_flags_array.c
  568. rename_flags_tbl := $(srctree)/tools/perf/trace/beauty/rename_flags.sh
  569. $(rename_flags_array): $(beauty_uapi_linux_dir)/fs.h $(rename_flags_tbl)
  570. $(Q)$(SHELL) '$(rename_flags_tbl)' $(beauty_uapi_linux_dir) > $@
  571. arch_errno_name_array := $(beauty_outdir)/arch_errno_name_array.c
  572. arch_errno_hdr_dir := $(srctree)/tools
  573. arch_errno_tbl := $(srctree)/tools/perf/trace/beauty/arch_errno_names.sh
  574. $(arch_errno_name_array): $(arch_errno_tbl)
  575. $(Q)$(SHELL) '$(arch_errno_tbl)' '$(patsubst -%,,$(CC))' $(arch_errno_hdr_dir) > $@
  576. statx_mask_array := $(beauty_outdir)/statx_mask_array.c
  577. statx_mask_tbl := $(srctree)/tools/perf/trace/beauty/statx_mask.sh
  578. $(statx_mask_array): $(beauty_uapi_linux_dir)/stat.h $(statx_mask_tbl)
  579. $(Q)$(SHELL) '$(statx_mask_tbl)' $(beauty_uapi_linux_dir) > $@
  580. sync_file_range_arrays := $(beauty_outdir)/sync_file_range_arrays.c
  581. sync_file_range_tbls := $(srctree)/tools/perf/trace/beauty/sync_file_range.sh
  582. $(sync_file_range_arrays): $(beauty_uapi_linux_dir)/fs.h $(sync_file_range_tbls)
  583. $(Q)$(SHELL) '$(sync_file_range_tbls)' $(beauty_uapi_linux_dir) > $@
  584. TESTS_CORESIGHT_DIR := $(srctree)/tools/perf/tests/shell/coresight
  585. tests-coresight-targets: FORCE
  586. $(Q)$(MAKE) -C $(TESTS_CORESIGHT_DIR)
  587. tests-coresight-targets-clean:
  588. $(call QUIET_CLEAN, coresight)
  589. $(Q)$(MAKE) -C $(TESTS_CORESIGHT_DIR) O=$(OUTPUT) clean >/dev/null
  590. all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) tests-coresight-targets
  591. # Create python binding output directory if not already present
  592. $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python')
  593. $(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py $(PERFLIBS)
  594. $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \
  595. CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBS)' \
  596. $(PYTHON_WORD) util/setup.py \
  597. --quiet build_ext; \
  598. cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/
  599. python_perf_target:
  600. @echo "Target is: $(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX)"
  601. please_set_SHELL_PATH_to_a_more_modern_shell:
  602. $(Q)$$(:)
  603. shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
  604. strip: $(PROGRAMS) $(OUTPUT)perf
  605. $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf
  606. PERF_IN := $(OUTPUT)perf-in.o
  607. export NO_JEVENTS
  608. build := -f $(srctree)/tools/build/Makefile.build dir=. obj
  609. $(PERF_IN): prepare FORCE
  610. $(Q)$(MAKE) $(build)=perf
  611. $(LIBPMU_EVENTS_IN): FORCE prepare
  612. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events
  613. $(LIBPMU_EVENTS): $(LIBPMU_EVENTS_IN)
  614. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $<
  615. $(LIBPERF_BENCH_IN): FORCE prepare
  616. $(Q)$(MAKE) $(build)=perf-bench
  617. $(LIBPERF_BENCH): $(LIBPERF_BENCH_IN)
  618. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $<
  619. $(LIBPERF_TEST_IN): FORCE prepare
  620. $(Q)$(MAKE) $(build)=perf-test
  621. $(LIBPERF_TEST): $(LIBPERF_TEST_IN)
  622. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $<
  623. $(LIBPERF_UI_IN): FORCE prepare
  624. $(Q)$(MAKE) $(build)=perf-ui
  625. $(LIBPERF_UI): $(LIBPERF_UI_IN)
  626. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $<
  627. $(LIBPERF_UTIL_IN): FORCE prepare
  628. $(Q)$(MAKE) $(build)=perf-util
  629. $(LIBPERF_UTIL): $(LIBPERF_UTIL_IN)
  630. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $<
  631. $(OUTPUT)perf: $(PERFLIBS) $(PERF_IN)
  632. $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) \
  633. $(PERF_IN) $(LIBS) -o $@
  634. $(GTK_IN): FORCE prepare
  635. $(Q)$(MAKE) $(build)=gtk
  636. $(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS)
  637. $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS)
  638. $(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt
  639. $(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt)
  640. $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@
  641. $(SCRIPTS) : % : %.sh
  642. $(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@'
  643. $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE
  644. $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
  645. # These can record PERF_VERSION
  646. perf.spec $(SCRIPTS) \
  647. : $(OUTPUT)PERF-VERSION-FILE
  648. .SUFFIXES:
  649. #
  650. # If a target does not match any of the later rules then prefix it by $(OUTPUT)
  651. # This makes targets like 'make O=/tmp/perf perf.o' work in a natural way.
  652. #
  653. ifneq ($(OUTPUT),)
  654. %.o: $(OUTPUT)%.o
  655. @echo " # Redirected target $@ => $(OUTPUT)$@"
  656. pmu-events/%.o: $(OUTPUT)pmu-events/%.o
  657. @echo " # Redirected target $@ => $(OUTPUT)$@"
  658. util/%.o: $(OUTPUT)util/%.o
  659. @echo " # Redirected target $@ => $(OUTPUT)$@"
  660. bench/%.o: $(OUTPUT)bench/%.o
  661. @echo " # Redirected target $@ => $(OUTPUT)$@"
  662. tests/%.o: $(OUTPUT)tests/%.o
  663. @echo " # Redirected target $@ => $(OUTPUT)$@"
  664. endif
  665. # These two need to be here so that when O= is not used they take precedence
  666. # over the general rule for .o
  667. # get relative building directory (to $(OUTPUT))
  668. # and '.' if it's $(OUTPUT) itself
  669. __build-dir = $(subst $(OUTPUT),,$(dir $@))
  670. build-dir = $(or $(__build-dir),.)
  671. prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders \
  672. arm64-sysreg-defs \
  673. $(fs_at_flags_array) \
  674. $(clone_flags_array) \
  675. $(drm_ioctl_array) \
  676. $(fadvise_advice_array) \
  677. $(fsconfig_arrays) \
  678. $(fsmount_arrays) \
  679. $(fspick_arrays) \
  680. $(pkey_alloc_access_rights_array) \
  681. $(sndrv_pcm_ioctl_array) \
  682. $(sndrv_ctl_ioctl_array) \
  683. $(kcmp_type_array) \
  684. $(kvm_ioctl_array) \
  685. $(socket_arrays) \
  686. $(sockaddr_arrays) \
  687. $(vhost_virtio_ioctl_array) \
  688. $(madvise_behavior_array) \
  689. $(mmap_flags_array) \
  690. $(mmap_prot_array) \
  691. $(mremap_flags_array) \
  692. $(mount_flags_array) \
  693. $(move_mount_flags_array) \
  694. $(perf_ioctl_array) \
  695. $(prctl_option_array) \
  696. $(usbdevfs_ioctl_array) \
  697. $(x86_arch_irq_vectors_array) \
  698. $(x86_arch_MSRs_array) \
  699. $(x86_arch_prctl_code_array) \
  700. $(rename_flags_array) \
  701. $(arch_errno_name_array) \
  702. $(statx_mask_array) \
  703. $(sync_file_range_arrays) \
  704. $(LIBAPI) \
  705. $(LIBPERF) \
  706. $(LIBSUBCMD) \
  707. $(LIBSYMBOL) \
  708. bpf-skel
  709. ifdef LIBBPF_STATIC
  710. prepare: $(LIBBPF)
  711. endif
  712. $(OUTPUT)%.o: %.c prepare FORCE
  713. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  714. $(OUTPUT)%.i: %.c prepare FORCE
  715. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  716. $(OUTPUT)%.s: %.c prepare FORCE
  717. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  718. $(OUTPUT)%-bison.o: %.c prepare FORCE
  719. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  720. $(OUTPUT)%-flex.o: %.c prepare FORCE
  721. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  722. $(OUTPUT)%.o: %.S prepare FORCE
  723. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  724. $(OUTPUT)%.i: %.S prepare FORCE
  725. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
  726. $(OUTPUT)perf-%: %.o $(PERFLIBS)
  727. $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)
  728. ifndef NO_PERF_READ_VDSO32
  729. $(OUTPUT)perf-read-vdso32: perf-read-vdso.c util/find-map.c
  730. $(QUIET_CC)$(CC) -m32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c
  731. endif
  732. ifndef NO_PERF_READ_VDSOX32
  733. $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-map.c
  734. $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c
  735. endif
  736. $(OUTPUT)dlfilters/%.o: dlfilters/%.c include/perf/perf_dlfilter.h
  737. $(Q)$(MKDIR) -p $(OUTPUT)dlfilters
  738. $(QUIET_CC)$(CC) -c -Iinclude $(EXTRA_CFLAGS) -o $@ -fpic $<
  739. .SECONDARY: $(DLFILTERS:.so=.o)
  740. $(OUTPUT)dlfilters/%.so: $(OUTPUT)dlfilters/%.o
  741. $(QUIET_LINK)$(CC) $(EXTRA_CFLAGS) -shared -o $@ $<
  742. ifndef NO_JVMTI
  743. LIBJVMTI_IN := $(OUTPUT)jvmti/jvmti-in.o
  744. $(LIBJVMTI_IN): FORCE
  745. $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=jvmti obj=jvmti
  746. $(OUTPUT)$(LIBJVMTI): $(LIBJVMTI_IN)
  747. $(QUIET_LINK)$(CC) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIBJVMTI) -o $@ $<
  748. endif
  749. $(patsubst perf-%,%.o,$(PROGRAMS)): $(wildcard */*.h)
  750. $(LIBAPI): FORCE | $(LIBAPI_OUTPUT)
  751. $(Q)$(MAKE) -C $(LIBAPI_DIR) O=$(LIBAPI_OUTPUT) \
  752. DESTDIR=$(LIBAPI_DESTDIR) prefix= subdir= \
  753. $@ install_headers
  754. $(LIBAPI)-clean:
  755. $(call QUIET_CLEAN, libapi)
  756. $(Q)$(RM) -r -- $(LIBAPI_OUTPUT)
  757. $(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
  758. $(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \
  759. O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \
  760. EXTRA_CFLAGS="-fPIC" $@ install_headers
  761. $(LIBBPF)-clean:
  762. $(call QUIET_CLEAN, libbpf)
  763. $(Q)$(RM) -r -- $(LIBBPF_OUTPUT)
  764. $(LIBPERF): FORCE | $(LIBPERF_OUTPUT)
  765. $(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(LIBPERF_OUTPUT) \
  766. DESTDIR=$(LIBPERF_DESTDIR) prefix= subdir= \
  767. $@ install_headers
  768. $(LIBPERF)-clean:
  769. $(call QUIET_CLEAN, libperf)
  770. $(Q)$(RM) -r -- $(LIBPERF_OUTPUT)
  771. $(LIBSUBCMD): FORCE | $(LIBSUBCMD_OUTPUT)
  772. $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
  773. DESTDIR=$(LIBSUBCMD_DESTDIR) prefix= subdir= \
  774. $@ install_headers
  775. $(LIBSUBCMD)-clean:
  776. $(call QUIET_CLEAN, libsubcmd)
  777. $(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
  778. $(LIBSYMBOL): FORCE | $(LIBSYMBOL_OUTPUT)
  779. $(Q)$(MAKE) -C $(LIBSYMBOL_DIR) O=$(LIBSYMBOL_OUTPUT) \
  780. DESTDIR=$(LIBSYMBOL_DESTDIR) prefix= subdir= \
  781. $@ install_headers
  782. $(LIBSYMBOL)-clean:
  783. $(call QUIET_CLEAN, libsymbol)
  784. $(Q)$(RM) -r -- $(LIBSYMBOL_OUTPUT)
  785. help:
  786. @echo 'Perf make targets:'
  787. @echo ' doc - make *all* documentation (see below)'
  788. @echo ' man - make manpage documentation (access with man <foo>)'
  789. @echo ' html - make html documentation'
  790. @echo ' info - make GNU info documentation (access with info <foo>)'
  791. @echo ' pdf - make pdf documentation'
  792. @echo ' TAGS - use etags to make tag information for source browsing'
  793. @echo ' tags - use ctags to make tag information for source browsing'
  794. @echo ' cscope - use cscope to make interactive browsing database'
  795. @echo ''
  796. @echo 'Perf install targets:'
  797. @echo ' NOTE: documentation build requires asciidoc, xmlto packages to be installed'
  798. @echo ' HINT: use "prefix" or "DESTDIR" to install to a particular'
  799. @echo ' path like "make prefix=/usr/local install install-doc"'
  800. @echo ' install - install compiled binaries'
  801. @echo ' install-doc - install *all* documentation'
  802. @echo ' install-man - install manpage documentation'
  803. @echo ' install-html - install html documentation'
  804. @echo ' install-info - install GNU info documentation'
  805. @echo ' install-pdf - install pdf documentation'
  806. @echo ''
  807. @echo ' quick-install-doc - alias for quick-install-man'
  808. @echo ' quick-install-man - install the documentation quickly'
  809. @echo ' quick-install-html - install the html documentation quickly'
  810. @echo ''
  811. @echo 'Perf maintainer targets:'
  812. @echo ' clean - clean all binary objects and build output'
  813. DOC_TARGETS := doc man html info pdf
  814. INSTALL_DOC_TARGETS := $(patsubst %,install-%,$(DOC_TARGETS)) try-install-man
  815. INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html
  816. # 'make doc' should call 'make -C Documentation all'
  817. $(DOC_TARGETS):
  818. $(Q)$(MAKE) -C $(DOC_DIR) O=$(OUTPUT) $(@:doc=all) ASCIIDOC_EXTRA=$(ASCIIDOC_EXTRA)
  819. TAG_FOLDERS= . ../lib ../include
  820. TAG_FILES= ../../include/uapi/linux/perf_event.h
  821. TAGS:
  822. $(QUIET_GEN)$(RM) TAGS; \
  823. $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print -o -name '*.cpp' -print | xargs etags -a $(TAG_FILES)
  824. tags:
  825. $(QUIET_GEN)$(RM) tags; \
  826. $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print -o -name '*.cpp' -print | xargs ctags -a $(TAG_FILES)
  827. cscope:
  828. $(QUIET_GEN)$(RM) cscope*; \
  829. $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print -o -name '*.cpp' -print | xargs cscope -b $(TAG_FILES)
  830. ### Testing rules
  831. # GNU make supports exporting all variables by "export" without parameters.
  832. # However, the environment gets quite big, and some programs have problems
  833. # with that.
  834. check: $(OUTPUT)common-cmds.h
  835. if sparse; \
  836. then \
  837. for i in *.c */*.c; \
  838. do \
  839. sparse $(CFLAGS) $(SPARSE_FLAGS) $$i || exit; \
  840. done; \
  841. else \
  842. exit 1; \
  843. fi
  844. ### Installation rules
  845. ifdef GTK2
  846. install-gtk: $(OUTPUT)libperf-gtk.so
  847. $(call QUIET_INSTALL, 'GTK UI') \
  848. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(libdir_SQ)'; \
  849. $(INSTALL) $(OUTPUT)libperf-gtk.so '$(DESTDIR_SQ)$(libdir_SQ)'
  850. else
  851. install-gtk:
  852. endif
  853. install-tools: all install-gtk
  854. $(call QUIET_INSTALL, binaries) \
  855. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'; \
  856. $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'; \
  857. $(LN) '$(DESTDIR_SQ)$(bindir_SQ)/perf' '$(DESTDIR_SQ)$(bindir_SQ)/trace'; \
  858. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(includedir_SQ)/perf'; \
  859. $(INSTALL) -m 644 include/perf/perf_dlfilter.h -t '$(DESTDIR_SQ)$(includedir_SQ)/perf'
  860. ifndef NO_PERF_READ_VDSO32
  861. $(call QUIET_INSTALL, perf-read-vdso32) \
  862. $(INSTALL) $(OUTPUT)perf-read-vdso32 '$(DESTDIR_SQ)$(bindir_SQ)';
  863. endif
  864. ifndef NO_PERF_READ_VDSOX32
  865. $(call QUIET_INSTALL, perf-read-vdsox32) \
  866. $(INSTALL) $(OUTPUT)perf-read-vdsox32 '$(DESTDIR_SQ)$(bindir_SQ)';
  867. endif
  868. ifndef NO_JVMTI
  869. $(call QUIET_INSTALL, $(LIBJVMTI)) \
  870. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(libdir_SQ)'; \
  871. $(INSTALL) $(OUTPUT)$(LIBJVMTI) '$(DESTDIR_SQ)$(libdir_SQ)';
  872. endif
  873. $(call QUIET_INSTALL, libexec) \
  874. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
  875. $(call QUIET_INSTALL, perf-archive) \
  876. $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
  877. $(call QUIET_INSTALL, perf-iostat) \
  878. $(INSTALL) $(OUTPUT)perf-iostat -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
  879. ifndef NO_LIBAUDIT
  880. $(call QUIET_INSTALL, strace/groups) \
  881. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(STRACE_GROUPS_INSTDIR_SQ)'; \
  882. $(INSTALL) trace/strace/groups/* -m 644 -t '$(DESTDIR_SQ)$(STRACE_GROUPS_INSTDIR_SQ)'
  883. endif
  884. ifndef NO_LIBPERL
  885. $(call QUIET_INSTALL, perl-scripts) \
  886. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'; \
  887. $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'; \
  888. $(INSTALL) scripts/perl/*.pl -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'; \
  889. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'; \
  890. $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
  891. endif
  892. ifndef NO_LIBPYTHON
  893. $(call QUIET_INSTALL, python-scripts) \
  894. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'; \
  895. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'; \
  896. $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'; \
  897. $(INSTALL) scripts/python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \
  898. $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
  899. endif
  900. $(call QUIET_INSTALL, dlfilters) \
  901. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/dlfilters'; \
  902. $(INSTALL) $(DLFILTERS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/dlfilters';
  903. $(call QUIET_INSTALL, perf_completion-script) \
  904. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \
  905. $(INSTALL) perf-completion.sh -m 644 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'
  906. $(call QUIET_INSTALL, perf-tip) \
  907. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(tip_instdir_SQ)'; \
  908. $(INSTALL) Documentation/tips.txt -m 644 -t '$(DESTDIR_SQ)$(tip_instdir_SQ)'
  909. install-tests: all install-gtk
  910. $(call QUIET_INSTALL, tests) \
  911. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
  912. $(INSTALL) tests/attr.py -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
  913. $(INSTALL) tests/pe-file.exe* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
  914. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \
  915. $(INSTALL) tests/attr/* -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \
  916. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell'; \
  917. $(INSTALL) tests/shell/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell'; \
  918. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
  919. $(INSTALL) tests/shell/lib/*.sh -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
  920. $(INSTALL) tests/shell/lib/*.py -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
  921. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
  922. $(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
  923. $(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
  924. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
  925. $(INSTALL) tests/shell/base_probe/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
  926. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_report'; \
  927. $(INSTALL) tests/shell/base_report/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_report'; \
  928. $(INSTALL) tests/shell/base_report/*.txt '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_report'; \
  929. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight' ; \
  930. $(INSTALL) tests/shell/coresight/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight'
  931. $(Q)$(MAKE) -C tests/shell/coresight install-tests
  932. install-bin: install-tools install-tests
  933. install: install-bin try-install-man
  934. install-python_ext:
  935. $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'
  936. # 'make install-doc' should call 'make -C Documentation install'
  937. $(INSTALL_DOC_TARGETS):
  938. $(Q)$(MAKE) -C $(DOC_DIR) O=$(OUTPUT) $(@:-doc=) ASCIIDOC_EXTRA=$(ASCIIDOC_EXTRA) subdir=
  939. ### Cleaning rules
  940. python-clean:
  941. $(python-clean)
  942. SKEL_OUT := $(abspath $(OUTPUT)util/bpf_skel)
  943. SKEL_TMP_OUT := $(abspath $(SKEL_OUT)/.tmp)
  944. SKELETONS := $(SKEL_OUT)/bpf_prog_profiler.skel.h
  945. SKELETONS += $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h
  946. SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
  947. SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
  948. SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h $(SKEL_OUT)/sample_filter.skel.h
  949. SKELETONS += $(SKEL_OUT)/kwork_top.skel.h
  950. SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h
  951. SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h
  952. $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
  953. $(Q)$(MKDIR) -p $@
  954. ifeq ($(CONFIG_PERF_BPF_SKEL),y)
  955. BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool
  956. # Get Clang's default includes on this system, as opposed to those seen by
  957. # '--target=bpf'. This fixes "missing" files on some architectures/distros,
  958. # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
  959. #
  960. # Use '-idirafter': Don't interfere with include mechanics except where the
  961. # build would have failed anyways.
  962. define get_sys_includes
  963. $(shell $(1) $(2) -v -E - </dev/null 2>&1 \
  964. | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
  965. $(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
  966. endef
  967. ifneq ($(CROSS_COMPILE),)
  968. CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
  969. endif
  970. CLANG_OPTIONS = -Wall
  971. CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
  972. BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
  973. TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi
  974. ifneq ($(WERROR),0)
  975. CLANG_OPTIONS += -Werror
  976. endif
  977. $(BPFTOOL): | $(SKEL_TMP_OUT)
  978. $(Q)CFLAGS= $(MAKE) -C ../bpf/bpftool \
  979. OUTPUT=$(SKEL_TMP_OUT)/ bootstrap
  980. # Paths to search for a kernel to generate vmlinux.h from.
  981. VMLINUX_BTF_ELF_PATHS ?= $(if $(O),$(O)/vmlinux) \
  982. $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
  983. ../../vmlinux \
  984. /boot/vmlinux-$(shell uname -r)
  985. # Paths to BTF information.
  986. VMLINUX_BTF_BTF_PATHS ?= /sys/kernel/btf/vmlinux
  987. # Filter out kernels that don't exist or without a BTF section.
  988. VMLINUX_BTF_ELF_ABSPATHS ?= $(abspath $(wildcard $(VMLINUX_BTF_ELF_PATHS)))
  989. VMLINUX_BTF_PATHS ?= $(shell for file in $(VMLINUX_BTF_ELF_ABSPATHS); \
  990. do \
  991. if [ -f $$file ] && ($(READELF) -S "$$file" | grep -q .BTF); \
  992. then \
  993. echo "$$file"; \
  994. fi; \
  995. done) \
  996. $(wildcard $(VMLINUX_BTF_BTF_PATHS))
  997. # Select the first as the source of vmlinux.h.
  998. VMLINUX_BTF ?= $(firstword $(VMLINUX_BTF_PATHS))
  999. ifeq ($(VMLINUX_H),)
  1000. ifeq ($(VMLINUX_BTF),)
  1001. $(error Missing bpftool input for generating vmlinux.h)
  1002. endif
  1003. endif
  1004. $(SKEL_OUT)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) $(VMLINUX_H)
  1005. ifeq ($(VMLINUX_H),)
  1006. $(QUIET_GEN)$(BPFTOOL) btf dump file $< format c > $@
  1007. else
  1008. $(Q)cp "$(VMLINUX_H)" $@
  1009. endif
  1010. $(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlinux.h | $(SKEL_TMP_OUT)
  1011. $(QUIET_CLANG)$(CLANG) -g -O2 --target=bpf $(CLANG_OPTIONS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \
  1012. -c $(filter util/bpf_skel/%.bpf.c,$^) -o $@
  1013. $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o | $(BPFTOOL)
  1014. $(QUIET_GENSKEL)$(BPFTOOL) gen skeleton $< > $@
  1015. bpf-skel: $(SKELETONS)
  1016. .PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o
  1017. else # CONFIG_PERF_BPF_SKEL
  1018. bpf-skel:
  1019. endif # CONFIG_PERF_BPF_SKEL
  1020. bpf-skel-clean:
  1021. $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS) $(SKEL_OUT)/vmlinux.h
  1022. clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean \
  1023. arm64-sysreg-defs-clean fixdep-clean python-clean bpf-skel-clean \
  1024. tests-coresight-targets-clean
  1025. $(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive \
  1026. $(OUTPUT)perf-iostat $(LANG_BINDINGS)
  1027. $(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '*.a' -delete -o \
  1028. -name '\.*.cmd' -delete -o -name '\.*.d' -delete -o -name '*.shellcheck_log' -delete
  1029. $(Q)$(RM) $(OUTPUT).config-detected
  1030. $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 \
  1031. perf-read-vdsox32 $(OUTPUT)$(LIBJVMTI).so
  1032. $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo \
  1033. $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE \
  1034. $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
  1035. $(OUTPUT)util/intel-pt-decoder/inat-tables.c \
  1036. $(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c \
  1037. $(OUTPUT)pmu-events/pmu-events.c \
  1038. $(OUTPUT)pmu-events/test-empty-pmu-events.c \
  1039. $(OUTPUT)pmu-events/empty-pmu-events.log \
  1040. $(OUTPUT)pmu-events/metric_test.log \
  1041. $(OUTPUT)$(fadvise_advice_array) \
  1042. $(OUTPUT)$(fsconfig_arrays) \
  1043. $(OUTPUT)$(fsmount_arrays) \
  1044. $(OUTPUT)$(fspick_arrays) \
  1045. $(OUTPUT)$(madvise_behavior_array) \
  1046. $(OUTPUT)$(mmap_flags_array) \
  1047. $(OUTPUT)$(mmap_prot_array) \
  1048. $(OUTPUT)$(mremap_flags_array) \
  1049. $(OUTPUT)$(mount_flags_array) \
  1050. $(OUTPUT)$(move_mount_flags_array) \
  1051. $(OUTPUT)$(drm_ioctl_array) \
  1052. $(OUTPUT)$(pkey_alloc_access_rights_array) \
  1053. $(OUTPUT)$(sndrv_ctl_ioctl_array) \
  1054. $(OUTPUT)$(sndrv_pcm_ioctl_array) \
  1055. $(OUTPUT)$(kvm_ioctl_array) \
  1056. $(OUTPUT)$(kcmp_type_array) \
  1057. $(OUTPUT)$(socket_arrays) \
  1058. $(OUTPUT)$(sockaddr_arrays) \
  1059. $(OUTPUT)$(vhost_virtio_ioctl_array) \
  1060. $(OUTPUT)$(perf_ioctl_array) \
  1061. $(OUTPUT)$(prctl_option_array) \
  1062. $(OUTPUT)$(usbdevfs_ioctl_array) \
  1063. $(OUTPUT)$(x86_arch_irq_vectors_array) \
  1064. $(OUTPUT)$(x86_arch_MSRs_array) \
  1065. $(OUTPUT)$(x86_arch_prctl_code_array) \
  1066. $(OUTPUT)$(rename_flags_array) \
  1067. $(OUTPUT)$(arch_errno_name_array) \
  1068. $(OUTPUT)$(sync_file_range_arrays)
  1069. $(call QUIET_CLEAN, Documentation) \
  1070. $(MAKE) -C $(DOC_DIR) O=$(OUTPUT) clean >/dev/null
  1071. #
  1072. # To provide FEATURE-DUMP into $(FEATURE_DUMP_COPY)
  1073. # file if defined, with no further action.
  1074. feature-dump:
  1075. ifdef FEATURE_DUMP_COPY
  1076. @cp $(OUTPUT)FEATURE-DUMP $(FEATURE_DUMP_COPY)
  1077. @echo "FEATURE-DUMP file copied into $(FEATURE_DUMP_COPY)"
  1078. else
  1079. @echo "FEATURE-DUMP file available in $(OUTPUT)FEATURE-DUMP"
  1080. endif
  1081. FORCE:
  1082. .PHONY: all install clean config-clean strip install-gtk
  1083. .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
  1084. .PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare
  1085. .PHONY: archheaders python_perf_target
  1086. endif # force_fixdep
  1087. # Delete partially updated (corrupted) files on error
  1088. .DELETE_ON_ERROR: