summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-11-04 14:30:43 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-11-04 14:30:43 +0100
commit7495c61d49208a9fc90b937bca548d9005ff17c8 (patch)
tree5eec5f802d3146b8b1f788aa1275ea1c44a24d31 /pkgs/build-support
parented867a50eb89a90db3b1741bf4c0bf0cd4557dba (diff)
parent899d81b37ba6dc26431b82b40300505f19504e03 (diff)
downloadnixlib-7495c61d49208a9fc90b937bca548d9005ff17c8.tar
nixlib-7495c61d49208a9fc90b937bca548d9005ff17c8.tar.gz
nixlib-7495c61d49208a9fc90b937bca548d9005ff17c8.tar.bz2
nixlib-7495c61d49208a9fc90b937bca548d9005ff17c8.tar.lz
nixlib-7495c61d49208a9fc90b937bca548d9005ff17c8.tar.xz
nixlib-7495c61d49208a9fc90b937bca548d9005ff17c8.tar.zst
nixlib-7495c61d49208a9fc90b937bca548d9005ff17c8.zip
Merge remote-tracking branch 'origin/darwin-clang-stdenv' into staging
Conflicts:
	pkgs/applications/editors/vim/macvim.nix
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/cabal/default.nix5
-rw-r--r--pkgs/build-support/clang-wrapper/add-flags24
-rw-r--r--pkgs/build-support/clang-wrapper/builder.sh137
-rw-r--r--pkgs/build-support/clang-wrapper/clang-wrapper.sh150
-rw-r--r--pkgs/build-support/clang-wrapper/default.nix89
-rw-r--r--pkgs/build-support/clang-wrapper/setup-hook.sh38
-rw-r--r--pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh11
-rw-r--r--pkgs/build-support/gcc-wrapper/add-flags16
-rw-r--r--pkgs/build-support/gcc-wrapper/builder.sh214
-rw-r--r--pkgs/build-support/gcc-wrapper/default.nix246
-rw-r--r--pkgs/build-support/gcc-wrapper/gcc-wrapper.sh80
-rw-r--r--pkgs/build-support/gcc-wrapper/gnat-wrapper.sh50
-rw-r--r--pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh22
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh2
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-wrapper.sh62
-rw-r--r--pkgs/build-support/gcc-wrapper/setup-hook.sh20
-rw-r--r--pkgs/build-support/gcc-wrapper/utils.sh8
-rw-r--r--pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh6
18 files changed, 323 insertions, 857 deletions
diff --git a/pkgs/build-support/cabal/default.nix b/pkgs/build-support/cabal/default.nix
index 3fa833876921..49618266d79b 100644
--- a/pkgs/build-support/cabal/default.nix
+++ b/pkgs/build-support/cabal/default.nix
@@ -218,6 +218,10 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
                 configureFlags+=" --ghc-option=-optl=-Wl,-headerpad_max_install_names"
               ''}
 
+              ${optionalString self.stdenv.isDarwin ''
+                configureFlags+=" --with-gcc=clang"
+              ''}
+
               echo "configure flags: $extraConfigureFlags $configureFlags"
               ./Setup configure --verbose --prefix="$out" --libdir='$prefix/lib/$compiler' \
                 --libsubdir='$pkgid' $extraConfigureFlags $configureFlags 2>&1 \
@@ -240,6 +244,7 @@ assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
 
               export GHC_PACKAGE_PATH=$(${ghc.GHCPackages})
               test -n "$noHaddock" || ./Setup haddock --html --hoogle \
+                  --ghc-options=-optP-P \
                   ${optionalString self.hyperlinkSource "--hyperlink-source"}
 
               eval "$postBuild"
diff --git a/pkgs/build-support/clang-wrapper/add-flags b/pkgs/build-support/clang-wrapper/add-flags
deleted file mode 100644
index 7a9711290aa1..000000000000
--- a/pkgs/build-support/clang-wrapper/add-flags
+++ /dev/null
@@ -1,24 +0,0 @@
-# `-B@out@/bin' forces clang to use ld-wrapper.sh when calling ld.
-export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
-
-if test -e @out@/nix-support/libc-cflags; then
-    export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
-fi
-
-if test -e @out@/nix-support/clang-cflags; then
-    export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/clang-cflags) $NIX_CFLAGS_COMPILE"
-fi
-
-if test -e @out@/nix-support/libc-ldflags; then
-    export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/libc-ldflags)"
-fi
-
-if test -e @out@/nix-support/clang-ldflags; then
-    export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/clang-ldflags)"
-fi
-
-if test -e @out@/nix-support/libc-ldflags-before; then
-    export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
-fi
-
-export NIX_GCC_WRAPPER_FLAGS_SET=1
diff --git a/pkgs/build-support/clang-wrapper/builder.sh b/pkgs/build-support/clang-wrapper/builder.sh
deleted file mode 100644
index 0cdb2b96135e..000000000000
--- a/pkgs/build-support/clang-wrapper/builder.sh
+++ /dev/null
@@ -1,137 +0,0 @@
-source $stdenv/setup
-
-
-mkdir -p $out/bin
-mkdir -p $out/nix-support
-
-
-if test -z "$nativeLibc"; then
-    dynamicLinker="$libc/lib/$dynamicLinker"
-    echo $dynamicLinker > $out/nix-support/dynamic-linker
-
-    if test -e $libc/lib/32/ld-linux.so.2; then
-        echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
-    fi
-
-    # The "-B$libc/lib/" flag is a quick hack to force clang to link
-    # against the crt1.o from our own glibc, rather than the one in
-    # /usr/lib.  (This is only an issue when using an `impure'
-    # compiler/linker, i.e., one that searches /usr/lib and so on.)
-    echo "-B$libc/lib/ -idirafter $libc/include" > $out/nix-support/libc-cflags
-
-    echo "-L$libc/lib" > $out/nix-support/libc-ldflags
-
-    # The dynamic linker is passed in `ldflagsBefore' to allow
-    # explicit overrides of the dynamic linker by callers to clang/ld
-    # (the *last* value counts, so ours should come first).
-    echo "-dynamic-linker $dynamicLinker" > $out/nix-support/libc-ldflags-before
-fi
-
-if test -n "$nativeTools"; then
-    clangPath="$nativePrefix/bin"
-    ldPath="$nativePrefix/bin"
-else
-    basePath=`echo $gcc/lib/*/*/*`
-    # Need libgcc until the llvm compiler-rt library is complete
-    clangLDFlags="$clangLDFlags -L$basePath"
-    if test -e "$gcc/lib64"; then
-        clangLDFlags="$clangLDFlags -L$gcc/lib64"
-    else
-        clangLDFlags="$clangLDFlags -L$gcc/lib"
-    fi
-
-    clangLDFlags="$clangLDFlags -L$clang/lib"
-    echo "$clangLDFlags" > $out/nix-support/clang-ldflags
-
-    # Need files like crtbegin.o from gcc
-    # It's unclear if these will ever be provided by an LLVM project
-    clangCFlags="$clangCFlags -B$basePath"
-
-    clangCFlags="$clangCFlags -isystem$clang/lib/clang/$clangVersion/include"
-    echo "$clangCFlags" > $out/nix-support/clang-cflags
-    
-    clangPath="$clang/bin"
-    ldPath="$binutils/bin"
-fi
-
-
-doSubstitute() {
-    local src=$1
-    local dst=$2
-    local uselibcxx=
-    local uselibcxxabi=
-    if test -n "$libcxx" && echo $dst | fgrep ++; then uselibcxx=$libcxx; fi
-    if test -n "$libcxxabi" && echo $dst | fgrep ++; then uselibcxxabi=$libcxxabi; fi
-    # Can't use substitute() here, because replace may not have been
-    # built yet (in the bootstrap).
-    sed \
-        -e "s^@out@^$out^g" \
-        -e "s^@shell@^$shell^g" \
-        -e "s^@libcxx@^$uselibcxx^g" \
-        -e "s^@libcxxabi@^$uselibcxxabi^g" \
-        -e "s^@clang@^$clang^g" \
-        -e "s^@clangProg@^$clangProg^g" \
-        -e "s^@binutils@^$binutils^g" \
-        -e "s^@coreutils@^$coreutils^g" \
-        -e "s^@libc@^$libc^g" \
-        -e "s^@ld@^$ldPath/ld^g" \
-        < "$src" > "$dst" 
-}
-
-
-# Make wrapper scripts around clang and clang++.  Also make symlinks
-# cc and c++
-mkClangWrapper() {
-    local dst=$1
-    local src=$2
-
-    if ! test -f "$src"; then
-        echo "$src does not exist (skipping)"
-        return 1
-    fi
-
-    clangProg="$src"
-    doSubstitute "$clangWrapper" "$dst"
-    chmod +x "$dst"
-}
-
-if mkClangWrapper $out/bin/clang $clangPath/clang
-then
-    ln -sv clang $out/bin/cc
-fi
-
-if mkClangWrapper $out/bin/clang++ $clangPath/clang++
-then
-    ln -sv clang++ $out/bin/c++
-fi
-
-
-# Create a symlink to as (the assembler).  This is useful when a
-# clang-wrapper is installed in a user environment, as it ensures that
-# the right assembler is called.
-ln -s $ldPath/as $out/bin/as
-
-
-# Make a wrapper around the linker.
-doSubstitute "$ldWrapper" "$out/bin/ld"
-chmod +x "$out/bin/ld"
-
-
-# Emit a setup hook.  Also store the path to the original Clang and
-# libc.
-test -n "$clang" && echo $clang > $out/nix-support/orig-clang
-test -n "$libc" && echo $libc > $out/nix-support/orig-libc
-
-doSubstitute "$addFlags" "$out/nix-support/add-flags.sh"
-
-doSubstitute "$setupHook" "$out/nix-support/setup-hook"
-
-cp -p $utils $out/nix-support/utils.sh
-
-
-# Propagate the wrapped clang so that if you install the wrapper, you get
-# llvm tools, the manpages, etc. as well (including for binutils
-# and Glibc).
-if test -z "$nativeTools"; then
-    echo $clang $binutils $libc > $out/nix-support/propagated-user-env-packages
-fi
diff --git a/pkgs/build-support/clang-wrapper/clang-wrapper.sh b/pkgs/build-support/clang-wrapper/clang-wrapper.sh
deleted file mode 100644
index 57715274f1e2..000000000000
--- a/pkgs/build-support/clang-wrapper/clang-wrapper.sh
+++ /dev/null
@@ -1,150 +0,0 @@
-#! @shell@ -e
-
-if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
-    source "$NIX_GCC_WRAPPER_START_HOOK"
-fi
-
-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
-    source @out@/nix-support/add-flags.sh
-fi
-
-source @out@/nix-support/utils.sh
-
-
-# Figure out if linker flags should be passed.  Clang prints annoying
-# warnings when they are not needed. (does it really? Copied from gcc-wrapper)
-dontLink=0
-getVersion=0
-nonFlagArgs=0
-
-for i in "$@"; do
-    if test "$i" = "-c"; then
-        dontLink=1
-    elif test "$i" = "-S"; then
-        dontLink=1
-    elif test "$i" = "-E"; then
-        dontLink=1
-    elif test "$i" = "-E"; then
-        dontLink=1
-    elif test "$i" = "-M"; then
-        dontLink=1
-    elif test "$i" = "-MM"; then
-        dontLink=1
-    elif test "$i" = "-x"; then
-        # At least for the cases c-header or c++-header we should set dontLink.
-        # I expect no one use -x other than making precompiled headers.
-        dontLink=1
-    elif test "${i:0:1}" != "-"; then
-        nonFlagArgs=1
-    elif test "$i" = "-m32"; then
-        if test -e @out@/nix-support/dynamic-linker-m32; then
-            NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
-        fi
-    fi
-done
-
-# If we pass a flag like -Wl, then clang will call the linker unless it
-# can figure out that it has to do something else (e.g., because of a
-# "-c" flag).  So if no non-flag arguments are given, don't pass any
-# linker flags.  This catches cases like "clang" (should just print
-# "clang: no input files") and "clang -v" (should print the version).
-if test "$nonFlagArgs" = "0"; then
-    dontLink=1
-fi
-
-# Optionally filter out paths not refering to the store.
-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/" && badPath "${p:2}"; then
-            skip $p
-        elif test "$p" = "-L" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
-            skip $p
-        elif test "$p" = "-I" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "$p" = "-isystem" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        else
-            rest=("${rest[@]}" "$p")
-        fi
-        n=$((n + 1))
-    done
-    params=("${rest[@]}")
-    NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE --sysroot=/var/empty"
-fi
-
-if test -n "@libcxx@"; then
-    NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem@libcxx@/include/c++/v1 -stdlib=libc++"
-    NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK -L@libcxx@/lib -stdlib=libc++ -L@libcxxabi@/lib -lc++abi"
-fi
-
-# Add the flags for the C compiler proper.
-extraAfter=($NIX_CFLAGS_COMPILE)
-extraBefore=()
-
-if test "$dontLink" != "1"; then
-
-    # Add the flags that should only be passed to the compiler when
-    # linking.
-    extraAfter=(${extraAfter[@]} $NIX_CFLAGS_LINK)
-
-    # Add the flags that should be passed to the linker (and prevent
-    # `ld-wrapper' from adding NIX_LDFLAGS again).
-    for i in $NIX_LDFLAGS_BEFORE; do
-        extraBefore=(${extraBefore[@]} "-Wl,$i")
-    done
-    for i in $NIX_LDFLAGS; do
-	if test "${i:0:3}" = "-L/"; then
-	    extraAfter=(${extraAfter[@]} "$i")
-	else
-	    extraAfter=(${extraAfter[@]} "-Wl,$i")
-	fi
-    done
-    export NIX_LDFLAGS_SET=1
-fi
-
-# As a very special hack, if the arguments are just `-v', then don't
-# add anything.  This is to prevent `clang -v' (which normally prints
-# out the version number and returns exit code 0) from printing out
-# `No input files specified' and returning exit code 1.
-if test "$*" = "-v"; then
-    extraAfter=()
-    extraBefore=()
-fi    
-
-# Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @clangProg@:" >&2
-  for i in "${params[@]}"; do
-      echo "  $i" >&2
-  done
-  echo "extraBefore flags to @clangProg@:" >&2
-  for i in ${extraBefore[@]}; do
-      echo "  $i" >&2
-  done
-  echo "extraAfter flags to @clangProg@:" >&2
-  for i in ${extraAfter[@]}; do
-      echo "  $i" >&2
-  done
-fi
-
-if test -n "$NIX_CLANG_WRAPPER_EXEC_HOOK"; then
-    source "$NIX_CLANG_WRAPPER_EXEC_HOOK"
-fi
-
-# Call the real `clang'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_CLANG_NEEDS_GREP"; then
-    @clangProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
-else
-    (@clangProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi    
diff --git a/pkgs/build-support/clang-wrapper/default.nix b/pkgs/build-support/clang-wrapper/default.nix
deleted file mode 100644
index 7a5d87127d90..000000000000
--- a/pkgs/build-support/clang-wrapper/default.nix
+++ /dev/null
@@ -1,89 +0,0 @@
-# The Nix `clang' stdenv.mkDerivation is not directly usable, since it doesn't
-# know where the C library and standard header files are.  Therefore
-# the compiler produced by that package cannot be installed directly
-# in a user environment and used from the command line.  This
-# stdenv.mkDerivation provides a wrapper that sets up the right environment
-# variables so that the compiler and the linker just "work".
-
-{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
-, clang ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
-, zlib ? null, libcxx ? null
-}:
-
-assert nativeTools -> nativePrefix != "";
-assert !nativeTools -> clang != null && binutils != null && coreutils != null;
-assert !nativeLibc -> libc != null;
-
-let
-
-  clangVersion = (builtins.parseDrvName clang.name).version;
-  clangName = (builtins.parseDrvName clang.name).name;
-
-in
-
-stdenv.mkDerivation {
-  name =
-    (if name != "" then name else clangName + "-wrapper") +
-    (if clang != null && clangVersion != "" then "-" + clangVersion else "");
-
-  builder = ./builder.sh;
-  setupHook = ./setup-hook.sh;
-  clangWrapper = ./clang-wrapper.sh;
-  ldWrapper = ../gcc-wrapper/ld-wrapper.sh;
-  utils = ../gcc-wrapper/utils.sh;
-  addFlags = ./add-flags;
-
-  inherit nativeTools nativeLibc nativePrefix clang clangVersion libcxx;
-
-  libcxxabi = libcxx.abi or null;
-
-  gcc = clang.gcc;
-  libc = if nativeLibc then null else libc;
-  binutils = if nativeTools then null else binutils;
-  # The wrapper scripts use 'cat', so we may need coreutils
-  coreutils = if nativeTools then null else coreutils;
-
-  langC = true;
-  langCC = true;
-  shell = if shell == "" then stdenv.shell else
-    if builtins.isAttrs shell then (shell + shell.shellPath)
-    else shell;
-
-  crossAttrs = {
-    shell = shell.crossDrv + shell.crossDrv.shellPath;
-    libc = libc.crossDrv;
-    coreutils = coreutils.crossDrv;
-    binutils = binutils.crossDrv;
-    clang = clang.crossDrv;
-    #
-    # This is not the best way to do this. I think the reference should be
-    # the style in the gcc-cross-wrapper, but to keep a stable stdenv now I
-    # do this sufficient if/else.
-    dynamicLinker =
-      (if stdenv.cross.arch == "arm" then "ld-linux.so.3" else
-       if stdenv.cross.arch == "mips" then "ld.so.1" else
-       if stdenv.lib.hasSuffix "pc-gnu" stdenv.cross.config then "ld.so.1" else
-       abort "don't know the name of the dynamic linker for this platform");
-  };
-
-  meta =
-    let clang_ = if clang != null then clang else {}; in
-    (if clang_ ? meta then removeAttrs clang.meta ["priority"] else {}) //
-    { description =
-        stdenv.lib.attrByPath ["meta" "description"] "System C compiler" clang_
-        + " (wrapper script)";
-    };
-
-  # The dynamic linker has different names on different Linux platforms.
-  dynamicLinker =
-    if !nativeLibc then
-      (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
-       if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
-       if stdenv.isArm then "ld-linux.so.3" else
-       if stdenv.system == "powerpc-linux" then "ld.so.1" else
-       if stdenv.system == "mips64el-linux" then "ld.so.1" else
-       abort "don't know the name of the dynamic linker for this platform")
-    else "";
-
-  preferLocalBuild = true;
-}
diff --git a/pkgs/build-support/clang-wrapper/setup-hook.sh b/pkgs/build-support/clang-wrapper/setup-hook.sh
deleted file mode 100644
index 0bd531050c47..000000000000
--- a/pkgs/build-support/clang-wrapper/setup-hook.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-export NIX_GCC=@out@
-
-addCVars () {
-    if test -d $1/include; then
-        export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
-    fi
-
-    if test -d $1/lib64; then
-        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib64"
-    fi
-
-    if test -d $1/lib; then
-        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib"
-    fi
-}
-
-envHooks+=(addCVars)
-
-# Note: these come *after* $out in the PATH (see setup.sh).
-
-if test -n "@clang@"; then
-    addToSearchPath PATH @clang@/bin
-fi
-
-if test -n "@binutils@"; then
-    addToSearchPath PATH @binutils@/bin
-fi
-
-if test -n "@libc@"; then
-    addToSearchPath PATH @libc@/bin
-fi
-
-if test -n "@coreutils@"; then
-    addToSearchPath PATH @coreutils@/bin
-fi
-
-: ${CXX:=clang++}
-export CXX
diff --git a/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
index f954cae05d86..ec1f6004edd9 100644
--- a/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
+++ b/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
@@ -114,13 +114,4 @@ fi
 # We want gcc to call the wrapper linker, not that of binutils.
 export PATH="@ldPath@:$PATH"
 
-# Call the real `gcc'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_GCC_NEEDS_GREP"; then
-    @gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
-else
-    (@gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi    
+exec @gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
diff --git a/pkgs/build-support/gcc-wrapper/add-flags b/pkgs/build-support/gcc-wrapper/add-flags
index 26e536f6d575..d75f378e2c97 100644
--- a/pkgs/build-support/gcc-wrapper/add-flags
+++ b/pkgs/build-support/gcc-wrapper/add-flags
@@ -1,27 +1,27 @@
 # `-B@out@/bin' forces gcc to use ld-wrapper.sh when calling ld.
 export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
 
-if test -e @out@/nix-support/libc-cflags; then
+if [ -e @out@/nix-support/libc-cflags ]; then
     export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
 fi
 
-if test -e @out@/nix-support/gcc-cflags; then
+if [ -e @out@/nix-support/gcc-cflags ]; then
     export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/gcc-cflags) $NIX_CFLAGS_COMPILE"
 fi
 
-if test -e @out@/nix-support/gnat-cflags; then
+if [ -e @out@/nix-support/gnat-cflags ]; then
     export NIX_GNATFLAGS_COMPILE="$(cat @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
 fi
 
-if test -e @out@/nix-support/libc-ldflags; then
-    export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/libc-ldflags)"
+if [ -e @out@/nix-support/libc-ldflags ]; then
+    export NIX_LDFLAGS+=" $(cat @out@/nix-support/libc-ldflags)"
 fi
 
-if test -e @out@/nix-support/gcc-ldflags; then
-    export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/gcc-ldflags)"
+if [ -e @out@/nix-support/gcc-ldflags ]; then
+    export NIX_LDFLAGS+=" $(cat @out@/nix-support/gcc-ldflags)"
 fi
 
-if test -e @out@/nix-support/libc-ldflags-before; then
+if [ -e @out@/nix-support/libc-ldflags-before ]; then
     export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
 fi
 
diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh
deleted file mode 100644
index c79680712ee7..000000000000
--- a/pkgs/build-support/gcc-wrapper/builder.sh
+++ /dev/null
@@ -1,214 +0,0 @@
-source $stdenv/setup
-
-
-mkdir -p $out/bin
-mkdir -p $out/nix-support
-
-
-if test -z "$nativeLibc"; then
-    dynamicLinker="$libc/lib/$dynamicLinker"
-    echo $dynamicLinker > $out/nix-support/dynamic-linker
-
-    if test -e $libc/lib/32/ld-linux.so.2; then
-        echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
-    fi
-
-    # The "-B$libc/lib/" flag is a quick hack to force gcc to link
-    # against the crt1.o from our own glibc, rather than the one in
-    # /usr/lib.  (This is only an issue when using an `impure'
-    # compiler/linker, i.e., one that searches /usr/lib and so on.)
-    #
-    # Unfortunately, setting -B appears to override the default search
-    # path. Thus, the gcc-specific "../includes-fixed" directory is
-    # now longer searched and glibc's <limits.h> header fails to
-    # compile, because it uses "#include_next <limits.h>" to find the
-    # limits.h file in ../includes-fixed. To remedy the problem,
-    # another -idirafter is necessary to add that directory again.
-    echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
-
-    echo "-L$libc/lib" > $out/nix-support/libc-ldflags
-
-    # The dynamic linker is passed in `ldflagsBefore' to allow
-    # explicit overrides of the dynamic linker by callers to gcc/ld
-    # (the *last* value counts, so ours should come first).
-    echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
-fi
-
-if test -n "$nativeTools"; then
-    gccPath="$nativePrefix/bin"
-    ldPath="$nativePrefix/bin"
-else
-    if test -e "$gcc/lib64"; then
-        gccLDFlags="$gccLDFlags -L$gcc/lib64"
-    fi
-    gccLDFlags="$gccLDFlags -L$gcc/lib"
-    if [ -n "$langVhdl" ]; then
-        gccLDFlags="$gccLDFlags -L$zlib/lib"
-    fi
-    echo "$gccLDFlags" > $out/nix-support/gcc-ldflags
-
-    # GCC shows $gcc/lib in `gcc -print-search-dirs', but not
-    # $gcc/lib64 (even though it does actually search there...)..
-    # This confuses libtool.  So add it to the compiler tool search
-    # path explicitly.
-    if test -e "$gcc/lib64"; then
-        gccCFlags="$gccCFlags -B$gcc/lib64"
-    fi
-
-    # Find the gcc libraries path (may work only without multilib)
-    if [ -n "$langAda" ]; then
-        basePath=`echo $gcc/lib/*/*/*`
-        gccCFlags="$gccCFlags -B$basePath -I$basePath/adainclude"
-
-        gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
-        echo "$gnatCFlags" > $out/nix-support/gnat-cflags
-    fi
-    echo "$gccCFlags" > $out/nix-support/gcc-cflags
-    
-    gccPath="$gcc/bin"
-    # On Illumos/Solaris we might prefer native ld
-    if test -n "$nativePrefix"; then
-      ldPath="$nativePrefix/bin"
-    else
-      ldPath="$binutils/bin"
-    fi;
-fi
-
-
-doSubstitute() {
-    local src=$1
-    local dst=$2
-    local ld="$ldPath/ld"
-    if $ld -V 2>&1 |grep Solaris; then
-      # Use Solaris specific linker wrapper
-      ld="$out/bin/ld-solaris"
-    fi
-    # Can't use substitute() here, because replace may not have been
-    # built yet (in the bootstrap).
-    sed \
-        -e "s^@out@^$out^g" \
-        -e "s^@shell@^$shell^g" \
-        -e "s^@gcc@^$gcc^g" \
-        -e "s^@gccProg@^$gccProg^g" \
-        -e "s^@gnatProg@^$gnatProg^g" \
-        -e "s^@gnatlinkProg@^$gnatlinkProg^g" \
-        -e "s^@binutils@^$binutils^g" \
-        -e "s^@coreutils@^$coreutils^g" \
-        -e "s^@libc@^$libc^g" \
-        -e "s^@ld@^$ld^g" \
-        < "$src" > "$dst" 
-}
-
-
-# Make wrapper scripts around gcc, g++, and gfortran.  Also make symlinks
-# cc, c++, and f77.
-mkGccWrapper() {
-    local dst=$1
-    local src=$2
-
-    if ! test -f "$src"; then
-        echo "$src does not exist (skipping)"
-        return 1
-    fi
-
-    gccProg="$src"
-    doSubstitute "$gccWrapper" "$dst"
-    chmod +x "$dst"
-}
-
-mkGnatWrapper() {
-    local dst=$1
-    local src=$2
-
-    if ! test -f "$src"; then
-        echo "$src does not exist (skipping)"
-        return 1
-    fi
-
-    gnatProg="$src"
-    doSubstitute "$gnatWrapper" "$dst"
-    chmod +x "$dst"
-}
-
-mkGnatLinkWrapper() {
-    local dst=$1
-    local src=$2
-
-    if ! test -f "$src"; then
-        echo "$src does not exist (skipping)"
-        return 1
-    fi
-
-    gnatlinkProg="$src"
-    doSubstitute "$gnatlinkWrapper" "$dst"
-    chmod +x "$dst"
-}
-
-if mkGccWrapper $out/bin/gcc $gccPath/gcc
-then
-    ln -sv gcc $out/bin/cc
-fi
-
-if mkGccWrapper $out/bin/g++ $gccPath/g++
-then
-    ln -sv g++ $out/bin/c++
-fi
-
-mkGccWrapper $out/bin/cpp $gccPath/cpp || true
-
-if mkGccWrapper $out/bin/gfortran $gccPath/gfortran
-then
-    ln -sv gfortran $out/bin/g77
-    ln -sv gfortran $out/bin/f77
-fi
-
-mkGccWrapper $out/bin/gcj $gccPath/gcj || true
-
-mkGccWrapper $out/bin/gccgo $gccPath/gccgo || true
-
-mkGccWrapper $out/bin/gnatgcc $gccPath/gnatgcc || true
-mkGnatWrapper $out/bin/gnatmake $gccPath/gnatmake || true
-mkGnatWrapper $out/bin/gnatbind $gccPath/gnatbind || true
-mkGnatLinkWrapper $out/bin/gnatlink $gccPath/gnatlink || true
-
-if [ -f $gccPath/ghdl ]; then
-    ln -sf $gccPath/ghdl $out/bin/ghdl
-fi
-
-
-# Create a symlink to as (the assembler).  This is useful when a
-# gcc-wrapper is installed in a user environment, as it ensures that
-# the right assembler is called.
-ln -s $ldPath/as $out/bin/as
-
-
-# Make a wrapper around the linker.
-doSubstitute "$ldWrapper" "$out/bin/ld"
-chmod +x "$out/bin/ld"
-
-# Copy solaris ld wrapper if needed
-if $ldPath/ld -V 2>&1 |grep Solaris; then
-  # Use Solaris specific linker wrapper
-  sed -e "s^@ld@^$ldPath/ld^g" < "$ldSolarisWrapper" > "$out/bin/ld-solaris"
-  chmod +x "$out/bin/ld-solaris"
-fi
-
-
-# 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 "$libc" && echo $libc > $out/nix-support/orig-libc
-
-doSubstitute "$addFlags" "$out/nix-support/add-flags.sh"
-
-doSubstitute "$setupHook" "$out/nix-support/setup-hook"
-
-cp -p $utils $out/nix-support/utils.sh
-
-
-# Propagate the wrapped gcc so that if you install the wrapper, you get
-# tools like gcov, the manpages, etc. as well (including for binutils
-# and Glibc).
-if test -z "$nativeTools"; then
-    echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages
-fi
diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix
index 8e8b0b909454..b2f7d07560d3 100644
--- a/pkgs/build-support/gcc-wrapper/default.nix
+++ b/pkgs/build-support/gcc-wrapper/default.nix
@@ -1,28 +1,29 @@
-# The Nix `gcc' stdenv.mkDerivation is not directly usable, since it doesn't
-# know where the C library and standard header files are.  Therefore
-# the compiler produced by that package cannot be installed directly
-# in a user environment and used from the command line.  This
-# stdenv.mkDerivation provides a wrapper that sets up the right environment
-# variables so that the compiler and the linker just "work".
+# The Nixpkgs GCC is not directly usable, since it doesn't know where
+# the C library and standard header files are. Therefore the compiler
+# produced by that package cannot be installed directly in a user
+# environment and used from the command line. So we use a wrapper
+# script that sets up the right environment variables so that the
+# compiler and the linker just "work".
 
 { name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
-, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
-, zlib ? null
+, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenv.shell
+, zlib ? null, extraPackages ? []
 }:
 
+with stdenv.lib;
+
 assert nativeTools -> nativePrefix != "";
 assert !nativeTools -> gcc != null && binutils != null && coreutils != null;
 assert !nativeLibc -> libc != null;
 
-# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper
-assert (gcc != null && gcc ? langVhdl && gcc.langVhdl) -> zlib != null;
+# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper.
+assert gcc.langVhdl or false -> zlib != null;
 
 let
 
   gccVersion = (builtins.parseDrvName gcc.name).version;
   gccName = (builtins.parseDrvName gcc.name).name;
 
-  langGo = if nativeTools then false else gcc ? langGo && gcc.langGo;
 in
 
 stdenv.mkDerivation {
@@ -30,31 +31,198 @@ stdenv.mkDerivation {
     (if name != "" then name else gccName + "-wrapper") +
     (if gcc != null && gccVersion != "" then "-" + gccVersion else "");
 
-  builder = ./builder.sh;
-  setupHook = ./setup-hook.sh;
-  gccWrapper = ./gcc-wrapper.sh;
-  gnatWrapper = ./gnat-wrapper.sh;
-  gnatlinkWrapper = ./gnatlink-wrapper.sh;
-  ldWrapper = ./ld-wrapper.sh;
-  ldSolarisWrapper = ./ld-solaris-wrapper.sh;
-  utils = ./utils.sh;
-  addFlags = ./add-flags;
-
-  inherit nativeTools nativeLibc nativePrefix gcc;
+  preferLocalBuild = true;
+
+  inherit gcc shell;
   libc = if nativeLibc then null else libc;
   binutils = if nativeTools then null else binutils;
-  # The wrapper scripts use 'cat', so we may need coreutils
+  # The wrapper scripts use 'cat', so we may need coreutils.
   coreutils = if nativeTools then null else coreutils;
 
-  langC = if nativeTools then true else gcc.langC;
-  langCC = if nativeTools then true else gcc.langCC;
-  langFortran = if nativeTools then false else gcc ? langFortran;
-  langAda = if nativeTools then false else gcc ? langAda && gcc.langAda;
-  langVhdl = if nativeTools then false else gcc ? langVhdl && gcc.langVhdl;
-  zlib = if gcc != null && gcc ? langVhdl then zlib else null;
-  shell = if shell == "" then stdenv.shell else
-    if builtins.isAttrs shell then (shell + shell.shellPath)
-    else shell;
+  passthru = { inherit nativeTools nativeLibc nativePrefix; };
+
+  buildCommand =
+    ''
+      mkdir -p $out/bin $out/nix-support
+
+      wrap() {
+        local dst="$1"
+        local wrapper="$2"
+        export prog="$3"
+        substituteAll "$wrapper" "$out/bin/$dst"
+        chmod +x "$out/bin/$dst"
+      }
+    ''
+
+    + optionalString (!nativeLibc) ''
+      dynamicLinker="$libc/lib/$dynamicLinker"
+      echo $dynamicLinker > $out/nix-support/dynamic-linker
+
+      if [ -e $libc/lib/32/ld-linux.so.2 ]; then
+        echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
+      fi
+
+      # The "-B$libc/lib/" flag is a quick hack to force gcc to link
+      # against the crt1.o from our own glibc, rather than the one in
+      # /usr/lib.  (This is only an issue when using an `impure'
+      # compiler/linker, i.e., one that searches /usr/lib and so on.)
+      #
+      # Unfortunately, setting -B appears to override the default search
+      # path. Thus, the gcc-specific "../includes-fixed" directory is
+      # now longer searched and glibc's <limits.h> header fails to
+      # compile, because it uses "#include_next <limits.h>" to find the
+      # limits.h file in ../includes-fixed. To remedy the problem,
+      # another -idirafter is necessary to add that directory again.
+      echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
+
+      echo "-L$libc/lib" > $out/nix-support/libc-ldflags
+
+      # The dynamic linker is passed in `ldflagsBefore' to allow
+      # explicit overrides of the dynamic linker by callers to gcc/ld
+      # (the *last* value counts, so ours should come first).
+      echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
+
+      echo $libc > $out/nix-support/orig-libc
+    ''
+
+    + (if nativeTools then ''
+      gccPath="${nativePrefix}/bin"
+      ldPath="${nativePrefix}/bin"
+    '' else ''
+      echo $gcc > $out/nix-support/orig-gcc
+
+      # GCC shows $gcc/lib in `gcc -print-search-dirs', but not
+      # $gcc/lib64 (even though it does actually search there...)..
+      # This confuses libtool.  So add it to the compiler tool search
+      # path explicitly.
+      if [ -e "$gcc/lib64" -a ! -L "$gcc/lib64" ]; then
+        gccLDFlags+=" -L$gcc/lib64"
+        gccCFlags+=" -B$gcc/lib64"
+      fi
+      gccLDFlags+=" -L$gcc/lib"
+
+      ${optionalString gcc.langVhdl or false ''
+        gccLDFlags+=" -L${zlib}/lib"
+      ''}
+
+      # Find the gcc libraries path (may work only without multilib).
+      ${optionalString gcc.langAda or false ''
+        basePath=`echo $gcc/lib/*/*/*`
+        gccCFlags+=" -B$basePath -I$basePath/adainclude"
+        gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
+        echo "$gnatCFlags" > $out/nix-support/gnat-cflags
+      ''}
+
+      echo "$gccLDFlags" > $out/nix-support/gcc-ldflags
+      echo "$gccCFlags" > $out/nix-support/gcc-cflags
+
+      gccPath="$gcc/bin"
+      ldPath="$binutils/bin"
+
+      # Propagate the wrapped gcc so that if you install the wrapper,
+      # you get tools like gcov, the manpages, etc. as well (including
+      # for binutils and Glibc).
+      echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages
+
+      echo ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs
+    ''
+
+    + optionalString (stdenv.isSunOS && nativePrefix != "") ''
+      # Solaris needs an additional ld wrapper.
+      ldPath="${nativePrefix}/bin"
+      ld="$out/bin/ld-solaris"
+      wrap ld-solaris ${./ld-solaris-wrapper.sh}
+    '')
+
+    + ''
+      # Create a symlink to as (the assembler).  This is useful when a
+      # gcc-wrapper is installed in a user environment, as it ensures that
+      # the right assembler is called.
+      if [ -e $ldPath/as ]; then
+        ln -s $ldPath/as $out/bin/as
+      fi
+
+      wrap ld ${./ld-wrapper.sh} ''${ld:-$ldPath/ld}
+
+      if [ -e $binutils/bin/ld.gold ]; then
+        wrap ld.gold ${./ld-wrapper.sh} $binutils/bin/ld.gold
+      fi
+
+      if [ -e $binutils/bin/ld.bfd ]; then
+        wrap ld.bfd ${./ld-wrapper.sh} $binutils/bin/ld.bfd
+      fi
+
+      if [ -e $gccPath/gcc ]; then
+        wrap gcc ${./gcc-wrapper.sh} $gccPath/gcc
+        ln -s gcc $out/bin/cc
+      elif [ -e $gccPath/clang ]; then
+        wrap clang ${./gcc-wrapper.sh} $gccPath/clang
+        ln -s clang $out/bin/cc
+      fi
+
+      if [ -e $gccPath/g++ ]; then
+        wrap g++ ${./gcc-wrapper.sh} $gccPath/g++
+        ln -s g++ $out/bin/c++
+      elif [ -e $gccPath/clang++ ]; then
+        wrap clang++ ${./gcc-wrapper.sh} $gccPath/clang++
+        ln -s clang++ $out/bin/c++
+      fi
+
+      if [ -e $gccPath/cpp ]; then
+        wrap cpp ${./gcc-wrapper.sh} $gccPath/cpp
+      fi
+    ''
+
+    + optionalString gcc.langFortran or false ''
+      wrap gfortran ${./gcc-wrapper.sh} $gccPath/gfortran
+      ln -sv gfortran $out/bin/g77
+      ln -sv gfortran $out/bin/f77
+    ''
+
+    + optionalString gcc.langJava or false ''
+      wrap gcj ${./gcc-wrapper.sh} $gccPath/gcj
+    ''
+
+    + optionalString gcc.langGo or false ''
+      wrap gccgo ${./gcc-wrapper.sh} $gccPath/gccgo
+    ''
+
+    + optionalString gcc.langAda or false ''
+      wrap gnatgcc ${./gcc-wrapper.sh} $gccPath/gnatgcc
+      wrap gnatmake ${./gnat-wrapper.sh} $gccPath/gnatmake
+      wrap gnatbind ${./gnat-wrapper.sh} $gccPath/gnatbind
+      wrap gnatlink ${./gnatlink-wrapper.sh} $gccPath/gnatlink
+    ''
+
+    + optionalString gcc.langVhdl or false ''
+      ln -s $gccPath/ghdl $out/bin/ghdl
+    ''
+
+    + ''
+      substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook
+      substituteAll ${./add-flags} $out/nix-support/add-flags.sh
+      cp -p ${./utils.sh} $out/nix-support/utils.sh
+
+      if [ -e $out/bin/clang ]; then
+        echo 'export CC; : ''${CC:=clang}' >> $out/nix-support/setup-hook
+      fi
+
+      if [ -e $out/bin/clang++ ]; then
+        echo 'export CXX; : ''${CXX:=clang++}' >> $out/nix-support/setup-hook
+      fi
+    '';
+
+  # The dynamic linker has different names on different Linux platforms.
+  dynamicLinker =
+    if !nativeLibc then
+      (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
+       if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
+       # ARM with a wildcard, which can be "" or "-armhf".
+       if stdenv.isArm then "ld-linux*.so.3" else
+       if stdenv.system == "powerpc-linux" then "ld.so.1" else
+       if stdenv.system == "mips64el-linux" then "ld.so.1" else
+       abort "Don't know the name of the dynamic linker for this platform.")
+    else "";
 
   crossAttrs = {
     shell = shell.crossDrv + shell.crossDrv.shellPath;
@@ -73,8 +241,6 @@ stdenv.mkDerivation {
        abort "don't know the name of the dynamic linker for this platform");
   };
 
-  preferLocalBuild = true;
-
   meta =
     let gcc_ = if gcc != null then gcc else {}; in
     (if gcc_ ? meta then removeAttrs gcc.meta ["priority"] else {}) //
@@ -82,16 +248,4 @@ stdenv.mkDerivation {
         stdenv.lib.attrByPath ["meta" "description"] "System C compiler" gcc_
         + " (wrapper script)";
     };
-
-  # The dynamic linker has different names on different Linux platforms.
-  dynamicLinker =
-    if !nativeLibc then
-      (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
-       if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
-       # ARM with a wildcard, which can be "" or "-armhf".
-       if stdenv.isArm then "ld-linux*.so.3" else
-       if stdenv.system == "powerpc-linux" then "ld.so.1" else
-       if stdenv.system == "mips64el-linux" then "ld.so.1" else
-       abort "don't know the name of the dynamic linker for this platform")
-    else "";
 }
diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
index 11ee85929321..d0c82c82dc1c 100644
--- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
@@ -1,10 +1,10 @@
 #! @shell@ -e
 
-if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
+if [ -n "$NIX_GCC_WRAPPER_START_HOOK" ]; then
     source "$NIX_GCC_WRAPPER_START_HOOK"
 fi
 
-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
+if [ -z "$NIX_GCC_WRAPPER_FLAGS_SET" ]; then
     source @out@/nix-support/add-flags.sh
 fi
 
@@ -18,26 +18,26 @@ getVersion=0
 nonFlagArgs=0
 
 for i in "$@"; do
-    if test "$i" = "-c"; then
+    if [ "$i" = -c ]; then
         dontLink=1
-    elif test "$i" = "-S"; then
+    elif [ "$i" = -S ]; then
         dontLink=1
-    elif test "$i" = "-E"; then
+    elif [ "$i" = -E ]; then
         dontLink=1
-    elif test "$i" = "-E"; then
+    elif [ "$i" = -E ]; then
         dontLink=1
-    elif test "$i" = "-M"; then
+    elif [ "$i" = -M ]; then
         dontLink=1
-    elif test "$i" = "-MM"; then
+    elif [ "$i" = -MM ]; then
         dontLink=1
-    elif test "$i" = "-x"; then
+    elif [ "$i" = -x ]; then
         # At least for the cases c-header or c++-header we should set dontLink.
         # I expect no one use -x other than making precompiled headers.
         dontLink=1
-    elif test "${i:0:1}" != "-"; then
+    elif [ "${i:0:1}" != - ]; then
         nonFlagArgs=1
-    elif test "$i" = "-m32"; then
-        if test -e @out@/nix-support/dynamic-linker-m32; then
+    elif [ "$i" = -m32 ]; then
+        if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
             NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
         fi
     fi
@@ -48,28 +48,28 @@ done
 # "-c" flag).  So if no non-flag arguments are given, don't pass any
 # linker flags.  This catches cases like "gcc" (should just print
 # "gcc: no input files") and "gcc -v" (should print the version).
-if test "$nonFlagArgs" = "0"; then
+if [ "$nonFlagArgs" = 0 ]; then
     dontLink=1
 fi
 
 
 # Optionally filter out paths not refering to the store.
 params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
     rest=()
     n=0
-    while test $n -lt ${#params[*]}; do
+    while [ $n -lt ${#params[*]} ]; do
         p=${params[n]}
         p2=${params[$((n+1))]}
-        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
+        if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "$p" = "-L" && badPath "$p2"; then
+        elif [ "$p" = -L ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
+        elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "$p" = "-I" && badPath "$p2"; then
+        elif [ "$p" = -I ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "$p" = "-isystem" && badPath "$p2"; then
+        elif [ "$p" = -isystem ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
         else
             rest=("${rest[@]}" "$p")
@@ -86,14 +86,14 @@ extraBefore=()
 
 # When enforcing purity, pretend gcc can't find the current date and
 # time
-if test "$NIX_ENFORCE_PURITY" = "1"; then
+if [ "$NIX_ENFORCE_PURITY" = 1 ]; then
     extraAfter+=('-D__DATE__="Jan 01 1970"'
         '-D__TIME__="00:00:01"'
         -Wno-builtin-macro-redefined)
 fi
 
 
-if test "$dontLink" != "1"; then
+if [ "$dontLink" != 1 ]; then
 
     # Add the flags that should only be passed to the compiler when
     # linking.
@@ -105,11 +105,11 @@ if test "$dontLink" != "1"; then
         extraBefore=(${extraBefore[@]} "-Wl,$i")
     done
     for i in $NIX_LDFLAGS; do
-	if test "${i:0:3}" = "-L/"; then
-	    extraAfter+=("$i")
-	else
-	    extraAfter+=("-Wl,$i")
-	fi
+        if [ "${i:0:3}" = -L/ ]; then
+            extraAfter+=("$i")
+        else
+            extraAfter+=("-Wl,$i")
+        fi
     done
     export NIX_LDFLAGS_SET=1
 fi
@@ -118,39 +118,29 @@ fi
 # add anything.  This is to prevent `gcc -v' (which normally prints
 # out the version number and returns exit code 0) from printing out
 # `No input files specified' and returning exit code 1.
-if test "$*" = "-v"; then
+if [ "$*" = -v ]; then
     extraAfter=()
     extraBefore=()
-fi    
+fi
 
 # Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @gccProg@:" >&2
+if [ -n "$NIX_DEBUG" ]; then
+  echo "original flags to @prog@:" >&2
   for i in "${params[@]}"; do
       echo "  $i" >&2
   done
-  echo "extraBefore flags to @gccProg@:" >&2
+  echo "extraBefore flags to @prog@:" >&2
   for i in ${extraBefore[@]}; do
       echo "  $i" >&2
   done
-  echo "extraAfter flags to @gccProg@:" >&2
+  echo "extraAfter flags to @prog@:" >&2
   for i in ${extraAfter[@]}; do
       echo "  $i" >&2
   done
 fi
 
-if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then
+if [ -n "$NIX_GCC_WRAPPER_EXEC_HOOK" ]; then
     source "$NIX_GCC_WRAPPER_EXEC_HOOK"
 fi
 
-
-# Call the real `gcc'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_GCC_NEEDS_GREP"; then
-    @gccProg@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
-else
-    (@gccProg@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}" 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi    
+exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
diff --git a/pkgs/build-support/gcc-wrapper/gnat-wrapper.sh b/pkgs/build-support/gcc-wrapper/gnat-wrapper.sh
index f6fa4b18400a..3514ccd67325 100644
--- a/pkgs/build-support/gcc-wrapper/gnat-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gnat-wrapper.sh
@@ -1,10 +1,10 @@
 #! @shell@ -e
 
-if test -n "$NIX_GNAT_WRAPPER_START_HOOK"; then
+if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then
     source "$NIX_GNAT_WRAPPER_START_HOOK"
 fi
 
-if test -z "$NIX_GNAT_WRAPPER_FLAGS_SET"; then
+if [ -z "$NIX_GNAT_WRAPPER_FLAGS_SET" ]; then
     source @out@/nix-support/add-flags.sh
 fi
 
@@ -18,14 +18,14 @@ getVersion=0
 nonFlagArgs=0
 
 for i in "$@"; do
-    if test "$i" = "-c"; then
+    if [ "$i" = -c ]; then
         dontLink=1
-    elif test "$i" = "-M"; then
+    elif [ "$i" = -M ]; then
         dontLink=1
-    elif test "${i:0:1}" != "-"; then
+    elif [ "${i:0:1}" != - ]; then
         nonFlagArgs=1
-    elif test "$i" = "-m32"; then
-        if test -e @out@/nix-support/dynamic-linker-m32; then
+    elif [ "$i" = -m32 ]; then
+        if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
             NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
         fi
     fi
@@ -36,26 +36,26 @@ done
 # "-c" flag).  So if no non-flag arguments are given, don't pass any
 # linker flags.  This catches cases like "gcc" (should just print
 # "gcc: no input files") and "gcc -v" (should print the version).
-if test "$nonFlagArgs" = "0"; then
+if [ "$nonFlagArgs" = 0 ]; then
     dontLink=1
 fi
 
 
 # Optionally filter out paths not refering to the store.
 params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
     rest=()
     n=0
-    while test $n -lt ${#params[*]}; do
+    while [ $n -lt ${#params[*]} ]; do
         p=${params[n]}
         p2=${params[$((n+1))]}
-        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
+        if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
+        elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "${p:0:4}" = "-aI/" && badPath "${p:3}"; then
+        elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
             skip $p
-        elif test "${p:0:4}" = "-aO/" && badPath "${p:3}"; then
+        elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
             skip $p
         else
             rest=("${rest[@]}" "$p")
@@ -81,33 +81,23 @@ fi
 #done
 
 # Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @gnatProg@:" >&2
+if [ -n "$NIX_DEBUG" ]; then
+  echo "original flags to @prog@:" >&2
   for i in "${params[@]}"; do
       echo "  $i" >&2
   done
-  echo "extraBefore flags to @gnatProg@:" >&2
+  echo "extraBefore flags to @prog@:" >&2
   for i in ${extraBefore[@]}; do
       echo "  $i" >&2
   done
-  echo "extraAfter flags to @gnatProg@:" >&2
+  echo "extraAfter flags to @prog@:" >&2
   for i in ${extraAfter[@]}; do
       echo "  $i" >&2
   done
 fi
 
-if test -n "$NIX_GNAT_WRAPPER_EXEC_HOOK"; then
+if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
     source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
 fi
 
-
-# Call the real `gcc'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_GNAT_NEEDS_GREP"; then
-    @gnatProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
-else
-    (@gnatProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi
+exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
diff --git a/pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh b/pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh
index 25907108b4db..c9958dbbb413 100644
--- a/pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/gnatlink-wrapper.sh
@@ -11,33 +11,23 @@ extraBefore=()
 #done
 
 # Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @gnatlinkProg@:" >&2
+if [ -n "$NIX_DEBUG" ]; then
+  echo "original flags to @prog@:" >&2
   for i in "$@"; do
       echo "  $i" >&2
   done
-  echo "extraBefore flags to @gnatlinkProg@:" >&2
+  echo "extraBefore flags to @prog@:" >&2
   for i in ${extraBefore[@]}; do
       echo "  $i" >&2
   done
-  echo "extraAfter flags to @gnatlinkProg@:" >&2
+  echo "extraAfter flags to @prog@:" >&2
   for i in ${extraAfter[@]}; do
       echo "  $i" >&2
   done
 fi
 
-if test -n "$NIX_GNAT_WRAPPER_EXEC_HOOK"; then
+if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
     source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
 fi
 
-
-# Call the real `gcc'.  Filter out warnings from stderr about unused
-# `-B' flags, since they confuse some programs.  Deep bash magic to
-# apply grep to stderr (by swapping stdin/stderr twice).
-if test -z "$NIX_GNAT_NEEDS_GREP"; then
-    @gnatlinkProg@ ${extraBefore[@]} "$@" ${extraAfter[@]}
-else
-    (@gnatlinkProg@ ${extraBefore[@]} "$@" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
-        | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
-    exit $?
-fi
+exec @prog@ ${extraBefore[@]} "$@" ${extraAfter[@]}
diff --git a/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh
index 5a7b92b5ad7d..9216ea3198dd 100644
--- a/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh
@@ -6,7 +6,7 @@ set -u
 # I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
 # Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
 #   but still no success.
-cmd="@ld@ -z ignore"
+cmd="@prog@ -z ignore"
 
 args=("$@");
 
diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
index 822c4a03a218..894dbf9a352c 100644
--- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
@@ -1,10 +1,10 @@
 #! @shell@ -e
 
-if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
+if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then
     source "$NIX_LD_WRAPPER_START_HOOK"
 fi
 
-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
+if [ -z "$NIX_GCC_WRAPPER_FLAGS_SET" ]; then
     source @out@/nix-support/add-flags.sh
 fi
 
@@ -13,26 +13,26 @@ source @out@/nix-support/utils.sh
 
 # Optionally filter out paths not refering to the store.
 params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE" \
-        -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \); then
+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" \
+        -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \) ]; then
     rest=()
     n=0
-    while test $n -lt ${#params[*]}; do
+    while [ $n -lt ${#params[*]} ]; do
         p=${params[n]}
         p2=${params[$((n+1))]}
-        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
+        if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
             skip $p
-        elif test "$p" = "-L" && badPath "$p2"; then
+        elif [ "$p" = -L ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "$p" = "-rpath" && badPath "$p2"; then
+        elif [ "$p" = -rpath ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "$p" = "-dynamic-linker" && badPath "$p2"; then
+        elif [ "$p" = -dynamic-linker ] && badPath "$p2"; then
             n=$((n + 1)); skip $p2
-        elif test "${p:0:1}" = "/" && badPath "$p"; then
+        elif [ "${p:0:1}" = / ] && badPath "$p"; then
             # We cannot skip this; barf.
             echo "impure path \`$p' used in link" >&2
             exit 1
-        elif test "${p:0:9}" = "--sysroot"; then
+        elif [ "${p:0:9}" = --sysroot ]; then
             # Our ld is not built with sysroot support (Can we fix that?)
             :
         else
@@ -47,7 +47,7 @@ fi
 extra=()
 extraBefore=()
 
-if test -z "$NIX_LDFLAGS_SET"; then
+if [ -z "$NIX_LDFLAGS_SET" ]; then
     extra+=($NIX_LDFLAGS)
     extraBefore+=($NIX_LDFLAGS_BEFORE)
 fi
@@ -56,12 +56,12 @@ extra+=($NIX_LDFLAGS_AFTER)
 
 
 # Add all used dynamic libraries to the rpath.
-if test "$NIX_DONT_SET_RPATH" != "1"; then
+if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
 
     libPath=""
     addToLibPath() {
         local path="$1"
-        if test "${path:0:1}" != "/"; then return 0; fi
+        if [ "${path:0:1}" != / ]; then return 0; fi
         case "$path" in
             *..*|*./*|*/.*|*//*)
                 local path2
@@ -75,12 +75,12 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
         esac
         libPath="$libPath $path "
     }
-    
+
     addToRPath() {
         # If the path is not in the store, don't add it to the rpath.
         # This typically happens for libraries in /tmp that are later
         # copied to $out/lib.  If not, we're screwed.
-        if test "${1:0:${#NIX_STORE}}" != "$NIX_STORE"; then return 0; fi
+        if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi
         case $rpath in
             *\ $1\ *) return 0 ;;
         esac
@@ -97,21 +97,21 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
     # First, find all -L... switches.
     allParams=("${params[@]}" ${extra[@]})
     n=0
-    while test $n -lt ${#allParams[*]}; do
+    while [ $n -lt ${#allParams[*]} ]; do
         p=${allParams[n]}
         p2=${allParams[$((n+1))]}
-        if test "${p:0:3}" = "-L/"; then
+        if [ "${p:0:3}" = -L/ ]; then
             addToLibPath ${p:2}
-        elif test "$p" = "-L"; then
+        elif [ "$p" = -L ]; then
             addToLibPath ${p2}
             n=$((n + 1))
-        elif test "$p" = "-l"; then
+        elif [ "$p" = -l ]; then
             addToLibs ${p2}
             n=$((n + 1))
-        elif test "${p:0:2}" = "-l"; then
+        elif [ "${p:0:2}" = -l ]; then
             addToLibs ${p:2}
-        elif test "$p" = "-dynamic-linker"; then
-            # Ignore the dynamic linker argument, or it 
+        elif [ "$p" = -dynamic-linker ]; then
+            # Ignore the dynamic linker argument, or it
             # will get into the next 'elif'. We don't want
             # the dynamic linker path rpath to go always first.
             n=$((n + 1))
@@ -129,16 +129,16 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
     # so, add the directory to the rpath.
     # It's important to add the rpath in the order of -L..., so
     # the link time chosen objects will be those of runtime linking.
-    
+
     for i in $libPath; do
         for j in $libs; do
-            if test -f "$i/lib$j.so"; then
+            if [ -f "$i/lib$j.so" ]; then
                 addToRPath $i
                 break
             fi
         done
     done
-    
+
 
     # Finally, add `-rpath' switches.
     for i in $rpath; do
@@ -148,19 +148,19 @@ fi
 
 
 # Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @ld@:" >&2
+if [ -n "$NIX_DEBUG" ]; then
+  echo "original flags to @prog@:" >&2
   for i in "${params[@]}"; do
       echo "  $i" >&2
   done
-  echo "extra flags to @ld@:" >&2
+  echo "extra flags to @prog@:" >&2
   for i in ${extra[@]}; do
       echo "  $i" >&2
   done
 fi
 
-if test -n "$NIX_LD_WRAPPER_EXEC_HOOK"; then
+if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then
     source "$NIX_LD_WRAPPER_EXEC_HOOK"
 fi
 
-exec @ld@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
+exec @prog@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh
index a3ada9e984fd..a6b7edbcb694 100644
--- a/pkgs/build-support/gcc-wrapper/setup-hook.sh
+++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh
@@ -1,16 +1,16 @@
 export NIX_GCC=@out@
 
 addCVars () {
-    if test -d $1/include; then
-        export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
+    if [ -d $1/include ]; then
+        export NIX_CFLAGS_COMPILE+=" -isystem $1/include"
     fi
 
-    if test -d $1/lib64; then
-        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib64"
+    if [ -d $1/lib64 -a ! -L $1/lib64 ]; then
+        export NIX_LDFLAGS+=" -L$1/lib64"
     fi
 
-    if test -d $1/lib; then
-        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib"
+    if [ -d $1/lib ]; then
+        export NIX_LDFLAGS+=" -L$1/lib"
     fi
 }
 
@@ -18,18 +18,18 @@ envHooks+=(addCVars)
 
 # Note: these come *after* $out in the PATH (see setup.sh).
 
-if test -n "@gcc@"; then
+if [ -n "@gcc@" ]; then
     addToSearchPath PATH @gcc@/bin
 fi
 
-if test -n "@binutils@"; then
+if [ -n "@binutils@" ]; then
     addToSearchPath PATH @binutils@/bin
 fi
 
-if test -n "@libc@"; then
+if [ -n "@libc@" ]; then
     addToSearchPath PATH @libc@/bin
 fi
 
-if test -n "@coreutils@"; then
+if [ -n "@coreutils@" ]; then
     addToSearchPath PATH @coreutils@/bin
 fi
diff --git a/pkgs/build-support/gcc-wrapper/utils.sh b/pkgs/build-support/gcc-wrapper/utils.sh
index 753b3772e956..3ab512d85c4e 100644
--- a/pkgs/build-support/gcc-wrapper/utils.sh
+++ b/pkgs/build-support/gcc-wrapper/utils.sh
@@ -1,5 +1,5 @@
 skip () {
-    if test "$NIX_DEBUG" = "1"; then
+    if [ -n "$NIX_DEBUG" ]; then
         echo "skipping impure path $1" >&2
     fi
 }
@@ -9,11 +9,11 @@ skip () {
 # `/nix/store/.../lib/foo.so' isn't.
 badPath() {
     local p=$1
-    
+
     # Relative paths are okay (since they're presumably relative to
     # the temporary build directory).
-    if test "${p:0:1}" != "/"; then return 1; fi
-    
+    if [ "${p:0:1}" != / ]; then return 1; fi
+
     # Otherwise, the path should refer to the store or some temporary
     # directory (including the build directory).
     test \
diff --git a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
index 5962bf039069..2b64fbf8f093 100644
--- a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
+++ b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
@@ -10,6 +10,8 @@
 # their absolute path (using "install_name_tool -id").  It also
 # rewrites references in other dylibs to absolute paths.
 
+postFixupHooks+=('fixDarwinDylibNamesIn $prefix')
+
 fixDarwinDylibNames() {
     local flags=()
     local old_id
@@ -29,7 +31,3 @@ fixDarwinDylibNamesIn() {
     local dir="$1"
     fixDarwinDylibNames $(find "$dir" -name "*.dylib")
 }
-
-postFixup() {
-    fixDarwinDylibNamesIn "$prefix"
-}