1{ lib, stdenv, kernel, elfutils, python, perl, newt, slang, asciidoc, xmlto
2, docbook_xsl, docbook_xml_dtd_45, libxslt, flex, bison, pkgconfig, libunwind, binutils
3, withGtk ? false, gtk ? null }:
4
5with lib;
6
7assert withGtk -> gtk != null;
8assert versionAtLeast kernel.version "3.12";
9
10stdenv.mkDerivation {
11 name = "perf-linux-${kernel.version}";
12
13 inherit (kernel) src patches;
14
15 preConfigure = ''
16 cd tools/perf
17 sed -i s,/usr/include/elfutils,$elfutils/include/elfutils, Makefile
18 ${optionalString (versionOlder kernel.version "3.13") "patch -p1 < ${./perf.diff}"}
19 [ -f bash_completion ] && sed -i 's,^have perf,_have perf,' bash_completion
20 export makeFlags="DESTDIR=$out $makeFlags"
21 '';
22
23 # perf refers both to newt and slang
24 # binutils is required for libbfd.
25 nativeBuildInputs = [ asciidoc xmlto docbook_xsl docbook_xml_dtd_45 libxslt flex bison ];
26 buildInputs = [ elfutils python perl newt slang pkgconfig libunwind binutils ] ++
27 stdenv.lib.optional withGtk gtk;
28
29 NIX_CFLAGS_COMPILE = "-Wno-error=cpp";
30
31 installFlags = "install install-man ASCIIDOC8=1";
32
33 inherit elfutils;
34
35 crossAttrs = {
36 /* I don't want cross-python or cross-perl -
37 I don't know if cross-python even works */
38 propagatedBuildInputs = [ elfutils.crossDrv newt.crossDrv ];
39 makeFlags = "CROSS_COMPILE=${stdenv.cross.config}-";
40 elfutils = elfutils.crossDrv;
41 inherit (kernel.crossDrv) src patches;
42 };
43
44 meta = {
45 homepage = https://perf.wiki.kernel.org/;
46 description = "Linux tools to profile with performance counters";
47 maintainers = with stdenv.lib.maintainers; [viric];
48 platforms = with stdenv.lib.platforms; linux;
49 };
50}