nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv
2, lib
3, fetchpatch
4, fetchurl
5, pkg-config
6, hidapi
7, libftdi1
8, libusb1
9, libgpiod
10}:
11
12stdenv.mkDerivation rec {
13 pname = "openocd";
14 version = "0.11.0";
15 src = fetchurl {
16 url = "mirror://sourceforge/project/${pname}/${pname}/${version}/${pname}-${version}.tar.bz2";
17 sha256 = "0z8y7mmv0mhn2l5gs3vz6l7cnwak7agklyc7ml33f7gz99rwx8s3";
18 };
19
20 nativeBuildInputs = [ pkg-config ];
21
22 buildInputs = [ hidapi libftdi1 libusb1 ]
23 ++ lib.optional stdenv.isLinux libgpiod;
24
25 patches = [
26 # Patch is upstream, so can be removed when OpenOCD 0.12.0 or later is released.
27 (fetchpatch
28 {
29 url = "https://github.com/openocd-org/openocd/commit/cff0e417da58adef1ceef9a63a99412c2cc87ff3.patch";
30 sha256 = "Xxzf5miWy4S34sbQq8VQdAbY/oqGyhL/AJxiEPRuj3Q=";
31 })
32 ];
33
34 configureFlags = [
35 "--disable-werror"
36 "--enable-jtag_vpi"
37 "--enable-usb_blaster_libftdi"
38 (lib.enableFeature (! stdenv.isDarwin) "amtjtagaccel")
39 (lib.enableFeature (! stdenv.isDarwin) "gw16012")
40 "--enable-presto_libftdi"
41 "--enable-openjtag_ftdi"
42 (lib.enableFeature (! stdenv.isDarwin) "oocd_trace")
43 "--enable-buspirate"
44 (lib.enableFeature stdenv.isLinux "sysfsgpio")
45 (lib.enableFeature stdenv.isLinux "linuxgpiod")
46 "--enable-remote-bitbang"
47 ];
48
49 NIX_CFLAGS_COMPILE = lib.optionals stdenv.cc.isGNU [
50 "-Wno-error=cpp"
51 "-Wno-error=strict-prototypes" # fixes build failure with hidapi 0.10.0
52 ];
53
54 postInstall = lib.optionalString stdenv.isLinux ''
55 mkdir -p "$out/etc/udev/rules.d"
56 rules="$out/share/openocd/contrib/60-openocd.rules"
57 if [ ! -f "$rules" ]; then
58 echo "$rules is missing, must update the Nix file."
59 exit 1
60 fi
61 ln -s "$rules" "$out/etc/udev/rules.d/"
62 '';
63
64 meta = with lib; {
65 description = "Free and Open On-Chip Debugging, In-System Programming and Boundary-Scan Testing";
66 longDescription = ''
67 OpenOCD provides on-chip programming and debugging support with a layered
68 architecture of JTAG interface and TAP support, debug target support
69 (e.g. ARM, MIPS), and flash chip drivers (e.g. CFI, NAND, etc.). Several
70 network interfaces are available for interactiving with OpenOCD: HTTP,
71 telnet, TCL, and GDB. The GDB server enables OpenOCD to function as a
72 "remote target" for source-level debugging of embedded systems using the
73 GNU GDB program.
74 '';
75 homepage = "https://openocd.sourceforge.net/";
76 license = licenses.gpl2Plus;
77 maintainers = with maintainers; [ bjornfor prusnak ];
78 platforms = platforms.unix;
79 };
80}