diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 328706c..af5d677 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -17,6 +17,13 @@
 #include "cmGeneratorTarget.h"
 #include "cmVersion.h"
 
+#ifndef _WIN32
+#include <limits.h> // PATH_MAX
+#include <stdlib.h> // realpath
+#include <errno.h>  // errno
+#include <string.h> // strerror
+#endif
+
 const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja";
 const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja";
 const char* cmGlobalNinjaGenerator::INDENT = "  ";
@@ -66,7 +73,7 @@ std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident,
   if (std::find_if(ident.begin(), ident.end(),
                    std::not1(std::ptr_fun(IsIdentChar))) != ident.end()) {
     static unsigned VarNum = 0;
-    std::ostringstream names;
+    cmOStringStream names;
     names << "ident" << VarNum++;
     vars << names.str() << " = " << ident << "\n";
     return "$" + names.str();
@@ -89,7 +96,23 @@ std::string cmGlobalNinjaGenerator::EncodePath(const std::string &path)
 {
   std::string result = path;
 #ifdef _WIN32
-  cmSystemTools::ReplaceString(result, "/", "\\");
+  cmSystemTools::ReplaceString(result, "/", "\\");  //FIXME why? ck
+#else
+#if 0
+  if ((path != "all") && (path != "help") && (path != "clean") &&
+      (path != "edit_cache") && (path != "rebuild_cache") && (path != "build.ninja")) {
+    //FIXME normalize() or canonical() path; but not if a phony target!
+    char buf[PATH_MAX];
+    char * ok = realpath(path.c_str(), buf);  // TODO use boost::filesystem::normalize()
+    if (ok) {
+        //TRACE std::cout << buf << std::endl;
+        result = buf;
+    } else {
+        //TRACE std::cerr << "::realpath(" << buf << "): " << strerror(errno) << std::endl;
+        result = buf;   //XXX path may be to short! ck
+    }
+  }
+#endif
 #endif
   return EncodeLiteral(result);
 }
@@ -123,7 +146,7 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
 
   cmGlobalNinjaGenerator::WriteComment(os, comment);
 
-  std::ostringstream builds;
+  cmOStringStream builds;
 
   // TODO: Better formatting for when there are multiple input/output files.
 
@@ -173,6 +196,8 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
       i != variables.end();
       ++i)
     cmGlobalNinjaGenerator::WriteVariable(os, i->first, i->second, "", 1);
+
+  os << "\n";
 }
 
 void cmGlobalNinjaGenerator::WritePhonyBuild(std::ostream& os,
@@ -288,6 +313,8 @@ void cmGlobalNinjaGenerator::WriteRule(std::ostream& os,
     cmGlobalNinjaGenerator::Indent(os, 1);
     os << "generator = 1\n";
     }
+
+  os << "\n";
 }
 
 void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os,
@@ -783,7 +810,7 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
   cmLocalGenerator *lg = this->LocalGenerators[0];
   cmMakefile* mfRoot = lg->GetMakefile();
 
-  std::ostringstream cmd;
+  cmOStringStream cmd;
   cmd << lg->ConvertToOutputFormat(
            mfRoot->GetRequiredDefinition("CMAKE_COMMAND"),
            cmLocalGenerator::SHELL)
@@ -830,9 +857,17 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
 
 void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
 {
+  cmLocalGenerator *lg = this->LocalGenerators[0];
+  cmMakefile* mfRoot = lg->GetMakefile();
+
+  cmOStringStream cmd;
+  cmd << lg->ConvertToOutputFormat(
+    mfRoot->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"),
+    cmLocalGenerator::SHELL) << " -t clean";
+
   WriteRule(*this->RulesFileStream,
             "CLEAN",
-            "ninja -t clean",
+            cmd.str(),
             "Cleaning all built files...",
             "Rule for cleaning all built files.",
             /*depfile=*/ "",
@@ -850,9 +885,17 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
 
 void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os)
 {
+  cmLocalGenerator *lg = this->LocalGenerators[0];
+  cmMakefile* mfRoot = lg->GetMakefile();
+
+  cmOStringStream cmd;
+  cmd << lg->ConvertToOutputFormat(
+    mfRoot->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"),
+    cmLocalGenerator::SHELL) << " -t targets";
+
   WriteRule(*this->RulesFileStream,
             "HELP",
-            "ninja -t targets",
+            cmd.str(),
             "All primary targets available:",
             "Rule for printing all primary targets available.",
             /*depfile=*/ "",
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 80007f1..e4fbf00 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -312,7 +312,7 @@ cmNinjaTargetGenerator
   this->GetRulesFileStream()
     << "# Rules for language " << language << "\n\n";
   this->WriteCompileRule(language);
-  this->GetRulesFileStream() << "\n";
+  this->GetRulesFileStream() << "\n\n";
 }
 
 void
@@ -365,9 +365,9 @@ cmNinjaTargetGenerator
     this->GetLocalGenerator()->BuildCommandLine(compileCmds);
 
   // Write the rule for compiling file of the given language.
-  std::ostringstream comment;
+  cmOStringStream comment;
   comment << "Rule for compiling " << language << " files.";
-  std::ostringstream description;
+  cmOStringStream description;
   description << "Building " << language << " object $out";
   this->GetGlobalGenerator()->AddRule(this->LanguageCompilerRule(language),
                                       cmdLine,
