blob: 11fa91764906c503a10f2e93525aefde87bb4d75 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SUMMARY = "Performance analysis tools for Linux"
2DESCRIPTION = "Performance counters for Linux are a new kernel-based \
3subsystem that provide a framework for all things \
4performance analysis. It covers hardware level \
5(CPU/PMU, Performance Monitoring Unit) features \
6and software features (software counters, tracepoints) \
7as well."
Joel Stanleye252c312017-12-14 15:11:12 +10308HOMEPAGE = "https://perf.wiki.kernel.org/index.php/Main_Page"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000010LICENSE = "GPL-2.0-only"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012
Andrew Geissler5082cc72023-09-11 08:41:39 -040013PACKAGECONFIG ??= "python tui libunwind libtraceevent"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080014PACKAGECONFIG[dwarf] = ",NO_DWARF=1"
Andrew Geissler5082cc72023-09-11 08:41:39 -040015PACKAGECONFIG[perl] = ",NO_LIBPERL=1,perl"
16PACKAGECONFIG[python] = ",NO_LIBPYTHON=1,python3 python3-setuptools-native"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017# gui support was added with kernel 3.6.35
18# since 3.10 libnewt was replaced by slang
19# to cover a wide range of kernel we add both dependencies
Joel Stanleye252c312017-12-14 15:11:12 +103020PACKAGECONFIG[tui] = ",NO_NEWT=1,libnewt slang"
21PACKAGECONFIG[libunwind] = ",NO_LIBUNWIND=1 NO_LIBDW_DWARF_UNWIND=1,libunwind"
22PACKAGECONFIG[libnuma] = ",NO_LIBNUMA=1"
Patrick Williams92b42cb2022-09-03 06:53:57 -050023PACKAGECONFIG[bfd] = ",NO_LIBBFD=1"
Joel Stanleye252c312017-12-14 15:11:12 +103024PACKAGECONFIG[systemtap] = ",NO_SDT=1,systemtap"
25PACKAGECONFIG[jvmti] = ",NO_JVMTI=1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040026# libaudit support would need scripting to be enabled
27PACKAGECONFIG[audit] = ",NO_LIBAUDIT=1,audit"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080028PACKAGECONFIG[manpages] = ",,xmlto-native asciidoc-native"
Brad Bishop64c979e2019-11-04 13:55:29 -050029PACKAGECONFIG[cap] = ",,libcap"
Patrick Williamse760df82023-05-26 11:10:49 -050030PACKAGECONFIG[libtraceevent] = ",NO_LIBTRACEEVENT=1,libtraceevent"
Patrick Williamsac13d5f2023-11-24 18:59:46 -060031# jevents requires host python for generating a .c file, but is
32# unrelated to the python item.
33PACKAGECONFIG[jevents] = ",NO_JEVENTS=1,python3-native"
Andrew Geisslerb7d28612020-07-24 16:15:54 -050034# Arm CoreSight
35PACKAGECONFIG[coresight] = "CORESIGHT=1,,opencsd"
Andrew Geissler5082cc72023-09-11 08:41:39 -040036PACKAGECONFIG[pfm4] = ",NO_LIBPFM4=1,libpfm4"
37PACKAGECONFIG[babeltrace] = ",NO_LIBBABELTRACE=1,babeltrace"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080038
39# libunwind is not yet ported for some architectures
Patrick Williams213cb262021-08-07 19:21:33 -050040PACKAGECONFIG:remove:arc = "libunwind"
Patrick Williams213cb262021-08-07 19:21:33 -050041PACKAGECONFIG:remove:riscv32 = "libunwind"
Brad Bishop316dfdd2018-06-25 12:45:53 -040042
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043DEPENDS = " \
44 virtual/${MLPREFIX}libc \
45 ${MLPREFIX}elfutils \
46 ${MLPREFIX}binutils \
Brad Bishop316dfdd2018-06-25 12:45:53 -040047 bison-native flex-native xz \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048"
49
50do_configure[depends] += "virtual/kernel:do_shared_workdir"
51
52PROVIDES = "virtual/perf"
53
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080054inherit linux-kernel-base kernel-arch manpages
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055
56# needed for building the tools/perf Python bindings
Patrick Williams56b44a92024-01-19 08:49:29 -060057inherit_defer ${@bb.utils.contains('PACKAGECONFIG', 'python', 'python3targetconfig', '', d)}
Brad Bishop79641f22019-09-10 07:20:22 -040058inherit python3-dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059export PYTHON_SITEPACKAGES_DIR
60
61#kernel 3.1+ supports WERROR to disable warnings as errors
62export WERROR = "0"
63
Andrew Geissler82c905d2020-04-13 13:39:40 -050064do_populate_lic[depends] += "virtual/kernel:do_shared_workdir"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065
66# needed for building the tools/perf Perl binding
Andrew Geissler5082cc72023-09-11 08:41:39 -040067include ${@bb.utils.contains('PACKAGECONFIG', 'perl', 'perf-perl.inc', '', d)}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068
69inherit kernelsrc
70
Brad Bishop316dfdd2018-06-25 12:45:53 -040071S = "${WORKDIR}/${BP}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072SPDX_S = "${S}/tools/perf"
73
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074# The LDFLAGS is required or some old kernels fails due missing
75# symbols and this is preferred than requiring patches to every old
76# supported kernel.
77LDFLAGS="-ldl -lutil"
78
Patrick Williamsac13d5f2023-11-24 18:59:46 -060079# Perf's build system adds its own optimization flags for most TUs,
80# overriding the flags included here. But for some, perf does not add
81# any -O option, so ensure the distro's chosen optimization gets used
82# for those. Since ${SELECTED_OPTIMIZATION} always includes
83# ${DEBUG_FLAGS} which in turn includes ${DEBUG_PREFIX_MAP}, this also
84# ensures perf is built with appropriate -f*-prefix-map options,
85# avoiding the 'buildpaths' QA warning.
86TARGET_CC_ARCH += "${SELECTED_OPTIMIZATION}"
87
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088EXTRA_OEMAKE = '\
Andrew Geissler635e0e42020-08-21 15:58:33 -050089 V=1 \
Andrew Geissler5082cc72023-09-11 08:41:39 -040090 VF=1 \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 -C ${S}/tools/perf \
92 O=${B} \
93 CROSS_COMPILE=${TARGET_PREFIX} \
94 ARCH=${ARCH} \
95 CC="${CC}" \
Andrew Geissler82c905d2020-04-13 13:39:40 -050096 CCLD="${CC}" \
97 LDSHARED="${CC} -shared" \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098 AR="${AR}" \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060099 LD="${LD}" \
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500100 EXTRA_CFLAGS="-ldw -I${S}" \
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600101 YFLAGS='-y --file-prefix-map=${WORKDIR}=${TARGET_DBGSRC_DIR}' \
Joel Stanleye252c312017-12-14 15:11:12 +1030102 EXTRA_LDFLAGS="${PERF_EXTRA_LDFLAGS}" \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103 perfexecdir=${libexecdir} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800104 NO_GTK2=1 \
Joel Stanleye252c312017-12-14 15:11:12 +1030105 ${PACKAGECONFIG_CONFARGS} \
Patrick Williamse760df82023-05-26 11:10:49 -0500106 PKG_CONFIG=pkg-config \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800107 TMPDIR="${B}" \
Brad Bishop19323692019-04-05 15:28:33 -0400108 LIBUNWIND_DIR=${STAGING_EXECPREFIXDIR} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109'
110
111EXTRA_OEMAKE += "\
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500112 'DESTDIR=${D}' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 'prefix=${prefix}' \
114 'bindir=${bindir}' \
115 'sharedir=${datadir}' \
116 'sysconfdir=${sysconfdir}' \
117 'perfexecdir=${libexecdir}/perf-core' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500118 'ETC_PERFCONFIG=${@os.path.relpath(sysconfdir, prefix)}' \
119 'sharedir=${@os.path.relpath(datadir, prefix)}' \
120 'mandir=${@os.path.relpath(mandir, prefix)}' \
121 'infodir=${@os.path.relpath(infodir, prefix)}' \
Andrew Geissler5082cc72023-09-11 08:41:39 -0400122 ${@bb.utils.contains('PACKAGECONFIG', 'python', 'PYTHON=python3 PYTHON_CONFIG=python3-config', '', d)} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500123"
124
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700125# During do_configure, we might run a 'make clean'. That often breaks
126# when done in parallel, so disable parallelism for do_configure. Note
127# that it has to be done this way rather than by passing -j1, since
128# perf's build system by default ignores any -j argument, but does
129# honour a JOBS variable.
Patrick Williams213cb262021-08-07 19:21:33 -0500130EXTRA_OEMAKE:append:task-configure = " JOBS=1"
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700131
Patrick Williams44b3caf2024-04-12 16:51:14 -0500132# the architectures that need this file can be found in
133# tools/include/uapi/asm/bpf_perf_event.h
134# We are only listing supported arches at the moment
135PERF_BPF_EVENT_SRC ?= '${@bb.utils.contains_any("ARCH", [ "riscv", "arm64" ], "arch/${ARCH}/include/uapi/asm/bpf_perf_event.h", "", d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400136PERF_SRC ?= "Makefile \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400137 tools/arch \
138 tools/build \
139 tools/include \
140 tools/lib \
141 tools/Makefile \
142 tools/perf \
143 tools/scripts \
Brad Bishop64c979e2019-11-04 13:55:29 -0500144 scripts/ \
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600145 arch/arm64/tools \
Patrick Williams44b3caf2024-04-12 16:51:14 -0500146 ${PERF_BPF_EVENT_SRC} \
Brad Bishop64c979e2019-11-04 13:55:29 -0500147 arch/${ARCH}/Makefile \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400148"
149
Joel Stanleye252c312017-12-14 15:11:12 +1030150PERF_EXTRA_LDFLAGS = ""
151
Andrew Geissler595f6302022-01-24 19:11:47 +0000152# MIPS N32/N64
Patrick Williams213cb262021-08-07 19:21:33 -0500153PERF_EXTRA_LDFLAGS:mipsarchn32eb = "-m elf32btsmipn32"
154PERF_EXTRA_LDFLAGS:mipsarchn32el = "-m elf32ltsmipn32"
Andrew Geissler595f6302022-01-24 19:11:47 +0000155PERF_EXTRA_LDFLAGS:mipsarchn64eb = "-m elf64btsmip"
156PERF_EXTRA_LDFLAGS:mipsarchn64el = "-m elf64ltsmip"
Joel Stanleye252c312017-12-14 15:11:12 +1030157
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158do_compile() {
159 # Linux kernel build system is expected to do the right thing
160 unset CFLAGS
Patrick Williamsb542dec2023-06-09 01:26:37 -0500161 test -e ${S}/tools/lib/traceevent/plugins/Makefile && \
162 sed -i -e 's|\$(libdir)/traceevent/plugins|\$(libdir)/traceevent_${KERNEL_VERSION}/plugins|g' ${S}/tools/lib/traceevent/plugins/Makefile
163 test -e ${S}/tools/perf/Makefile.config && \
164 sed -i -e 's|\$(libdir)/traceevent/plugins|\$(libdir)/traceevent_${KERNEL_VERSION}/plugins|g' ${S}/tools/perf/Makefile.config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165 oe_runmake all
166}
167
168do_install() {
169 # Linux kernel build system is expected to do the right thing
170 unset CFLAGS
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500171 oe_runmake install
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172 # we are checking for this make target to be compatible with older perf versions
Andrew Geissler5082cc72023-09-11 08:41:39 -0400173 if ${@bb.utils.contains('PACKAGECONFIG', 'python', 'true', 'false', d)} && grep -q install-python_ext ${S}/tools/perf/Makefile*; then
Brad Bishop79641f22019-09-10 07:20:22 -0400174 oe_runmake DESTDIR=${D} install-python_ext
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500175 if [ -e ${D}${libdir}/python*/site-packages/perf-*/SOURCES.txt ]; then
176 sed -i -e 's#${WORKDIR}##g' ${D}${libdir}/python*/site-packages/perf-*/SOURCES.txt
177 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 fi
179}
180
Brad Bishop316dfdd2018-06-25 12:45:53 -0400181do_configure[prefuncs] += "copy_perf_source_from_kernel"
182python copy_perf_source_from_kernel() {
183 sources = (d.getVar("PERF_SRC") or "").split()
184 src_dir = d.getVar("STAGING_KERNEL_DIR")
185 dest_dir = d.getVar("S")
186 bb.utils.mkdirhier(dest_dir)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500187 bb.utils.prunedir(dest_dir)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400188 for s in sources:
189 src = oe.path.join(src_dir, s)
190 dest = oe.path.join(dest_dir, s)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800191 if not os.path.exists(src):
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600192 bb.warn("Path does not exist: %s. Maybe PERF_SRC lists more files than what your kernel version provides and needs." % src)
193 continue
Brad Bishop316dfdd2018-06-25 12:45:53 -0400194 if os.path.isdir(src):
195 oe.path.copyhardlinktree(src, dest)
196 else:
Brad Bishop64c979e2019-11-04 13:55:29 -0500197 src_path = os.path.dirname(s)
198 os.makedirs(os.path.join(dest_dir,src_path),exist_ok=True)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400199 bb.utils.copyfile(src, dest)
200}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500201
Patrick Williams213cb262021-08-07 19:21:33 -0500202do_configure:prepend () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500203 # If building a multlib based perf, the incorrect library path will be
204 # detected by perf, since it triggers via: ifeq ($(ARCH),x86_64). In a 32 bit
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700205 # build, with a 64 bit multilib, the arch won't match and the detection of a
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 # 64 bit build (and library) are not exected. To ensure that libraries are
207 # installed to the correct location, we can use the weak assignment in the
208 # config/Makefile.
209 #
210 # Also need to relocate .config-detected to $(OUTPUT)/config-detected
211 # for kernel sources that do not already do this
212 # as two builds (e.g. perf and lib32-perf from mutlilib can conflict
213 # with each other if its in the shared source directory
214 #
215 if [ -e "${S}/tools/perf/config/Makefile" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600216 perfconfig="${S}/tools/perf/config/Makefile"
217 fi
218 if [ -e "${S}/tools/perf/Makefile.config" ]; then
219 perfconfig="${S}/tools/perf/Makefile.config"
220 fi
221 if [ -n "${perfconfig}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222 # Match $(prefix)/$(lib) and $(prefix)/lib
223 sed -i -e 's,^libdir = \($(prefix)/.*lib\),libdir ?= \1,' \
224 -e 's,^perfexecdir = \(.*\),perfexecdir ?= \1,' \
225 -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600226 ${perfconfig}
227 fi
228 # The man pages installation is "$(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)"
229 # in ${S}/tools/perf/Documentation/Makefile, if the mandir set to '?=', it
230 # will use the relative path 'share/man', in the way it will resulting in
231 # incorrect installation for man pages.
232 if [ -e "${S}/tools/perf/Documentation/Makefile" ]; then
233 sed -i 's,^mandir?=,mandir:=,' ${S}/tools/perf/Documentation/Makefile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 fi
235 if [ -e "${S}/tools/perf/Makefile.perf" ]; then
236 sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
237 ${S}/tools/perf/Makefile.perf
Patrick Williams03514f12024-04-05 07:04:11 -0500238 # Variant with linux-yocto-specific patch
Patrick Williams92b42cb2022-09-03 06:53:57 -0500239 sed -i -e "s,prefix='\$(DESTDIR_SQ)/usr'$,prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(PYTHON_SITEPACKAGES_DIR)' --root='\$(DESTDIR)',g" \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240 ${S}/tools/perf/Makefile.perf
Patrick Williams03514f12024-04-05 07:04:11 -0500241 # Variant for mainline Linux
242 sed -i -e "s,root='/\$(DESTDIR_SQ)',prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(PYTHON_SITEPACKAGES_DIR)' --root='/\$(DESTDIR_SQ)',g" \
243 ${S}/tools/perf/Makefile.perf
Andrew Geissler635e0e42020-08-21 15:58:33 -0500244 # backport https://github.com/torvalds/linux/commit/e4ffd066ff440a57097e9140fa9e16ceef905de8
245 sed -i -e 's,\($(Q)$(SHELL) .$(arch_errno_tbl).\) $(CC) $(arch_errno_hdr_dir),\1 $(firstword $(CC)) $(arch_errno_hdr_dir),g' \
246 ${S}/tools/perf/Makefile.perf
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247 fi
248 sed -i -e "s,--root='/\$(DESTDIR_SQ)',--prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \
Patrick Williams03514f12024-04-05 07:04:11 -0500249 ${S}/tools/perf/Makefile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500250
251 if [ -e "${S}/tools/build/Makefile.build" ]; then
252 sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
253 ${S}/tools/build/Makefile.build
254 fi
255
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500256 # start reproducibility substitutions
257 if [ -e "${S}/tools/perf/Makefile.config" ]; then
258 # The following line in the Makefle:
259 # override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON_AUTO))
260 # "PYTHON" / "PYTHON_AUTO" have the full path as part of the variable. We've
261 # ensure that the environment is setup and we do not need the full path to be
262 # captured, since the symbol gets built into the executable, making it not
263 # reproducible.
264 sed -i -e 's,$(call get-executable-or-default\,PYTHON\,$(PYTHON_AUTO)),$(notdir $(call get-executable-or-default\,PYTHON\,$(PYTHON_AUTO))),g' \
265 ${S}/tools/perf/Makefile.config
Patrick Williamsdb4c27e2022-08-05 08:10:29 -0500266 # The same line is in older releases, but looking explicitly for Python 2
267 sed -i -e 's,$(call get-executable-or-default\,PYTHON\,$(PYTHON2)),$(notdir $(call get-executable-or-default\,PYTHON\,$(PYTHON2))),g' \
268 ${S}/tools/perf/Makefile.config
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500269
Andrew Geissler615f2f12022-07-15 14:00:58 -0500270 # likewise with this substitution. Kernels with commit 18f2967418d031a39
271 # [perf tools: Use Python devtools for version autodetection rather than runtime]
272 # need this substitution for reproducibility.
273 sed -i -e 's,$(call get-executable-or-default\,PYTHON\,$(subst -config\,\,$(PYTHON_AUTO))),$(notdir $(call get-executable-or-default\,PYTHON\,$(subst -config\,\,$(PYTHON_AUTO)))),g' \
274 ${S}/tools/perf/Makefile.config
275
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500276 # The following line:
277 # srcdir_SQ = $(patsubst %tools/perf,tools/perf,$(subst ','\'',$(srcdir))),
278 # Captures the full src path of perf, which of course makes it not
279 # reproducible. We really only need the relative location 'tools/perf', so we
280 # change the Makefile line to remove everything before 'tools/perf'
281 sed -i -e "s%srcdir_SQ = \$(subst ','\\\'',\$(srcdir))%srcdir_SQ = \$(patsubst \%tools/perf,tools/perf,\$(subst ','\\\'',\$(srcdir)))%g" \
282 ${S}/tools/perf/Makefile.config
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500283 # Avoid hardcoded path to python-native
284 sed -i -e 's#\(PYTHON_WORD := \)$(call shell-wordify,$(PYTHON))#\1 python3#g' \
285 ${S}/tools/perf/Makefile.config
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500286 fi
287 if [ -e "${S}/tools/perf/tests/Build" ]; then
288 # OUTPUT is the full path, we have python on the path so we remove it from the
289 # definition. This is captured in the perf binary, so breaks reproducibility
290 sed -i -e 's,PYTHONPATH="BUILD_STR($(OUTPUT)python)",PYTHONPATH="BUILD_STR(python)",g' \
291 ${S}/tools/perf/tests/Build
292 fi
293 if [ -e "${S}/tools/perf/util/Build" ]; then
294 # To avoid bison generating #ifdefs that have captured paths, we make sure
295 # all the calls have YFLAGS, which contains prefix mapping information.
296 sed -i -e 's,$(BISON),$(BISON) $(YFLAGS),g' ${S}/tools/perf/util/Build
297 fi
298 if [ -e "${S}/scripts/Makefile.host" ]; then
299 # To avoid yacc (bison) generating #ifdefs that have captured paths, we make sure
300 # all the calls have YFLAGS, which contains prefix mapping information.
301 sed -i -e 's,$(YACC),$(YACC) $(YFLAGS),g' ${S}/scripts/Makefile.host
302 fi
303 if [ -e "${S}/tools/perf/pmu-events/Build" ]; then
304 target='$(OUTPUT)pmu-events/pmu-events.c $(V)'
305 replacement1='$(OUTPUT)pmu-events/pmu-events.c $(V)\n'
306 replacement2='\t$(srctree)/sort-pmuevents.py $(OUTPUT)pmu-events/pmu-events.c $(OUTPUT)pmu-events/pmu-events.c.new\n'
307 replacement3='\tcp $(OUTPUT)pmu-events/pmu-events.c.new $(OUTPUT)pmu-events/pmu-events.c'
308 sed -i -e "s,$target,$replacement1$replacement2$replacement3,g" \
309 "${S}/tools/perf/pmu-events/Build"
310 fi
Patrick Williams864cc432023-02-09 14:54:44 -0600311 if [ -e "${S}/tools/perf/pmu-events/jevents.py" ]; then
312 sed -i -e "s#os.scandir(path)#sorted(os.scandir(path), key=lambda e: e.name)#g" \
313 "${S}/tools/perf/pmu-events/jevents.py"
314 fi
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500315 if [ -e "${S}/tools/perf/arch/arm64/Makefile" ]; then
316 sed -i 's,sysdef := $(srctree)/,sysdef := ,' ${S}/tools/perf/arch/arm64/Makefile
317 sed -i 's,$(incpath) $(sysdef),$(incpath) $(srctree)/$(sysdef) $(sysdef),' ${S}/tools/perf/arch/arm64/Makefile
318 fi
319 if [ -e "${S}/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl" ]; then
320 if ! grep -q input_rel ${S}/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl; then
321 sed -i 's,input=$4,input=$4\ninput_rel=$5,' ${S}/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl
322 fi
323 sed -i 's,#include \\"\$input\\",#include \\"\$input_rel\\",' ${S}/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl
324 fi
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500325 # end reproducibility substitutions
326
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500327 # We need to ensure the --sysroot option in CC is preserved
328 if [ -e "${S}/tools/perf/Makefile.perf" ]; then
329 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/perf/Makefile.perf
330 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/perf/Makefile.perf
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600331 sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/perf/Makefile.perf
Patrick Williamse760df82023-05-26 11:10:49 -0500332 sed -i 's,PKG_CONFIG = $(CROSS_COMPILE)pkg-config,#PKG_CONFIG,' ${S}/tools/perf/Makefile.perf
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500333 fi
334 if [ -e "${S}/tools/lib/api/Makefile" ]; then
335 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/api/Makefile
336 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/api/Makefile
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600337 sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/lib/api/Makefile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500339 if [ -e "${S}/tools/lib/subcmd/Makefile" ]; then
340 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/subcmd/Makefile
341 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/subcmd/Makefile
342 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343 if [ -e "${S}/tools/perf/config/feature-checks/Makefile" ]; then
344 sed -i 's,CC := $(CROSS_COMPILE)gcc -MD,CC += -MD,' ${S}/tools/perf/config/feature-checks/Makefile
345 fi
346 if [ -e "${S}/tools/build/Makefile.feature" ]; then
347 sed -i 's,CFLAGS=,CC="\$(CC)" CFLAGS=,' ${S}/tools/build/Makefile.feature
348 fi
Andrew Geissler5082cc72023-09-11 08:41:39 -0400349 # The libperl feature check produces fatal warnings due to -Werror being
350 # used, silence enough errors that the check passes.
351 sed -i 's/\(FLAGS_PERL_EMBED=.*\)/\1 -Wno-error=unused-function -Wno-error=attributes/' ${S}/tools/build/feature/Makefile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352
353 # 3.17-rc1+ has a include issue for arm/powerpc. Temporarily sed in the appropriate include
354 if [ -e "${S}/tools/perf/arch/$ARCH/util/skip-callchain-idx.c" ]; then
355 sed -i 's,#include "util/callchain.h",#include "util/callchain.h"\n#include "util/debug.h",' ${S}/tools/perf/arch/$ARCH/util/skip-callchain-idx.c
356 fi
357 if [ -e "${S}/tools/perf/arch/arm/util/unwind-libunwind.c" ] && [ -e "${S}/tools/perf/arch/arm/tests/dwarf-unwind.c" ]; then
358 sed -i 's,#include "tests/tests.h",#include "tests/tests.h"\n#include "util/debug.h",' ${S}/tools/perf/arch/arm/tests/dwarf-unwind.c
359 sed -i 's,#include "perf_regs.h",#include "perf_regs.h"\n#include "util/debug.h",' ${S}/tools/perf/arch/arm/util/unwind-libunwind.c
360 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500361
362 # use /usr/bin/env instead of version specific python
Andrew Geissler82c905d2020-04-13 13:39:40 -0500363 for s in `find ${S}/tools/perf/ -name '*.py'` `find ${S}/scripts/ -name 'bpf_helpers_doc.py'`; do
364 sed -i -e "s,#!.*python.*,#!${USRBINPATH}/env python3," ${s}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500365 done
Brad Bishop19323692019-04-05 15:28:33 -0400366
367 # unistd.h can be out of sync between libc-headers and the captured version in the perf source
368 # so we copy it from the sysroot unistd.h to the perf unistd.h
Brad Bishopc342db32019-05-15 21:57:59 -0400369 install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/tools/include/uapi/asm-generic/unistd.h
Brad Bishop79641f22019-09-10 07:20:22 -0400370 install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/include/uapi/asm-generic/unistd.h
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500371
372 # the fetcher is inhibited by the 'inherit kernelsrc', so we do a quick check and
373 # copy for a helper script we need
374 for p in $(echo ${FILESPATH} | tr ':' '\n'); do
375 if [ -e $p/sort-pmuevents.py ]; then
376 cp $p/sort-pmuevents.py ${S}
377 fi
378 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500379}
380
Patrick Williams213cb262021-08-07 19:21:33 -0500381python do_package:prepend() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500382 d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500383}
384
385PACKAGE_ARCH = "${MACHINE_ARCH}"
386
387
388PACKAGES =+ "${PN}-archive ${PN}-tests ${PN}-perl ${PN}-python"
389
Patrick Williams213cb262021-08-07 19:21:33 -0500390RDEPENDS:${PN} += "elfutils bash"
391RDEPENDS:${PN}-archive =+ "bash"
392RDEPENDS:${PN}-python =+ "bash python3 python3-modules ${@bb.utils.contains('PACKAGECONFIG', 'audit', 'audit-python', '', d)}"
393RDEPENDS:${PN}-perl =+ "bash perl perl-modules"
Patrick Williams03514f12024-04-05 07:04:11 -0500394RDEPENDS:${PN}-tests =+ "python3 bash perl"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500395
Andrew Geissler5082cc72023-09-11 08:41:39 -0400396RSUGGESTS:${PN} += "${PN}-archive ${PN}-tests \
397 ${@bb.utils.contains('PACKAGECONFIG', 'perl', '${PN}-perl', '', d)} \
398 ${@bb.utils.contains('PACKAGECONFIG', 'python', '${PN}-python', '', d)} \
399 "
Brad Bishop19323692019-04-05 15:28:33 -0400400FILES_SOLIBSDEV = ""
Patrick Williamsb542dec2023-06-09 01:26:37 -0500401FILES:${PN} += "${libexecdir}/perf-core ${exec_prefix}/libexec/perf-core ${libdir}/traceevent* ${libdir}/libperf-jvmti.so"
Patrick Williams213cb262021-08-07 19:21:33 -0500402FILES:${PN}-archive = "${libdir}/perf/perf-core/perf-archive"
403FILES:${PN}-tests = "${libdir}/perf/perf-core/tests ${libexecdir}/perf-core/tests"
404FILES:${PN}-python = " \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400405 ${PYTHON_SITEPACKAGES_DIR} \
406 ${libexecdir}/perf-core/scripts/python \
407 "
Patrick Williams213cb262021-08-07 19:21:33 -0500408FILES:${PN}-perl = "${libexecdir}/perf-core/scripts/perl"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409
Patrick Williams213cb262021-08-07 19:21:33 -0500410DEBUG_OPTIMIZATION:append = " -Wno-error=maybe-uninitialized"
Patrick Williams864cc432023-02-09 14:54:44 -0600411
412PACKAGESPLITFUNCS =+ "perf_fix_sources"
413
414perf_fix_sources () {
415 for f in util/parse-events-flex.h util/parse-events-flex.c util/pmu-flex.c \
Andrew Geissler8f840682023-07-21 09:09:43 -0500416 util/pmu-flex.h util/expr-flex.h util/expr-flex.c; do
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600417 f=${PKGD}${TARGET_DBGSRC_DIR}/$f
Patrick Williams864cc432023-02-09 14:54:44 -0600418 if [ -e $f ]; then
419 sed -i -e 's#${S}/##g' $f
420 fi
421 done
422}