Index: /trunk/qmake/generators/os2/gnumake.cpp
===================================================================
--- /trunk/qmake/generators/os2/gnumake.cpp	(revision 669)
+++ /trunk/qmake/generators/os2/gnumake.cpp	(revision 670)
@@ -90,5 +90,7 @@
     // dependency escaping is always done Unix-way since this is a requirement
     // of GNU make which allows " and ' to be part of the file name.
-    // Note that if the string is a make variable reference, we don't eascape!
+    // Note that if the string is a make variable reference, we don't eascape
+    // but instead use the q function defined in writeMakefile() that will do
+    // it at runtime.
     QString ret = path;
     QString trimmed = path.trimmed();
@@ -96,4 +98,6 @@
         ret.remove('\"');
         ret.replace(' ', "\\ ");
+    } else {
+        ret = escapeFileVars(ret);
     }
     return ret;
@@ -522,6 +526,10 @@
 {
     t << "first: all" << endl;
-    t << "all: " << escapeDependencyPath(fileFixify(Option::output.fileName())) << " " << valGlue(escapeDependencyPaths(project->values("ALL_DEPS"))," "," "," ") << escapeFileVars(" $(DESTDIR_TARGET)") << endl << endl;
-    t << escapeFileVars("$(DESTDIR_TARGET): ") << var("PRE_TARGETDEPS") << " $(OBJECTS) " << var("POST_TARGETDEPS");
+    t << "all: " << escapeDependencyPath(fileFixify(Option::output.fileName())) << " "
+                 << valGlue(escapeDependencyPaths(project->values("ALL_DEPS"))," "," "," ")
+                 << escapeFileVars(" $(DESTDIR_TARGET)") << endl << endl;
+    t << escapeFileVars("$(DESTDIR_TARGET): ") << escapeFileVars(var("PRE_TARGETDEPS"))
+                                               << escapeFileVars(" $(OBJECTS) ")
+                                               << escapeFileVars(var("POST_TARGETDEPS"));
     if (!project->isEmpty("QMAKE_PRE_LINK"))
         t << "\n\t" <<var("QMAKE_PRE_LINK");
@@ -564,9 +572,9 @@
             if (!project->isEmpty("DEF_FILE_TEMPLATE")) {
                 t << "DEF_FILE_TEMPLATE = " << escapeFilePath(var("DEF_FILE_TEMPLATE")) << endl;
-                project->values("QMAKE_GENDEF_DEPS") += escapeFileVars("$(DEF_FILE_TEMPLATE)");
+                project->values("QMAKE_GENDEF_DEPS") += "$(DEF_FILE_TEMPLATE)";
             }
             if (!project->isEmpty("DEF_FILE_MAP")) {
                 t << "DEF_FILE_MAP  = " << escapeFilePath(var("DEF_FILE_MAP")) << endl;
-                project->values("QMAKE_GENDEF_DEPS") += escapeFileVars("$(DEF_FILE_MAP)");
+                project->values("QMAKE_GENDEF_DEPS") += "$(DEF_FILE_MAP)";
             }
         }
@@ -578,5 +586,5 @@
         }
         t << "DEF_FILE      = " << escapeFilePath(var("DEF_FILE")) << endl;
-        project->values("POST_TARGETDEPS") += escapeFileVars("$(DEF_FILE)");
+        project->values("POST_TARGETDEPS") += "$(DEF_FILE)";
     }
 
@@ -598,5 +606,5 @@
         if (project->isEmpty("DEF_FILE")) {
             /* generate a DEF file for the DLL when not supplied */
-            t << escapeFileVars("$(DEF_FILE): ") << var("QMAKE_GENDEF_DEPS");
+            t << escapeFileVars("$(DEF_FILE): ") << escapeFileVars(var("QMAKE_GENDEF_DEPS"));
             t << valGlue(var("QMAKE_RUN_GENDEF").split(";;"), "\n\t", "\n\t", "") << endl;
         }
@@ -755,21 +763,20 @@
 }
 
+// static
 QString GNUMakefileGenerator::escapeFileVars(const QString &vars)
 {
     /* In DOS environment, we escape spaces and other illegal characters in
-     * filenames with double quotes. However, this is not appropriate for make
-     * rule definitions (targets/dependencies) where Unix escaping is
+     * filenames with double quotes. However, this is not appropriate for GNU
+     * make rule definitions (targets/dependencies) where Unix escaping is
      * expected. If we'd deal only with immediate strings, we could provide
      * necessary escaping in place, but we often use make variables instead of
      * direct file names so we must perform such escaping on the fly. This is
      * what we do here using the q function that we define in writeMakefile().*/
-    if (isDosLikeShell()) {
-        QString ret = vars;
-        QRegExp rx = QRegExp("\\$\\((.+)\\)");
-        rx.setMinimal(true);
-        ret.replace(rx, "$(call q,$(\\1))");
-        return ret;
-    }
-    return vars;
+    QString ret = vars;
+    QRegExp rx = QRegExp("(?:\\$\\(call q,\\$\\((.+)\\)\\))|"
+                         "(?:\\$\\(([^$)]+)\\))");
+    rx.setMinimal(true);
+    ret.replace(rx, "$(call q,$(\\1\\2))");
+    return ret;
 }
 
Index: /trunk/qmake/generators/os2/gnumake.h
===================================================================
--- /trunk/qmake/generators/os2/gnumake.h	(revision 669)
+++ /trunk/qmake/generators/os2/gnumake.h	(revision 670)
@@ -89,5 +89,6 @@
     void createLinkerResponseFiles(QTextStream &t);
     void createCompilerResponseFiles(QTextStream &t);
-    QString escapeFileVars(const QString &base);
+
+    static QString escapeFileVars(const QString &base);
 
     bool init_flag;
