1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, autoreconfHook
6, pkg-config
7, enableUdev ? stdenv.isLinux && !stdenv.targetPlatform.isStatic
8, udev
9, libobjc
10, IOKit
11, Security
12, withExamples ? false
13, withStatic ? false
14}:
15
16stdenv.mkDerivation rec {
17 pname = "libusb";
18 version = "1.0.26";
19
20 src = fetchFromGitHub {
21 owner = "libusb";
22 repo = "libusb";
23 rev = "v${version}";
24 sha256 = "sha256-LEy45YiFbueCCi8d2hguujMsxBezaTUERHUpFsTKGZQ=";
25 };
26
27 outputs = [ "out" "dev" ];
28
29 nativeBuildInputs = [ pkg-config autoreconfHook ];
30 propagatedBuildInputs =
31 lib.optional enableUdev udev ++
32 lib.optionals stdenv.isDarwin [ libobjc IOKit Security ];
33
34 dontDisableStatic = withStatic;
35
36 configureFlags =
37 lib.optional (!enableUdev) "--disable-udev"
38 ++ lib.optional (withExamples) "--enable-examples-build";
39
40 preFixup = lib.optionalString enableUdev ''
41 sed 's,-ludev,-L${lib.getLib udev}/lib -ludev,' -i $out/lib/libusb-1.0.la
42 '';
43
44 postInstall = lib.optionalString withExamples ''
45 mkdir -p $out/{bin,sbin,examples/bin}
46 cp -r examples/.libs/* $out/examples/bin
47 ln -s $out/examples/bin/fxload $out/sbin/fxload
48 '';
49
50 meta = with lib; {
51 homepage = "https://libusb.info/";
52 description = "cross-platform user-mode USB device library";
53 longDescription = ''
54 libusb is a cross-platform user-mode library that provides access to USB devices.
55 '';
56 platforms = platforms.all;
57 license = licenses.lgpl21Plus;
58 maintainers = with maintainers; [ prusnak realsnick ];
59 };
60}