xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-kernel/perf/perf.bb (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunSUMMARY = "Performance analysis tools for Linux"
2*4882a593SmuzhiyunDESCRIPTION = "Performance counters for Linux are a new kernel-based \
3*4882a593Smuzhiyunsubsystem that provide a framework for all things \
4*4882a593Smuzhiyunperformance analysis. It covers hardware level \
5*4882a593Smuzhiyun(CPU/PMU, Performance Monitoring Unit) features \
6*4882a593Smuzhiyunand software features (software counters, tracepoints) \
7*4882a593Smuzhiyunas well."
8*4882a593SmuzhiyunHOMEPAGE = "https://perf.wiki.kernel.org/index.php/Main_Page"
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunLICENSE = "GPL-2.0-only"
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunPR = "r9"
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunPACKAGECONFIG ??= "scripting tui libunwind"
15*4882a593SmuzhiyunPACKAGECONFIG[dwarf] = ",NO_DWARF=1"
16*4882a593SmuzhiyunPACKAGECONFIG[scripting] = ",NO_LIBPERL=1 NO_LIBPYTHON=1,perl python3 python3-setuptools-native"
17*4882a593Smuzhiyun# gui support was added with kernel 3.6.35
18*4882a593Smuzhiyun# since 3.10 libnewt was replaced by slang
19*4882a593Smuzhiyun# to cover a wide range of kernel we add both dependencies
20*4882a593SmuzhiyunPACKAGECONFIG[tui] = ",NO_NEWT=1,libnewt slang"
21*4882a593SmuzhiyunPACKAGECONFIG[libunwind] = ",NO_LIBUNWIND=1 NO_LIBDW_DWARF_UNWIND=1,libunwind"
22*4882a593SmuzhiyunPACKAGECONFIG[libnuma] = ",NO_LIBNUMA=1"
23*4882a593SmuzhiyunPACKAGECONFIG[systemtap] = ",NO_SDT=1,systemtap"
24*4882a593SmuzhiyunPACKAGECONFIG[jvmti] = ",NO_JVMTI=1"
25*4882a593Smuzhiyun# libaudit support would need scripting to be enabled
26*4882a593SmuzhiyunPACKAGECONFIG[audit] = ",NO_LIBAUDIT=1,audit"
27*4882a593SmuzhiyunPACKAGECONFIG[manpages] = ",,xmlto-native asciidoc-native"
28*4882a593SmuzhiyunPACKAGECONFIG[cap] = ",,libcap"
29*4882a593Smuzhiyun# Arm CoreSight
30*4882a593SmuzhiyunPACKAGECONFIG[coresight] = "CORESIGHT=1,,opencsd"
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun# libunwind is not yet ported for some architectures
33*4882a593SmuzhiyunPACKAGECONFIG:remove:arc = "libunwind"
34*4882a593SmuzhiyunPACKAGECONFIG:remove:riscv32 = "libunwind"
35*4882a593Smuzhiyun
36*4882a593SmuzhiyunDEPENDS = " \
37*4882a593Smuzhiyun    virtual/${MLPREFIX}libc \
38*4882a593Smuzhiyun    ${MLPREFIX}elfutils \
39*4882a593Smuzhiyun    ${MLPREFIX}binutils \
40*4882a593Smuzhiyun    bison-native flex-native xz \
41*4882a593Smuzhiyun"
42*4882a593Smuzhiyun
43*4882a593Smuzhiyundo_configure[depends] += "virtual/kernel:do_shared_workdir"
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunPROVIDES = "virtual/perf"
46*4882a593Smuzhiyun
47*4882a593Smuzhiyuninherit linux-kernel-base kernel-arch manpages
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun# needed for building the tools/perf Python bindings
50*4882a593Smuzhiyuninherit ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'python3targetconfig', '', d)}
51*4882a593Smuzhiyuninherit python3-dir
52*4882a593Smuzhiyunexport PYTHON_SITEPACKAGES_DIR
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun#kernel 3.1+ supports WERROR to disable warnings as errors
55*4882a593Smuzhiyunexport WERROR = "0"
56*4882a593Smuzhiyun
57*4882a593Smuzhiyundo_populate_lic[depends] += "virtual/kernel:do_shared_workdir"
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun# needed for building the tools/perf Perl binding
60*4882a593Smuzhiyuninclude ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'perf-perl.inc', '', d)}
61*4882a593Smuzhiyun
62*4882a593Smuzhiyuninherit kernelsrc
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunS = "${WORKDIR}/${BP}"
65*4882a593SmuzhiyunSPDX_S = "${S}/tools/perf"
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun# The LDFLAGS is required or some old kernels fails due missing
68*4882a593Smuzhiyun# symbols and this is preferred than requiring patches to every old
69*4882a593Smuzhiyun# supported kernel.
70*4882a593SmuzhiyunLDFLAGS="-ldl -lutil"
71*4882a593Smuzhiyun
72*4882a593SmuzhiyunEXTRA_OEMAKE = '\
73*4882a593Smuzhiyun    V=1 \
74*4882a593Smuzhiyun    -C ${S}/tools/perf \
75*4882a593Smuzhiyun    O=${B} \
76*4882a593Smuzhiyun    CROSS_COMPILE=${TARGET_PREFIX} \
77*4882a593Smuzhiyun    ARCH=${ARCH} \
78*4882a593Smuzhiyun    CC="${CC}" \
79*4882a593Smuzhiyun    CCLD="${CC}" \
80*4882a593Smuzhiyun    LDSHARED="${CC} -shared" \
81*4882a593Smuzhiyun    AR="${AR}" \
82*4882a593Smuzhiyun    LD="${LD}" \
83*4882a593Smuzhiyun    EXTRA_CFLAGS="-ldw" \
84*4882a593Smuzhiyun    YFLAGS='-y --file-prefix-map=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}' \
85*4882a593Smuzhiyun    EXTRA_LDFLAGS="${PERF_EXTRA_LDFLAGS}" \
86*4882a593Smuzhiyun    perfexecdir=${libexecdir} \
87*4882a593Smuzhiyun    NO_GTK2=1 \
88*4882a593Smuzhiyun    ${PACKAGECONFIG_CONFARGS} \
89*4882a593Smuzhiyun    TMPDIR="${B}" \
90*4882a593Smuzhiyun    LIBUNWIND_DIR=${STAGING_EXECPREFIXDIR} \
91*4882a593Smuzhiyun'
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunEXTRA_OEMAKE += "\
94*4882a593Smuzhiyun    'DESTDIR=${D}' \
95*4882a593Smuzhiyun    'prefix=${prefix}' \
96*4882a593Smuzhiyun    'bindir=${bindir}' \
97*4882a593Smuzhiyun    'sharedir=${datadir}' \
98*4882a593Smuzhiyun    'sysconfdir=${sysconfdir}' \
99*4882a593Smuzhiyun    'perfexecdir=${libexecdir}/perf-core' \
100*4882a593Smuzhiyun    'ETC_PERFCONFIG=${@os.path.relpath(sysconfdir, prefix)}' \
101*4882a593Smuzhiyun    'sharedir=${@os.path.relpath(datadir, prefix)}' \
102*4882a593Smuzhiyun    'mandir=${@os.path.relpath(mandir, prefix)}' \
103*4882a593Smuzhiyun    'infodir=${@os.path.relpath(infodir, prefix)}' \
104*4882a593Smuzhiyun    ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'PYTHON=python3 PYTHON_CONFIG=python3-config', '', d)} \
105*4882a593Smuzhiyun"
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun# During do_configure, we might run a 'make clean'. That often breaks
108*4882a593Smuzhiyun# when done in parallel, so disable parallelism for do_configure. Note
109*4882a593Smuzhiyun# that it has to be done this way rather than by passing -j1, since
110*4882a593Smuzhiyun# perf's build system by default ignores any -j argument, but does
111*4882a593Smuzhiyun# honour a JOBS variable.
112*4882a593SmuzhiyunEXTRA_OEMAKE:append:task-configure = " JOBS=1"
113*4882a593Smuzhiyun
114*4882a593SmuzhiyunPERF_SRC ?= "Makefile \
115*4882a593Smuzhiyun             tools/arch \
116*4882a593Smuzhiyun             tools/build \
117*4882a593Smuzhiyun             tools/include \
118*4882a593Smuzhiyun             tools/lib \
119*4882a593Smuzhiyun             tools/Makefile \
120*4882a593Smuzhiyun             tools/perf \
121*4882a593Smuzhiyun             tools/scripts \
122*4882a593Smuzhiyun             scripts/ \
123*4882a593Smuzhiyun             arch/${ARCH}/Makefile \
124*4882a593Smuzhiyun"
125*4882a593Smuzhiyun
126*4882a593SmuzhiyunPERF_EXTRA_LDFLAGS = ""
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun# MIPS N32/N64
129*4882a593SmuzhiyunPERF_EXTRA_LDFLAGS:mipsarchn32eb = "-m elf32btsmipn32"
130*4882a593SmuzhiyunPERF_EXTRA_LDFLAGS:mipsarchn32el = "-m elf32ltsmipn32"
131*4882a593SmuzhiyunPERF_EXTRA_LDFLAGS:mipsarchn64eb = "-m elf64btsmip"
132*4882a593SmuzhiyunPERF_EXTRA_LDFLAGS:mipsarchn64el = "-m elf64ltsmip"
133*4882a593Smuzhiyun
134*4882a593Smuzhiyundo_compile() {
135*4882a593Smuzhiyun	# Linux kernel build system is expected to do the right thing
136*4882a593Smuzhiyun	unset CFLAGS
137*4882a593Smuzhiyun	oe_runmake all
138*4882a593Smuzhiyun}
139*4882a593Smuzhiyun
140*4882a593Smuzhiyundo_install() {
141*4882a593Smuzhiyun	# Linux kernel build system is expected to do the right thing
142*4882a593Smuzhiyun	unset CFLAGS
143*4882a593Smuzhiyun	oe_runmake install
144*4882a593Smuzhiyun	# we are checking for this make target to be compatible with older perf versions
145*4882a593Smuzhiyun	if ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'true', 'false', d)} && grep -q install-python_ext ${S}/tools/perf/Makefile*; then
146*4882a593Smuzhiyun	    oe_runmake DESTDIR=${D} install-python_ext
147*4882a593Smuzhiyun	    if [ -e ${D}${libdir}/python*/site-packages/perf-*/SOURCES.txt ]; then
148*4882a593Smuzhiyun		sed -i -e 's#${WORKDIR}##g' ${D}${libdir}/python*/site-packages/perf-*/SOURCES.txt
149*4882a593Smuzhiyun	    fi
150*4882a593Smuzhiyun	fi
151*4882a593Smuzhiyun}
152*4882a593Smuzhiyun
153*4882a593Smuzhiyundo_configure[prefuncs] += "copy_perf_source_from_kernel"
154*4882a593Smuzhiyunpython copy_perf_source_from_kernel() {
155*4882a593Smuzhiyun    sources = (d.getVar("PERF_SRC") or "").split()
156*4882a593Smuzhiyun    src_dir = d.getVar("STAGING_KERNEL_DIR")
157*4882a593Smuzhiyun    dest_dir = d.getVar("S")
158*4882a593Smuzhiyun    bb.utils.mkdirhier(dest_dir)
159*4882a593Smuzhiyun    bb.utils.prunedir(dest_dir)
160*4882a593Smuzhiyun    for s in sources:
161*4882a593Smuzhiyun        src = oe.path.join(src_dir, s)
162*4882a593Smuzhiyun        dest = oe.path.join(dest_dir, s)
163*4882a593Smuzhiyun        if not os.path.exists(src):
164*4882a593Smuzhiyun            bb.fatal("Path does not exist: %s. Maybe PERF_SRC does not match the kernel version." % src)
165*4882a593Smuzhiyun        if os.path.isdir(src):
166*4882a593Smuzhiyun            oe.path.copyhardlinktree(src, dest)
167*4882a593Smuzhiyun        else:
168*4882a593Smuzhiyun            src_path = os.path.dirname(s)
169*4882a593Smuzhiyun            os.makedirs(os.path.join(dest_dir,src_path),exist_ok=True)
170*4882a593Smuzhiyun            bb.utils.copyfile(src, dest)
171*4882a593Smuzhiyun}
172*4882a593Smuzhiyun
173*4882a593Smuzhiyundo_configure:prepend () {
174*4882a593Smuzhiyun    # If building a multlib based perf, the incorrect library path will be
175*4882a593Smuzhiyun    # detected by perf, since it triggers via: ifeq ($(ARCH),x86_64). In a 32 bit
176*4882a593Smuzhiyun    # build, with a 64 bit multilib, the arch won't match and the detection of a
177*4882a593Smuzhiyun    # 64 bit build (and library) are not exected. To ensure that libraries are
178*4882a593Smuzhiyun    # installed to the correct location, we can use the weak assignment in the
179*4882a593Smuzhiyun    # config/Makefile.
180*4882a593Smuzhiyun    #
181*4882a593Smuzhiyun    # Also need to relocate .config-detected to $(OUTPUT)/config-detected
182*4882a593Smuzhiyun    # for kernel sources that do not already do this
183*4882a593Smuzhiyun    # as two builds (e.g. perf and lib32-perf from mutlilib can conflict
184*4882a593Smuzhiyun    # with each other if its in the shared source directory
185*4882a593Smuzhiyun    #
186*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/config/Makefile" ]; then
187*4882a593Smuzhiyun        perfconfig="${S}/tools/perf/config/Makefile"
188*4882a593Smuzhiyun    fi
189*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/Makefile.config" ]; then
190*4882a593Smuzhiyun        perfconfig="${S}/tools/perf/Makefile.config"
191*4882a593Smuzhiyun    fi
192*4882a593Smuzhiyun    if [ -n "${perfconfig}" ]; then
193*4882a593Smuzhiyun        # Match $(prefix)/$(lib) and $(prefix)/lib
194*4882a593Smuzhiyun        sed -i -e 's,^libdir = \($(prefix)/.*lib\),libdir ?= \1,' \
195*4882a593Smuzhiyun               -e 's,^perfexecdir = \(.*\),perfexecdir ?= \1,' \
196*4882a593Smuzhiyun               -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
197*4882a593Smuzhiyun            ${perfconfig}
198*4882a593Smuzhiyun    fi
199*4882a593Smuzhiyun    # The man pages installation is "$(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)"
200*4882a593Smuzhiyun    # in ${S}/tools/perf/Documentation/Makefile, if the mandir set to '?=', it
201*4882a593Smuzhiyun    # will use the relative path 'share/man', in the way it will resulting in
202*4882a593Smuzhiyun    # incorrect installation for man pages.
203*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/Documentation/Makefile" ]; then
204*4882a593Smuzhiyun	sed -i 's,^mandir?=,mandir:=,' ${S}/tools/perf/Documentation/Makefile
205*4882a593Smuzhiyun    fi
206*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/Makefile.perf" ]; then
207*4882a593Smuzhiyun        sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
208*4882a593Smuzhiyun            ${S}/tools/perf/Makefile.perf
209*4882a593Smuzhiyun        sed -i -e "s,prefix='\$(DESTDIR_SQ)/usr'$,prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(PYTHON_SITEPACKAGES_DIR)' --root='\$(DESTDIR)',g" \
210*4882a593Smuzhiyun            ${S}/tools/perf/Makefile.perf
211*4882a593Smuzhiyun        # backport https://github.com/torvalds/linux/commit/e4ffd066ff440a57097e9140fa9e16ceef905de8
212*4882a593Smuzhiyun        sed -i -e 's,\($(Q)$(SHELL) .$(arch_errno_tbl).\) $(CC) $(arch_errno_hdr_dir),\1 $(firstword $(CC)) $(arch_errno_hdr_dir),g' \
213*4882a593Smuzhiyun            ${S}/tools/perf/Makefile.perf
214*4882a593Smuzhiyun    fi
215*4882a593Smuzhiyun    sed -i -e "s,--root='/\$(DESTDIR_SQ)',--prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \
216*4882a593Smuzhiyun        ${S}/tools/perf/Makefile*
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun    if [ -e "${S}/tools/build/Makefile.build" ]; then
219*4882a593Smuzhiyun        sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
220*4882a593Smuzhiyun            ${S}/tools/build/Makefile.build
221*4882a593Smuzhiyun    fi
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun    # start reproducibility substitutions
224*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/Makefile.config" ]; then
225*4882a593Smuzhiyun        # The following line in the Makefle:
226*4882a593Smuzhiyun        #     override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON_AUTO))
227*4882a593Smuzhiyun        # "PYTHON" / "PYTHON_AUTO" have the full path as part of the variable. We've
228*4882a593Smuzhiyun        # ensure that the environment is setup and we do not need the full path to be
229*4882a593Smuzhiyun        # captured, since the symbol gets built into the executable, making it not
230*4882a593Smuzhiyun        # reproducible.
231*4882a593Smuzhiyun        sed -i -e 's,$(call get-executable-or-default\,PYTHON\,$(PYTHON_AUTO)),$(notdir $(call get-executable-or-default\,PYTHON\,$(PYTHON_AUTO))),g' \
232*4882a593Smuzhiyun            ${S}/tools/perf/Makefile.config
233*4882a593Smuzhiyun        # The same line is in older releases, but looking explicitly for Python 2
234*4882a593Smuzhiyun        sed -i -e 's,$(call get-executable-or-default\,PYTHON\,$(PYTHON2)),$(notdir $(call get-executable-or-default\,PYTHON\,$(PYTHON2))),g' \
235*4882a593Smuzhiyun            ${S}/tools/perf/Makefile.config
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun	# likewise with this substitution. Kernels with commit 18f2967418d031a39
238*4882a593Smuzhiyun	# [perf tools: Use Python devtools for version autodetection rather than runtime]
239*4882a593Smuzhiyun	# need this substitution for reproducibility.
240*4882a593Smuzhiyun	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' \
241*4882a593Smuzhiyun	    ${S}/tools/perf/Makefile.config
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun        # The following line:
244*4882a593Smuzhiyun        #     srcdir_SQ = $(patsubst %tools/perf,tools/perf,$(subst ','\'',$(srcdir))),
245*4882a593Smuzhiyun        # Captures the full src path of perf, which of course makes it not
246*4882a593Smuzhiyun        # reproducible. We really only need the relative location 'tools/perf', so we
247*4882a593Smuzhiyun        # change the Makefile line to remove everything before 'tools/perf'
248*4882a593Smuzhiyun        sed -i -e "s%srcdir_SQ = \$(subst ','\\\'',\$(srcdir))%srcdir_SQ = \$(patsubst \%tools/perf,tools/perf,\$(subst ','\\\'',\$(srcdir)))%g" \
249*4882a593Smuzhiyun            ${S}/tools/perf/Makefile.config
250*4882a593Smuzhiyun        # Avoid hardcoded path to python-native
251*4882a593Smuzhiyun        sed -i -e 's#\(PYTHON_WORD := \)$(call shell-wordify,$(PYTHON))#\1 python3#g' \
252*4882a593Smuzhiyun            ${S}/tools/perf/Makefile.config
253*4882a593Smuzhiyun    fi
254*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/tests/Build" ]; then
255*4882a593Smuzhiyun        # OUTPUT is the full path, we have python on the path so we remove it from the
256*4882a593Smuzhiyun        # definition. This is captured in the perf binary, so breaks reproducibility
257*4882a593Smuzhiyun        sed -i -e 's,PYTHONPATH="BUILD_STR($(OUTPUT)python)",PYTHONPATH="BUILD_STR(python)",g' \
258*4882a593Smuzhiyun            ${S}/tools/perf/tests/Build
259*4882a593Smuzhiyun    fi
260*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/util/Build" ]; then
261*4882a593Smuzhiyun        # To avoid bison generating #ifdefs that have captured paths, we make sure
262*4882a593Smuzhiyun        # all the calls have YFLAGS, which contains prefix mapping information.
263*4882a593Smuzhiyun        sed -i -e 's,$(BISON),$(BISON) $(YFLAGS),g' ${S}/tools/perf/util/Build
264*4882a593Smuzhiyun    fi
265*4882a593Smuzhiyun    if [ -e "${S}/scripts/Makefile.host" ]; then
266*4882a593Smuzhiyun        # To avoid yacc (bison) generating #ifdefs that have captured paths, we make sure
267*4882a593Smuzhiyun        # all the calls have YFLAGS, which contains prefix mapping information.
268*4882a593Smuzhiyun        sed -i -e 's,$(YACC),$(YACC) $(YFLAGS),g' ${S}/scripts/Makefile.host
269*4882a593Smuzhiyun    fi
270*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/pmu-events/Build" ]; then
271*4882a593Smuzhiyun        target='$(OUTPUT)pmu-events/pmu-events.c $(V)'
272*4882a593Smuzhiyun        replacement1='$(OUTPUT)pmu-events/pmu-events.c $(V)\n'
273*4882a593Smuzhiyun        replacement2='\t$(srctree)/sort-pmuevents.py $(OUTPUT)pmu-events/pmu-events.c $(OUTPUT)pmu-events/pmu-events.c.new\n'
274*4882a593Smuzhiyun        replacement3='\tcp $(OUTPUT)pmu-events/pmu-events.c.new $(OUTPUT)pmu-events/pmu-events.c'
275*4882a593Smuzhiyun        sed -i -e "s,$target,$replacement1$replacement2$replacement3,g" \
276*4882a593Smuzhiyun                       "${S}/tools/perf/pmu-events/Build"
277*4882a593Smuzhiyun    fi
278*4882a593Smuzhiyun    # end reproducibility substitutions
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun    # We need to ensure the --sysroot option in CC is preserved
281*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/Makefile.perf" ]; then
282*4882a593Smuzhiyun        sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/perf/Makefile.perf
283*4882a593Smuzhiyun        sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/perf/Makefile.perf
284*4882a593Smuzhiyun        sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/perf/Makefile.perf
285*4882a593Smuzhiyun    fi
286*4882a593Smuzhiyun    if [ -e "${S}/tools/lib/api/Makefile" ]; then
287*4882a593Smuzhiyun        sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/api/Makefile
288*4882a593Smuzhiyun        sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/api/Makefile
289*4882a593Smuzhiyun        sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/lib/api/Makefile
290*4882a593Smuzhiyun    fi
291*4882a593Smuzhiyun    if [ -e "${S}/tools/lib/subcmd/Makefile" ]; then
292*4882a593Smuzhiyun        sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/subcmd/Makefile
293*4882a593Smuzhiyun        sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/subcmd/Makefile
294*4882a593Smuzhiyun    fi
295*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/config/feature-checks/Makefile" ]; then
296*4882a593Smuzhiyun        sed -i 's,CC := $(CROSS_COMPILE)gcc -MD,CC += -MD,' ${S}/tools/perf/config/feature-checks/Makefile
297*4882a593Smuzhiyun    fi
298*4882a593Smuzhiyun    if [ -e "${S}/tools/build/Makefile.feature" ]; then
299*4882a593Smuzhiyun        sed -i 's,CFLAGS=,CC="\$(CC)" CFLAGS=,' ${S}/tools/build/Makefile.feature
300*4882a593Smuzhiyun    fi
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun    # 3.17-rc1+ has a include issue for arm/powerpc. Temporarily sed in the appropriate include
303*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/arch/$ARCH/util/skip-callchain-idx.c" ]; then
304*4882a593Smuzhiyun        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
305*4882a593Smuzhiyun    fi
306*4882a593Smuzhiyun    if [ -e "${S}/tools/perf/arch/arm/util/unwind-libunwind.c" ] && [ -e "${S}/tools/perf/arch/arm/tests/dwarf-unwind.c" ]; then
307*4882a593Smuzhiyun        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
308*4882a593Smuzhiyun        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
309*4882a593Smuzhiyun    fi
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun    # use /usr/bin/env instead of version specific python
312*4882a593Smuzhiyun    for s in `find ${S}/tools/perf/ -name '*.py'` `find ${S}/scripts/ -name 'bpf_helpers_doc.py'`; do
313*4882a593Smuzhiyun        sed -i -e "s,#!.*python.*,#!${USRBINPATH}/env python3," ${s}
314*4882a593Smuzhiyun    done
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun    # unistd.h can be out of sync between libc-headers and the captured version in the perf source
317*4882a593Smuzhiyun    # so we copy it from the sysroot unistd.h to the perf unistd.h
318*4882a593Smuzhiyun    install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/tools/include/uapi/asm-generic/unistd.h
319*4882a593Smuzhiyun    install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/include/uapi/asm-generic/unistd.h
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun    # the fetcher is inhibited by the 'inherit kernelsrc', so we do a quick check and
322*4882a593Smuzhiyun    # copy for a helper script we need
323*4882a593Smuzhiyun    for p in $(echo ${FILESPATH} | tr ':' '\n'); do
324*4882a593Smuzhiyun	if [ -e $p/sort-pmuevents.py ]; then
325*4882a593Smuzhiyun	    cp $p/sort-pmuevents.py ${S}
326*4882a593Smuzhiyun	fi
327*4882a593Smuzhiyun    done
328*4882a593Smuzhiyun}
329*4882a593Smuzhiyun
330*4882a593Smuzhiyunpython do_package:prepend() {
331*4882a593Smuzhiyun    d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0])
332*4882a593Smuzhiyun}
333*4882a593Smuzhiyun
334*4882a593SmuzhiyunPACKAGE_ARCH = "${MACHINE_ARCH}"
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun
337*4882a593SmuzhiyunPACKAGES =+ "${PN}-archive ${PN}-tests ${PN}-perl ${PN}-python"
338*4882a593Smuzhiyun
339*4882a593SmuzhiyunRDEPENDS:${PN} += "elfutils bash"
340*4882a593SmuzhiyunRDEPENDS:${PN}-archive =+ "bash"
341*4882a593SmuzhiyunRDEPENDS:${PN}-python =+ "bash python3 python3-modules ${@bb.utils.contains('PACKAGECONFIG', 'audit', 'audit-python', '', d)}"
342*4882a593SmuzhiyunRDEPENDS:${PN}-perl =+ "bash perl perl-modules"
343*4882a593SmuzhiyunRDEPENDS:${PN}-tests =+ "python3 bash"
344*4882a593Smuzhiyun
345*4882a593SmuzhiyunRSUGGESTS_SCRIPTING = "${@bb.utils.contains('PACKAGECONFIG', 'scripting', '${PN}-perl ${PN}-python', '',d)}"
346*4882a593SmuzhiyunRSUGGESTS:${PN} += "${PN}-archive ${PN}-tests ${RSUGGESTS_SCRIPTING}"
347*4882a593Smuzhiyun
348*4882a593SmuzhiyunFILES_SOLIBSDEV = ""
349*4882a593SmuzhiyunFILES:${PN} += "${libexecdir}/perf-core ${exec_prefix}/libexec/perf-core ${libdir}/traceevent ${libdir}/libperf-jvmti.so"
350*4882a593SmuzhiyunFILES:${PN}-archive = "${libdir}/perf/perf-core/perf-archive"
351*4882a593SmuzhiyunFILES:${PN}-tests = "${libdir}/perf/perf-core/tests ${libexecdir}/perf-core/tests"
352*4882a593SmuzhiyunFILES:${PN}-python = " \
353*4882a593Smuzhiyun                       ${PYTHON_SITEPACKAGES_DIR} \
354*4882a593Smuzhiyun                       ${libexecdir}/perf-core/scripts/python \
355*4882a593Smuzhiyun                       "
356*4882a593SmuzhiyunFILES:${PN}-perl = "${libexecdir}/perf-core/scripts/perl"
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun
359*4882a593SmuzhiyunINHIBIT_PACKAGE_DEBUG_SPLIT="1"
360*4882a593SmuzhiyunDEBUG_OPTIMIZATION:append = " -Wno-error=maybe-uninitialized"
361