* gcc-wrapper now filters out -L and -I flags referring to paths

outside the store (in pure builds).

svn path=/nixpkgs/trunk/; revision=817
This commit is contained in:
Eelco Dolstra 2004-03-08 18:29:08 +00:00
parent ce50734cf0
commit 946a2d4a48
10 changed files with 68 additions and 15 deletions

View File

@ -57,6 +57,7 @@ test -z "$isNative" && echo $glibc > $out/nix-support/orig-glibc
sed \
-e "s^@isNative@^$isNative^g" \
-e "s^@enforcePurity@^$enforcePurity^g" \
-e "s^@gcc@^$gcc^g" \
-e "s^@glibc@^$glibc^g" \
< $setupHook > $out/nix-support/setup-hook

View File

@ -17,6 +17,7 @@ derivation {
gccWrapper = ./gcc-wrapper.sh;
ldWrapper = ./ld-wrapper.sh;
inherit name stdenv isNative gcc glibc binutils;
enforcePurity = if isNative then false else gcc.noSysDirs;
langC = if isNative then true else gcc.langC;
langCC = if isNative then true else gcc.langCC;
langF77 = if isNative then false else gcc.langF77;

View File

@ -10,6 +10,7 @@ if test -z "$NIX_GLIBC_FLAGS_SET"; then
NIX_LDFLAGS="@ldflags@ $NIX_LDFLAGS"
fi
# Figure out if linker flags should be passed. GCC prints annoying
# warnings when they are not needed.
dontLink=0
@ -33,6 +34,40 @@ else
done
fi
# Optionally filter out paths not refering to the store.
skip () {
if test "$NIX_DEBUG" = "1"; then
echo "skipping impure path $1" >&2
fi
}
params=("$@")
if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
rest=()
n=0
while test $n -lt ${#params[*]}; do
p=${params[n]}
p2=${params[$((n+1))]}
if test "${p:0:3}" = "-L/" -a "${p:2:${#NIX_STORE}}" != "$NIX_STORE"; then
skip $p
elif test "$p" = "-L" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then
n=$((n + 1)); skip $p2
elif test "${p:0:3}" = "-I/" -a "${p:2:${#NIX_STORE}}" != "$NIX_STORE"; then
skip $p
elif test "$p" = "-I" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then
n=$((n + 1)); skip $p2
elif test "$p" = "-isystem" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then
n=$((n + 1)); skip $p2
else
rest=("${rest[@]}" "$p")
fi
n=$((n + 1))
done
params=("${rest[@]}")
fi
# Add the flags for the C compiler proper.
extra=($NIX_CFLAGS_COMPILE)
@ -58,7 +93,7 @@ fi
# Optionally print debug info.
if test "$NIX_DEBUG" = "1"; then
echo "original flags to @gcc@:" >&2
for i in "$@"; do
for i in "${params[@]}"; do
echo " $i" >&2
done
echo "extra flags to @gcc@:" >&2
@ -71,4 +106,4 @@ if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then
. "$NIX_GCC_WRAPPER_EXEC_HOOK"
fi
exec @gcc@ "$@" ${extra[@]}
exec @gcc@ "${params[@]}" ${extra[@]}

View File

@ -13,3 +13,5 @@ envHooks=(${envHooks[@]} addCVars)
if test -z "@isNative@"; then
PATH=$PATH:@gcc@/bin:@glibc@/bin
fi
export NIX_ENFORCE_PURITY=@enforcePurity@

View File

@ -1,19 +1,16 @@
{ stdenv, fetchurl
{ stdenv, fetchurl, noSysDirs ? true
, langC ? true, langCC ? true, langF77 ? false
}:
assert langC;
derivation {
name = "gcc-3.3.2";
name = "gcc-3.3.3";
system = stdenv.system;
builder = ./builder.sh;
src = fetchurl {
# url = ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-3.3.3/gcc-3.3.3.tar.bz2;
# md5 = "3c6cfd9fcd180481063b4058cf6faff2";
url = ftp://ftp.nluug.nl/pub/gnu/gcc/gcc-3.3.2/gcc-3.3.2.tar.bz2;
md5 = "65999f654102f5438ac8562d13a6eced";
url = ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-3.3.3/gcc-3.3.3.tar.bz2;
md5 = "3c6cfd9fcd180481063b4058cf6faff2";
};
noSysDirs = stdenv.noSysDirs;
inherit stdenv langC langCC langF77;
inherit stdenv noSysDirs langC langCC langF77;
}

View File

@ -15,7 +15,7 @@ LDFLAGS=-Wl,-S ../glibc-*/configure --prefix=$out --enable-add-ons --disable-pro
make || exit 1
make install || exit 1
make localedata/install-locales || exit 1
#make localedata/install-locales || exit 1
strip -S $out/lib/*.a $out/lib/*.so $out/lib/gconv/*.so
strip -s $out/bin/* $out/sbin/* $out/libexec/*

View File

@ -21,6 +21,11 @@ param5=@param5@
. @preHook@
if test -f @gcc@/nix-support/setup-hook; then
. @gcc@/nix-support/setup-hook
fi
# Recursively find all build inputs.
findInputs()
{
@ -76,6 +81,10 @@ export NIX_STRIP_DEBUG=1
export NIX_CFLAGS_STRIP="-g0 -Wl,-s"
# Where is the store? This is required for purity checking.
export NIX_STORE=$(dirname $out)/ # !!! hack
# Execute the post-hook.
. @postHook@

View File

@ -12,6 +12,6 @@
# Select the right instantiation.
body =
if system == "i686-linux"
then stdenvs.stdenvLinuxPkgs
then stdenvs.stdenvNativePkgs #stdenvs.stdenvLinuxPkgs
else stdenvs.stdenvNixPkgs;
}

View File

@ -8,12 +8,19 @@
{system, allPackages}: rec {
# Trivial environment used for building other environments.
stdenvInitial = (import ../stdenv/initial) {
name = "stdenv-initial";
inherit system;
};
# The native (i.e., impure) build environment. This one uses the
# tools installed on the system outside of the Nix environment,
# i.e., the stuff in /bin, /usr/bin, etc. This environment should
# be used with care, since many Nix packages will not build properly
# with it (e.g., because they require GNU Make).
stdenvNative = (import ../stdenv/native) {system = system;};
stdenvNative = (import ../stdenv/native) {stdenv = stdenvInitial;};
stdenvNativePkgs = allPackages {system = system; stdenv = stdenvNative;};

View File

@ -4,7 +4,7 @@ export NIX_DEBUG=1
. $stdenv/setup
export NIX_CFLAGS_COMPILE="-v $NIX_CFLAGS_COMPILE"
#export NIX_CFLAGS_COMPILE="-v $NIX_CFLAGS_COMPILE"
mkdir $out
mkdir $out/bin
@ -19,7 +19,8 @@ int main(int argc, char * * argv)
}
EOF
gcc hello.c -o $out/bin/hello
#gcc -I/nix/store/foo -I /nix/store/foo -I/usr/lib -I /usr/lib hello.c -o $out/bin/hello
gcc -L /nix/store/abcd/lib -isystem /usr/lib hello.c -o $out/bin/hello
$out/bin/hello