=== modified file 'Source/cmGlobalNinjaGenerator.cxx'
--- old/Source/cmGlobalNinjaGenerator.cxx	2012-05-24 17:38:13 +0000
+++ new/Source/cmGlobalNinjaGenerator.cxx	2012-06-01 17:02:28 +0000
@@ -200,6 +200,7 @@
                 "$DESC",
                 "Rule for running custom commands.",
                 /*depfile*/ "",
+                /*rspfile*/ "",
                 /*restat*/ true);
 }
 
@@ -233,6 +234,7 @@
                                        const std::string& description,
                                        const std::string& comment,
                                        const std::string& depfile,
+                                       const std::string& rspfile,
                                        bool restat,
                                        bool generator)
 {
@@ -277,6 +279,14 @@
     os << "description = " << description << "\n";
     }
 
+  if(!rspfile.empty())
+    {
+      cmGlobalNinjaGenerator::Indent(os, 1);
+      os << "rspfile = " << rspfile << "\n";
+      cmGlobalNinjaGenerator::Indent(os, 1);
+      os << "rspfile_content = $in" << "\n";
+    }
+
   if(restat)
     {
     cmGlobalNinjaGenerator::Indent(os, 1);
@@ -481,6 +491,7 @@
                                      const std::string& description,
                                      const std::string& comment,
                                      const std::string& depfile,
+                                     const std::string& rspfile,
                                      bool restat,
                                      bool generator)
 {
@@ -495,6 +506,7 @@
                                     description,
                                     comment,
                                     depfile,
+                                    rspfile,
                                     restat,
                                     generator);
 }
@@ -799,6 +811,7 @@
             "Re-running CMake...",
             "Rule for re-running cmake.",
             /*depfile=*/ "",
+            /*rspfile=*/ "",
             /*restat=*/ false,
             /*generator=*/ true);
 
@@ -836,6 +849,7 @@
             "Cleaning all built files...",
             "Rule for cleaning all built files.",
             /*depfile=*/ "",
+            /*rspfile=*/ "",
             /*restat=*/ false,
             /*generator=*/ false);
   WriteBuild(os,
@@ -856,6 +870,7 @@
             "All primary targets available:",
             "Rule for printing all primary targets available.",
             /*depfile=*/ "",
+            /*rspfile=*/ "",
             /*restat=*/ false,
             /*generator=*/ false);
   WriteBuild(os,

=== modified file 'Source/cmGlobalNinjaGenerator.h'
--- old/Source/cmGlobalNinjaGenerator.h	2012-05-24 17:38:13 +0000
+++ new/Source/cmGlobalNinjaGenerator.h	2012-05-31 20:08:50 +0000
@@ -113,6 +113,7 @@
                         const std::string& description,
                         const std::string& comment = "",
                         const std::string& depfile = "",
+                        const std::string& rspfile = ""					,
                         bool restat = false,
                         bool generator = false);
 
@@ -223,6 +224,7 @@
                const std::string& description,
                const std::string& comment = "",
                const std::string& depfile = "",
+               const std::string& rspfile = "",
                bool restat = false,
                bool generator = false);
 

=== modified file 'Source/cmLocalNinjaGenerator.cxx'
--- old/Source/cmLocalNinjaGenerator.cxx	2012-05-30 20:52:35 +0000
+++ new/Source/cmLocalNinjaGenerator.cxx	2012-06-01 16:51:09 +0000
@@ -275,12 +275,7 @@
     return ":";
 #endif
 
-  // TODO: This will work only on Unix platforms. I don't
-  // want to use a link.txt file because I will lose the benefit of the
-  // $in variables. A discussion about dealing with multiple commands in
-  // a rule is started here:
-  // groups.google.com/group/ninja-build/browse_thread/thread/d515f23a78986008
-  std::ostringstream cmd;
+ std::ostringstream cmd;
   for (std::vector<std::string>::const_iterator li = cmdLines.begin();
        li != cmdLines.end(); ++li) {
     if (li != cmdLines.begin()) {

=== modified file 'Source/cmNinjaNormalTargetGenerator.cxx'
--- old/Source/cmNinjaNormalTargetGenerator.cxx	2012-05-24 17:38:13 +0000
+++ new/Source/cmNinjaNormalTargetGenerator.cxx	2012-06-01 17:24:15 +0000
@@ -148,13 +148,28 @@
 {
   cmTarget::TargetType targetType = this->GetTarget()->GetType();
   std::string ruleName = this->LanguageLinkerRule();
-
+  std::string rspfile;
+  if (targetType == cmTarget::EXECUTABLE) {
+    rspfile = "$out.rsp";    // TODO: use only if really needed!
+  }
   if (!this->GetGlobalGenerator()->HasRule(ruleName)) {
     cmLocalGenerator::RuleVariables vars;
     vars.RuleLauncher = "RULE_LAUNCH_LINK";
     vars.CMTarget = this->GetTarget();
     vars.Language = this->TargetLinkLanguage;
-    vars.Objects = "$in";
+    if (rspfile.empty())
+      {
+      vars.Objects = "$in";
+      }
+    else
+      {    // handle response file
+#ifdef _WIN32
+      vars.Objects = "@$out.rsp";       // valid for MSVC linker,
+#else
+      // but not if ar is used to link static lib! ck
+      vars.Objects = "-Wl,@$out.rsp";   // FIXME valid for newer gcc linker
+#endif
+      }
     std::string objdir =
       this->GetLocalGenerator()->GetHomeRelativeOutputPath();
     objdir += objdir.empty() ? "" : "/";
@@ -201,7 +216,7 @@
       vars.LanguageCompileFlags = langFlags.c_str();
     }
 
-    // Rule for linking library.
+    // Rule for linking library/executable.
     std::vector<std::string> linkCmds = this->ComputeLinkCmd();
     for(std::vector<std::string>::iterator i = linkCmds.begin();
         i != linkCmds.end();
@@ -214,7 +229,7 @@
     std::string linkCmd =
       this->GetLocalGenerator()->BuildCommandLine(linkCmds);
 
-    // Write the linker rule.
+    // Write the linker rule with response file if needed.
     std::ostringstream comment;
     comment << "Rule for linking " << this->TargetLinkLanguage << " "
             << this->GetVisibleTypeName() << ".";
@@ -224,7 +239,9 @@
     this->GetGlobalGenerator()->AddRule(ruleName,
                                         linkCmd,
                                         description.str(),
-                                        comment.str());
+                                        comment.str(),
+                                        /*depfile*/ "",
+                                        rspfile);
   }
 
   if (this->TargetNameOut != this->TargetNameReal) {

