Index: /trunk/mkspecs/os2-g++/qmake.conf
===================================================================
--- /trunk/mkspecs/os2-g++/qmake.conf	(revision 102)
+++ /trunk/mkspecs/os2-g++/qmake.conf	(revision 103)
@@ -100,5 +100,5 @@
 
 QMAKE_RUN_LINK          = $(LINK) $(LFLAGS) -o $(DESTDIR_TARGET) $(DEF_FILE) $$QMAKE_OBJECTS_REF $(LIBS)
-QMAKE_RUN_IMPLIB        = emximp -p 128 -o $(basename $(DESTDIR_TARGET)).lib $(DEF_FILE)
+QMAKE_RUN_IMPLIB        = emximp -p 128 -o $(TARGET_IMPLIB) $(DEF_FILE)
 
 QMAKE_RUN_GENDEF        = \
@@ -112,5 +112,5 @@
             $$QMAKE_OBJECTS_REF)
 
-QMAKE_GENDEF_DEPS       = $(OBJECTS)
+QMAKE_GENDEF_DEPS       = $(OBJECTS) $$_PRO_FILE_
 
 QMAKE_LIBS              =
Index: /trunk/qmake/generators/os2/gnumake.cpp
===================================================================
--- /trunk/qmake/generators/os2/gnumake.cpp	(revision 102)
+++ /trunk/qmake/generators/os2/gnumake.cpp	(revision 103)
@@ -95,4 +95,62 @@
 }
 
+QString
+GNUMakefileGenerator::findBestVersion(const QString &d, const QString &stem, const QString &ext)
+{
+    QString bd = Option::fixPathToLocalOS(d, true);
+    if(!exists(bd))
+        return QString();
+
+    QString dllStem = stem + QTDLL_POSTFIX;
+
+    QString versionOverride;
+    if(!project->values("QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE").isEmpty())
+        versionOverride = project->values("QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE").first();
+
+    if (project->isActiveConfig("link_prl")) {
+        QMakeMetaInfo libinfo;
+        if (libinfo.readLib(bd + Option::dir_sep + dllStem)) {
+            QString target = libinfo.first("QMAKE_PRL_TARGET");
+            if (target.isEmpty())
+                target = stem;
+            if (!versionOverride.isEmpty())
+                target += versionOverride;
+            else if (!libinfo.isEmpty("QMAKE_PRL_VERSION"))
+                target += libinfo.first("QMAKE_PRL_VERSION").replace(".", "");
+
+            const QStringList &in = libinfo.values("QMAKE_PRL_LIBS");
+            QStringList &out = project->values("QMAKE_INTERNAL_PRL_LIBS");
+            for (QStringList::ConstIterator it = in.begin(); it != in.end(); ++it) {
+                if (!out.contains(*it))
+                    out.append((*it));
+            }
+            return target;
+        }
+    }
+
+    if (!versionOverride.isEmpty())
+        return stem + versionOverride;
+
+    int biggest = -1;
+    if(!project->isActiveConfig("no_versionlink")) {
+        QDir dir(bd);
+        QStringList entries = dir.entryList();
+        QRegExp regx(QString("((lib)?%1([0-9]*))(%2)$").arg(dllStem).arg(ext), Qt::CaseInsensitive);
+        for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) {
+            if(regx.exactMatch((*it))) {
+				if (!regx.cap(3).isEmpty()) {
+					bool ok = true;
+					int num = regx.cap(3).toInt(&ok);
+					biggest = qMax(biggest, (!ok ? -1 : num));
+				}
+			}
+        }
+    }
+    if (biggest != -1)
+        return stem + QString::number(biggest);
+
+    return QString();
+}
+
 bool GNUMakefileGenerator::findLibraries()
 {
@@ -107,32 +165,36 @@
     }
 
-    QStringList::Iterator it = l.begin();
-    while (it != l.end()) {
-        if ((*it).startsWith("-l")) {
-            QString steam = (*it).mid(2), out;
+    for (QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
+        if((*it).startsWith("-L")) {
+            dirs.append(QMakeLocalFileName((*it).mid(2)));
+        } else {
+            QString stem = *it, out;
+
+            if (stem.startsWith("-l"))
+                stem = stem.mid(2);
+
             QString suffix;
-            if (!project->isEmpty("QMAKE_" + steam.toUpper() + "_SUFFIX"))
-                suffix = project->first("QMAKE_" + steam.toUpper() + "_SUFFIX");
+            if (!project->isEmpty("QMAKE_" + stem.toUpper() + "_SUFFIX"))
+                suffix = project->first("QMAKE_" + stem.toUpper() + "_SUFFIX");
             for (QList<QMakeLocalFileName>::Iterator dir_it = dirs.begin(); dir_it != dirs.end(); ++dir_it) {
-                QString extension;
-                int ver = findHighestVersion((*dir_it).local(), steam, "dll.lib|lib");
-                if (ver != -1)
-                    extension += QString::number(ver);
-                extension += suffix;
-                if(QMakeMetaInfo::libExists((*dir_it).local() + Option::dir_sep + steam) ||
-                    exists((*dir_it).local() + Option::dir_sep + steam + extension + ".lib") ||
-                    exists((*dir_it).local() + Option::dir_sep + steam + extension + ".dll.lib")) {
-                        out = (*it) + extension;
-                        break;
+                QString best = findBestVersion((*dir_it).local(), stem,
+                                               QString("%1.lib").arg(suffix));
+                if (!best.isEmpty()) {
+                    out = best.prepend("-l");
+                    break;
                 }
             }
             if (!out.isEmpty()) // We assume if it never finds it that its correct
-                (*it) = out;
-	    } else if((*it).startsWith("-L")) {
-            dirs.append(QMakeLocalFileName((*it).mid(2)));
-        }
-
-        ++it;
-    }
+                if (!project->values("QMAKE_LIBS").contains(out))
+                    (*it) = out;
+        }
+    }
+
+    QStringList l2 = project->values("QMAKE_INTERNAL_PRL_LIBS");
+    for (QStringList::ConstIterator it = l2.begin(); it != l2.end(); ++it) {
+        if (!l.contains(*it))
+            l.append((*it));
+    }
+
     return true;
 }
@@ -383,7 +445,4 @@
             t << "\n\t" << var("QMAKE_RUN_RC2EXE");
         }
-        if (mode == DLL && !project->isEmpty("QMAKE_RUN_IMPLIB")) {
-            t << "\n\t" << var("QMAKE_RUN_IMPLIB");
-        }
     }
     if(!project->isEmpty("QMAKE_POST_LINK"))
@@ -399,8 +458,4 @@
     if (!project->isEmpty("RES_FILE")) {
         t << "RES_FILE      = " << valList(escapeFilePaths(project->values("RES_FILE"))) << endl;
-    }
-    if (mode == DLL && !project->isEmpty("QMAKE_RUN_IMPLIB")) {
-        t << "TARGET_IMPLIB = $(basename $(DESTDIR_TARGET)).lib" << endl;
-        project->values("QMAKE_CLEAN").append("$(TARGET_IMPLIB)");
     }
 
@@ -429,4 +484,10 @@
         project->values("POST_TARGETDEPS") += escapeFileVars("$(DEF_FILE)");
     }
+
+    if (mode == DLL && !project->isEmpty("QMAKE_RUN_IMPLIB")) {
+        t << "TARGET_IMPLIB = $(basename $(DESTDIR_TARGET)).lib" << endl;
+        project->values("QMAKE_CLEAN").append("$(TARGET_IMPLIB)");
+        project->values("POST_TARGETDEPS") += escapeFileVars("$(TARGET_IMPLIB)");
+    }
 }
 
@@ -439,8 +500,15 @@
     }
 
-    if (project->isEmpty("DEF_FILE") && mode == DLL) {
-        /* generate a DEF file for the DLL when not supplied */
-        t << escapeFileVars("$(DEF_FILE): ") << var("QMAKE_GENDEF_DEPS");
-        t << valGlue(var("QMAKE_RUN_GENDEF").split(";;"), "\n\t", "\n\t", "") << endl;
+    if (mode == DLL) {
+        if (project->isEmpty("DEF_FILE")) {
+            /* generate a DEF file for the DLL when not supplied */
+            t << escapeFileVars("$(DEF_FILE): ") << var("QMAKE_GENDEF_DEPS");
+            t << valGlue(var("QMAKE_RUN_GENDEF").split(";;"), "\n\t", "\n\t", "") << endl;
+        }
+        if (!project->isEmpty("QMAKE_RUN_IMPLIB")) {
+            /* generate the import library */
+            t << escapeFileVars("$(TARGET_IMPLIB): ") << escapeFileVars("$(DEF_FILE)");
+            t << "\n\t" << var("QMAKE_RUN_IMPLIB") << endl;
+        }
     }
 }
@@ -470,16 +538,14 @@
 void GNUMakefileGenerator::processPrlVariable(const QString &var, const QStringList &l)
 {
-    if (var == "QMAKE_PRL_LIBS") {
-        QString where = "QMAKE_LIBS";
-        if (!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
-            where = project->first("QMAKE_INTERNAL_PRL_LIBS");
-        QStringList &out = project->values(where);
-        for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
-            out.removeAll((*it));
-            out.append((*it));
-        }
-    } else {
-        Win32MakefileGenerator::processPrlVariable(var, l);
-    }
+    // we don't do any processing here; everything we need is done in
+    // GNUMakefileGenerator::findLibraries()
+    return;
+}
+
+void GNUMakefileGenerator::processPrlFiles()
+{
+    // we don't do any processing here; everything we need is done in
+    // GNUMakefileGenerator::findLibraries()
+    return;
 }
 
Index: /trunk/qmake/generators/os2/gnumake.h
===================================================================
--- /trunk/qmake/generators/os2/gnumake.h	(revision 102)
+++ /trunk/qmake/generators/os2/gnumake.h	(revision 103)
@@ -71,4 +71,5 @@
     void processRcFileVar();
     void processPrlVariable(const QString &var, const QStringList &l);
+    void processPrlFiles();
 
     QStringList &findDependencies(const QString &file);
@@ -76,4 +77,5 @@
     QString preCompHeaderOut;
 
+    QString findBestVersion(const QString &d, const QString &stem, const QString &ext);
     virtual bool findLibraries();
     void fixTargetExt();
