aboutsummaryrefslogtreecommitdiff
path: root/tools/mhmake/src/rule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mhmake/src/rule.cpp')
-rw-r--r--tools/mhmake/src/rule.cpp88
1 files changed, 54 insertions, 34 deletions
diff --git a/tools/mhmake/src/rule.cpp b/tools/mhmake/src/rule.cpp
index aa2ce1a13..dc8ab3b00 100644
--- a/tools/mhmake/src/rule.cpp
+++ b/tools/mhmake/src/rule.cpp
@@ -1,6 +1,6 @@
/* This file is part of mhmake.
*
- * Copyright (C) 2001-2009 Marc Haesen
+ * Copyright (C) 2001-2010 marha@sourceforge.net
*
* Mhmake is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,19 +27,19 @@
refptr<rule> NullRule;
-map< string, vector<pair<string,refptr<rule> > > > IMPLICITRULE::m_ImplicitRules;
+vector<pair<fileinfo *, vector<pair< fileinfo *,refptr<rule> > > > > IMPLICITRULE::m_ImplicitRules;
makecommand g_MakeCommand; // Order is important since sm_Statics is using g_MakeCommand
const string g_QuoteString("\""); // Order is important since sm_Statics is using g_QuoteString
loadedmakefile::loadedmakefile_statics loadedmakefile::sm_Statics;
///////////////////////////////////////////////////////////////////////////////
-static bool FindDep(const string &DepName,vector<pair<string,refptr<rule> > >&ImplicitRule,refptr<rule> &Rule)
+static bool FindDep(fileinfo *pDep, vector<pair<fileinfo*,refptr<rule> > >*pImplicitRule,refptr<rule> &Rule)
{
- vector<pair<string,refptr<rule> > >::iterator SecIt=ImplicitRule.begin();
- while (SecIt!=ImplicitRule.end())
+ vector<pair<fileinfo*,refptr<rule> > >::iterator SecIt=pImplicitRule->begin();
+ while (SecIt!=pImplicitRule->end())
{
- if (SecIt->first==DepName)
+ if (SecIt->first==pDep)
{
#ifdef _DEBUG
// Check if the rule has the same commands
@@ -51,9 +51,9 @@ static bool FindDep(const string &DepName,vector<pair<string,refptr<rule> > >&Im
{
string ErrorMessage;
if (bCommandsDifferent)
- ErrorMessage += "Implicit Rule '"+ DepName + "' defined twice with different commands\n";
+ ErrorMessage += "Implicit Rule '"+ pDep->GetFullFileName() + "' defined twice with different commands\n";
else
- ErrorMessage += "Implicit Rule '"+ DepName + "' defined twice with same commands\n";
+ ErrorMessage += "Implicit Rule '"+ pDep->GetFullFileName() + "' defined twice with same commands\n";
ErrorMessage += "Command 1: makedir = " + SecIt->second->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()+ "\n";
vector<string>::const_iterator It;
@@ -86,7 +86,7 @@ static bool FindDep(const string &DepName,vector<pair<string,refptr<rule> > >&Im
{
if (pOldMakefile->ExpandExpression(*OldIt)!=pNewMakefile->ExpandExpression(*NewIt))
{
- string ErrorMessage = string("Implicit Rule '") + DepName + "' defined twice with different commands\n";
+ string ErrorMessage = string("Implicit Rule '") + pDep->GetFullFileName() + "' defined twice with different commands\n";
ErrorMessage += "Command 1: makedir = " + pOldMakefile->GetMakeDir()->GetQuotedFullFileName()+ "\n";
ErrorMessage += " " + pOldMakefile->ExpandExpression(*OldIt) + "\n";
ErrorMessage += "Command 2: makedir = " + pNewMakefile->GetMakeDir()->GetQuotedFullFileName()+ "\n";
@@ -105,56 +105,76 @@ static bool FindDep(const string &DepName,vector<pair<string,refptr<rule> > >&Im
}
///////////////////////////////////////////////////////////////////////////////
-void IMPLICITRULE::AddImplicitRule(const refptr<fileinfo> &Target,const vector< refptr<fileinfo> > &Deps,refptr<rule> Rule)
+void IMPLICITRULE::AddImplicitRule(fileinfo *pTarget,const vector<fileinfo*> &Deps,refptr<rule> Rule)
{
- vector<pair<string,refptr<rule> > >& ImplicitRule=m_ImplicitRules[Target->GetFullFileName()];
+ // first search if there is already the same target in the current list of implicit rules
+ vector<pair<fileinfo*,refptr<rule> > >* pImplicitRule=NULL;
+ vector<pair<fileinfo *, vector<pair< fileinfo *,refptr<rule> > > > >::iterator RuleIt=m_ImplicitRules.begin();
+ while (RuleIt!=m_ImplicitRules.end())
+ {
+ if (pTarget==RuleIt->first)
+ {
+ pImplicitRule=&(RuleIt->second);
+ }
+ RuleIt++;
+ }
+ if (!pImplicitRule)
+{
+ // Add a new entry
+ m_ImplicitRules.push_back(pair<fileinfo *, vector<pair< fileinfo *,refptr<rule> > > >(pTarget,vector<pair<fileinfo*,refptr<rule> > >()));
+ pImplicitRule=&((m_ImplicitRules.end()-1)->second);
+ }
+
if (Deps.size())
{
- vector< refptr<fileinfo> >::const_iterator DepIt=Deps.begin();
+ vector<fileinfo*>::const_iterator DepIt=Deps.begin();
while (DepIt!=Deps.end())
{
- const string &DepName=(*DepIt)->GetFullFileName();
- if (!FindDep(DepName,ImplicitRule,Rule))
- ImplicitRule.push_back(pair<string,refptr<rule> >(DepName,Rule));
+ #ifdef _DEBUG
+ if (*DepIt==pTarget)
+ throw(string("Implicit rule : ")+pTarget->GetFullFileName()+" is directly dependent on itself. This is not allowed.");
+ #endif
+ if (!FindDep(*DepIt,pImplicitRule,Rule))
+ pImplicitRule->push_back(pair<fileinfo*,refptr<rule> >(*DepIt,Rule));
DepIt++;
}
}
else
{
- if (!FindDep(g_EmptyString,ImplicitRule,Rule))
- ImplicitRule.push_back(pair<string,refptr<rule> >(g_EmptyString,Rule));
+ if (!FindDep(NULL,pImplicitRule,Rule))
+ pImplicitRule->push_back(pair<fileinfo*,refptr<rule> >((fileinfo*)NULL,Rule));
}
}
///////////////////////////////////////////////////////////////////////////////
-void IMPLICITRULE::SearchImplicitRule(const refptr<fileinfo> &Target,vector< pair<refptr<fileinfo>,refptr<rule> > >&Result)
+void IMPLICITRULE::SearchImplicitRule(const fileinfo *pTarget,vector< pair<fileinfo*,refptr<rule> > >&Result)
{
- string TargetFileName=Target->GetFullFileName();
+ string TargetFileName=pTarget->GetFullFileName();
- map< string, vector<pair<string,refptr<rule> > > >::iterator ImpRegExIt=m_ImplicitRules.begin();
+ vector<pair<fileinfo *, vector<pair< fileinfo *,refptr<rule> > > > >::iterator ImpRegExIt=m_ImplicitRules.begin();
while (ImpRegExIt!=m_ImplicitRules.end())
{
matchres Res;
- if (PercentMatch(TargetFileName,ImpRegExIt->first,&Res))
+ if (PercentMatch(TargetFileName,ImpRegExIt->first->GetFullFileName(),&Res))
{
- vector<pair<string,refptr<rule> > >::iterator ResIt=ImpRegExIt->second.begin();
+ vector<pair<fileinfo*,refptr<rule> > >::iterator ResIt=ImpRegExIt->second.begin();
while (ResIt!=ImpRegExIt->second.end())
{
#ifdef _DEBUG
if (!ResIt->second)
{
- throw string("No rhs for implicit rule : ") + ImpRegExIt->first;
+ throw string("No rhs for implicit rule : ") + ImpRegExIt->first->GetFullFileName();
}
#endif
ResIt->second->SetStem(Res.m_Stem);
- if (!ResIt->first.empty())
+ if (ResIt->first!=NULL)
{
- string Dependent=ReplaceWithStem(ResIt->first,Res.m_Stem);
- Result.push_back(pair<refptr<fileinfo>,refptr<rule> >(GetFileInfo(Dependent,ResIt->second->GetMakefile()->GetMakeDir()),ResIt->second));
+ string Dependent=ReplaceWithStem(ResIt->first->GetFullFileName(),Res.m_Stem);
+ Result.push_back(pair<fileinfo*,refptr<rule> >(GetFileInfo(Dependent,ResIt->second->GetMakefile()->GetMakeDir()),ResIt->second));
}
else
- Result.push_back(pair<refptr<fileinfo>,refptr<rule> >(NullFileInfo,ResIt->second));
+ Result.push_back(pair<fileinfo*,refptr<rule> >((fileinfo*)NULL,ResIt->second));
ResIt++;
}
}
@@ -210,11 +230,11 @@ void rule::SetTargetsIsBuilding(const fileinfo *pSrc)
///////////////////////////////////////////////////////////////////////////////
void IMPLICITRULE::PrintImplicitRules()
{
- map< string, vector<pair<string,refptr<rule> > > >::iterator ImpRegExIt=m_ImplicitRules.begin();
+ vector<pair<fileinfo *, vector<pair< fileinfo *,refptr<rule> > > > >::iterator ImpRegExIt=m_ImplicitRules.begin();
while (ImpRegExIt!=m_ImplicitRules.end())
{
- vector<pair<string,refptr<rule> > >::iterator SecIt=ImpRegExIt->second.begin();
- cout << ImpRegExIt->first << " :\n";
+ vector<pair<fileinfo*,refptr<rule> > >::iterator SecIt=ImpRegExIt->second.begin();
+ cout << ImpRegExIt->first->GetFullFileName() << " :\n";
while (SecIt!=ImpRegExIt->second.end())
{
cout << " : " << SecIt->first <<endl;
@@ -234,16 +254,16 @@ void IMPLICITRULE::PrintImplicitRules()
}
///////////////////////////////////////////////////////////////////////////////
-void rule::PrintCommands(refptr<fileinfo> Target) const
+void rule::PrintCommands(fileinfo *pTarget) const
{
- if (Target)
- m_pMakefile->SetRuleThatIsBuild(Target);
+ if (pTarget)
+ m_pMakefile->SetRuleThatIsBuild(pTarget);
vector<string>::const_iterator pCommandIt=m_Commands.begin();
while (pCommandIt!=m_Commands.end())
{
cout<<g_SpaceString<<*pCommandIt<<endl;
- if (Target)
+ if (pTarget)
{
cout<<" ("<<m_pMakefile->ExpandExpression(*pCommandIt)<<")\n";
}