--- common/autoconf/toolchain.m4.orig
+++ common/autoconf/toolchain.m4
@@ -77,7 +77,7 @@ AC_DEFUN([TOOLCHAIN_CHECK_COMPILER_VERSI
 # $2 = human readable name of compiler (C or C++)
 AC_DEFUN([TOOLCHAIN_EXTRACT_COMPILER_VERSION],
 [
-  COMPILER=[$]$1
+  COMPILER="[$]$1"
   COMPILER_NAME=$2
 
   if test "x$OPENJDK_TARGET_OS" = xsolaris; then
@@ -174,64 +174,37 @@ AC_DEFUN([TOOLCHAIN_FIND_COMPILER],
 [
   COMPILER_NAME=$2
 
-  $1=
+  FOUND_$1=
+
+  if test "x[$]$1" != "x"; then
+    FOUND_$1="[$]$1"
+  fi
+
   # If TOOLS_DIR is set, check for all compiler names in there first
   # before checking the rest of the PATH.
-  if test -n "$TOOLS_DIR"; then
+  if test "x[$]FOUND_$1" = x -a -n "$TOOLS_DIR"; then
     PATH_save="$PATH"
     PATH="$TOOLS_DIR"
     AC_PATH_PROGS(TOOLS_DIR_$1, $3)
-    $1=$TOOLS_DIR_$1
+    FOUND_$1=$TOOLS_DIR_$1
     PATH="$PATH_save"
   fi
 
   # AC_PATH_PROGS can't be run multiple times with the same variable,
   # so create a new name for this run.
-  if test "x[$]$1" = x; then
+  if test "x[$]FOUND_$1" = x; then
     AC_PATH_PROGS(POTENTIAL_$1, $3)
-    $1=$POTENTIAL_$1
+    FOUND_$1=$POTENTIAL_$1
   fi
 
-  if test "x[$]$1" = x; then
+  if test "x[$]FOUND_$1" = x; then
     HELP_MSG_MISSING_DEPENDENCY([devkit])
     AC_MSG_ERROR([Could not find a $COMPILER_NAME compiler. $HELP_MSG])
   fi
-  BASIC_FIXUP_EXECUTABLE($1)
-  TEST_COMPILER="[$]$1"
-  # Don't remove symbolic links on AIX because 'xlc_r' and 'xlC_r' may all be links
-  # to 'xlc' but it is crucial that we invoke the compiler with the right name!
-  if test "x$OPENJDK_BUILD_OS" != xaix; then
-    AC_MSG_CHECKING([resolved symbolic links for $1])
-    BASIC_REMOVE_SYMBOLIC_LINKS(TEST_COMPILER)
-    AC_MSG_RESULT([$TEST_COMPILER])
-  fi
-  AC_MSG_CHECKING([if $1 is disguised ccache])
-
-  COMPILER_BASENAME=`$BASENAME "$TEST_COMPILER"`
-  if test "x$COMPILER_BASENAME" = "xccache"; then
-    AC_MSG_RESULT([yes, trying to find proper $COMPILER_NAME compiler])
-    # We /usr/lib/ccache in the path, so cc is a symlink to /usr/bin/ccache.
-    # We want to control ccache invocation ourselves, so ignore this cc and try
-    # searching again.
-
-    # Remove the path to the fake ccache cc from the PATH
-    RETRY_COMPILER_SAVED_PATH="$PATH"
-    COMPILER_DIRNAME=`$DIRNAME [$]$1`
-    PATH="`$ECHO $PATH | $SED -e "s,$COMPILER_DIRNAME,,g" -e "s,::,:,g" -e "s,^:,,g"`"
-
-    # Try again looking for our compiler
-    AC_CHECK_TOOLS(PROPER_COMPILER_$1, $3)
-    BASIC_FIXUP_EXECUTABLE(PROPER_COMPILER_$1)
-    PATH="$RETRY_COMPILER_SAVED_PATH"
-
-    AC_MSG_CHECKING([for resolved symbolic links for $1])
-    BASIC_REMOVE_SYMBOLIC_LINKS(PROPER_COMPILER_$1)
-    AC_MSG_RESULT([$PROPER_COMPILER_$1])
-    $1="$PROPER_COMPILER_$1"
-  else
-    AC_MSG_RESULT([no, keeping $1])
-    $1="$TEST_COMPILER"
-  fi
+  BASIC_FIXUP_EXECUTABLE(FOUND_$1)
+  TEST_COMPILER="[$]FOUND_$1"
+
+  $1="$TEST_COMPILER"
   TOOLCHAIN_EXTRACT_COMPILER_VERSION([$1], [$COMPILER_NAME])
 ])
 
@@ -265,12 +238,12 @@ AC_DEFUN([TOOLCHAIN_SETUP_PATHS],
     # otherwise we might pick up cross-compilers which don't use standard naming.
     # Otherwise, we'll set the BUILD_tools to the native tools, but that'll have
     # to wait until they are properly discovered.
-    AC_PATH_PROGS(BUILD_CC, [cl cc gcc])
-    BASIC_FIXUP_EXECUTABLE(BUILD_CC)
-    AC_PATH_PROGS(BUILD_CXX, [cl CC g++])
-    BASIC_FIXUP_EXECUTABLE(BUILD_CXX)
-    AC_PATH_PROG(BUILD_LD, ld)
-    BASIC_FIXUP_EXECUTABLE(BUILD_LD)
+    AS_IF([test "x${BUILD_CC}" = "x"], [AC_PATH_PROGS(BUILD_CC, [cl cc gcc])
+    BASIC_FIXUP_EXECUTABLE(BUILD_CC)])
+    AS_IF([test "x${BUILD_CXX}" = "x"], [AC_PATH_PROGS(BUILD_CXX, [cl CC g++])
+    BASIC_FIXUP_EXECUTABLE(BUILD_CXX)])
+    AS_IF([test "x${BUILD_LD}" = "x"], [AC_PATH_PROG(BUILD_LD, ld)
+    BASIC_FIXUP_EXECUTABLE(BUILD_LD)])
   fi
   AC_SUBST(BUILD_CC)
   AC_SUBST(BUILD_CXX)
--- common/autoconf/basics.m4.orig
+++ common/autoconf/basics.m4
@@ -171,8 +171,15 @@ AC_DEFUN([BASIC_REMOVE_SYMBOLIC_LINKS],
       fi
     fi
 
+    # First separate the path from the arguments. This will split at the first
+    # space.
+    complete="[$]$1"
+    path="${complete%% *}"
+    tmp="$complete EOL"
+    arguments="${tmp#* }"
+
     if test "x$READLINK" != x; then
-      $1=`$READLINK -f [$]$1`
+      new_path=`$READLINK -f $path`
     else
       # Save the current directory for restoring afterwards
       STARTDIR=$PWD
@@ -198,8 +205,9 @@ AC_DEFUN([BASIC_REMOVE_SYMBOLIC_LINKS],
         let COUNTER=COUNTER+1
       done
       cd $STARTDIR
-      $1=$sym_link_dir/$sym_link_file
+      new_path=$sym_link_dir/$sym_link_file
     fi
+    $1="$new_path ${arguments% *}"
   fi
 ])