* 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
. $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 <<EOF
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
doSubstitute "$addFlags" "$out/nix-support/add-flags"
sed \
-e "s^@gcc@^$gcc^g" \
-e "s^@binutils@^$binutils^g" \
-e "s^@glibc@^$glibc^g" \
< $setupHook > $out/nix-support/setup-hook
doSubstitute "$setupHook" "$out/nix-support/setup-hook"
cp -p $utils $out/nix-support/utils

View file

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

View file

@ -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[@]}

View file

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

View file

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

View file

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