From 867357235ecfe12edd9940d5c8ef08f4e6ac559d Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Date: Tue, 8 Mar 2016 19:38:59 +0100
Subject: [PATCH] delay application of configure -D/-I/-L/-l/-R flags

it is important that the flags coming from the current qt build appear
first, as otherwise a pre-existing qt installation may interfere with
the build.

the windows configure does not have any of this magic to start with.

Task-number: QTBUG-6351
Change-Id: Iacc1d9b5aa9eed9a5f0513baef9f6c6ffcef0735
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
---
 configure                            |  8 ++++----
 mkspecs/features/qt_build_config.prf |  3 +++
 mkspecs/features/qt_build_extra.prf  | 27 +++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 4 deletions(-)
 create mode 100644 mkspecs/features/qt_build_extra.prf

diff --git a/configure b/configure
index 7feed4c9e83..203155c819c 100755
--- a/configure
+++ b/configure
@@ -6439,9 +6439,9 @@ fi
 [ "$CFG_SYSTEM_PROXIES" = "yes" ] && QT_CONFIG="$QT_CONFIG system-proxies"
 [ "$CFG_DIRECTWRITE" = "yes" ] && QT_CONFIG="$QT_CONFIG directwrite"
 
-[ '!' -z "$DEFINES" ] && QMakeVar add DEFINES "$DEFINES"
-[ '!' -z "$INCLUDES" ] && QMakeVar add INCLUDEPATH "$INCLUDES"
-[ '!' -z "$L_FLAGS" ] && QMakeVar add LIBS "$L_FLAGS"
+[ '!' -z "$DEFINES" ] && QMakeVar add EXTRA_DEFINES "$DEFINES"
+[ '!' -z "$INCLUDES" ] && QMakeVar add EXTRA_INCLUDEPATH "$INCLUDES"
+[ '!' -z "$L_FLAGS" ] && QMakeVar add EXTRA_LIBS "$L_FLAGS"
 
 if [ -z "`getXQMakeConf 'QMAKE_(LFLAGS_)?RPATH'`" ]; then
     if [ -n "$RPATH_FLAGS" ]; then
@@ -6457,7 +6457,7 @@ if [ -z "`getXQMakeConf 'QMAKE_(LFLAGS_)?RPATH'`" ]; then
 else
     if [ -n "$RPATH_FLAGS" ]; then
         # add the user defined rpaths
-	QMakeVar add QMAKE_RPATHDIR "$RPATH_FLAGS"
+        QMakeVar add EXTRA_RPATHS "$RPATH_FLAGS"
     fi
 fi
 if [ "$CFG_RPATH" = "yes" ]; then
diff --git a/mkspecs/features/qt_build_config.prf b/mkspecs/features/qt_build_config.prf
index b3081b960ec..2d437e7f910 100644
--- a/mkspecs/features/qt_build_config.prf
+++ b/mkspecs/features/qt_build_config.prf
@@ -52,6 +52,9 @@ QMAKE_DIR_REPLACE_SANE = PRECOMPILED_DIR OBJECTS_DIR MOC_DIR RCC_DIR UI_DIR
     unset(modpath)
 }
 
+# Apply extra compiler flags passed via configure last.
+CONFIG = qt_build_extra $$CONFIG
+
 # Don't actually try to install anything in non-prefix builds.
 # This is much easier and safer than making every single INSTALLS
 # assignment conditional.
diff --git a/mkspecs/features/qt_build_extra.prf b/mkspecs/features/qt_build_extra.prf
new file mode 100644
index 00000000000..4b01c7b285f
--- /dev/null
+++ b/mkspecs/features/qt_build_extra.prf
@@ -0,0 +1,27 @@
+#
+#  W A R N I N G
+#  -------------
+#
+# This file is not part of the Qt API.  It exists purely as an
+# implementation detail.  It may change from version to version
+# without notice, or even be removed.
+#
+# We mean it.
+#
+
+equals(TEMPLATE, subdirs): return()
+
+# The headersclean check needs defines and includes even for
+# header-only modules.
+DEFINES += $$EXTRA_DEFINES
+INCLUDEPATH += $$EXTRA_INCLUDEPATH
+
+# The other flags are relevant only for actual libraries.
+equals(TEMPLATE, aux): return()
+
+LIBS += $$EXTRA_LIBS
+
+# Static libs need no rpaths
+static: return()
+
+QMAKE_RPATHDIR += $$EXTRA_RPATHS
-- 
GitLab