@@ -53,42 +53,13 @@ let
5353 "-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)";
5454
5555 dashlessTarget = stdenv.lib.replaceStrings ["-"] ["_"] targetPlatform.config;
56− # TODO(@Ericson2314) Make unconditional
57− infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) dashlessTarget;
58− infixSalt_ = stdenv.lib.optionalString (targetPlatform != hostPlatform) (dashlessTarget + "_");
59− _infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) ("_" + dashlessTarget);
60−
61− # We want to prefix all NIX_ flags with the target triple
62− preWrap = textFile:
63− # TODO: Do even when not cross on next mass-rebuild
64− # TODO: use @target_tripple@ for consistency
65− if targetPlatform == hostPlatform
66− then textFile
67− else runCommand "sed-nix-env-vars" {} (''
68− cp --no-preserve=mode ${textFile} $out
69−
70− sed -i $out \
71− -e 's^NIX_^NIX_${infixSalt_}^g' \
72− -e 's^addCVars^addCVars${_infixSalt}^g' \
73− -e 's^\[ -z "\$crossConfig" \]^\[\[ "${builtins.toString (targetPlatform != hostPlatform)}" || -z "$crossConfig" \]\]^g'
74−
75− # NIX_ things which we don't both use and define, we revert them
76− #asymmetric=$(
77− # for pre in "" "\\$"
78− # do
79− # grep -E -ho $pre'NIX_[a-zA-Z_]*' ./* | sed 's/\$//' | sort | uniq
80− # done | sort | uniq -c | sort -nr | sed -n 's/^1 NIX_//gp')
81−
82− # hard-code for now
83− asymmetric=("CXXSTDLIB_COMPILE" "CC")
84−
85− # The ([^a-zA-Z_]|$) bussiness is to ensure environment variables that
86− # begin with `NIX_CC` don't also get blacklisted.
87− for var in "''${asymmetric[@]}"
88− do
89− sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g"
90− done
91− '');
56+
57+ # The "infix salt" is a arbitrary string added in the middle of env vars
58+ # defined by cc-wrapper's hooks so that multiple cc-wrappers can be used
59+ # without interfering. For the moment, it is defined as the target triple,
60+ # adjusted to be a valid bash identifier. This should be considered an
61+ # unstable implementation detail, however.
62+ infixSalt = dashlessTarget;
9263
9364 # The dynamic linker has different names on different platforms. This is a
9465 # shell glob that ought to match it.
@@ -129,20 +100,21 @@ stdenv.mkDerivation {
129100 gnugrep_bin = if nativeTools then "" else gnugrep;
130101
131102 binPrefix = prefix;
103+ inherit infixSalt;
132104
133105 passthru = {
134106 inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile
135− prefix infixSalt infixSalt_ _infixSalt;
107+ prefix;
136108
137109 emacsBufferSetup = pkgs: ''
138110 ; We should handle propagation here too
139111 (mapc (lambda (arg)
140112 (when (file-directory-p (concat arg "/include"))
141− (setenv "NIX_${infixSalt_}CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt_}CFLAGS_COMPILE") " -isystem " arg "/include")))
113+ (setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include")))
142114 (when (file-directory-p (concat arg "/lib"))
143− (setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib")))
115+ (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib")))
144116 (when (file-directory-p (concat arg "/lib64"))
145− (setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
117+ (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
146118 '';
147119 };
148120
@@ -268,7 +240,7 @@ stdenv.mkDerivation {
268240 # Solaris needs an additional ld wrapper.
269241 ldPath="${nativePrefix}/bin"
270242 exec="$ldPath/${prefix}ld"
271− wrap ld-solaris ${preWrap ./ld-solaris-wrapper.sh}
243+ wrap ld-solaris ${./ld-solaris-wrapper.sh}
272244 '')
273245
274246 + ''
@@ -282,7 +254,6 @@ stdenv.mkDerivation {
282254 '' + (if !useMacosReexportHack then ''
283255 wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
284256 '' else ''
285− export binPrefix=${prefix}
286257 ldInner="${prefix}ld-reexport-delegate"
287258 wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld}
288259 wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner"
@@ -290,11 +261,11 @@ stdenv.mkDerivation {
290261 '') + ''
291262
292263 if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then
293− wrap ${prefix}ld.gold ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
264+ wrap ${prefix}ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
294265 fi
295266
296267 if [ -e ${binutils_bin}/bin/ld.bfd ]; then
297− wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd
268+ wrap ${prefix}ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd
298269 fi
299270
300271 # We export environment variables pointing to the wrapped nonstandard
@@ -306,49 +277,49 @@ stdenv.mkDerivation {
306277 export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}"
307278
308279 if [ -e $ccPath/${prefix}gcc ]; then
309− wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc
280+ wrap ${prefix}gcc ${./cc-wrapper.sh} $ccPath/${prefix}gcc
310281 ln -s ${prefix}gcc $out/bin/${prefix}cc
311282 export named_cc=${prefix}gcc
312283 export named_cxx=${prefix}g++
313284 elif [ -e $ccPath/clang ]; then
314− wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang
285+ wrap ${prefix}clang ${./cc-wrapper.sh} $ccPath/clang
315286 ln -s ${prefix}clang $out/bin/${prefix}cc
316287 export named_cc=${prefix}clang
317288 export named_cxx=${prefix}clang++
318289 fi
319290
320291 if [ -e $ccPath/${prefix}g++ ]; then
321− wrap ${prefix}g++ ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}g++
292+ wrap ${prefix}g++ ${./cc-wrapper.sh} $ccPath/${prefix}g++
322293 ln -s ${prefix}g++ $out/bin/${prefix}c++
323294 elif [ -e $ccPath/clang++ ]; then
324− wrap ${prefix}clang++ ${preWrap ./cc-wrapper.sh} $ccPath/clang++
295+ wrap ${prefix}clang++ ${./cc-wrapper.sh} $ccPath/clang++
325296 ln -s ${prefix}clang++ $out/bin/${prefix}c++
326297 fi
327298
328299 if [ -e $ccPath/cpp ]; then
329− wrap ${prefix}cpp ${preWrap ./cc-wrapper.sh} $ccPath/cpp
300+ wrap ${prefix}cpp ${./cc-wrapper.sh} $ccPath/cpp
330301 fi
331302 ''
332303
333304 + optionalString cc.langFortran or false ''
334− wrap ${prefix}gfortran ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gfortran
305+ wrap ${prefix}gfortran ${./cc-wrapper.sh} $ccPath/${prefix}gfortran
335306 ln -sv ${prefix}gfortran $out/bin/${prefix}g77
336307 ln -sv ${prefix}gfortran $out/bin/${prefix}f77
337308 ''
338309
339310 + optionalString cc.langJava or false ''
340− wrap ${prefix}gcj ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcj
311+ wrap ${prefix}gcj ${./cc-wrapper.sh} $ccPath/${prefix}gcj
341312 ''
342313
343314 + optionalString cc.langGo or false ''
344− wrap ${prefix}gccgo ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gccgo
315+ wrap ${prefix}gccgo ${./cc-wrapper.sh} $ccPath/${prefix}gccgo
345316 ''
346317
347318 + optionalString cc.langAda or false ''
348− wrap ${prefix}gnatgcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gnatgcc
349− wrap ${prefix}gnatmake ${preWrap ./gnat-wrapper.sh} $ccPath/${prefix}gnatmake
350− wrap ${prefix}gnatbind ${preWrap ./gnat-wrapper.sh} $ccPath/${prefix}gnatbind
351− wrap ${prefix}gnatlink ${preWrap ./gnatlink-wrapper.sh} $ccPath/${prefix}gnatlink
319+ wrap ${prefix}gnatgcc ${./cc-wrapper.sh} $ccPath/${prefix}gnatgcc
320+ wrap ${prefix}gnatmake ${./gnat-wrapper.sh} $ccPath/${prefix}gnatmake
321+ wrap ${prefix}gnatbind ${./gnat-wrapper.sh} $ccPath/${prefix}gnatbind
322+ wrap ${prefix}gnatlink ${./gnatlink-wrapper.sh} $ccPath/${prefix}gnatlink
352323 ''
353324
354325 + optionalString cc.langVhdl or false ''
@@ -356,7 +327,7 @@ stdenv.mkDerivation {
356327 ''
357328
358329 + ''
359− substituteAll ${preWrap ./setup-hook.sh} $out/nix-support/setup-hook.tmp
330+ substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook.tmp
360331 cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook
361332 rm $out/nix-support/setup-hook.tmp
362333
@@ -375,9 +346,9 @@ stdenv.mkDerivation {
375346 ''
376347
377348 + ''
378− substituteAll ${preWrap ./add-flags.sh} $out/nix-support/add-flags.sh
379− substituteAll ${preWrap ./add-hardening.sh} $out/nix-support/add-hardening.sh
380− substituteAll ${preWrap ./utils.sh} $out/nix-support/utils.sh
349+ substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
350+ substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
351+ substituteAll ${./utils.sh} $out/nix-support/utils.sh
381352 ''
382353 + extraBuildCommands;
383354