lol
1{ lib, callPackage, stdenv, fetchFromGitHub, cmake, bison, flex, libusb1, elfutils
2, libftdi1, readline, hidapi, libserialport
3# Documentation building doesn't work on Darwin. It fails with:
4# Undefined subroutine &Locale::Messages::dgettext called in ... texi2html
5#
6# https://github.com/NixOS/nixpkgs/issues/224761
7, docSupport ? (!stdenv.hostPlatform.isDarwin), texliveMedium, texinfo, texi2html, unixtools }:
8
9let
10 useElfutils = lib.meta.availableOn stdenv.hostPlatform elfutils;
11in
12
13stdenv.mkDerivation (finalAttrs: {
14 pname = "avrdude";
15 version = "7.3";
16
17 src = fetchFromGitHub {
18 owner = "avrdudes";
19 repo = "avdude";
20 rev = "v${finalAttrs.version}";
21 sha256 = "sha256-JqW3AOMmAfcy+PQRcqviWlxA6GoMSEfzIFt1pRYY7Dw=";
22 };
23
24 nativeBuildInputs = [ cmake bison flex ] ++ lib.optionals docSupport [
25 unixtools.more
26 texliveMedium
27 texinfo
28 texi2html
29 ];
30
31 buildInputs = [
32 (if useElfutils then elfutils else finalAttrs.finalPackage.passthru.libelf)
33 hidapi
34 libusb1
35 libftdi1
36 libserialport
37 readline
38 ];
39
40 postPatch = lib.optionalString (!useElfutils) ''
41 # vendored libelf is a static library
42 sed -i "s/PREFERRED_LIBELF elf/PREFERRED_LIBELF libelf.a elf/" CMakeLists.txt
43 '';
44
45 # Not used:
46 # -DHAVE_LINUXGPIO=ON because it's incompatible with libgpiod 2.x
47 cmakeFlags = lib.optionals docSupport [ "-DBUILD_DOC=ON" ]
48 ++ lib.optionals stdenv.hostPlatform.isLinux [ "-DHAVE_LINUXSPI=ON" "-DHAVE_PARPORT=ON" ];
49
50 # dvips output references texlive in comments, resulting in a huge closure
51 postInstall = lib.optionalString docSupport ''
52 rm $out/share/doc/avrdude/*.ps
53 '';
54
55 passthru = {
56 # Vendored and mutated copy of libelf for avrdudes use.
57 # Produces a static library only.
58 libelf = callPackage ./libelf.nix { };
59 };
60
61 meta = with lib; {
62 description = "Command-line tool for programming Atmel AVR microcontrollers";
63 mainProgram = "avrdude";
64 longDescription = ''
65 AVRDUDE (AVR Downloader/UploaDEr) is an utility to
66 download/upload/manipulate the ROM and EEPROM contents of AVR
67 microcontrollers using the in-system programming technique (ISP).
68 '';
69 homepage = "https://www.nongnu.org/avrdude/";
70 license = licenses.gpl2Plus;
71 platforms = with platforms; linux ++ darwin;
72 maintainers = [ maintainers.bjornfor ];
73 };
74})