about summary refs log tree commit diff
path: root/pkgs/build-support/gcc-wrapper
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/gcc-wrapper')
-rwxr-xr-xpkgs/build-support/gcc-wrapper/builder.sh5
-rw-r--r--pkgs/build-support/gcc-wrapper/default.nix1
-rw-r--r--pkgs/build-support/gcc-wrapper/gcc-wrapper.sh17
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-wrapper.sh28
-rw-r--r--pkgs/build-support/gcc-wrapper/utils.sh13
5 files changed, 36 insertions, 28 deletions
diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh
index 352a5895135fd..5da6af4bdb60d 100755
--- a/pkgs/build-support/gcc-wrapper/builder.sh
+++ b/pkgs/build-support/gcc-wrapper/builder.sh
@@ -56,6 +56,7 @@ ln -s g77 $out/bin/f77
 
 
 sed \
+    -e "s^@out@^$out^g" \
     -e "s^@ldflags@^$ldflags^g" \
     -e "s^@ld@^$ldPath/ld^g" \
     < $ldWrapper > $out/bin/ld
@@ -63,7 +64,7 @@ chmod +x $out/bin/ld
 
 
 mkdir $out/nix-support
-test -z "$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
 
 cat > $out/nix-support/add-flags <<EOF
@@ -77,3 +78,5 @@ sed \
     -e "s^@binutils@^$binutils^g" \
     -e "s^@glibc@^$glibc^g" \
     < $setupHook > $out/nix-support/setup-hook
+
+cp -p $utils $out/nix-support/utils
\ No newline at end of file
diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix
index a9c3f3382b850..304f919138f3a 100644
--- a/pkgs/build-support/gcc-wrapper/default.nix
+++ b/pkgs/build-support/gcc-wrapper/default.nix
@@ -19,6 +19,7 @@ derivation {
   setupHook = ./setup-hook.sh;
   gccWrapper = ./gcc-wrapper.sh;
   ldWrapper = ./ld-wrapper.sh;
+  utils = ./utils.sh;
   inherit name stdenv nativeTools nativeGlibc nativePrefix gcc glibc binutils;
   langC = if nativeTools then true else gcc.langC;
   langCC = if nativeTools then true else gcc.langCC;
diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
index 29d3ffb8e492f..d144e142d2145 100644
--- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
@@ -8,13 +8,15 @@ if test -z "$NIX_GLIBC_FLAGS_SET"; then
     . @out@/nix-support/add-flags
 fi
 
+. @out@/nix-support/utils
+
 
 # Figure out if linker flags should be passed.  GCC prints annoying
 # warnings when they are not needed.
 dontLink=0
 if test "$*" = "-v" -o -z "$*"; then
     dontLink=1
-else    
+else
     for i in "$@"; do
         if test "$i" = "-c"; then
             dontLink=1
@@ -34,19 +36,8 @@ fi
 
 
 # Optionally filter out paths not refering to the store.
-skip () {
-    if test "$NIX_DEBUG" = "1"; then
-        echo "skipping impure path $1" >&2
-    fi
-}
-
-badPath() {
-    p=$1
-    test "${p:0:${#NIX_STORE}}" = "$NIX_STORE" -o "${p:0:4}" = "/tmp"
-}
-
 params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1x" -a -n "$NIX_STORE"; then
+if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
     rest=()
     n=0
     while test $n -lt ${#params[*]}; do
diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
index bf59b2a8afbb6..45bb210aa6d9f 100644
--- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
@@ -4,30 +4,29 @@ if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
     . "$NIX_LD_WRAPPER_START_HOOK"
 fi
 
-# Optionally filter out paths not refering to the store.
-skip () {
-    if test "$NIX_DEBUG" = "1"; then
-        echo "skipping impure path $1" >&2
-    fi
-}
+. @out@/nix-support/utils
+
 
+# Optionally filter out paths not refering to the store.
 params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1x" -a -n "$NIX_STORE"; then
+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
+        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
             skip $p
-        elif test "$p" = "-L" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then
+        elif test "$p" = "-L" && badPath "$p2"; then
+            n=$((n + 1)); skip $p2
+        elif test "$p" = "-rpath" && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "$p" = "-dynamic-linker" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then
+        elif test "$p" = "-dynamic-linker" && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-#        elif test "${p:0:1}" = "/" -a "${p:0:${#NIX_STORE}}" != "$NIX_STORE"; then
-#            # We cannot skip this; barf.
-#            echo "impure path \`$p' used in link"
-#            exit 1
+        elif test "${p:0:1}" = "/" && badPath "$p"; then
+            # We cannot skip this; barf.
+            echo "impure path \`$p' used in link" >&2
+            exit 1
         else
             rest=("${rest[@]}" "$p")
         fi
@@ -43,6 +42,7 @@ if test -z "$NIX_LDFLAGS_SET"; then
     extra=(${extra[@]} $NIX_LDFLAGS)
 fi
 
+# Optionally print debug info.
 if test "$NIX_DEBUG" = "1"; then
   echo "original flags to @ld@:" >&2
   for i in "${params[@]}"; do
diff --git a/pkgs/build-support/gcc-wrapper/utils.sh b/pkgs/build-support/gcc-wrapper/utils.sh
new file mode 100644
index 0000000000000..5163c239527c4
--- /dev/null
+++ b/pkgs/build-support/gcc-wrapper/utils.sh
@@ -0,0 +1,13 @@
+skip () {
+    if test "$NIX_DEBUG" = "1"; then
+        echo "skipping impure path $1" >&2
+    fi
+}
+
+badPath() {
+    local p=$1
+    test \
+        "${p:0:${#NIX_STORE}}" != "$NIX_STORE" -a \
+        "${p:0:4}" != "/tmp" -a \
+        "${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP"
+}