From 093cc00cdd9d8cf31ecce5bc1dd3645c460a1b98 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 26 Jun 2017 01:17:09 -0400 Subject: [PATCH] cc-wrapper: Always export environment variables for binutils Before, this only happened when cross compiling. --- pkgs/build-support/cc-wrapper/default.nix | 33 +++++++-------------- pkgs/build-support/cc-wrapper/setup-hook.sh | 27 +++++++++++++---- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 4dc3d1845a48..1b52a0b8b123 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -71,22 +71,6 @@ let -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 windres - 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 - - sed -i $out -e 's_envHooks_crossEnvHooks_g' - '' + '' - # NIX_ things which we don't both use and define, we revert them #asymmetric=$( # for pre in "" "\\$" @@ -143,6 +127,7 @@ stdenv.mkDerivation { inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin; gnugrep_bin = if nativeTools then "" else gnugrep; + binPrefix = prefix; passthru = { inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile @@ -303,20 +288,24 @@ stdenv.mkDerivation { wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd fi - export real_cc=${prefix}cc - export real_cxx=${prefix}c++ + # We export environment variables pointing to the wrapped nonstandard + # cmds, lest some lousy configure script use those to guess compiler + # version. + export named_cc=${prefix}cc + export named_cxx=${prefix}c++ + export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}" if [ -e $ccPath/${prefix}gcc ]; then wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc ln -s ${prefix}gcc $out/bin/${prefix}cc - export real_cc=${prefix}gcc - export real_cxx=${prefix}g++ + export named_cc=${prefix}gcc + export named_cxx=${prefix}g++ elif [ -e $ccPath/clang ]; then wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang ln -s ${prefix}clang $out/bin/${prefix}cc - export real_cc=clang - export real_cxx=clang++ + export named_cc=${prefix}clang + export named_cxx=${prefix}clang++ fi if [ -e $ccPath/${prefix}g++ ]; then diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index f4f7ab181d3e..2900dc71a417 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -1,5 +1,3 @@ -export NIX_CC=@out@ - addCVars () { if [ -d $1/include ]; then export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" @@ -39,9 +37,26 @@ if [ -n "@coreutils_bin@" ]; then fi if [ -z "$crossConfig" ]; then - export CC=@real_cc@ - export CXX=@real_cxx@ + ENV_PREFIX="" else - export BUILD_CC=@real_cc@ - export BUILD_CXX=@real_cxx@ + ENV_PREFIX="BUILD_" fi + +export NIX_${ENV_PREFIX}CC=@out@ + +export ${ENV_PREFIX}CC=@named_cc@ +export ${ENV_PREFIX}CXX=@named_cxx@ + +for CMD in \ + cpp \ + ar as nm objcopy ranlib strip strings size ld windres +do + if + PATH=$_PATH type -p @binPrefix@$CMD > /dev/null + then + export ${ENV_PREFIX}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}; + fi +done + +# No local scope available for sourced files +unset ENV_PREFIX