virtual/perl-Parse-CPAN-Meta: keyword ~riscv
[gentoo.git] / dev-util / perf / perf-4.20.3.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python2_7 )
7 inherit bash-completion-r1 estack eutils toolchain-funcs python-single-r1 linux-info
8
9 MY_PV="${PV/_/-}"
10 MY_PV="${MY_PV/-pre/-git}"
11
12 DESCRIPTION="Userland tools for Linux Performance Counters"
13 HOMEPAGE="https://perf.wiki.kernel.org/"
14
15 LINUX_V="${PV:0:1}.x"
16 if [[ ${PV} == *_rc* ]] ; then
17         LINUX_VER=$(ver_cut 1-2).$(($(ver_cut 3)-1))
18         PATCH_VERSION=$(ver_cut 1-3)
19         LINUX_PATCH=patch-${PV//_/-}.xz
20         SRC_URI="mirror://kernel/linux/kernel/v${LINUX_V}/testing/${LINUX_PATCH}
21                 mirror://kernel/linux/kernel/v${LINUX_V}/testing/v${PATCH_VERSION}/${LINUX_PATCH}"
22 elif [[ ${PV} == *.*.* ]] ; then
23         # stable-release series
24         LINUX_VER=$(ver_cut 1-2)
25         LINUX_PATCH=patch-${PV}.xz
26         SRC_URI="mirror://kernel/linux/kernel/v${LINUX_V}/${LINUX_PATCH}"
27 else
28         LINUX_VER=${PV}
29         SRC_URI=""
30 fi
31
32 LINUX_SOURCES="linux-${LINUX_VER}.tar.xz"
33 SRC_URI+=" mirror://kernel/linux/kernel/v${LINUX_V}/${LINUX_SOURCES}"
34
35 LICENSE="GPL-2"
36 SLOT="0"
37 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~mips ~ppc ~ppc64 ~x86 ~amd64-linux ~x86-linux"
38 IUSE="audit clang crypt debug +demangle +doc gtk java lzma numa perl python slang systemtap unwind zlib"
39 # TODO babeltrace
40 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
41
42 RDEPEND="audit? ( sys-process/audit )
43         crypt? ( dev-libs/openssl:0= )
44         clang? (
45                 sys-devel/clang:*
46                 sys-devel/llvm:*
47         )
48         demangle? ( sys-libs/binutils-libs:= )
49         gtk? ( x11-libs/gtk+:2 )
50         java? ( virtual/jre:* )
51         lzma? ( app-arch/xz-utils )
52         numa? ( sys-process/numactl )
53         perl? ( dev-lang/perl )
54         python? ( ${PYTHON_DEPS} )
55         slang? ( sys-libs/slang )
56         systemtap? ( dev-util/systemtap )
57         unwind? ( sys-libs/libunwind )
58         zlib? ( sys-libs/zlib )
59         dev-libs/elfutils"
60 DEPEND="${RDEPEND}
61         >=sys-kernel/linux-headers-4.19
62         ${LINUX_PATCH+dev-util/patchutils}
63         sys-devel/bison
64         sys-devel/flex
65         java? ( virtual/jdk )
66         doc? (
67                 app-text/asciidoc
68                 app-text/sgml-common
69                 app-text/xmlto
70                 sys-process/time
71         )"
72
73 S_K="${WORKDIR}/linux-${LINUX_VER}"
74 S="${S_K}/tools/perf"
75
76 CONFIG_CHECK="~PERF_EVENTS ~KALLSYMS"
77
78 pkg_setup() {
79         linux-info_pkg_setup
80         use python && python-single-r1_pkg_setup
81 }
82
83 src_unpack() {
84         local paths=(
85                 tools/arch tools/build tools/include tools/lib tools/perf tools/scripts
86                 include lib "arch/*/lib"
87         )
88
89         # We expect the tar implementation to support the -j option (both
90         # GNU tar and libarchive's tar support that).
91         echo ">>> Unpacking ${LINUX_SOURCES} (${paths[*]}) to ${PWD}"
92         tar --wildcards -xpf "${DISTDIR}"/${LINUX_SOURCES} \
93                 "${paths[@]/#/linux-${LINUX_VER}/}" || die
94
95         if [[ -n ${LINUX_PATCH} ]] ; then
96                 eshopts_push -o noglob
97                 ebegin "Filtering partial source patch"
98                 filterdiff -p1 ${paths[@]/#/-i } -z "${DISTDIR}"/${LINUX_PATCH} \
99                         > ${P}.patch
100                 eend $? || die "filterdiff failed"
101                 eshopts_pop
102         fi
103
104         local a
105         for a in ${A}; do
106                 [[ ${a} == ${LINUX_SOURCES} ]] && continue
107                 [[ ${a} == ${LINUX_PATCH} ]] && continue
108                 unpack ${a}
109         done
110 }
111
112 src_prepare() {
113         default
114         if [[ -n ${LINUX_PATCH} ]] ; then
115                 cd "${S_K}"
116                 eapply "${WORKDIR}"/${P}.patch
117         fi
118
119         # Drop some upstream too-developer-oriented flags and fix the
120         # Makefile in general
121         sed -i \
122                 -e "s:\$(sysconfdir_SQ)/bash_completion.d:$(get_bashcompdir):" \
123                 "${S}"/Makefile.perf || die
124         # A few places still use -Werror w/out $(WERROR) protection.
125         sed -i -e 's:-Werror::' \
126                 "${S}"/Makefile.perf "${S_K}"/tools/lib/bpf/Makefile || die
127
128         # Avoid the call to make kernelversion
129         echo "#define PERF_VERSION \"${MY_PV}\"" > PERF-VERSION-FILE
130
131         # The code likes to compile local assembly files which lack ELF markings.
132         find -name '*.S' -exec sed -i '$a.section .note.GNU-stack,"",%progbits' {} +
133 }
134
135 puse() { usex $1 "" no; }
136 perf_make() {
137         # The arch parsing is a bit funky.  The perf tools package is integrated
138         # into the kernel, so it wants an ARCH that looks like the kernel arch,
139         # but it also wants to know about the split value -- i386/x86_64 vs just
140         # x86.  We can get that by telling the func to use an older linux version.
141         # It's kind of a hack, but not that bad ...
142
143         # LIBDIR sets a search path of perf-gtk.so. Bug 515954
144
145         local arch=$(tc-arch-kernel)
146         local java_dir
147         use java && java_dir="/etc/java-config-2/current-system-vm"
148         # FIXME: NO_CORESIGHT
149         # FIXME: NO_LIBBABELTRACE
150         emake V=1 VF=1 \
151                 CC="$(tc-getCC)" CXX="$(tc-getCXX)" AR="$(tc-getAR)" LD="$(tc-getLD)" \
152                 prefix="${EPREFIX}/usr" bindir_relative="bin" \
153                 EXTRA_CFLAGS="${CFLAGS}" \
154                 ARCH="${arch}" \
155                 JDIR="${java_dir}" \
156                 LIBCLANGLLVM=$(usex clang 1 "") \
157                 NO_AUXTRACE="" \
158                 NO_BACKTRACE="" \
159                 NO_CORESIGHT=1 \
160                 NO_DEMANGLE=$(puse demangle) \
161                 NO_GTK2=$(puse gtk) \
162                 NO_JVMTI=$(puse java) \
163                 NO_LIBAUDIT=$(puse audit) \
164                 NO_LIBBABELTRACE=1 \
165                 NO_LIBBIONIC=1 \
166                 NO_LIBBPF="" \
167                 NO_LIBCRYPTO=$(puse crypt) \
168                 NO_LIBDW_DWARF_UNWIND="" \
169                 NO_LIBELF="" \
170                 NO_LIBNUMA=$(puse numa) \
171                 NO_LIBPERL=$(puse perl) \
172                 NO_LIBPYTHON=$(puse python) \
173                 NO_LIBUNWIND=$(puse unwind) \
174                 NO_SDT=$(puse systemtap) \
175                 NO_SLANG=$(puse slang) \
176                 NO_LZMA=$(puse lzma) \
177                 NO_ZLIB= \
178                 WERROR=0 \
179                 LIBDIR="/usr/libexec/perf-core" \
180                 "$@"
181 }
182
183 src_compile() {
184         # test-clang.bin not build with g++
185         if use clang; then
186                 pushd "${S_K}/tools/build/feature/" || die
187                 make V=1 CXX=${CHOST}-clang++ test-clang.bin || die
188                 popd
189         fi
190         perf_make -f Makefile.perf
191         use doc && perf_make -C Documentation
192 }
193
194 src_test() {
195         :
196 }
197
198 src_install() {
199         perf_make -f Makefile.perf install DESTDIR="${D}"
200
201         rm -rv "${D}"/usr/share/doc/perf-tip || die
202
203         if use gtk; then
204                 mv "${D}"/usr/$(get_libdir)/libperf-gtk.so \
205                         "${D}"/usr/libexec/perf-core || die
206         fi
207
208         dodoc CREDITS
209
210         dodoc *txt Documentation/*.txt
211         if use doc ; then
212                 HTML_DOCS="Documentation/*.html" einstalldocs
213                 doman Documentation/*.1
214         fi
215 }
216
217 pkg_postinst() {
218         if ! use doc ; then
219                 elog "Without the doc USE flag you won't get any documentation nor man pages."
220                 elog "And without man pages, you won't get any --help output for perf and its"
221                 elog "sub-tools."
222         fi
223 }