diff --git a/pkgs/development/embedded/avrdude/default.nix b/pkgs/development/embedded/avrdude/default.nix index f03efa1dc820..b3d6d25f4502 100644 --- a/pkgs/development/embedded/avrdude/default.nix +++ b/pkgs/development/embedded/avrdude/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, cmake, bison, flex, libusb1, libelf +{ 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 @@ -6,6 +6,10 @@ # https://github.com/NixOS/nixpkgs/issues/224761 , docSupport ? (!stdenv.hostPlatform.isDarwin), texliveMedium, texinfo, texi2html, unixtools }: +let + useElfutils = lib.meta.availableOn stdenv.hostPlatform elfutils; +in + stdenv.mkDerivation rec { pname = "avrdude"; version = "7.3"; @@ -24,7 +28,19 @@ stdenv.mkDerivation rec { texi2html ]; - buildInputs = [ hidapi libusb1 libelf libftdi1 libserialport readline ]; + 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: # @@ -39,6 +55,12 @@ stdenv.mkDerivation rec { rm $out/share/doc/${pname}/*.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"; diff --git a/pkgs/development/embedded/avrdude/libelf.nix b/pkgs/development/embedded/avrdude/libelf.nix new file mode 100644 index 000000000000..bd7b7be7066a --- /dev/null +++ b/pkgs/development/embedded/avrdude/libelf.nix @@ -0,0 +1,36 @@ +{ + lib, + stdenv, + cmake, + fetchFromGitHub, +}: + +stdenv.mkDerivation { + pname = "libelf"; + version = "0.8.13-unstable-2023-01-14"; + + src = fetchFromGitHub { + owner = "avrdudes"; + repo = "libelf"; + rev = "0c55bfe1d3020a20bddf6ce57c0d9d98ccb12586"; + hash = "sha256-jz7Ef0Eg673IJVZvVNklY40s13LCuMVAc7FGrRI7scQ="; + }; + + nativeBuildInputs = [ cmake ]; + + installPhase = '' + runHook preInstall + mkdir -p $out/lib + cp liblibelf.a $out/lib/libelf.a + cp -r $src/include $out/include + runHook postInstall + ''; + + meta = { + description = "ELF object file access library (vendored by avrdudes)"; + homepage = "https://github.com/avrdudes/libelf"; + license = lib.licenses.lgpl2Plus; + platforms = lib.platforms.all; + maintainers = [ lib.maintainers.bjornfor ]; + }; +}