* Use the generic substituter in the generation of stdenv and gcc-wrapper.

svn path=/nixpkgs/trunk/; revision=2269
This commit is contained in:
Eelco Dolstra 2005-02-22 14:32:56 +00:00
parent 290fba0cb6
commit 2e0380b7a0
7 changed files with 66 additions and 46 deletions

View File

@ -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

View File

@ -1,4 +1,5 @@
. $stdenv/setup . $stdenv/setup
. $substitute
# Force gcc to use ld-wrapper.sh when calling ld. # Force gcc to use ld-wrapper.sh when calling ld.
@ -29,9 +30,30 @@ fi
mkdir $out mkdir $out
mkdir $out/bin 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 dst=$1
local src=$2 local src=$2
@ -40,12 +62,9 @@ mkGccWrapper () {
return return
fi fi
sed \ gccProg="$src"
-e "s^@gcc@^$src^g" \ doSubstitute "$gccWrapper" "$dst"
-e "s^@out@^$out^g" \ chmod +x "$dst"
-e "s^@shell@^$shell^g" \
< $gccWrapper > $dst
chmod +x $dst
} }
mkGccWrapper $out/bin/gcc $gccPath/gcc mkGccWrapper $out/bin/gcc $gccPath/gcc
@ -58,33 +77,18 @@ mkGccWrapper $out/bin/g77 $gccPath/g77
ln -s g77 $out/bin/f77 ln -s g77 $out/bin/f77
sed \ # Make a wrapper around the linker.
-e "s^@out@^$out^g" \ doSubstitute "$ldWrapper" "$out/bin/ld"
-e "s^@ldflags@^$ldflags^g" \ chmod +x "$out/bin/ld"
-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
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 "$gcc" && echo $gcc > $out/nix-support/orig-gcc
test -n "$glibc" && echo $glibc > $out/nix-support/orig-glibc test -n "$glibc" && echo $glibc > $out/nix-support/orig-glibc
cat > $out/nix-support/add-flags <<EOF doSubstitute "$addFlags" "$out/nix-support/add-flags"
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
#export GCC_EXEC_PREFIX=$gcc/libexec/gcc/i686-pc-linux-gnu/3.4.3
EOF
sed \ doSubstitute "$setupHook" "$out/nix-support/setup-hook"
-e "s^@gcc@^$gcc^g" \
-e "s^@binutils@^$binutils^g" \
-e "s^@glibc@^$glibc^g" \
< $setupHook > $out/nix-support/setup-hook
cp -p $utils $out/nix-support/utils cp -p $utils $out/nix-support/utils

View File

@ -15,10 +15,12 @@ assert !nativeGlibc -> glibc != null;
stdenv.mkDerivation { stdenv.mkDerivation {
builder = ./builder.sh; builder = ./builder.sh;
substitute = ../substitute/substitute.sh;
setupHook = ./setup-hook.sh; setupHook = ./setup-hook.sh;
gccWrapper = ./gcc-wrapper.sh; gccWrapper = ./gcc-wrapper.sh;
ldWrapper = ./ld-wrapper.sh; ldWrapper = ./ld-wrapper.sh;
utils = ./utils.sh; utils = ./utils.sh;
addFlags = ./add-flags;
inherit nativeTools nativeGlibc nativePrefix gcc glibc binutils; inherit nativeTools nativeGlibc nativePrefix gcc glibc binutils;
name = if name == "" then gcc.name else name; name = if name == "" then gcc.name else name;
langC = if nativeTools then true else gcc.langC; langC = if nativeTools then true else gcc.langC;

View File

@ -90,15 +90,15 @@ fi
# Optionally print debug info. # Optionally print debug info.
if test "$NIX_DEBUG" = "1"; then if test "$NIX_DEBUG" = "1"; then
echo "original flags to @gcc@:" >&2 echo "original flags to @gccProg@:" >&2
for i in "${params[@]}"; do for i in "${params[@]}"; do
echo " $i" >&2 echo " $i" >&2
done done
echo "extraBefore flags to @gcc@:" >&2 echo "extraBefore flags to @gccProg@:" >&2
for i in ${extraBefore[@]}; do for i in ${extraBefore[@]}; do
echo " $i" >&2 echo " $i" >&2
done done
echo "extraAfter flags to @gcc@:" >&2 echo "extraAfter flags to @gccProg@:" >&2
for i in ${extraAfter[@]}; do for i in ${extraAfter[@]}; do
echo " $i" >&2 echo " $i" >&2
done done
@ -108,4 +108,4 @@ if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then
. "$NIX_GCC_WRAPPER_EXEC_HOOK" . "$NIX_GCC_WRAPPER_EXEC_HOOK"
fi fi
exec @gcc@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} exec @gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}

View File

@ -22,6 +22,13 @@ substitute() {
sedArgs=("${sedArgs[@]}" "-e" "s^@${varName}@^${!varName}^g") sedArgs=("${sedArgs[@]}" "-e" "s^@${varName}@^${!varName}^g")
fi 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 done
sed "${sedArgs[@]}" < "$input" > "$output".tmp sed "${sedArgs[@]}" < "$input" > "$output".tmp

View File

@ -5,18 +5,18 @@ p4=$param4
p5=$param5 p5=$param5
. $stdenv/setup . $stdenv/setup
. $substitute
mkdir $out || exit 1 mkdir $out
sed \ substitute "$setup" "$out/setup" \
-e "s^@preHook@^$preHook^g" \ --subst-var preHook \
-e "s^@postHook@^$postHook^g" \ --subst-var postHook \
-e "s^@initialPath@^$initialPath^g" \ --subst-var initialPath \
-e "s^@gcc@^$gcc^g" \ --subst-var gcc \
-e "s^@shell@^$shell^g" \ --subst-var shell \
-e "s^@param1@^$p1^g" \ --subst-var-by param1 "$p1" \
-e "s^@param2@^$p2^g" \ --subst-var-by param2 "$p2" \
-e "s^@param3@^$p3^g" \ --subst-var-by param3 "$p3" \
-e "s^@param4@^$p4^g" \ --subst-var-by param4 "$p4" \
-e "s^@param5@^$p5^g" \ --subst-var-by param5 "$p5"
< $setup > $out/setup || exit 1

View File

@ -11,6 +11,8 @@ let {
builder = ./builder.sh; builder = ./builder.sh;
substitute = ../../build-support/substitute/substitute.sh;
setup = ./setup.sh; setup = ./setup.sh;
inherit preHook postHook initialPath gcc shell; inherit preHook postHook initialPath gcc shell;