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 = [ elfutils 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 = "-Wno-error=cpp -Wno-error=bool-compare -Wno-error=deprecated-declarations";
34
35 installFlags = "install install-man ASCIIDOC8=1";
36
37 crossAttrs = {
38 /* I don't want cross-python or cross-perl -
39 I don't know if cross-python even works */
40 propagatedBuildInputs = [ elfutils.crossDrv newt.crossDrv ];
41 makeFlags = "CROSS_COMPILE=${stdenv.cross.config}-";
42 elfutils = elfutils.crossDrv;
43 inherit (kernel.crossDrv) src patches;
44 };
45
46 meta = {
47 homepage = https://perf.wiki.kernel.org/;
48 description = "Linux tools to profile with performance counters";
49 maintainers = with stdenv.lib.maintainers; [viric];
50 platforms = with stdenv.lib.platforms; linux;
51 };
52}