diff --git a/pkgs/build-support/gcc-wrapper/add-flags b/pkgs/build-support/gcc-wrapper/add-flags new file mode 100644 index 000000000000..ac1e58ebb812 --- /dev/null +++ b/pkgs/build-support/gcc-wrapper/add-flags @@ -0,0 +1,5 @@ +export NIX_CFLAGS_COMPILE="@cflagsCompile@ $NIX_CFLAGS_COMPILE" +export NIX_CFLAGS_LINK="@cflagsLink@ $NIX_CFLAGS_LINK" +export NIX_LDFLAGS="@ldflags@ $NIX_LDFLAGS" +export NIX_LDFLAGS_BEFORE="@ldflagsBefore@ $NIX_LDFLAGS_BEFORE" +export NIX_GLIBC_FLAGS_SET=1 diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh index 2e2c14f90bf6..ade66fcef1cf 100644 --- a/pkgs/build-support/gcc-wrapper/builder.sh +++ b/pkgs/build-support/gcc-wrapper/builder.sh @@ -1,4 +1,5 @@ . $stdenv/setup +. $substitute # Force gcc to use ld-wrapper.sh when calling ld. @@ -29,9 +30,30 @@ fi mkdir $out mkdir $out/bin +mkdir $out/nix-support -mkGccWrapper () { +doSubstitute() { + local src=$1 + local dst=$2 + substitute "$src" "$dst" \ + --subst-var "out" \ + --subst-var "shell" \ + --subst-var "gcc" \ + --subst-var "gccProg" \ + --subst-var "binutils" \ + --subst-var "glibc" \ + --subst-var "cflagsCompile" \ + --subst-var "cflagsLink" \ + --subst-var "ldflags" \ + --subst-var "ldflagsBefore" \ + --subst-var-by "ld" "$ldPath/ld" +} + + +# Make wrapper scripts around gcc, g++, and g77. Also make symlinks +# cc, c++, and f77. +mkGccWrapper() { local dst=$1 local src=$2 @@ -40,12 +62,9 @@ mkGccWrapper () { return fi - sed \ - -e "s^@gcc@^$src^g" \ - -e "s^@out@^$out^g" \ - -e "s^@shell@^$shell^g" \ - < $gccWrapper > $dst - chmod +x $dst + gccProg="$src" + doSubstitute "$gccWrapper" "$dst" + chmod +x "$dst" } mkGccWrapper $out/bin/gcc $gccPath/gcc @@ -58,33 +77,18 @@ mkGccWrapper $out/bin/g77 $gccPath/g77 ln -s g77 $out/bin/f77 -sed \ - -e "s^@out@^$out^g" \ - -e "s^@ldflags@^$ldflags^g" \ - -e "s^@ldflagsBefore@^$ldflagsBefore^g" \ - -e "s^@ld@^$ldPath/ld^g" \ - -e "s^@shell@^$shell^g" \ - < $ldWrapper > $out/bin/ld -chmod +x $out/bin/ld +# Make a wrapper around the linker. +doSubstitute "$ldWrapper" "$out/bin/ld" +chmod +x "$out/bin/ld" -mkdir $out/nix-support +# Emit a setup hook. Also store the path to the original GCC and +# Glibc. test -n "$gcc" && echo $gcc > $out/nix-support/orig-gcc test -n "$glibc" && echo $glibc > $out/nix-support/orig-glibc -cat > $out/nix-support/add-flags < $out/nix-support/setup-hook +doSubstitute "$setupHook" "$out/nix-support/setup-hook" cp -p $utils $out/nix-support/utils diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix index 80c8c7abd647..4296aef67c8b 100644 --- a/pkgs/build-support/gcc-wrapper/default.nix +++ b/pkgs/build-support/gcc-wrapper/default.nix @@ -15,10 +15,12 @@ assert !nativeGlibc -> glibc != null; stdenv.mkDerivation { builder = ./builder.sh; + substitute = ../substitute/substitute.sh; setupHook = ./setup-hook.sh; gccWrapper = ./gcc-wrapper.sh; ldWrapper = ./ld-wrapper.sh; utils = ./utils.sh; + addFlags = ./add-flags; inherit nativeTools nativeGlibc nativePrefix gcc glibc binutils; name = if name == "" then gcc.name else name; langC = if nativeTools then true else gcc.langC; diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh index fa2abe07650f..e9b912ba6629 100644 --- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh @@ -90,15 +90,15 @@ fi # Optionally print debug info. if test "$NIX_DEBUG" = "1"; then - echo "original flags to @gcc@:" >&2 + echo "original flags to @gccProg@:" >&2 for i in "${params[@]}"; do echo " $i" >&2 done - echo "extraBefore flags to @gcc@:" >&2 + echo "extraBefore flags to @gccProg@:" >&2 for i in ${extraBefore[@]}; do echo " $i" >&2 done - echo "extraAfter flags to @gcc@:" >&2 + echo "extraAfter flags to @gccProg@:" >&2 for i in ${extraAfter[@]}; do echo " $i" >&2 done @@ -108,4 +108,4 @@ if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then . "$NIX_GCC_WRAPPER_EXEC_HOOK" fi -exec @gcc@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} +exec @gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} diff --git a/pkgs/build-support/substitute/substitute.sh b/pkgs/build-support/substitute/substitute.sh index bd318522cae1..c1a32488e1d7 100644 --- a/pkgs/build-support/substitute/substitute.sh +++ b/pkgs/build-support/substitute/substitute.sh @@ -22,6 +22,13 @@ substitute() { sedArgs=("${sedArgs[@]}" "-e" "s^@${varName}@^${!varName}^g") fi + if test "$p" = "--subst-var-by"; then + varName=${params[$((n + 1))]} + replacement=${params[$((n + 2))]} + n=$((n + 2)) + sedArgs=("${sedArgs[@]}" "-e" "s^@${varName}@^$replacement^g") + fi + done sed "${sedArgs[@]}" < "$input" > "$output".tmp diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index bbcd19448cb7..eb68a9782a06 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -5,18 +5,18 @@ p4=$param4 p5=$param5 . $stdenv/setup +. $substitute -mkdir $out || exit 1 +mkdir $out -sed \ - -e "s^@preHook@^$preHook^g" \ - -e "s^@postHook@^$postHook^g" \ - -e "s^@initialPath@^$initialPath^g" \ - -e "s^@gcc@^$gcc^g" \ - -e "s^@shell@^$shell^g" \ - -e "s^@param1@^$p1^g" \ - -e "s^@param2@^$p2^g" \ - -e "s^@param3@^$p3^g" \ - -e "s^@param4@^$p4^g" \ - -e "s^@param5@^$p5^g" \ - < $setup > $out/setup || exit 1 +substitute "$setup" "$out/setup" \ + --subst-var preHook \ + --subst-var postHook \ + --subst-var initialPath \ + --subst-var gcc \ + --subst-var shell \ + --subst-var-by param1 "$p1" \ + --subst-var-by param2 "$p2" \ + --subst-var-by param3 "$p3" \ + --subst-var-by param4 "$p4" \ + --subst-var-by param5 "$p5" diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 3aa2d3bfac07..f57eebe9c742 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -11,6 +11,8 @@ let { builder = ./builder.sh; + substitute = ../../build-support/substitute/substitute.sh; + setup = ./setup.sh; inherit preHook postHook initialPath gcc shell;