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