btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / by-name / op / openocd / package.nix
blob86dfd687ed2f9891c27987fba623844fe687ad92
1 { stdenv
2 , lib
3 , fetchurl
4 , pkg-config
5 , hidapi
6 , tcl
7 , jimtcl
8 , libjaylink
9 , libusb1
10 , libgpiod_1
12 , enableFtdi ? true, libftdi1
14 # Allow selection the hardware targets (SBCs, JTAG Programmers, JTAG Adapters)
15 , extraHardwareSupport ? []
16 }: let
18   isWindows = stdenv.hostPlatform.isWindows;
19   notWindows = !isWindows;
22 stdenv.mkDerivation rec {
23   pname = "openocd";
24   version = "0.12.0";
25   src = fetchurl {
26     url = "mirror://sourceforge/project/${pname}/${pname}/${version}/${pname}-${version}.tar.bz2";
27     sha256 = "sha256-ryVHiL6Yhh8r2RA/5uYKd07Jaow3R0Tu+Rl/YEMHWvo=";
28   };
30   nativeBuildInputs = [ pkg-config tcl ];
32   buildInputs = [ libusb1 ]
33     ++ lib.optionals notWindows [ hidapi jimtcl libftdi1 libjaylink ]
34     ++
35     # tracking issue for v2 api changes https://sourceforge.net/p/openocd/tickets/306/
36     lib.optional stdenv.hostPlatform.isLinux libgpiod_1;
38   configureFlags = [
39     "--disable-werror"
40     "--enable-jtag_vpi"
41     "--enable-remote-bitbang"
42     (lib.enableFeature notWindows "buspirate")
43     (lib.enableFeature (notWindows && enableFtdi) "ftdi")
44     (lib.enableFeature stdenv.hostPlatform.isLinux "linuxgpiod")
45     (lib.enableFeature stdenv.hostPlatform.isLinux "sysfsgpio")
46     (lib.enableFeature isWindows "internal-jimtcl")
47     (lib.enableFeature isWindows "internal-libjaylink")
48   ] ++
49     map (hardware: "--enable-${hardware}") extraHardwareSupport
50   ;
52   enableParallelBuilding = true;
54   env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isGNU [
55     "-Wno-error=cpp"
56     "-Wno-error=strict-prototypes" # fixes build failure with hidapi 0.10.0
57   ]);
59   postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
60     mkdir -p "$out/etc/udev/rules.d"
61     rules="$out/share/openocd/contrib/60-openocd.rules"
62     if [ ! -f "$rules" ]; then
63         echo "$rules is missing, must update the Nix file."
64         exit 1
65     fi
66     ln -s "$rules" "$out/etc/udev/rules.d/"
67   '';
69   meta = with lib; {
70     description = "Free and Open On-Chip Debugging, In-System Programming and Boundary-Scan Testing";
71     mainProgram = "openocd";
72     longDescription = ''
73       OpenOCD provides on-chip programming and debugging support with a layered
74       architecture of JTAG interface and TAP support, debug target support
75       (e.g. ARM, MIPS), and flash chip drivers (e.g. CFI, NAND, etc.).  Several
76       network interfaces are available for interactiving with OpenOCD: HTTP,
77       telnet, TCL, and GDB.  The GDB server enables OpenOCD to function as a
78       "remote target" for source-level debugging of embedded systems using the
79       GNU GDB program.
80     '';
81     homepage = "https://openocd.sourceforge.net/";
82     license = licenses.gpl2Plus;
83     maintainers = with maintainers; [ bjornfor prusnak ];
84     platforms = platforms.unix ++ platforms.windows;
85   };