summary refs log tree commit diff
path: root/pkgs/development/tools/misc/unixbench/default.nix
blob: 3d1b424ab0b8f3d0fc3b2ca231cb38ad34137780 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{ lib
, stdenv
, fetchFromGitHub
, makeWrapper
, pandoc
, installShellFiles
, perl
, xorg
, libGL
, coreutils
, unixtools
, targetPackages
, gnugrep
, gawk
, withGL? true
, withX11perf? true
}:

stdenv.mkDerivation rec {
  pname = "unixbench";
  version = "unstable-2023-02-27";

  src = fetchFromGitHub {
    owner = "kdlucas";
    repo = "byte-unixbench";
    rev = "a07fcc03264915c624f0e4818993c5b4df3fa703";
    hash = "sha256-gmRWAqE9/HBb0S9rK0DXoaCoiGbtat0gmdeozhbv0NI=";
  };

  patches = [
    ./common.patch
  ];

  patchFlags = [ "-p2" ];

  sourceRoot = "source/UnixBench";

  postPatch = ''
    substituteInPlace Makefile \
      --replace "-Wa,-q" ""
  '';

  nativeBuildInputs = [
    makeWrapper
    pandoc
    installShellFiles
  ];

  buildInputs = [ perl ] ++ lib.optionals withGL [
    xorg.libX11
    xorg.libXext
    libGL
  ];

  runtimeDependencies = [
    coreutils
    unixtools.nettools
    unixtools.locale
    targetPackages.stdenv.cc
    gnugrep
    gawk
  ] ++ lib.optionals withX11perf [
    xorg.x11perf
  ];

  makeFlags = [
    "CC=${stdenv.cc.targetPrefix}cc"
  ] ++ lib.optionals withGL [
    "GRAPHIC_TESTS=defined"
  ];

  installPhase = ''
    runHook preInstall
    mkdir -p $out/{bin,libexec,share}
    install -D Run $out/bin/ubench
    cp -r pgms $out/libexec/
    cp -r testdir $out/share/
    runHook postInstall
  '';

  postInstall = ''
    substituteInPlace USAGE \
      --replace 'Run"' 'ubench"' \
      --replace './Run' 'ubench' \
      --replace 'Run ' 'ubench '
    pandoc -f rst -t man USAGE -o ubench.1
    installManPage ubench.1
  '';

  preFixup = ''
    substituteInPlace $out/libexec/pgms/multi.sh \
      --replace '/bin/sh "$' '${targetPackages.runtimeShell} "$'

    substituteInPlace $out/bin/ubench \
      --subst-var out

    wrapProgram $out/bin/ubench \
      --prefix PATH : ${lib.makeBinPath runtimeDependencies}
  '';

  meta = with lib; {
    description = "A basic indicator of the performance of a Unix-like system";
    homepage = "https://github.com/kdlucas/byte-unixbench";
    license = licenses.gpl2Plus;
    mainProgram = "ubench";
    maintainers = with maintainers; [ aleksana ];
    platforms = platforms.unix;
  };
}