summaryrefslogtreecommitdiffstats
path: root/pkgs/development/misc/msp430/mspdebug.nix
blob: ce3162fe9d03cf1f41d1fce16ee7e48c96c6db09 (plain)
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
{
  lib,
  stdenv,
  fetchFromGitHub,
  autoPatchelfHook,
  libusb-compat-0_1,
  readline ? null,
  enableReadline ? true,
  hidapi ? null,
  pkg-config ? null,
  mspds ? null,
  enableMspds ? false,
}:

assert stdenv.hostPlatform.isDarwin -> hidapi != null && pkg-config != null;
assert enableReadline -> readline != null;
assert enableMspds -> mspds != null;

stdenv.mkDerivation rec {
  version = "0.26";
  pname = "mspdebug";
  src = fetchFromGitHub {
    owner = "dlbeer";
    repo = "mspdebug";
    rev = "v${version}";
    sha256 = "sha256-4TisC0Nm3lYMWCJ3TtaHDAfLDejMQZJIruh2f7fCndU=";
  };

  enableParallelBuilding = true;
  nativeBuildInputs =
    lib.optional stdenv.hostPlatform.isDarwin pkg-config
    ++ lib.optional (enableMspds && stdenv.hostPlatform.isLinux) autoPatchelfHook;
  buildInputs = [
    libusb-compat-0_1
  ]
  ++ lib.optional stdenv.hostPlatform.isDarwin hidapi
  ++ lib.optional enableReadline readline;

  postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
    # TODO: remove once a new 0.26+ release is made
    substituteInPlace drivers/tilib_api.c --replace .so ${stdenv.hostPlatform.extensions.sharedLibrary}

    # Makefile only uses pkg-config if it detects homebrew
    substituteInPlace Makefile --replace brew true
  '';

  # TODO: wrap with MSPDEBUG_TILIB_PATH env var instead of these rpath fixups in 0.26+
  runtimeDependencies = lib.optional enableMspds mspds;
  postFixup = lib.optionalString (enableMspds && stdenv.hostPlatform.isDarwin) ''
    # autoPatchelfHook only works on linux so...
    for dep in $runtimeDependencies; do
      install_name_tool -add_rpath $dep/lib $out/bin/$pname
    done
  '';

  installFlags = [
    "PREFIX=$(out)"
    "INSTALL=install"
  ];
  makeFlags = [ "UNAME_S=$(unameS)" ] ++ lib.optional (!enableReadline) "WITHOUT_READLINE=1";
  unameS = lib.optionalString stdenv.hostPlatform.isDarwin "Darwin";

  meta = {
    description = "Free programmer, debugger, and gdb proxy for MSP430 MCUs";
    mainProgram = "mspdebug";
    homepage = "https://dlbeer.co.nz/mspdebug/";
    license = lib.licenses.gpl2;
    platforms = lib.platforms.all;
    maintainers = with lib.maintainers; [ aerialx ];
  };
}