ENH: some more reorg

This commit is contained in:
Ken Martin 2005-05-17 11:15:09 -04:00
parent 226f7f6639
commit 61358ac75c
4 changed files with 57 additions and 193 deletions

View File

@ -101,7 +101,6 @@ void cmGlobalUnixMakefileGenerator3::Generate()
this->WriteMainCMakefile();
// now write the support Makefiles
this->WriteDependMakefile();
this->WriteBuildMakefile();
this->WriteCleanMakefile();
}
@ -316,64 +315,6 @@ void cmGlobalUnixMakefileGenerator3
}
}
void cmGlobalUnixMakefileGenerator3::WriteDependMakefile()
{
unsigned int i;
// Open the output file. This should not be copy-if-different
// because the check-build-system step compares the makefile time to
// see if the build system must be regenerated.
std::string makefileName = this->GetCMakeInstance()->GetHomeOutputDirectory();
makefileName += "/depend.make";
cmGeneratedFileStream makefileStream(makefileName.c_str());
if(!makefileStream)
{
return;
}
// get a local generator for some useful methods
cmLocalUnixMakefileGenerator3 *lg =
static_cast<cmLocalUnixMakefileGenerator3 *>(m_LocalGenerators[0]);
// Write the do not edit header.
lg->WriteDisclaimer(makefileStream);
//lg->WriteMakeVariables(makefileStream);
// add the generic dependency
std::vector<std::string> depends;
std::vector<std::string> no_commands;
lg->WriteMakeRule(makefileStream, 0, "depend", depends, no_commands);
// include the build rules
makefileStream
<< "# Include make rules for build targets\n";
makefileStream
<< lg->GetIncludeDirective() << " "
<< lg->ConvertToOutputForExisting("build.make").c_str()
<< "\n\n";
// include all the target depends
for (i = 0; i < m_LocalGenerators.size(); ++i)
{
cmLocalUnixMakefileGenerator3 *lg2 =
static_cast<cmLocalUnixMakefileGenerator3 *>(m_LocalGenerators[i]);
// are any parents excluded
bool exclude = false;
cmLocalGenerator *lg3 = lg2;
while (lg3)
{
if (lg3->GetExcludeAll())
{
exclude = true;
break;
}
lg3 = lg3->GetParent();
}
lg2->WriteMainTargetIncludes(makefileStream,"depend.make","depend");
lg2->WriteMainTargetRules(makefileStream,"depend.make","depend",!exclude);
}
}
void cmGlobalUnixMakefileGenerator3::WriteBuildMakefile()
{
unsigned int i;
@ -401,6 +342,8 @@ void cmGlobalUnixMakefileGenerator3::WriteBuildMakefile()
std::vector<std::string> depends;
std::vector<std::string> no_commands;
lg->WriteMakeRule(makefileStream, 0, "build", depends, no_commands);
lg->WriteMakeRule(makefileStream, 0, "depend", depends, no_commands);
lg->WriteMakeRule(makefileStream, 0, "requires", depends, no_commands);
// include all the target depends
for (i = 0; i < m_LocalGenerators.size(); ++i)
@ -420,8 +363,9 @@ void cmGlobalUnixMakefileGenerator3::WriteBuildMakefile()
lg3 = lg3->GetParent();
}
lg2->WriteMainTargetIncludes(makefileStream,"build.make","build");
lg2->WriteMainTargetRules(makefileStream,"build.make","build",!exclude);
lg2->WriteMainTargetRules(makefileStream,"build.make","depend",!exclude);
lg2->WriteMainTargetRules(makefileStream,"build.make","requires",!exclude);
lg2->WriteMainTargetRules(makefileStream,"build.make","build",!exclude);
}
}
@ -483,8 +427,8 @@ void cmGlobalUnixMakefileGenerator3
// Check the build system in this directory.
depends.push_back("cmake_check_build_system");
commands.push_back(lg->GetRecursiveMakeCall("depend.make",0));
commands.push_back(lg->GetRecursiveMakeCall("depend.make","requires"));
commands.push_back(lg->GetRecursiveMakeCall("build.make","depend"));
commands.push_back(lg->GetRecursiveMakeCall("build.make","requires"));
commands.push_back(lg->GetRecursiveMakeCall("build.make",0));
// Write the rule.
@ -520,10 +464,10 @@ cmGlobalUnixMakefileGenerator3
commands.clear();
makeTargetName = dir;
makeTargetName += "/depend";
commands.push_back(lg->GetRecursiveMakeCall("depend.make",makeTargetName.c_str()));
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));
makeTargetName = dir;
makeTargetName += "/requires";
commands.push_back(lg->GetRecursiveMakeCall("depend.make",makeTargetName.c_str()));
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));
makeTargetName = dir;
makeTargetName += "/build";
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));
@ -548,10 +492,10 @@ cmGlobalUnixMakefileGenerator3
commands.clear();
makeTargetName = localName;
makeTargetName += "/depend";
commands.push_back(lg->GetRecursiveMakeCall("depend.make",makeTargetName.c_str()));
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));
makeTargetName = localName;
makeTargetName += "/requires";
commands.push_back(lg->GetRecursiveMakeCall("depend.make",makeTargetName.c_str()));
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));
makeTargetName = localName;
makeTargetName += "/build";
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));

View File

@ -60,7 +60,6 @@ public:
protected:
void WriteMainMakefile();
void WriteMainCMakefile();
void WriteDependMakefile();
void WriteBuildMakefile();
void WriteCleanMakefile();
void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream);

View File

@ -428,11 +428,12 @@ cmLocalUnixMakefileGenerator3
//----------------------------------------------------------------------------
void
cmLocalUnixMakefileGenerator3
::WriteObjectDependFile(std::string &obj,
const char * lang,
const cmSourceFile& source,
std::vector<std::string>& depends,
std::string& depMakeFile)
::WriteObjectDependRules(std::ostream& ruleFileStream,
std::string &obj,
const char * lang,
const cmSourceFile& source,
std::vector<std::string>& depends,
std::string& depMakeFile)
{
// TODO: what the heck is this?
// Generate the build-time dependencies file for this object file.
@ -445,21 +446,6 @@ cmLocalUnixMakefileGenerator3
return;
}
// Open the rule file for writing. This should be copy-if-different
// because the rules may depend on this file itself.
std::string ruleFileName = obj;
ruleFileName += ".depend.make";
std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
ruleFileStream.SetCopyIfDifferent(true);
if(!ruleFileStream)
{
return;
}
this->WriteDisclaimer(ruleFileStream);
ruleFileStream
<< "# depend stage file for object file " << obj.c_str() << ".\n\n";
// Create the list of dependencies known at cmake time. These are
// shared between the object file and dependency scanning rule.
depends.push_back(source.GetFullPath());
@ -473,7 +459,6 @@ cmLocalUnixMakefileGenerator3
depends.push_back(i->c_str());
}
}
this->AppendRuleDepend(depends, ruleFileNameFull.c_str());
// Write the dependency generation rule.
std::string relativeObj = this->GetHomeRelativeOutputPath();
@ -532,6 +517,12 @@ cmLocalUnixMakefileGenerator3
ruleFileStream
<< "# Rule file for object file " << obj.c_str() << ".\n\n";
// generate the depend scanning rule
this->WriteObjectDependRules(ruleFileStream, obj, lang, source,
depends, depMakeFile);
this->AppendRuleDepend(depends, ruleFileNameFull.c_str());
// Include the dependencies for the target.
std::string depPath = this->GetHomeRelativeOutputPath();
depPath += depMakeFile;
@ -543,7 +534,6 @@ cmLocalUnixMakefileGenerator3
<< "\n\n";
// Write the build rule.
{
// Build the set of compiler flags.
std::string flags;
@ -621,11 +611,10 @@ cmLocalUnixMakefileGenerator3
// Write the rule.
this->WriteMakeRule(ruleFileStream, 0,
relativeObj.c_str(), depends, commands);
}
// If the language needs provides-requires mode, create the
// corresponding targets.
std::string objectRequires = obj;
std::string objectRequires = relativeObj;
objectRequires += ".requires";
std::vector<std::string> no_commands;
@ -713,9 +702,6 @@ cmLocalUnixMakefileGenerator3
std::vector<std::string> depends;
std::string depMakeFile;
// generate the depends rule file
this->WriteObjectDependFile(obj, lang, source, depends, depMakeFile);
// generate the build rule file
this->WriteObjectBuildFile(obj, lang, target, source, depends, depMakeFile,
provides_requires);
@ -1430,62 +1416,30 @@ cmLocalUnixMakefileGenerator3
void
cmLocalUnixMakefileGenerator3
::WriteTargetRequiresRule(std::ostream& ruleFileStream, const cmTarget& target,
const std::vector<std::string>& provides_requires)
const std::vector<std::string>& objects)
{
// Create the driving make target.
std::string dir = m_Makefile->GetStartOutputDirectory();
dir += "/";
dir += this->GetTargetDirectory(target);
std::string targetRequires = dir;
targetRequires += "/requires";
targetRequires = this->Convert(targetRequires.c_str(),HOME_OUTPUT,MAKEFILE);
std::vector<std::string> depends;
std::vector<std::string> no_commands;
std::string buildTarget = dir;
buildTarget += "/build";
buildTarget = this->Convert(buildTarget.c_str(),HOME_OUTPUT,MAKEFILE);
std::string comment = "Directory-level requires rule for this target.";
if(provides_requires.empty())
{
// No provides-requires mode objects in this target. Anything
// that requires the target can build it directly.
std::vector<std::string> no_commands;
std::vector<std::string> depends;
depends.push_back(buildTarget);
this->WriteMakeRule(ruleFileStream, comment.c_str(),
targetRequires.c_str(), depends, no_commands);
}
else
{
// There are provides-requires mode objects in this target. Use
// provides-requires mode to build the target itself.
std::string targetProvides = dir;
targetProvides += "/provides";
targetProvides = this->Convert(targetProvides.c_str(),HOME_OUTPUT,MAKEFILE);
{
std::vector<std::string> no_commands;
std::vector<std::string> depends;
depends.push_back(buildTarget);
this->WriteMakeRule(ruleFileStream, 0,
targetProvides.c_str(), depends, no_commands);
}
{
// Build list of require-level dependencies.
std::vector<std::string> depends;
for(std::vector<std::string>::const_iterator
pr = provides_requires.begin();
pr != provides_requires.end(); ++pr)
{
depends.push_back(*pr);
}
// Construct the name of the dependency generation target.
std::string depTarget = this->GetRelativeTargetDirectory(target);
depTarget += "/requires";
// Write the requires rule for this target.
std::vector<std::string> commands;
//commands.push_back(this->GetRecursiveMakeCall(targetProvides.c_str()));
this->WriteMakeRule(ruleFileStream, comment.c_str(),
targetRequires.c_str(), depends, commands);
}
// This target drives dependency generation for all object files.
std::string relPath = this->GetHomeRelativeOutputPath();
std::string objTarget;
for(std::vector<std::string>::const_iterator obj = objects.begin();
obj != objects.end(); ++obj)
{
objTarget = relPath;
objTarget += *obj;
objTarget += ".requires";
depends.push_back(objTarget);
}
// Write the rule.
this->WriteMakeRule(ruleFileStream, 0,
depTarget.c_str(), depends, no_commands);
}
//----------------------------------------------------------------------------
@ -1499,7 +1453,7 @@ cmLocalUnixMakefileGenerator3
const std::vector<std::string>& provides_requires)
{
// Write the dependency generation rule.
this->WriteTargetDependRule(ruleFileName, target, objects);
this->WriteTargetDependRule(ruleFileStream, target, objects);
std::vector<std::string> commands;
@ -1666,7 +1620,7 @@ cmLocalUnixMakefileGenerator3
this->WriteTargetCleanRule(ruleFileName, target, cleanFiles, objects, external_objects);
// Write the driving make target.
this->WriteTargetRequiresRule(ruleFileStream, target, provides_requires);
this->WriteTargetRequiresRule(ruleFileStream, target, objects);
}
//----------------------------------------------------------------------------
@ -1772,7 +1726,7 @@ cmLocalUnixMakefileGenerator3
const std::vector<std::string>& provides_requires)
{
// Write the dependency generation rule.
this->WriteTargetDependRule(ruleFileName, target, objects);
this->WriteTargetDependRule(ruleFileStream, target, objects);
// TODO: Merge the methods that call this method to avoid
// code duplication.
@ -1991,7 +1945,7 @@ cmLocalUnixMakefileGenerator3
this->WriteTargetCleanRule(ruleFileName, target, cleanFiles, objects, external_objects);
// Write the driving make target.
this->WriteTargetRequiresRule(ruleFileStream, target, provides_requires);
this->WriteTargetRequiresRule(ruleFileStream, target, objects);
}
//----------------------------------------------------------------------------
@ -2048,25 +2002,10 @@ cmLocalUnixMakefileGenerator3
//----------------------------------------------------------------------------
void
cmLocalUnixMakefileGenerator3
::WriteTargetDependRule(const char* ruleFileName,
::WriteTargetDependRule(std::ostream& ruleFileStream,
const cmTarget& target,
const std::vector<std::string>& objects)
{
std::string dir = cmSystemTools::GetFilenamePath(ruleFileName);
std::string dependFileName = dir;
dependFileName += "/depend.make";
// Open the rule file. This should be copy-if-different because the
// rules may depend on this file itself.
std::string ruleFileNameFull = this->ConvertToFullPath(dependFileName);
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
ruleFileStream.SetCopyIfDifferent(true);
if(!ruleFileStream)
{
return;
}
this->WriteDisclaimer(ruleFileStream);
std::vector<std::string> depends;
std::vector<std::string> no_commands;
@ -2089,25 +2028,6 @@ cmLocalUnixMakefileGenerator3
// Write the rule.
this->WriteMakeRule(ruleFileStream, 0,
depTarget.c_str(), depends, no_commands);
// Include the rule file for each object.
if(!objects.empty())
{
ruleFileStream
<< "# Include depend rules for object files.\n";
for(std::vector<std::string>::const_iterator obj = objects.begin();
obj != objects.end(); ++obj)
{
objTarget = relPath;
objTarget += *obj;
objTarget += ".depend.make";
ruleFileStream
<< m_IncludeDirective << " "
<< this->ConvertToOutputForExisting(objTarget.c_str()).c_str()
<< "\n";
}
ruleFileStream << "\n";
}
}
//----------------------------------------------------------------------------

View File

@ -194,12 +194,13 @@ protected:
std::vector<std::string>& provides_requires);
// write the depend.make file for an object
void WriteObjectDependFile(std::string& obj,
const char *lang,
const cmSourceFile& source,
std::vector<std::string>& depends,
std::string& depMarkFile);
void WriteObjectDependRules(std::ostream& ruleFileStream,
std::string& obj,
const char *lang,
const cmSourceFile& source,
std::vector<std::string>& depends,
std::string& depMarkFile);
// this is used only by WriteObjectDependFile
bool GenerateDependsMakeFile(const std::string& lang,
const char* objFile,
@ -269,7 +270,7 @@ protected:
const std::vector<std::string>& external_objects,
std::string& variableName,
std::string& variableNameExternal);
void WriteTargetDependRule(const char* ruleFileName,
void WriteTargetDependRule(std::ostream& ruleFileStream,
const cmTarget& target,
const std::vector<std::string>& objects);
void WriteTargetCleanRule(const char *ruleFileName,
@ -279,7 +280,7 @@ protected:
const std::vector<std::string>& external_objects);
void WriteTargetRequiresRule(std::ostream& ruleFileStream,
const cmTarget& target,
const std::vector<std::string>& provides_requires);
const std::vector<std::string>& objects);
std::string GetTargetDirectory(const cmTarget& target);
std::string GetSubdirTargetName(const char* pass, const char* subdir);