@ -53,42 +53,13 @@ let
" - i s y s t e m $ ( e c h o - n ${ cc . gcc } / i n c l u d e / c + + / * ) - i s y s t e m $ ( e c h o - n ${ cc . gcc } / i n c l u d e / c + + / * ) / $ ( ${ cc . gcc } / b i n / g c c - d u m p m a c h i n e ) " ;
dashlessTarget = stdenv . lib . replaceStrings [ " - " ] [ " _ " ] targetPlatform . config ;
# TODO(@Ericson2314) Make unconditional
infixSalt = stdenv . lib . optionalString ( targetPlatform != hostPlatform ) dashlessTarget ;
infixSalt_ = stdenv . lib . optionalString ( targetPlatform != hostPlatform ) ( dashlessTarget + " _ " ) ;
_infixSalt = stdenv . lib . optionalString ( targetPlatform != hostPlatform ) ( " _ " + dashlessTarget ) ;
# We want to prefix all NIX_ flags with the target triple
preWrap = textFile :
# TODO: Do even when not cross on next mass-rebuild
# TODO: use @target_tripple@ for consistency
if targetPlatform == hostPlatform
then textFile
else runCommand " s e d - n i x - e n v - v a r s " { } ( ''
cp - - no-preserve = mode $ { textFile } $ out
sed - i $ out \
- e ' s ^ NIX_ ^ NIX_ $ { infixSalt_ } ^ g' \
- e ' s ^ addCVars ^ addCVars $ { _infixSalt } ^ g' \
- e ' s ^ \ [ - z " \$ c r o s s C o n f i g " \ ] ^ \ [ \ [ " ${ builtins . toString ( targetPlatform != hostPlatform ) } " || - z " $ c r o s s C o n f i g " \ ] \ ] ^ g'
# NIX_ things which we don't both use and define, we revert them
#asymmetric=$(
# for pre in "" "\\$"
# do
# grep -E -ho $pre'NIX_[a-zA-Z_]*' ./* | sed 's/\$//' | sort | uniq
# done | sort | uniq -c | sort -nr | sed -n 's/^1 NIX_//gp')
# hard-code for now
asymmetric = ( " C X X S T D L I B _ C O M P I L E " " C C " )
# The ([^a-zA-Z_]|$) bussiness is to ensure environment variables that
# begin with `NIX_CC` don't also get blacklisted.
for var in " ' ' ${ asymmetric [ @ ] } "
do
sed - i $ out - E - e " s ~ N I X _ ${ infixSalt_ } $ v a r ( [ ^ a - z A - Z _ ] | $ ) ~ N I X _ $ v a r \1 ~ g "
done
'' ) ;
# The "infix salt" is a arbitrary string added in the middle of env vars
# defined by cc-wrapper's hooks so that multiple cc-wrappers can be used
# without interfering. For the moment, it is defined as the target triple,
# adjusted to be a valid bash identifier. This should be considered an
# unstable implementation detail, however.
infixSalt = dashlessTarget ;
# The dynamic linker has different names on different platforms. This is a
# shell glob that ought to match it.
@ -129,20 +100,21 @@ stdenv.mkDerivation {
gnugrep_bin = if nativeTools then " " else gnugrep ;
binPrefix = prefix ;
inherit infixSalt ;
passthru = {
inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile
prefix infixSalt infixSalt_ _infixSalt ;
prefix ;
emacsBufferSetup = pkgs : ''
; We should handle propagation here too
( mapc ( lambda ( arg )
( when ( file-directory-p ( concat arg " / i n c l u d e " ) )
( setenv " N I X _ ${ infixSalt_ } C F L A G S _ C O M P I L E " ( concat ( getenv " N I X _ ${ infixSalt_ } C F L A G S _ C O M P I L E " ) " - i s y s t e m " arg " / i n c l u d e " ) ) )
( setenv " N I X _ ${ infixSalt } _ C F L A G S _ C O M P I L E " ( concat ( getenv " N I X _ ${ infixSalt } _ C F L A G S _ C O M P I L E " ) " - i s y s t e m " arg " / i n c l u d e " ) ) )
( when ( file-directory-p ( concat arg " / l i b " ) )
( setenv " N I X _ ${ infixSalt_ } L D F L A G S " ( concat ( getenv " N I X _ ${ infixSalt_ } L D F L A G S " ) " - L " arg " / l i b " ) ) )
( setenv " N I X _ ${ infixSalt } _ L D F L A G S " ( concat ( getenv " N I X _ ${ infixSalt } _ L D F L A G S " ) " - L " arg " / l i b " ) ) )
( when ( file-directory-p ( concat arg " / l i b 6 4 " ) )
( setenv " N I X _ ${ infixSalt_ } L D F L A G S " ( concat ( getenv " N I X _ ${ infixSalt_ } L D F L A G S " ) " - L " arg " / l i b 6 4 " ) ) ) ) ' ( $ { concatStringsSep " " ( map ( pkg : " \" ${ pkg } \" " ) pkgs ) } ) )
( setenv " N I X _ ${ infixSalt } _ L D F L A G S " ( concat ( getenv " N I X _ ${ infixSalt } _ L D F L A G S " ) " - L " arg " / l i b 6 4 " ) ) ) ) ' ( $ { concatStringsSep " " ( map ( pkg : " \" ${ pkg } \" " ) pkgs ) } ) )
'' ;
} ;
@ -268,7 +240,7 @@ stdenv.mkDerivation {
# Solaris needs an additional ld wrapper.
ldPath = " ${ nativePrefix } / b i n "
exec = " $ l d P a t h / ${ prefix } l d "
wrap ld-solaris $ { preWrap ./ld-solaris-wrapper.sh }
wrap ld-solaris $ { ./ld-solaris-wrapper.sh }
'' )
+ ''
@ -282,7 +254,6 @@ stdenv.mkDerivation {
'' + ( i f ! u s e M a c o s R e e x p o r t H a c k t h e n ''
wrap $ { prefix } ld $ { ./ld-wrapper.sh } '' ${ ld:-$ldPath/$ { prefix } ld }
'' e l s e ''
export binPrefix = $ { prefix }
ldInner = " ${ prefix } l d - r e e x p o r t - d e l e g a t e "
wrap " $ l d I n n e r " $ { ./macos-sierra-reexport-hack.bash } '' ${ ld:-$ldPath/$ { prefix } ld }
wrap " ${ prefix } l d " $ { ./ld-wrapper.sh } " $ o u t / b i n / $ l d I n n e r "
@ -290,11 +261,11 @@ stdenv.mkDerivation {
'' ) + ''
if [ - e $ { binutils_bin } /bin / $ { prefix } ld . gold ] ; then
wrap $ { prefix } ld . gold $ { preWrap ./ld-wrapper.sh } $ { binutils_bin } /bin / $ { prefix } ld . gold
wrap $ { prefix } ld . gold $ { ./ld-wrapper.sh } $ { binutils_bin } /bin / $ { prefix } ld . gold
fi
if [ - e $ { binutils_bin } /bin/ld.bfd ] ; then
wrap $ { prefix } ld . bfd $ { preWrap ./ld-wrapper.sh } $ { binutils_bin } /bin / $ { prefix } ld . bfd
wrap $ { prefix } ld . bfd $ { ./ld-wrapper.sh } $ { binutils_bin } /bin / $ { prefix } ld . bfd
fi
# We export environment variables pointing to the wrapped nonstandard
@ -306,49 +277,49 @@ stdenv.mkDerivation {
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
wrap $ { prefix } gcc $ { ./cc-wrapper.sh } $ ccPath / $ { prefix } gcc
ln - s $ { prefix } gcc $ out/bin / $ { prefix } cc
export named_cc = $ { prefix } gcc
export named_cxx = $ { prefix } g ++
elif [ - e $ ccPath/clang ] ; then
wrap $ { prefix } clang $ { preWrap ./cc-wrapper.sh } $ ccPath/clang
wrap $ { prefix } clang $ { ./cc-wrapper.sh } $ ccPath/clang
ln - s $ { prefix } clang $ out/bin / $ { prefix } cc
export named_cc = $ { prefix } clang
export named_cxx = $ { prefix } clang ++
fi
if [ - e $ ccPath / $ { prefix } g ++ ] ; then
wrap $ { prefix } g ++ $ { preWrap ./cc-wrapper.sh } $ ccPath / $ { prefix } g ++
wrap $ { prefix } g ++ $ { ./cc-wrapper.sh } $ ccPath / $ { prefix } g ++
ln - s $ { prefix } g ++ $ out/bin / $ { prefix } c ++
elif [ - e $ ccPath/clang++ ] ; then
wrap $ { prefix } clang ++ $ { preWrap ./cc-wrapper.sh } $ ccPath/clang++
wrap $ { prefix } clang ++ $ { ./cc-wrapper.sh } $ ccPath/clang++
ln - s $ { prefix } clang ++ $ out/bin / $ { prefix } c ++
fi
if [ - e $ ccPath/cpp ] ; then
wrap $ { prefix } cpp $ { preWrap ./cc-wrapper.sh } $ ccPath/cpp
wrap $ { prefix } cpp $ { ./cc-wrapper.sh } $ ccPath/cpp
fi
''
+ optionalString cc . langFortran or false ''
wrap $ { prefix } gfortran $ { preWrap ./cc-wrapper.sh } $ ccPath / $ { prefix } gfortran
wrap $ { prefix } gfortran $ { ./cc-wrapper.sh } $ ccPath / $ { prefix } gfortran
ln - sv $ { prefix } gfortran $ out/bin / $ { prefix } g77
ln - sv $ { prefix } gfortran $ out/bin / $ { prefix } f77
''
+ optionalString cc . langJava or false ''
wrap $ { prefix } gcj $ { preWrap ./cc-wrapper.sh } $ ccPath / $ { prefix } gcj
wrap $ { prefix } gcj $ { ./cc-wrapper.sh } $ ccPath / $ { prefix } gcj
''
+ optionalString cc . langGo or false ''
wrap $ { prefix } gccgo $ { preWrap ./cc-wrapper.sh } $ ccPath / $ { prefix } gccgo
wrap $ { prefix } gccgo $ { ./cc-wrapper.sh } $ ccPath / $ { prefix } gccgo
''
+ optionalString cc . langAda or false ''
wrap $ { prefix } gnatgcc $ { preWrap ./cc-wrapper.sh } $ ccPath / $ { prefix } gnatgcc
wrap $ { prefix } gnatmake $ { preWrap ./gnat-wrapper.sh } $ ccPath / $ { prefix } gnatmake
wrap $ { prefix } gnatbind $ { preWrap ./gnat-wrapper.sh } $ ccPath / $ { prefix } gnatbind
wrap $ { prefix } gnatlink $ { preWrap ./gnatlink-wrapper.sh } $ ccPath / $ { prefix } gnatlink
wrap $ { prefix } gnatgcc $ { ./cc-wrapper.sh } $ ccPath / $ { prefix } gnatgcc
wrap $ { prefix } gnatmake $ { ./gnat-wrapper.sh } $ ccPath / $ { prefix } gnatmake
wrap $ { prefix } gnatbind $ { ./gnat-wrapper.sh } $ ccPath / $ { prefix } gnatbind
wrap $ { prefix } gnatlink $ { ./gnatlink-wrapper.sh } $ ccPath / $ { prefix } gnatlink
''
+ optionalString cc . langVhdl or false ''
@ -356,7 +327,7 @@ stdenv.mkDerivation {
''
+ ''
substituteAll $ { preWrap ./setup-hook.sh } $ out/nix-support/setup-hook.tmp
substituteAll $ { ./setup-hook.sh } $ out/nix-support/setup-hook.tmp
cat $ out/nix-support/setup-hook.tmp > > $ out/nix-support/setup-hook
rm $ out/nix-support/setup-hook.tmp
@ -375,9 +346,9 @@ stdenv.mkDerivation {
''
+ ''
substituteAll $ { preWrap ./add-flags.sh } $ out/nix-support/add-flags.sh
substituteAll $ { preWrap ./add-hardening.sh } $ out/nix-support/add-hardening.sh
substituteAll $ { preWrap ./utils.sh } $ out/nix-support/utils.sh
substituteAll $ { ./add-flags.sh } $ out/nix-support/add-flags.sh
substituteAll $ { ./add-hardening.sh } $ out/nix-support/add-hardening.sh
substituteAll $ { ./utils.sh } $ out/nix-support/utils.sh
''
+ extraBuildCommands ;