summary refs log tree commit diff
path: root/pkgs/build-support/cc-wrapper/default.nix
diff options
context:
space:
mode:
authorRoss MacLeod <rmm-github@z.odi.ac>2017-05-30 23:31:44 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2017-06-22 17:52:28 -0400
commitc1fb71b74a15eba29c01ce8b2aa514310c437992 (patch)
tree8cb7f14b87e505f739ad2a3dfa7604bdf0ed5b5d /pkgs/build-support/cc-wrapper/default.nix
parente0492d58a68a825924493d381bcc52a20177e5ef (diff)
downloadnixpkgs-c1fb71b74a15eba29c01ce8b2aa514310c437992.tar
nixpkgs-c1fb71b74a15eba29c01ce8b2aa514310c437992.tar.gz
nixpkgs-c1fb71b74a15eba29c01ce8b2aa514310c437992.tar.bz2
nixpkgs-c1fb71b74a15eba29c01ce8b2aa514310c437992.tar.lz
nixpkgs-c1fb71b74a15eba29c01ce8b2aa514310c437992.tar.xz
nixpkgs-c1fb71b74a15eba29c01ce8b2aa514310c437992.tar.zst
nixpkgs-c1fb71b74a15eba29c01ce8b2aa514310c437992.zip
cc-wrapper: when cross building, wedge in setting AR, AS, and LD env vars to their cross building versions
I think it's ok to export things which aren't wrapped. The cc-wrapper
can be thought of as responsible for all of binutils and the c
compiler, only wrapping those binaries which are necessary to
interposition---as opposed to all binaries it thinks are relevaant.

Conversely, adding the setup hook to the unwrapped compilers would be
unforunate as hooks are ugly hacks and the compilers themselves take
a long time to rebuild. Better to wholely separate "pure packages" from
hacks.
Diffstat (limited to 'pkgs/build-support/cc-wrapper/default.nix')
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix20
1 files changed, 17 insertions, 3 deletions
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 77c0cfd63a7..83326777326 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -61,14 +61,28 @@ let
     # TODO: use @target_tripple@ for consistency
     if targetPlatform == hostPlatform
     then textFile
-    else runCommand "sed-nix-env-vars" {} ''
-      cp ${textFile} $out
+    else runCommand "sed-nix-env-vars" {} (''
+      cp --no-preserve=mode ${textFile} $out
 
       sed -i $out \
         -e 's^NIX_^NIX_${infixSalt_}^g' \
         -e 's^addCVars^addCVars${_infixSalt}^g' \
         -e 's^\[ -z "\$crossConfig" \]^\[\[ "${builtins.toString (targetPlatform != hostPlatform)}" || -z "$crossConfig" \]\]^g'
 
+    '' + stdenv.lib.optionalString (textFile == ./setup-hook.sh) ''
+      cat << 'EOF' >> $out
+        for CMD in ar as nm objcopy ranlib strip strings size ld
+        do
+          # which is not part of stdenv, but compgen will do for now
+          if
+            PATH=$_PATH type -p ${prefix}$CMD > /dev/null
+          then
+            export ''$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=${prefix}''${CMD};
+          fi
+        done
+      EOF
+    '' + ''
+
       # NIX_ things which we don't both use and define, we revert them
       #asymmetric=$(
       #  for pre in "" "\\$"
@@ -85,7 +99,7 @@ let
       do
         sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g"
       done
-    '';
+    '');
 in
 
 stdenv.mkDerivation {