diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in
index 45386de0..7efb2979 100644
--- a/scripts/crosstool-NG.sh.in
+++ b/scripts/crosstool-NG.sh.in
@@ -28,6 +28,9 @@
 # Overide the locale early, in case we ever translate crosstool-NG messages
 [ -z "${CT_NO_OVERIDE_LC_MESSAGES}" ] && export LC_ALL=C
 
+# remove . from PATH since it can cause gcc build failures
+CT_SanitizePath
+
 # Some sanity checks in the environment and needed tools
 CT_DoLog INFO "Performing some trivial sanity checks"
 CT_TestAndAbort "Don't set LD_LIBRARY_PATH. It screws up the build." -n "${LD_LIBRARY_PATH}"
diff --git a/scripts/functions b/scripts/functions
index c284881e..0250f051 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -137,6 +137,24 @@ CT_DoEnd()
     CT_DoLog ${level:-INFO} "(elapsed: ${elapsed_min}:${elapsed_sec}.${elapsed_csec})"
 }
 
+# Remove entries referring to ., /tmp and non-existing directories from $PATH
+# Usage: CT_SanitizePath
+CT_SanitizePath() {
+    local new
+    local tmp
+    local IFS=:
+    for p in $PATH; do
+        # Replace any occurence of . with $(pwd -P)
+        # Use /tmp as a default if the directory is non-existent
+        # Do not add /tmp in the PATH
+        tmp="$( cd /tmp; cd "${p}" 2>/dev/null || true; pwd -P )"
+        if [ "${tmp}" != "/tmp" ]; then
+            new="${new}${new:+:}${p}"
+        fi
+    done
+    PATH="${new}"
+}
+
 # Abort the execution with an error message
 # Usage: CT_Abort <message>
 CT_Abort() {