From d74d9f4e60e48260ff1fad3ff00aaf000f111a66 Mon Sep 17 00:00:00 2001 From: marha Date: Fri, 22 Oct 2010 14:00:01 +0000 Subject: Increased gnu make compatibility Optimised --- tools/mhmake/src/rule.cpp | 88 +++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 34 deletions(-) (limited to 'tools/mhmake/src/rule.cpp') 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 NullRule; -map< string, vector > > > IMPLICITRULE::m_ImplicitRules; +vector > > > > 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 > >&ImplicitRule,refptr &Rule) +static bool FindDep(fileinfo *pDep, vector > >*pImplicitRule,refptr &Rule) { - vector > >::iterator SecIt=ImplicitRule.begin(); - while (SecIt!=ImplicitRule.end()) + vector > >::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 > >&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::const_iterator It; @@ -86,7 +86,7 @@ static bool FindDep(const string &DepName,vector > >&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 > >&Im } /////////////////////////////////////////////////////////////////////////////// -void IMPLICITRULE::AddImplicitRule(const refptr &Target,const vector< refptr > &Deps,refptr Rule) +void IMPLICITRULE::AddImplicitRule(fileinfo *pTarget,const vector &Deps,refptr Rule) { - vector > >& ImplicitRule=m_ImplicitRules[Target->GetFullFileName()]; + // first search if there is already the same target in the current list of implicit rules + vector > >* pImplicitRule=NULL; + vector > > > >::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 > > >(pTarget,vector > >())); + pImplicitRule=&((m_ImplicitRules.end()-1)->second); + } + if (Deps.size()) { - vector< refptr >::const_iterator DepIt=Deps.begin(); + vector::const_iterator DepIt=Deps.begin(); while (DepIt!=Deps.end()) { - const string &DepName=(*DepIt)->GetFullFileName(); - if (!FindDep(DepName,ImplicitRule,Rule)) - ImplicitRule.push_back(pair >(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 >(*DepIt,Rule)); DepIt++; } } else { - if (!FindDep(g_EmptyString,ImplicitRule,Rule)) - ImplicitRule.push_back(pair >(g_EmptyString,Rule)); + if (!FindDep(NULL,pImplicitRule,Rule)) + pImplicitRule->push_back(pair >((fileinfo*)NULL,Rule)); } } /////////////////////////////////////////////////////////////////////////////// -void IMPLICITRULE::SearchImplicitRule(const refptr &Target,vector< pair,refptr > >&Result) +void IMPLICITRULE::SearchImplicitRule(const fileinfo *pTarget,vector< pair > >&Result) { - string TargetFileName=Target->GetFullFileName(); + string TargetFileName=pTarget->GetFullFileName(); - map< string, vector > > >::iterator ImpRegExIt=m_ImplicitRules.begin(); + vector > > > >::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 > >::iterator ResIt=ImpRegExIt->second.begin(); + vector > >::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 >(GetFileInfo(Dependent,ResIt->second->GetMakefile()->GetMakeDir()),ResIt->second)); + string Dependent=ReplaceWithStem(ResIt->first->GetFullFileName(),Res.m_Stem); + Result.push_back(pair >(GetFileInfo(Dependent,ResIt->second->GetMakefile()->GetMakeDir()),ResIt->second)); } else - Result.push_back(pair,refptr >(NullFileInfo,ResIt->second)); + Result.push_back(pair >((fileinfo*)NULL,ResIt->second)); ResIt++; } } @@ -210,11 +230,11 @@ void rule::SetTargetsIsBuilding(const fileinfo *pSrc) /////////////////////////////////////////////////////////////////////////////// void IMPLICITRULE::PrintImplicitRules() { - map< string, vector > > >::iterator ImpRegExIt=m_ImplicitRules.begin(); + vector > > > >::iterator ImpRegExIt=m_ImplicitRules.begin(); while (ImpRegExIt!=m_ImplicitRules.end()) { - vector > >::iterator SecIt=ImpRegExIt->second.begin(); - cout << ImpRegExIt->first << " :\n"; + vector > >::iterator SecIt=ImpRegExIt->second.begin(); + cout << ImpRegExIt->first->GetFullFileName() << " :\n"; while (SecIt!=ImpRegExIt->second.end()) { cout << " : " << SecIt->first < Target) const +void rule::PrintCommands(fileinfo *pTarget) const { - if (Target) - m_pMakefile->SetRuleThatIsBuild(Target); + if (pTarget) + m_pMakefile->SetRuleThatIsBuild(pTarget); vector::const_iterator pCommandIt=m_Commands.begin(); while (pCommandIt!=m_Commands.end()) { cout<ExpandExpression(*pCommandIt)<<")\n"; } -- cgit v1.2.3