From 8df17d233c62506f7758160d9af711dda4fc760e Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Date: Mon, 26 Oct 2015 12:38:50 +0100
Subject: [PATCH] introduce -optimized-tools option

instead of building host tools always in debug mode, follow the overall
build type, and provide an option to override it.

this supersedes the pre-existing -optimized-qmake option.
however, that option never existed in the windows configure, and this
legacy continues as far as qmake is concerned (msvc builds of qmake are
always somewhat optimized, but not mingw builds).

Change-Id: I42e7ef1a481840699a8dffff13fec2626af19cc6
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
---
 configure                        | 41 ++++++++++++++++++++------------
 mkspecs/features/qt_app.prf      |  2 +-
 mkspecs/features/qt_module.prf   |  2 +-
 tools/configure/configureapp.cpp | 16 +++++++++++++
 4 files changed, 44 insertions(+), 17 deletions(-)

diff --git a/configure b/configure
index 8f4aa8206de..1eb893d9cc5 100755
--- a/configure
+++ b/configure
@@ -604,6 +604,7 @@ CFG_MYSQL_CONFIG=
 CFG_PSQL_CONFIG=
 CFG_DEBUG_RELEASE=no
 CFG_FORCEDEBUGINFO=no
+CFG_RELEASE_TOOLS=no
 CFG_SHARED=yes
 CFG_SM=auto
 CFG_XSHAPE=auto
@@ -642,7 +643,6 @@ CFG_BUILD_PARTS=""
 CFG_NOBUILD_PARTS=""
 CFG_SKIP_MODULES=""
 CFG_COMPILE_EXAMPLES=yes
-CFG_RELEASE_QMAKE=no
 CFG_AUDIO_BACKEND=auto
 CFG_QML_DEBUG=yes
 CFG_PKGCONFIG=auto
@@ -1433,13 +1433,6 @@ while [ "$#" -gt 0 ]; do
             UNKNOWN_OPT=yes
         fi
         ;;
-    optimized-qmake)
-        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
-            CFG_RELEASE_QMAKE="$VAL"
-        else
-            UNKNOWN_OPT=yes
-        fi
-        ;;
     release)
         if [ "$VAL" = "yes" ]; then
             CFG_DEBUG=no
@@ -1455,6 +1448,13 @@ while [ "$#" -gt 0 ]; do
     force-debug-info)
         CFG_FORCEDEBUGINFO="$VAL"
         ;;
+    optimized-qmake|optimized-tools)
+        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
+            CFG_RELEASE_TOOLS="$VAL"
+        else
+            UNKNOWN_OPT=yes
+        fi
+        ;;
     developer-build)
         CFG_DEV="yes"
         ;;
@@ -2433,6 +2433,9 @@ Configure options:
 
     -developer-build ... Compile and link Qt with Qt developer options (including auto-tests exporting)
 
+ *  -no-optimized-tools ... Do not build optimized host tools even in debug build.
+    -optimized-tools ...... Build optimized host tools even in debug build.
+
     -opensource ........ Compile and link the Open-Source Edition of Qt.
     -commercial ........ Compile and link the Commercial Edition of Qt.
 
@@ -2618,9 +2621,6 @@ Additional options:
     -silent ............ Reduce the build output so that warnings and errors
                          can be seen more easily.
 
- *  -no-optimized-qmake ... Do not build qmake optimized.
-    -optimized-qmake ...... Build qmake optimized.
-
     -no-nis ............ Do not compile NIS support.
  *  -nis ............... Compile NIS support.
 
@@ -3387,6 +3387,10 @@ if [ "$CFG_FORCEDEBUGINFO" = "yes" ]; then
     QMAKE_CONFIG="$QMAKE_CONFIG force_debug_info"
 fi
 
+if [ "$CFG_RELEASE_TOOLS" = "yes" ]; then
+    QT_CONFIG="$QT_CONFIG release_tools"
+fi
+
 if [ "$XPLATFORM_MAC" = "yes" ]; then
     [ "$CFG_PKGCONFIG" = "auto" ] && CFG_PKGCONFIG="no"
 fi
@@ -4017,7 +4021,7 @@ if true; then ###[ '!' -f "$outpath/bin/qmake" ];
         setBootstrapVariable QMAKE_LFLAGS
         setBootstrapVariable QMAKE_LFLAGS_GCSECTIONS
 
-        if [ "$CFG_RELEASE_QMAKE" = "yes" ]; then
+        if [ "$CFG_RELEASE_TOOLS" = "yes" ]; then
             setBootstrapVariable QMAKE_CFLAGS_RELEASE
             setBootstrapVariable QMAKE_CXXFLAGS_RELEASE
             EXTRA_CFLAGS="$EXTRA_CFLAGS \$(QMAKE_CFLAGS_RELEASE)"
@@ -7237,10 +7241,12 @@ release="release"
 [ "$CFG_FORCEDEBUGINFO" = "yes" ] && release="release (with debug info)"
 [ "$CFG_DEBUG" = "yes" ] && build_mode="debug" || build_mode=$release
 if [ "$CFG_DEBUG_RELEASE" = "yes" ]; then
-   echo "  Mode ................... debug and $release; default link: $build_mode"
-else
-   echo "  Mode ................... $build_mode"
+    build_mode="debug and $release; default link: $build_mode"
 fi
+if [ "$CFG_RELEASE_TOOLS" = "yes" ]; then
+    build_mode="$build_mode; optimized tools"
+fi
+echo "  Mode ................... $build_mode"
 unset build_mode release
 echo "  Using sanitizer(s)...... $CFG_SANITIZERS"
 echo "  Using C++ standard ..... $CFG_STDCXX"
@@ -7406,6 +7412,11 @@ if [ "$CFG_QREAL" = double ] && [ "$CFG_ARCH" = arm ]; then
     echo "NOTE: Qt is using double for qreal on this system. This is binary incompatible against Qt 5.1."
     echo "Configure with '-qreal float' to create a build that is binary compatible with 5.1."
 fi
+if [ "$CFG_RELEASE_TOOLS" = "yes" -a \( "$CFG_DEBUG" = "no" -o "$CFG_DEBUG_RELEASE" = "yes" \) ]; then
+    echo
+    echo "NOTE: -optimized-tools is not useful in -release mode."
+    echo
+fi
 
 exec 1>&3 3>&- # restore stdout
 cat $outpath/config.summary # display config feedback to user
diff --git a/mkspecs/features/qt_app.prf b/mkspecs/features/qt_app.prf
index b446ed1cd1b..823a4c9490d 100644
--- a/mkspecs/features/qt_app.prf
+++ b/mkspecs/features/qt_app.prf
@@ -21,7 +21,7 @@ QMAKE_LFLAGS += $$QMAKE_LFLAGS_GCSECTIONS
 
 host_build: QT -= gui   # no host tool will ever use gui
 host_build:force_bootstrap {
-    !build_pass: CONFIG += release
+    !build_pass:contains(QT_CONFIG, release_tools): CONFIG += release
     contains(QT, core(-private)?|xml) {
         QT -= core core-private xml
         QT += bootstrap-private
diff --git a/mkspecs/features/qt_module.prf b/mkspecs/features/qt_module.prf
index 193629b532d..906657580e8 100644
--- a/mkspecs/features/qt_module.prf
+++ b/mkspecs/features/qt_module.prf
@@ -32,7 +32,7 @@ host_build {
     QMAKE_CFLAGS += $$QMAKE_CFLAGS_SPLIT_SECTIONS
     QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_SPLIT_SECTIONS
     force_bootstrap {
-        !build_pass: CONFIG += release
+        !build_pass:contains(QT_CONFIG, release_tools): CONFIG += release
         contains(QT, core(-private)?|xml) {
             QT -= core core-private xml
             QT += bootstrap-private
diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp
index 5ddb3cb4898..37676405366 100644
--- a/tools/configure/configureapp.cpp
+++ b/tools/configure/configureapp.cpp
@@ -230,6 +230,7 @@ Configure::Configure(int& argc, char** argv) : verbose(0)
     dictionary[ "BUILD" ]           = "debug";
     dictionary[ "BUILDALL" ]        = "auto"; // Means yes, but not explicitly
     dictionary[ "FORCEDEBUGINFO" ]  = "no";
+    dictionary[ "OPTIMIZED_TOOLS" ] = "no";
 
     dictionary[ "BUILDTYPE" ]      = "none";
 
@@ -460,6 +461,10 @@ void Configure::parseCmdLine()
             dictionary[ "SEPARATE_DEBUG_INFO" ] = "no";
         else if (configCmdLine.at(i) == "-separate-debug-info")
             dictionary[ "SEPARATE_DEBUG_INFO" ] = "yes";
+        else if (configCmdLine.at(i) == "-optimized-tools")
+            dictionary[ "RELEASE_TOOLS" ] = "yes";
+        else if (configCmdLine.at(i) == "-no-optimized-tools")
+            dictionary[ "RELEASE_TOOLS" ] = "no";
 
         else if (configCmdLine.at(i) == "-compile-examples") {
             dictionary[ "COMPILE_EXAMPLES" ] = "yes";
@@ -1814,6 +1819,9 @@ bool Configure::displayHelp()
 
         desc("BUILDDEV", "yes", "-developer-build",      "Compile and link Qt with Qt developer options (including auto-tests exporting)\n");
 
+        desc("RELEASE_TOOLS", "yes", "-optimized-tools", "Do not build optimized host tools even in debug build.");
+        desc("RELEASE_TOOLS", "no", "-no-optimized-tools", "Build optimized host tools even in debug build.\n");
+
         desc("OPENSOURCE", "opensource", "-opensource",   "Compile and link the Open-Source Edition of Qt.");
         desc("COMMERCIAL", "commercial", "-commercial",   "Compile and link the Commercial Edition of Qt.\n");
 
@@ -2738,6 +2746,8 @@ void Configure::generateOutputVars()
             qtConfig += "debug_and_release build_all debug";
         qtConfig += "release";
     }
+    if (dictionary[ "RELEASE_TOOLS" ] == "yes")
+        qtConfig += "release_tools";
 
     if (dictionary[ "C++STD" ] == "c++11")
         qtConfig += "c++11";
@@ -3837,6 +3847,8 @@ void Configure::displayConfig()
     }
     if (dictionary[ "BUILD" ] == "release" || dictionary[ "BUILDALL" ] == "yes")
         sout << "Force debug info............" << dictionary[ "FORCEDEBUGINFO" ] << endl;
+    if (dictionary[ "BUILD" ] == "debug")
+        sout << "Force optimized tools......." << dictionary[ "RELEASE_TOOLS" ] << endl;
     sout << "C++ language standard......." << dictionary[ "C++STD" ] << endl;
     sout << "Link Time Code Generation..." << dictionary[ "LTCG" ] << endl;
     sout << "Accessibility support......." << dictionary[ "ACCESSIBILITY" ] << endl;
@@ -4010,6 +4022,10 @@ void Configure::displayConfig()
              << "Qt 5.6 build, but you should update your build scripts to remove the" << endl
              << "option and, if necessary, upgrade your compiler." << endl;
     }
+    if (dictionary["RELEASE_TOOLS"] == "yes" && dictionary["BUILD"] != "debug" ) {
+        sout << endl
+             << "NOTE:  -optimized-tools is not useful in -release mode." << endl;
+    }
     if (!dictionary["PREFIX_COMPLAINTS"].isEmpty()) {
         sout << endl
              << dictionary["PREFIX_COMPLAINTS"] << endl
-- 
GitLab