1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 autoPatchelfHook,
6 libusb-compat-0_1,
7 readline ? null,
8 enableReadline ? true,
9 hidapi ? null,
10 pkg-config ? null,
11 mspds ? null,
12 enableMspds ? false,
13}:
14
15assert stdenv.hostPlatform.isDarwin -> hidapi != null && pkg-config != null;
16assert enableReadline -> readline != null;
17assert enableMspds -> mspds != null;
18
19stdenv.mkDerivation rec {
20 version = "0.25";
21 pname = "mspdebug";
22 src = fetchFromGitHub {
23 owner = "dlbeer";
24 repo = "mspdebug";
25 rev = "v${version}";
26 sha256 = "0prgwb5vx6fd4bj12ss1bbb6axj2kjyriyjxqrzd58s5jyyy8d3c";
27 };
28
29 enableParallelBuilding = true;
30 nativeBuildInputs =
31 lib.optional stdenv.hostPlatform.isDarwin pkg-config
32 ++ lib.optional (enableMspds && stdenv.hostPlatform.isLinux) autoPatchelfHook;
33 buildInputs = [
34 libusb-compat-0_1
35 ]
36 ++ lib.optional stdenv.hostPlatform.isDarwin hidapi
37 ++ lib.optional enableReadline readline;
38
39 postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
40 # TODO: remove once a new 0.26+ release is made
41 substituteInPlace drivers/tilib_api.c --replace .so ${stdenv.hostPlatform.extensions.sharedLibrary}
42
43 # Makefile only uses pkg-config if it detects homebrew
44 substituteInPlace Makefile --replace brew true
45 '';
46
47 # TODO: wrap with MSPDEBUG_TILIB_PATH env var instead of these rpath fixups in 0.26+
48 runtimeDependencies = lib.optional enableMspds mspds;
49 postFixup = lib.optionalString (enableMspds && stdenv.hostPlatform.isDarwin) ''
50 # autoPatchelfHook only works on linux so...
51 for dep in $runtimeDependencies; do
52 install_name_tool -add_rpath $dep/lib $out/bin/$pname
53 done
54 '';
55
56 installFlags = [
57 "PREFIX=$(out)"
58 "INSTALL=install"
59 ];
60 makeFlags = [ "UNAME_S=$(unameS)" ] ++ lib.optional (!enableReadline) "WITHOUT_READLINE=1";
61 unameS = lib.optionalString stdenv.hostPlatform.isDarwin "Darwin";
62
63 meta = with lib; {
64 description = "Free programmer, debugger, and gdb proxy for MSP430 MCUs";
65 mainProgram = "mspdebug";
66 homepage = "https://dlbeer.co.nz/mspdebug/";
67 license = licenses.gpl2;
68 platforms = platforms.all;
69 maintainers = with maintainers; [ aerialx ];
70 };
71}