about summary refs log tree commit diff
path: root/pkgs/development/embedded/avrdude/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/embedded/avrdude/default.nix')
-rw-r--r--pkgs/development/embedded/avrdude/default.nix52
1 files changed, 39 insertions, 13 deletions
diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix
index 924c502358216..41b6c5ffc9401 100644
--- a/pkgs/development/embedded/avrdude/default.nix
+++ b/pkgs/development/embedded/avrdude/default.nix
@@ -1,16 +1,23 @@
-{ lib, stdenv, fetchFromGitHub, cmake, bison, flex, libusb-compat-0_1, libelf
-, libftdi1, readline, libserialport
-# documentation building is broken on darwin
-, docSupport ? (!stdenv.isDarwin), texliveMedium, texinfo, texi2html, unixtools }:
+{ lib, callPackage, stdenv, fetchFromGitHub, cmake, bison, flex, libusb1, elfutils
+, libftdi1, readline, hidapi, libserialport
+# Documentation building doesn't work on Darwin. It fails with:
+#   Undefined subroutine &Locale::Messages::dgettext called in ... texi2html
+#
+# https://github.com/NixOS/nixpkgs/issues/224761
+, docSupport ? (!stdenv.hostPlatform.isDarwin), texliveMedium, texinfo, texi2html, unixtools }:
 
-stdenv.mkDerivation rec {
+let
+  useElfutils = lib.meta.availableOn stdenv.hostPlatform elfutils;
+in
+
+stdenv.mkDerivation (finalAttrs: {
   pname = "avrdude";
   version = "7.3";
 
   src = fetchFromGitHub {
     owner = "avrdudes";
-    repo = pname;
-    rev = "v${version}";
+    repo = "avdude";
+    rev = "v${finalAttrs.version}";
     sha256 = "sha256-JqW3AOMmAfcy+PQRcqviWlxA6GoMSEfzIFt1pRYY7Dw=";
   };
 
@@ -21,17 +28,36 @@ stdenv.mkDerivation rec {
     texi2html
   ];
 
-  buildInputs = [ libusb-compat-0_1 libelf libftdi1 libserialport readline ];
-
-  cmakeFlags = lib.optionals docSupport [
-    "-DBUILD_DOC=ON"
+  buildInputs = [
+    (if useElfutils then elfutils else finalAttrs.finalPackage.passthru.libelf)
+    hidapi
+    libusb1
+    libftdi1
+    libserialport
+    readline
   ];
 
+  postPatch = lib.optionalString (!useElfutils) ''
+    # vendored libelf is a static library
+    sed -i "s/PREFERRED_LIBELF elf/PREFERRED_LIBELF libelf.a elf/" CMakeLists.txt
+  '';
+
+  # Not used:
+  #   -DHAVE_LINUXGPIO=ON    because it's incompatible with libgpiod 2.x
+  cmakeFlags = lib.optionals docSupport [ "-DBUILD_DOC=ON" ]
+    ++ lib.optionals stdenv.hostPlatform.isLinux [ "-DHAVE_LINUXSPI=ON" "-DHAVE_PARPORT=ON" ];
+
   # dvips output references texlive in comments, resulting in a huge closure
   postInstall = lib.optionalString docSupport ''
-    rm $out/share/doc/${pname}/*.ps
+    rm $out/share/doc/avrdude/*.ps
   '';
 
+  passthru = {
+    # Vendored and mutated copy of libelf for avrdudes use.
+    # Produces a static library only.
+    libelf = callPackage ./libelf.nix { };
+  };
+
   meta = with lib; {
     description = "Command-line tool for programming Atmel AVR microcontrollers";
     mainProgram = "avrdude";
@@ -45,4 +71,4 @@ stdenv.mkDerivation rec {
     platforms = with platforms; linux ++ darwin;
     maintainers = [ maintainers.bjornfor ];
   };
-}
+})