diff --git a/configure b/configure
index e633a780bdc613e7c68788507cf82a3683d19e7a..d11a50554f2212dc584d7172d82f7c0ee7671eae 100755
--- a/configure
+++ b/configure
@@ -880,6 +880,7 @@ QT_DEFAULT_BUILD_PARTS="libs tools examples"
 CFG_BUILD_PARTS=""
 CFG_NOBUILD_PARTS=""
 CFG_SKIP_MODULES=""
+CFG_COMPILE_EXAMPLES=auto
 CFG_RELEASE_QMAKE=no
 CFG_AUDIO_BACKEND=auto
 CFG_V8SNAPSHOT=auto
@@ -1404,6 +1405,13 @@ while [ "$#" -gt 0 ]; do
         fi
         CFG_SKIP_MODULES="$CFG_SKIP_MODULES $VAL"
         ;;
+    compile-examples)
+        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
+            CFG_COMPILE_EXAMPLES="$VAL"
+        else
+            UNKNOWN_OPT=yes
+        fi
+        ;;
     sdk)
         if [ "$BUILD_ON_MAC" = "yes" ]; then
             DeviceVar set !host_build:QMAKE_MAC_SDK "$VAL"
@@ -3151,6 +3159,18 @@ else
     QT_HOST_DATA=`"$relpath/config.tests/unix/makeabs" "$QT_HOST_DATA"`
 fi
 
+# Do not actually build the examples in production builds with -prefix, unless requested
+if [ "$CFG_COMPILE_EXAMPLES" = auto ]; then
+    if [ "$CFG_DEV" = "yes" ] || [ "x$outpath" = "x$QT_INSTALL_PREFIX" ]; then
+        CFG_COMPILE_EXAMPLES=yes
+    else
+        CFG_COMPILE_EXAMPLES=no
+    fi
+fi
+if [ "$CFG_COMPILE_EXAMPLES" = "yes" ]; then
+    QMAKE_CONFIG="$QMAKE_CONFIG compile_examples"
+fi
+
 #-------------------------------------------------------------------------------
 # help - interactive parts of the script _after_ this section please
 #-------------------------------------------------------------------------------
@@ -3452,6 +3472,8 @@ Additional options:
 
     -skip <module> ..... Exclude an entire module from the build.
 
+    -compile-examples .. Compile examples even in a production build.
+
     -no-gui ............ Don't build the Qt GUI module and dependencies.
  +  -gui ............... Build the Qt GUI module and dependencies.
 
diff --git a/mkspecs/features/qt_example_installs.prf b/mkspecs/features/qt_example_installs.prf
index 479a16a90be25bd193d8c89fa41d9e9b381eda13..2db752c1e4edfb216d27d6ed8ad43e82a7c4f4b5 100644
--- a/mkspecs/features/qt_example_installs.prf
+++ b/mkspecs/features/qt_example_installs.prf
@@ -93,8 +93,7 @@ probase = $$relative_path($$_PRO_FILE_PWD_, $$dirname(_QMAKE_CONF_)/examples)
         !isEmpty(allfiles): warning("remaining files in $$_PRO_FILE_PWD_: $$allfiles")
     }
 
-    # Do not actually build the examples in production builds with -prefix
-    !equals(TEMPLATE, subdirs):prefix_build:!contains(QT_CONFIG, private_tests) {
+    !equals(TEMPLATE, subdirs):!compile_examples {
         TEMPLATE = aux
         CONFIG -= have_target qt staticlib dll
         SOURCES =
diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp
index a0303514437da91d49bd09a6f4a5f5ec3b78ee40..a83f451b81596b7f7d9d2788a539f65ed65e6830 100644
--- a/tools/configure/configureapp.cpp
+++ b/tools/configure/configureapp.cpp
@@ -276,6 +276,8 @@ Configure::Configure(int& argc, char** argv)
 
     dictionary[ "BUILDDEV" ]        = "no";
 
+    dictionary[ "COMPILE_EXAMPLES" ] = "auto";
+
     dictionary[ "C++11" ]           = "auto";
 
     dictionary[ "SHARED" ]          = "yes";
@@ -458,6 +460,13 @@ void Configure::parseCmdLine()
             dictionary[ "BUILDALL" ] = "yes";
         else if (configCmdLine.at(i) == "-force-debug-info")
             dictionary[ "FORCEDEBUGINFO" ] = "yes";
+
+        else if (configCmdLine.at(i) == "-compile-examples") {
+            dictionary[ "COMPILE_EXAMPLES" ] = "yes";
+        } else if (configCmdLine.at(i) == "-no-compile-examples") {
+            dictionary[ "COMPILE_EXAMPLES" ] = "no";
+        }
+
         else if (configCmdLine.at(i) == "-c++11")
             dictionary[ "C++11" ] = "yes";
         else if (configCmdLine.at(i) == "-no-c++11")
@@ -1696,6 +1705,8 @@ bool Configure::displayHelp()
 
         desc(                   "-skip <module>",       "Exclude an entire module from the build.\n");
 
+        desc(                   "-compile-examples",    "Compile examples even in a production build.\n");
+
         desc("WIDGETS", "no", "-no-widgets",            "Disable Qt Widgets module.\n");
         desc("GUI", "no", "-no-gui",                    "Disable Qt GUI module.\n");
 
@@ -1979,6 +1990,13 @@ QString Configure::defaultTo(const QString &option)
         && (!QFile::exists(sourcePath + "/bin/syncqt.pl")))
         return "no";
 
+    // Do not actually build the examples in production builds with -prefix, unless requested
+    if (option == "COMPILE_EXAMPLES"
+        && QDir::cleanPath(dictionary[ "QT_BUILD_TREE" ])
+            != QDir::cleanPath(dictionary[ "QT_INSTALL_PREFIX" ])
+        && dictionary[ "BUILDDEV" ] == "no")
+        return "no";
+
     return "yes";
 }
 
@@ -2560,6 +2578,8 @@ void Configure::generateOutputVars()
     if (!buildParts.contains("libs"))
         buildParts += "libs";
     buildParts.removeDuplicates();
+    if (dictionary[ "COMPILE_EXAMPLES" ] == "yes")
+        qmakeConfig += "compile_examples";
 
     if (dictionary["MSVC_MP"] == "yes")
         qmakeConfig += "msvc_mp";