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