summary refs log tree commit diff
path: root/pkgs/tools/misc/libcpuid/default.nix
blob: 8f258a38f7fc9978edc63e4fbb944a732d7f6418 (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
{ stdenv
, fetchgit
, libtool
, automake
, autoconf
, python
}:
stdenv.mkDerivation rec {
  name = "libcpuid-${version}";
  version = "0.2.2";

  src = fetchgit {
    url = https://github.com/anrieff/libcpuid.git;
    rev = "535ec64dd9d8df4c5a8d34b985280b58a5396fcf";
    sha256 = "1j9pg7fyvqhr859k5yh8ccl9jjx65c7rrsddji83qmqyg0vp1k1a";
  };

  patchPhase = ''
    libtoolize
    autoreconf --install
 '';

  configurePhase = ''
    mkdir -p Install
    ./configure --prefix=$(pwd)/Install
    substituteInPlace Makefile --replace "/usr/local" "$out"
  '';

  buildPhase = ''
    make all
  '';

  postInstall = ''
    pushd Install
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/lib ${python.interpreter} ../tests/run_tests.py ./bin/cpuid_tool ../tests/
    popd

    function fixRunPath {
      p0=$(patchelf --print-rpath $1)
      p1=$(echo $p0 | sed -re 's#.*Install/lib:##g')
      patchelf --set-rpath $p1 $1
    }

    fixRunPath Install/bin/cpuid_tool

    mkdir -p $out
    sed -i -re "s#(prefix=).*Install#\1$out#g" Install/lib/pkgconfig/libcpuid.pc
 
    cp -r Install/* $out
    cp -r tests $out
  '';

  buildInputs = [
    libtool
    automake
    autoconf
  ];

  meta = with stdenv.lib; {
    homepage = http://libcpuid.sourceforge.net/;
    description = "a small C library for x86 CPU detection and feature extraction";
    license = licenses.bsd3;
    maintainers = with maintainers; [ artuuge ];
  };
}