From 7f65718b3a076896f67fda6dcd1b32f806825b78 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Mon, 29 Oct 2018 12:40:49 +0000
Subject: [PATCH] qtbase qmake remove qtlibinfix from libname before finding
 prl

Change-Id: Ic5046e72d373d1ccbbb6b01773bc1b1fda5dd02e
---
 qtbase/qmake/generators/makefile.cpp          | 24 ++++++++++++++++++++++-
 qtbase/qmake/generators/win32/winmakefile.cpp | 27 +++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/qtbase/qmake/generators/makefile.cpp b/qtbase/qmake/generators/makefile.cpp
index a1f3352aa3..38205c33a5 100644
--- a/qtbase/qmake/generators/makefile.cpp
+++ b/qtbase/qmake/generators/makefile.cpp
@@ -893,7 +893,7 @@ MakefileGenerator::processPrlFile(QString &file)
     if (meta_file.isEmpty())
         return false;
     QMakeMetaInfo libinfo(project);
-    debug_msg(1, "Processing PRL file: %s", meta_file.toLatin1().constData());
+    debug_msg(0, "Processing PRL file: %s, try_replace_file: %d", meta_file.toLatin1().constData(), try_replace_file);
     if (!libinfo.readLib(meta_file)) {
         fprintf(stderr, "Error processing meta file %s\n", meta_file.toLatin1().constData());
         return false;
@@ -1084,6 +1084,27 @@ MakefileGenerator::prlFileName(bool fixify)
     int slsh = ret.lastIndexOf(Option::dir_sep);
     if(slsh != -1)
         ret.remove(0, slsh);
+    debug_msg(0, "MakefileGenerator::prlFileName :: fixify: %d (ret): %s", fixify, ret.toLatin1().constData());
+#ifdef QT_LIBINFIX
+    QString libinfix = QLatin1String(QT_LIBINFIX);
+#else
+    QString libinfix = project->propertyValue(ProKey("QT_LIBINFIX")).toQString();
+#endif
+
+    if (!libinfix.length())
+    {
+#ifdef QT_LIBINFIX
+    debug_msg(0, "MakefileGenerator::prlFileName :: libinfix nothing? (QT_LIBINFIX)");
+#else
+    debug_msg(0, "MakefileGenerator::prlFileName :: libinfix nothing? (ProKey)");
+#endif
+    }
+
+    // If you have and dots in here then the indexOf('.') goes wrong.
+    if (libinfix.length() && ret.contains(libinfix)) {
+        ret.replace(libinfix, QLatin1String(""));
+    }
+
     if(!ret.endsWith(Option::prl_ext)) {
         int dot = ret.indexOf('.');
         if(dot != -1)
@@ -1097,6 +1118,7 @@ MakefileGenerator::prlFileName(bool fixify)
             ret.prepend(project->first("DESTDIR").toQString());
         ret = fileFixify(ret, FileFixifyBackwards);
     }
+    debug_msg(0, "MakefileGenerator::prlFileName :: filename(ret): %s", ret.toLatin1().constData());
     return ret;
 }
 
diff --git a/qtbase/qmake/generators/win32/winmakefile.cpp b/qtbase/qmake/generators/win32/winmakefile.cpp
index 75bb5d236d..186d0e812b 100644
--- a/qtbase/qmake/generators/win32/winmakefile.cpp
+++ b/qtbase/qmake/generators/win32/winmakefile.cpp
@@ -46,8 +46,14 @@ Win32MakefileGenerator::Win32MakefileGenerator() : MakefileGenerator()
 
 ProString Win32MakefileGenerator::fixLibFlag(const ProString &lib)
 {
-    if (lib.startsWith("-l"))  // Fallback for unresolved -l libs.
+    if (lib.startsWith("-l")) {  // Fallback for unresolved -l libs.
+        // Complete hack in an attempt to allow -qtlibinfix to work
+        // on Windows. The other side of this hack is located in
+        // work/qtbase/mkspecs/features/qt.prf
+        if (lib.endsWith(".lib"))
+            return escapeFilePath(lib.mid(2));
         return escapeFilePath(lib.mid(2) + QLatin1String(".lib"));
+    }
     if (lib.startsWith("-L"))  // Lib search path. Needed only by -l above.
         return QLatin1String("/LIBPATH:")
                 + escapeFilePath(Option::fixPathToTargetOS(lib.mid(2).toQString(), false));
@@ -101,6 +107,25 @@ Win32MakefileGenerator::findLibraries(bool linkPrl, bool mergeLflags)
             (*it) = "-L" + lp.real();
         } else if (type == LibFlagLib) {
             QString lib = arg.toQString();
+#ifdef QT_LIBINFIX
+            QString libinfix = QLatin1String(QT_LIBINFIX);
+#else
+            QString libinfix = project->propertyValue(ProKey("QT_LIBINFIX")).toQString();
+#endif
+            debug_msg(0, "findLibraries (prl): lib %s", lib.toLatin1().constData());
+            if (libinfix.length()) {
+                if (lib.endsWith(libinfix + QLatin1String(".lib"))) {
+                    lib = lib.mid(0, lib.length() - libinfix.length() - 5);
+                } else if (lib.endsWith(libinfix + QLatin1String("d.lib"))) {
+                    lib = lib.mid(0, lib.length() - libinfix.length() - 6);
+                } else if (lib.endsWith(libinfix + QLatin1String("d"))) {
+                    lib = lib.mid(0, lib.length() - libinfix.length() - 1) + QLatin1String("d");
+                } else if (lib.endsWith(libinfix)) {
+                    lib = lib.mid(0, lib.length() - libinfix.length());
+                }
+                debug_msg(0, "findLibraries (prl): Replacing lib: %s (filename stub) due to libinfix: %s",
+                          lib.toLatin1().constData(), libinfix.toLatin1().constData());
+            }
             ProString verovr =
                     project->first(ProKey("QMAKE_" + lib.toUpper() + "_VERSION_OVERRIDE"));
             for (QList<QMakeLocalFileName>::Iterator dir_it = dirs.begin();
-- 
2.19.1

