1################################################################################
2#
3# perf
4#
5################################################################################
6
7LINUX_TOOLS += perf
8
9PERF_DEPENDENCIES = host-flex host-bison
10
11ifeq ($(BR2_PACKAGE_LINUX_TOOLS_PERF_NEEDS_HOST_PYTHON3),y)
12PERF_DEPENDENCIES += host-python3
13endif
14
15ifeq ($(NORMALIZED_ARCH),x86_64)
16PERF_ARCH=x86
17else
18PERF_ARCH=$(NORMALIZED_ARCH)
19endif
20
21PERF_MAKE_FLAGS = \
22	$(LINUX_MAKE_FLAGS) \
23	JOBS=$(PARALLEL_JOBS) \
24	ARCH=$(PERF_ARCH) \
25	DESTDIR=$(TARGET_DIR) \
26	prefix=/usr \
27	NO_GTK2=1 \
28	NO_LIBPERL=1 \
29	NO_LIBPYTHON=1 \
30	NO_LIBBIONIC=1 \
31	NO_LIBTRACEEVENT=1
32
33# We need to pass an argument to ld for setting the emulation when
34# building for MIPS architecture, otherwise the default one will always
35# be used and the compilation for most variants will fail.
36ifeq ($(BR2_mips),y)
37PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmip"
38else ifeq ($(BR2_mipsel),y)
39PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmip"
40else ifeq ($(BR2_mips64),y)
41ifeq ($(BR2_MIPS_NABI32),y)
42PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32btsmipn32"
43else
44PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64btsmip"
45endif
46else ifeq ($(BR2_mips64el),y)
47ifeq ($(BR2_MIPS_NABI32),y)
48PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf32ltsmipn32"
49else
50PERF_MAKE_FLAGS += LD="$(TARGET_LD) -m elf64ltsmip"
51endif
52endif
53
54# The call to backtrace() function fails for ARC, because for some
55# reason the unwinder from libgcc returns early. Thus the usage of
56# backtrace() should be disabled in perf explicitly: at build time
57# backtrace() appears to be available, but it fails at runtime: the
58# backtrace will contain only several functions from the top of stack,
59# instead of the complete backtrace.
60ifeq ($(BR2_arc),y)
61PERF_MAKE_FLAGS += NO_BACKTRACE=1
62endif
63
64ifeq ($(BR2_PACKAGE_LINUX_TOOLS_PERF_TUI),y)
65PERF_DEPENDENCIES += slang
66else
67PERF_MAKE_FLAGS += NO_NEWT=1 NO_SLANG=1
68endif
69
70ifeq ($(BR2_PACKAGE_AUDIT),y)
71PERF_DEPENDENCIES += audit
72else
73PERF_MAKE_FLAGS += NO_LIBAUDIT=1
74endif
75
76ifeq ($(BR2_PACKAGE_ZSTD),y)
77PERF_DEPENDENCIES += zstd
78endif
79
80ifeq ($(BR2_PACKAGE_LIBUNWIND),y)
81PERF_DEPENDENCIES += libunwind
82else
83PERF_MAKE_FLAGS += NO_LIBUNWIND=1
84endif
85
86ifeq ($(BR2_PACKAGE_NUMACTL),y)
87PERF_DEPENDENCIES += numactl
88else
89PERF_MAKE_FLAGS += NO_LIBNUMA=1
90endif
91
92ifeq ($(BR2_PACKAGE_ELFUTILS),y)
93PERF_DEPENDENCIES += elfutils
94else
95PERF_MAKE_FLAGS += NO_LIBELF=1 NO_DWARF=1
96endif
97
98ifeq ($(BR2_PACKAGE_BINUTILS),y)
99PERF_DEPENDENCIES += binutils
100else
101PERF_MAKE_FLAGS += NO_DEMANGLE=1
102endif
103
104ifeq ($(BR2_PACKAGE_OPENSSL),y)
105PERF_DEPENDENCIES += openssl
106else
107PERF_MAKE_FLAGS += NO_LIBCRYPTO=1
108endif
109
110ifeq ($(BR2_PACKAGE_ZLIB),y)
111PERF_DEPENDENCIES += zlib
112else
113PERF_MAKE_FLAGS += NO_ZLIB=1
114endif
115
116# lzma is provided by xz
117ifeq ($(BR2_PACKAGE_XZ),y)
118PERF_DEPENDENCIES += xz
119else
120PERF_MAKE_FLAGS += NO_LZMA=1
121endif
122
123ifeq ($(BR2_PACKAGE_OPENCSD),y)
124PERF_DEPENDENCIES += opencsd
125PERF_MAKE_FLAGS += CORESIGHT=1
126# There is no "else CORESIGHT=0" case, because "perf" Makefile uses
127# bare "ifdef CORESIGHT" constructs.
128endif
129
130# We really do not want to build the perf documentation, because it
131# has stringent requirement on the documentation generation tools,
132# like xmlto and asciidoc), which may be lagging behind on some
133# distributions.
134# We name it 'GNUmakefile' so that GNU make will use it instead of
135# the existing 'Makefile'.
136define PERF_DISABLE_DOCUMENTATION
137	if [ -f $(LINUX_DIR)/tools/perf/Documentation/Makefile ]; then \
138		printf "%%:\n\t@:\n" >$(LINUX_DIR)/tools/perf/Documentation/GNUmakefile; \
139	fi
140endef
141LINUX_TOOLS_POST_PATCH_HOOKS += PERF_DISABLE_DOCUMENTATION
142
143# O must be redefined here to overwrite the one used by Buildroot for
144# out of tree build. We build perf in $(LINUX_DIR)/tools/perf/ and not just
145# $(LINUX_DIR) so that it isn't built in the root directory of the kernel
146# sources.
147define PERF_BUILD_CMDS
148	$(Q)if test ! -f $(LINUX_DIR)/tools/perf/Makefile ; then \
149		echo "Your kernel version is too old and does not have the perf tool." ; \
150		echo "At least kernel 2.6.31 must be used." ; \
151		exit 1 ; \
152	fi
153	$(Q)if test "$(BR2_PACKAGE_ELFUTILS)" = "" ; then \
154		if ! grep -q NO_LIBELF $(LINUX_DIR)/tools/perf/Makefile* ; then \
155			if ! test -r $(LINUX_DIR)/tools/perf/config/Makefile ; then \
156				echo "The perf tool in your kernel cannot be built without libelf." ; \
157				echo "Either upgrade your kernel to >= 3.7, or enable the elfutils package." ; \
158				exit 1 ; \
159			fi \
160		fi \
161	fi
162	$(Q)if test "$(BR2_PACKAGE_LINUX_TOOLS_PERF_TUI)" = "y" ; then \
163		if ! grep -q NO_SLANG $(LINUX_DIR)/tools/perf/Makefile* ; then \
164			echo "The perf tool in your kernel cannot be build with the TUI." ; \
165			echo "Either upgrade your kernel to >= 3.10, or disable the TUI." ; \
166			exit 1 ; \
167		fi \
168	fi
169	$(TARGET_MAKE_ENV) $(MAKE1) $(PERF_MAKE_FLAGS) \
170		-C $(LINUX_DIR)/tools/perf O=$(LINUX_DIR)/tools/perf/
171endef
172
173# After installation, we remove the Perl and Python scripts from the
174# target unless BR2_PACKAGE_LINUX_TOOLS_PERF_SCRIPTS is enabled
175ifeq ($(BR2_PACKAGE_LINUX_TOOLS_PERF_SCRIPTS),)
176define PERF_INSTALL_REMOVE_SCRIPTS
177	$(RM) -r $(TARGET_DIR)/usr/libexec/perf-core/scripts/
178	$(RM) -r $(TARGET_DIR)/usr/libexec/perf-core/tests/
179endef
180
181LINUX_TOOLS_BIN_ARCH_EXCLUDE += \
182	/usr/libexec/perf-core/tests/pe-file.exe \
183	/usr/libexec/perf-core/tests/pe-file.exe.debug
184endif
185
186define PERF_INSTALL_TARGET_CMDS
187	$(TARGET_MAKE_ENV) $(MAKE1) $(PERF_MAKE_FLAGS) \
188		-C $(LINUX_DIR)/tools/perf O=$(LINUX_DIR)/tools/perf/ install
189	$(PERF_INSTALL_REMOVE_SCRIPTS)
190endef
191
192define PERF_LINUX_CONFIG_FIXUPS
193	$(call KCONFIG_ENABLE_OPT,CONFIG_PERF_EVENTS)
194endef
195