about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/libftdi/1.x.nix
blob: 1e35d4124615ce049a41a2f4eed4842589fa4be4 (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
{ lib
, stdenv
, fetchgit
, cmake
, pkg-config
, libusb1
, libconfuse
, cppSupport ? true
, boost
, pythonSupport ? true
, python3
, swig
, docSupport ? true
, doxygen
, graphviz
}:

let
  inherit (lib) optionals optionalString;
  onOff = a: if a then "ON" else "OFF";
in
stdenv.mkDerivation rec {
  pname = "libftdi";
  version = "1.5";

  src = fetchgit {
    url = "git://developer.intra2net.com/libftdi";
    rev = "v${version}";
    sha256 = "0vipg3y0kbbzjhxky6hfyxy42mpqhvwn1r010zr5givcfp8ghq26";
  };

  strictDeps = true;

  nativeBuildInputs = [ cmake pkg-config ]
    ++ optionals docSupport [ doxygen graphviz ]
    ++ optionals pythonSupport [ swig ];

  buildInputs = [ libconfuse ]
    ++ optionals cppSupport [ boost ];

  cmakeFlags = [
    "-DFTDIPP=${onOff cppSupport}"
    "-DBUILD_TESTS=${onOff cppSupport}"
    "-DLINK_PYTHON_LIBRARY=${onOff pythonSupport}"
    "-DPYTHON_BINDINGS=${onOff pythonSupport}"
    "-DDOCUMENTATION=${onOff docSupport}"
  ] ++ lib.optionals pythonSupport [
    "-DPYTHON_EXECUTABLE=${python3.pythonOnBuildForHost.interpreter}"
    "-DPYTHON_LIBRARY=${python3}/lib/libpython${python3.pythonVersion}${stdenv.hostPlatform.extensions.sharedLibrary}"
  ];

  propagatedBuildInputs = [ libusb1 ];

  postInstall = ''
    mkdir -p "$out/etc/udev/rules.d/"
    cp ../packages/99-libftdi.rules "$out/etc/udev/rules.d/"
  '' + optionalString docSupport ''
    cp -r doc/man "$out/share/"
    cp -r doc/html "$out/share/doc/libftdi1/"
  '';

  postFixup = optionalString cppSupport ''
    # This gets misassigned to the C++ version's path for some reason
    for fileToFix in $out/{bin/libftdi1-config,lib/pkgconfig/libftdi1.pc}; do
      substituteInPlace $fileToFix \
        --replace "$out/include/libftdipp1" "$out/include/libftdi1"
    done
  '';

  meta = with lib; {
    description = "A library to talk to FTDI chips using libusb";
    homepage = "https://www.intra2net.com/en/developer/libftdi/";
    license = with licenses; [ lgpl2Only gpl2Only ];
    platforms = platforms.all;
    maintainers = with maintainers; [ bjornfor ];
  };
}