Index: trunk/qmake/generators/os2/gnumake.cpp
===================================================================
--- trunk/qmake/generators/os2/gnumake.cpp	(revision 38)
+++ trunk/qmake/generators/os2/gnumake.cpp	(revision 39)
@@ -54,5 +54,5 @@
 GNUMakefileGenerator::GNUMakefileGenerator() : Win32MakefileGenerator(), init_flag(false)
 {
-    if (Option::shellPath.isEmpty())
+    if (isDosLikeShell())
         quote = "\"";
     else
@@ -69,10 +69,19 @@
 }
 
-QString GNUMakefileGenerator::escapeDependencyPath(const QString &path) const
+QString GNUMakefileGenerator::escapeFilePath(const QString &path) const
 {
     QString ret = path;
-    ret.remove('\"');
-    ret.replace('\\', "/");
-    ret.replace(' ', "\\ ");
+    if (!isDosLikeShell()) {
+        ret.remove('\"');
+        ret.replace('\\', "/");
+        ret.replace(' ', "\\ ");
+    } else {
+        ret.replace(QRegExp("\""), "");
+        if (ret.contains(QRegExp("[ +&;%]")))
+            ret = quote + ret + quote;
+        /* @todo exclude $(var) constructs from quoting like this:
+         *     $(OBJECTS_DIR)\my file.obj = > $(OBJECTS_DIR)\"my file.obj"
+         */
+    }
     return ret;
 }
@@ -191,5 +200,4 @@
     init_flag = true;
 
-    /* this should probably not be here, but I'm using it to wrap the .t files */
     if(project->first("TEMPLATE") == "app")
         project->values("QMAKE_APP_FLAG").append("1");
@@ -201,5 +209,5 @@
             project->values("QMAKE_COPY_FILE").append("$(COPY)");
         if(project->isEmpty("QMAKE_COPY_DIR"))
-            project->values("QMAKE_COPY_DIR").append("xcopy /s /q /y /i");
+            project->values("QMAKE_COPY_DIR").append("$(COPY)");
         if(project->isEmpty("QMAKE_INSTALL_FILE"))
             project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
@@ -219,8 +227,4 @@
     processVars();
 
-    if (!project->values("RES_FILE").isEmpty()) {
-        project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
-    }
-
     // LIBS defined in Profile comes first for gcc
     project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
@@ -238,7 +242,4 @@
             destDir = Option::fixPathToTargetOS(project->first("DESTDIR") + Option::dir_sep, false, false);
     }
-
-    if(!project->values("DEF_FILE").isEmpty())
-        project->values("QMAKE_LFLAGS").append(QString("-Wl,") + project->first("DEF_FILE"));
 
     MakefileGenerator::init();
@@ -270,11 +271,5 @@
 void GNUMakefileGenerator::fixTargetExt()
 {
-    if (project->isActiveConfig("staticlib") && project->first("TEMPLATE") == "lib") {
-        project->values("TARGET_EXT").append(".lib");
-        project->values("QMAKE_LFLAGS").append("-static");
-        project->values("TARGET").first() =  "lib" + project->first("TARGET");
-    } else {
-        Win32MakefileGenerator::fixTargetExt();
-    }
+    Win32MakefileGenerator::fixTargetExt();
 }
 
@@ -287,5 +282,5 @@
     QString incsSemicolon;
     for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
-        QString inc = maybeQuotePath(*incit);
+        QString inc = escapeFilePath(*incit);
         t << " " << opt << inc;
         incsSemicolon += inc + Option::dirlist_sep;
@@ -309,5 +304,5 @@
         QStringList libs = project->values("QMAKE_LIBS");
         for(QStringList::Iterator it = libs.begin(); it != libs.end(); ++it) {
-            QString lib = maybeQuotePath(*it);
+            QString lib = escapeFilePath(*it);
             /* lib may be prefixed with -l which is commonly used in e.g. PRF
              * (feature) files on all platforms; remove it before prepending
@@ -326,5 +321,5 @@
     QStringList libDirs = project->values("QMAKE_LIBDIR");
     for(QStringList::Iterator it = libDirs.begin(); it != libDirs.end(); ++it) {
-        QString libDir = maybeQuotePath(*it);
+        QString libDir = escapeFilePath(*it);
         /* libDir may be prefixed with -L which is commonly used in e.g. PRF
          * (feature) files on all platforms; remove it before prepending
@@ -353,8 +348,17 @@
     if(!project->isEmpty("QMAKE_PRE_LINK"))
         t << "\n\t" <<var("QMAKE_PRE_LINK");
-    if(project->isActiveConfig("staticlib") && project->first("TEMPLATE") == "lib") {
-        t << "\n\t" << "$(LIB) $(DESTDIR_TARGET) $(OBJECTS)";
+    if(project->first("TEMPLATE") == "lib" && project->isActiveConfig("staticlib")) {
+        /* static library */
+        t << "\n\t" << var("QMAKE_RUN_LIB");
     } else {
-        t << "\n\t" << "$(LINK) $(LFLAGS) -o $(DESTDIR_TARGET) $(OBJECTS) $(LIBS)";
+        /* application or DLL */
+        t << "\n\t" << var("QMAKE_RUN_LINK");
+        if (!project->isEmpty("RES_FILE") && !project->isEmpty("QMAKE_RUN_RC2EXE")) {
+            t << "\n\t" << var("QMAKE_RUN_RC2EXE");
+        }
+        if (project->first("TEMPLATE") == "lib") {
+            if (!project->isEmpty("QMAKE_RUN_IMPLIB"))
+                t << "\n\t" << var("QMAKE_RUN_IMPLIB");
+        }
     }
     if(!project->isEmpty("QMAKE_POST_LINK"))
@@ -363,17 +367,48 @@
 }
 
-void GNUMakefileGenerator::writeRcFilePart(QTextStream &t)
-{
-    const QString rc_file = fileFixify(project->first("RC_FILE"));
-
-    QString incPathStr = fileInfo(rc_file).path();
-    if (incPathStr != "." && QDir::isRelativePath(incPathStr))
-        incPathStr.prepend("./");
-
-    if (!rc_file.isEmpty()) {
-        t << escapeDependencyPath(var("RES_FILE")) << ": " << rc_file << "\n\t"
-          << var("QMAKE_RC") << " -i " << rc_file << " -o " << var("RES_FILE")
-          << " --include-dir=" << incPathStr << endl << endl;
-    }
+void GNUMakefileGenerator::writeRcAndDefVariables(QTextStream &t)
+{
+    if (!project->isEmpty("RC_FILE")) {
+        t << "RC_FILE       = " << escapeFilePath(var("RC_FILE")) << endl;
+    }
+    if (!project->isEmpty("RES_FILE")) {
+        t << "RES_FILE      = " << valList(escapeFilePaths(project->values("RES_FILE"))) << endl;
+    }
+    if (project->first("TEMPLATE") == "lib" && !project->isActiveConfig("staticlib") &&
+        !project->isEmpty( "QMAKE_RUN_IMPLIB")) {
+        t << "TARGET_IMPLIB = $(basename $(DESTDIR_TARGET)).lib" << endl;
+        project->values("QMAKE_CLEAN").append( "$(TARGET_IMPLIB)" );
+    }
+}
+
+void GNUMakefileGenerator::writeRcAndDefPart(QTextStream &t)
+{
+    if (!project->isEmpty("RC_FILE") && !project->isEmpty("RES_FILE") &&
+        !project->isEmpty("QMAKE_RUN_RC2RES")) {
+        t << "$(RES_FILE): $(RC_FILE)\n\t";
+        t << var("QMAKE_RUN_RC2RES") << endl;
+    }
+}
+
+void GNUMakefileGenerator::processRcFileVar()
+{
+    if (Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
+        return;
+
+    if (!project->values("RC_FILE").isEmpty()) {
+        if (!project->values("RES_FILE").isEmpty()) {
+            fprintf(stderr, "Both rc and res file specified.\n");
+            fprintf(stderr, "Please specify one of them, not both.");
+            exit(1);
+        }
+    	project->values("RES_FILE").prepend(escapeFilePath(QString("$(OBJECTS_DIR)") +
+                                                           QDir::separator() +
+                                                           QFileInfo(var("RC_FILE")).baseName() +
+                                                           ".res"));
+    	project->values("CLEAN_FILES") += "$(RES_FILE)";
+    }
+
+    if (!project->values("RES_FILE").isEmpty())
+        project->values("POST_TARGETDEPS") += "$(RES_FILE)";
 }
 
@@ -421,14 +456,4 @@
 }
 
-QString GNUMakefileGenerator::maybeQuotePath(const QString &path)
-{
-    QString quoted = path;
-    quoted.replace(QRegExp("\\\\$"), "");
-    quoted.replace(QRegExp("\""), "");
-    if (quoted.contains(QRegExp("[ +&;$%()]")))
-        quoted = quote + quoted + quote;
-    return quoted;
-}
-
 void GNUMakefileGenerator::writeProjectVarToStream(QTextStream &t, const QString &var)
 {
@@ -475,5 +500,9 @@
             if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
                 QTextStream rt(&file);
-                writeProjectVarToStream(rt, vars[i+1]);
+                if (!qstrcmp(vars[i+1], "INCPATH")) {
+                    QString opt = var("QMAKE_CFLAGS_INCDIR");
+                    rt << varGlue(vars[i+1], opt, "\n" + opt, QString::null);
+                } else
+                    rt << varGlue(vars[i+1], QString::null, "\n", QString::null);
                 rt.flush();
                 file.close();
@@ -494,5 +523,5 @@
         if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
             QTextStream rt(&file);
-            writeProjectVarToStream(rt, "OBJECTS");
+            rt << varGlue("OBJECTS", QString::null, "\n", QString::null);
             rt.flush();
             file.close();
Index: trunk/qmake/generators/os2/gnumake.h
===================================================================
--- trunk/qmake/generators/os2/gnumake.h	(revision 38)
+++ trunk/qmake/generators/os2/gnumake.h	(revision 39)
@@ -55,5 +55,5 @@
     ~GNUMakefileGenerator();
 protected:
-    QString escapeDependencyPath(const QString &path) const;
+    QString escapeFilePath(const QString &path) const;
     QString getLibTarget();
 private:
@@ -66,6 +66,8 @@
     void writeObjectsPart(QTextStream &t);
     void writeBuildRulesPart(QTextStream &t);
-    void writeRcFilePart(QTextStream &t);
+    void writeRcAndDefVariables(QTextStream &t);
+    void writeRcAndDefPart(QTextStream &t);
     void init();
+    void processRcFileVar();
     void processPrlVariable(const QString &var, const QStringList &l);
 
@@ -76,6 +78,4 @@
     virtual bool findLibraries();
     void fixTargetExt();
-
-    QString maybeQuotePath(const QString &path);
 
     void writeProjectVarToStream(QTextStream &t, const QString &var);
