From 60bcce7fa2956d3017666cd8805979b40ef1523b Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Fri, 20 May 2005 11:01:21 -0400 Subject: [PATCH] ENH: added help target and made custom commands execute in start output directory --- Source/cmGlobalUnixMakefileGenerator3.cxx | 52 ++++++++++++++++++++++- Source/cmGlobalUnixMakefileGenerator3.h | 3 +- Source/cmLocalUnixMakefileGenerator3.cxx | 48 ++++++++++++++++++++- Source/cmLocalUnixMakefileGenerator3.h | 5 ++- 4 files changed, 102 insertions(+), 6 deletions(-) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 861ee05a2..0ed9d1e57 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -101,7 +101,7 @@ void cmGlobalUnixMakefileGenerator3::Generate() this->WriteMainCMakefile(); // now write the support Makefiles - this->WriteBuildMakefile(); + //this->WriteBuildMakefile(); this->WriteCleanMakefile(); } @@ -167,6 +167,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile() this->WriteConvenienceRules(makefileStream,lg,exclude); } + this->WriteHelpRule(makefileStream); lg = static_cast(m_LocalGenerators[0]); lg->WriteSpecialTargetsBottom(makefileStream); } @@ -667,3 +668,52 @@ cmGlobalUnixMakefileGenerator3 } } } + +//---------------------------------------------------------------------------- +void +cmGlobalUnixMakefileGenerator3::WriteHelpRule(std::ostream& ruleFileStream) +{ + cmLocalUnixMakefileGenerator3 *lg = + static_cast(m_LocalGenerators[0]); + + // add the help target + std::string path; + std::vector no_depends; + std::vector commands; + lg->AppendEcho(commands, + "The following are some of the valid targets for this Makefile:"); + lg->AppendEcho(commands,"... all (the default if no target is provided)"); + lg->AppendEcho(commands,"... clean"); + lg->AppendEcho(commands,"... depend"); + lg->AppendEcho(commands,"... install"); + lg->AppendEcho(commands,"... rebuild_cache"); + + // for each local generator + unsigned int i; + for (i = 0; i < m_LocalGenerators.size(); ++i) + { + lg = static_cast(m_LocalGenerators[i]); + + + // for each target Generate the rule files for each target. + const cmTargets& targets = lg->GetMakefile()->GetTargets(); + for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t) + { + if((t->second.GetType() == cmTarget::EXECUTABLE) || + (t->second.GetType() == cmTarget::STATIC_LIBRARY) || + (t->second.GetType() == cmTarget::SHARED_LIBRARY) || + (t->second.GetType() == cmTarget::MODULE_LIBRARY) || + (t->second.GetType() == cmTarget::UTILITY)) + { + path = "... "; + path += t->second.GetName(); + lg->AppendEcho(commands,path.c_str()); + } + } + } + lg->WriteMakeRule(ruleFileStream, "Help Target", + "help:", + no_depends, commands); + ruleFileStream << "\n\n"; +} + diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 4bf5b4c8b..9cb049b1b 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -65,7 +65,8 @@ protected: void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream); void WriteAllRules(cmLocalUnixMakefileGenerator3 *lg, std::ostream& makefileStream); - + void WriteHelpRule(std::ostream& ruleFileStream); + void WriteConvenienceRules(std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3 *, bool exclude); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index a0d9ca74b..f5cf7cfe2 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -645,7 +645,10 @@ cmLocalUnixMakefileGenerator3 temp = relativeObj; temp += ".provides.build"; std::vector r_commands; - r_commands.push_back(this->GetRecursiveMakeCall("build.make",temp.c_str())); + std::string tgtMakefileName = this->GetRelativeTargetDirectory(target); + tgtMakefileName += "/build.make"; + r_commands.push_back(this->GetRecursiveMakeCall(tgtMakefileName.c_str(), + temp.c_str())); p_depends.clear(); p_depends.push_back(objectRequires); this->WriteMakeRule(ruleFileStream, 0, @@ -2514,6 +2517,8 @@ cmLocalUnixMakefileGenerator3 const cmCustomCommand& cc) { // TODO: Convert outputs/dependencies (arguments?) to relative paths. + + std::vector commands1; // Add each command line to the set of commands. for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin(); @@ -2523,7 +2528,7 @@ cmLocalUnixMakefileGenerator3 const cmCustomCommandLine& commandLine = *cl; std::string cmd = commandLine[0]; cmSystemTools::ReplaceString(cmd, "/./", "/"); - cmd = this->Convert(cmd.c_str(),HOME_OUTPUT); + cmd = this->Convert(cmd.c_str(),START_OUTPUT); if(cmd.find("/") == cmd.npos && commandLine[0].find("/") != cmd.npos) { @@ -2536,6 +2541,45 @@ cmLocalUnixMakefileGenerator3 cmd += " "; cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str()); } + + commands1.push_back(cmd); + } + + // stick this group of commands into a cd of the proper path + // Build the jump-and-build command list. + if(m_WindowsShell) + { + // On Windows we must perform each step separately and then jump + // back because the shell keeps the working directory between + // commands. + std::string cmd = "cd "; + cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory()); + commands.push_back(cmd); + + // push back the custom commands + commands.insert(commands.end(), commands1.begin(), commands1.end()); + + // Jump back to the home directory. + cmd = "cd "; + cmd += this->ConvertToOutputForExisting(m_Makefile->GetHomeOutputDirectory()); + commands.push_back(cmd); + } + else + { + // On UNIX we must construct a single shell command to jump and + // build because make resets the directory between each command. + std::string cmd = "cd "; + cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory()); + + // add the commands + unsigned int i; + for (i = 0; i < commands1.size(); ++i) + { + cmd += " && "; + cmd += commands1[i]; + } + + // Add the command as a single line. commands.push_back(cmd); } } diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index a6de93edb..9f5735c60 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -150,6 +150,9 @@ public: void AppendGlobalTargetDepends(std::vector& depends, const cmTarget& target); + void AppendEcho(std::vector& commands, + const char* text); + protected: // write the target rules for the local Makefile into the stream @@ -302,8 +305,6 @@ protected: const cmCustomCommand& cc); void AppendCleanCommand(std::vector& commands, const std::vector& files); - void AppendEcho(std::vector& commands, - const char* text); //========================================================================== bool SamePath(const char* path1, const char* path2);