diff --git a/src/core/config/mac_osx.pri b/src/core/config/mac_osx.pri
index b24d981b2d50824893d935cb5e7eb8f545d830f5..3f42b6fd7eb480dca43d402bfd9cb11f7260798d 100644
--- a/src/core/config/mac_osx.pri
+++ b/src/core/config/mac_osx.pri
@@ -1,5 +1,20 @@
+QMAKE_CLANG_DIR = "/usr"
+QMAKE_CLANG_PATH = $$eval(QMAKE_MAC_SDK.macx-clang.$${QMAKE_MAC_SDK}.QMAKE_CXX)
+!isEmpty(QMAKE_CLANG_PATH) {
+    clang_dir = $$clean_path("$$dirname(QMAKE_CLANG_PATH)/../")
+    exists($$clang_dir): QMAKE_CLANG_DIR = $$clang_dir
+}
+
+QMAKE_CLANG_PATH = "$${QMAKE_CLANG_DIR}/bin/clang++"
+message("Using clang++ from $${QMAKE_CLANG_PATH}")
+system("$${QMAKE_CLANG_PATH} --version")
+
 GYP_CONFIG += \
     qt_os=\"mac\" \
     mac_sdk_min=\"10.7\" \
     mac_deployment_target=\"$${QMAKE_MACOSX_DEPLOYMENT_TARGET}\" \
+    make_clang_dir=\"$${QMAKE_CLANG_DIR}\" \
     clang_use_chrome_plugins=0
+
+QMAKE_MAC_SDK_PATH = "$$eval(QMAKE_MAC_SDK.$${QMAKE_MAC_SDK}.path)"
+exists($$QMAKE_MAC_SDK_PATH): GYP_CONFIG += mac_sdk_path=\"$${QMAKE_MAC_SDK_PATH}\"
diff --git a/tools/buildscripts/gyp_qtwebengine b/tools/buildscripts/gyp_qtwebengine
index eb44477e76ea7de5ad98376c459208041566db0e..6f2bbc9363c301a2a7cbabdf17300d2dab02c50c 100755
--- a/tools/buildscripts/gyp_qtwebengine
+++ b/tools/buildscripts/gyp_qtwebengine
@@ -9,7 +9,6 @@ print 'using python: ' + sys.executable + ' version: ' + sys.version
 
 if sys.platform == "darwin":
   print 'xcode version: ' + subprocess.check_output(['xcodebuild', '-version']).replace('\n', ' ')
-  print 'clang++ version: ' + subprocess.check_output(['clang++', '--version']).replace('\n', ' ')
 
 qtwebengine_root = os.path.normcase(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
 import qtwebengine_utils as utils
@@ -87,12 +86,6 @@ if __name__ == '__main__':
   if 'qt_cross_compile=1' in sys.argv:
     os.environ['GYP_CROSSCOMPILE'] = '1'
 
-  # On Mac we want to override CXX and CC that is provided with
-  # the Chromium GYP environment.
-  if sys.platform.startswith('darwin') and not 'GYP_CROSSCOMPILE' in os.environ:
-    os.environ['CXX'] = 'clang++'
-    os.environ['CC'] = 'clang'
-
   gyp_helper.apply_chromium_gyp_env()
 
   # This could give false positives since it doesn't actually do real option