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