about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKier Davis <kierdavis@gmail.com>2018-01-12 00:48:35 +0000
committerKier Davis <kierdavis@gmail.com>2018-01-12 00:48:35 +0000
commit6bfa42218ddf2054f735145940585d05d84aaf64 (patch)
tree6c1b2040ee04b92f14967cc531929aee4d9caaf0
parent10c6439a8998466266ff6f440c0716ae8b9b1a84 (diff)
downloadnixlib-6bfa42218ddf2054f735145940585d05d84aaf64.tar
nixlib-6bfa42218ddf2054f735145940585d05d84aaf64.tar.gz
nixlib-6bfa42218ddf2054f735145940585d05d84aaf64.tar.bz2
nixlib-6bfa42218ddf2054f735145940585d05d84aaf64.tar.lz
nixlib-6bfa42218ddf2054f735145940585d05d84aaf64.tar.xz
nixlib-6bfa42218ddf2054f735145940585d05d84aaf64.tar.zst
nixlib-6bfa42218ddf2054f735145940585d05d84aaf64.zip
avrgcc: bake path to avr-ar into avr-gcc-ar
gcc provides wrappers for binutils' ar, nm and ranlib
executables, which must be used instead when using link-time
optimisation. See also:
http://manpages.ubuntu.com/manpages/zesty/man1/aarch64-linux-gnu-gcc-ar-5.1.html

The upstream version of avr-gcc-ar searches in paths passed to
the configure script for the avr-ar binary that it wraps, falling
back to searching PATH instead. Thus currently avr-gcc-ar works on
Nix, but only if avrbinutils is already in the environment.

This change bakes the path to avr-ar into avr-gcc-ar, since its path
is known at compile time. It also no longer searches PATH, meaning the
user's local environment won't override this path.

Note that avr-gcc-nm and avr-gcc-ranlib are compiled from the same
source file as avr-gcc-ar, just with different compiler flags.

Testing on master (without avrbinutils in the environment):

    $ nix-build -A avrgcc
    $ result/bin/avr-gcc-ar --version
    result/bin/avr-gcc-ar: Cannot find binary 'avr-ar'

Testing on branch with this fix:

    $ nix-build -A avrgcc
    $ result/bin/avr-gcc-ar --version
    GNU ar (GNU Binutils) 2.26.20160125
    ...
-rw-r--r--pkgs/development/misc/avr/gcc/avrbinutils-path.patch15
-rw-r--r--pkgs/development/misc/avr/gcc/default.nix10
2 files changed, 25 insertions, 0 deletions
diff --git a/pkgs/development/misc/avr/gcc/avrbinutils-path.patch b/pkgs/development/misc/avr/gcc/avrbinutils-path.patch
new file mode 100644
index 000000000000..f0ec21b7589f
--- /dev/null
+++ b/pkgs/development/misc/avr/gcc/avrbinutils-path.patch
@@ -0,0 +1,15 @@
+diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
+index 838ebc2..3ac4ee7 100644
+--- a/gcc/gcc-ar.c
++++ b/gcc/gcc-ar.c
+@@ -118,8 +118,8 @@ setup_prefixes (const char *exec_path)
+ 				dir_separator, NULL);
+   prefix_from_string (self_libexec_prefix, &target_path);
+ 
+-  /* Add path as a last resort.  */
+-  prefix_from_env ("PATH", &path);
++  /* Add path to avrbinutils.  */
++  prefix_from_string ("@avrbinutils@/bin", &path);
+ }
+ 
+ int 
diff --git a/pkgs/development/misc/avr/gcc/default.nix b/pkgs/development/misc/avr/gcc/default.nix
index f456214f9442..0bfa6d1f238d 100644
--- a/pkgs/development/misc/avr/gcc/default.nix
+++ b/pkgs/development/misc/avr/gcc/default.nix
@@ -11,6 +11,16 @@ stdenv.mkDerivation {
     sha256 = "0fihlcy5hnksdxk0sn6bvgnyq8gfrgs8m794b1jxwd1dxinzg3b0";
   };
 
+  patches = [
+    ./avrbinutils-path.patch
+  ];
+
+  # avrbinutils-path.patch introduces a reference to @avrbinutils@, substitute
+  # it now.
+  postPatch = ''
+    substituteInPlace gcc/gcc-ar.c --subst-var-by avrbinutils ${avrbinutils}
+  '';
+
   buildInputs = [ gmp mpfr libmpc zlib avrbinutils ];
 
   nativeBuildInputs = [ texinfo ];