diff --git a/tools/qmake/mkspecs/features/functions.prf b/tools/qmake/mkspecs/features/functions.prf
index 0fb6aca6076b4c88e72454180e4f94e25b66cbfe..93b5eec98eb3d44ee8a370c20615423c7fd1f4fb 100644
--- a/tools/qmake/mkspecs/features/functions.prf
+++ b/tools/qmake/mkspecs/features/functions.prf
@@ -2,11 +2,27 @@ defineTest(isPlatformSupported) {
   static: return(false)
   osx:lessThan(QMAKE_XCODE_VERSION, 5.1): return(false)
 
+  linux-g++*:!isGCCVersionSupported():return(false)
+  !isPythonVersionSupported(): return(false)
   linux-g++*|win32-msvc2013|macx-clang: return(true)
   boot2qt: return(true)
   return(false)
 }
 
+defineTest(isPythonVersionSupported) {
+  python_major_version = $$system("python -c 'import sys; print sys.version_info.major'")
+  python_minor_version = $$system("python -c 'import sys; print sys.version_info.minor'")
+  greaterThan(python_major_version, 1): greaterThan(python_minor_version, 6): return(true)
+  return(false)
+}
+
+defineTest(isGCCVersionSupported) {
+  // The below will work for gcc 4.6 and up and also match gcc 5
+  greaterThan(QT_GCC_MINOR_VERSION, 5):return(true)
+  greaterThan(QT_GCC_MAJOR_VERSION, 4):return(true)
+  return(false)
+}
+
 # Map to the correct target type for gyp
 defineReplace(toGypTargetType) {
   equals(TEMPLATE, "app"):return("executable")