From 58b69e7eb9be29c60e45d46a880b391e3809e76f Mon Sep 17 00:00:00 2001 From: marha Date: Fri, 18 Sep 2009 14:46:17 +0000 Subject: Changes for making it possible to have spaces in the MHMAKECONF environment variable. --- tools/mhmake/src/build.cpp | 103 ++++++++++++++-------------------- tools/mhmake/src/curdir.cpp | 2 +- tools/mhmake/src/fileinfo.cpp | 77 +++++++++++++++++++------ tools/mhmake/src/fileinfo.h | 24 +++++--- tools/mhmake/src/functions.cpp | 20 +++---- tools/mhmake/src/mhmakefileparser.cpp | 42 ++++++++------ tools/mhmake/src/mhmakeparser.y | 6 +- tools/mhmake/src/rule.cpp | 9 +-- tools/mhmake/src/util.cpp | 33 +++++------ tools/mhmake/src/util.h | 70 +++++++++++++---------- 10 files changed, 218 insertions(+), 168 deletions(-) (limited to 'tools') diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp index feae1eb25..97366d88a 100644 --- a/tools/mhmake/src/build.cpp +++ b/tools/mhmake/src/build.cpp @@ -305,7 +305,7 @@ string SearchCommand(const string &Command, const string &Extension="") pExt=NULL; else pExt=Extension.c_str(); - if (SearchPath(NULL,Command.c_str(),pExt,MAX_PATH,FullCommand,NULL)) + if (SearchPath(NULL,UnquoteFileName(Command).c_str(),pExt,MAX_PATH,FullCommand,NULL)) return FullCommand; #ifdef WIN32 /* See if we have a path for python.exe in the registry */ @@ -570,13 +570,13 @@ exit: { if (pNewDest->Exists()) { - cerr << pNewDest->GetFullFileName() << " exists and is not a directory.\n"; + cerr << pNewDest->GetQuotedFullFileName() << " exists and is not a directory.\n"; Error = false; goto exit; } if (-1==mkdir(pNewDest->GetFullFileName().c_str(),0777)) { - cerr << "Error creating directory " << pNewDest->GetFullFileName() << endl; + cerr << "Error creating directory " << pNewDest->GetQuotedFullFileName() << endl; Error = false; goto exit; } @@ -816,7 +816,7 @@ static const string &GetPythonExe() string FullCommand=SearchCommand(PYTHONEXE); if (!FullCommand.empty()) { - PythonExe="\""+FullCommand+"\" "; + PythonExe=QuoteFileName(FullCommand)+" "; } else { @@ -964,42 +964,20 @@ string mhmakefileparser::GetFullCommand(string Command) { s_Py2ExeInstalled=false; cout << "\nWarning: cannot convert "< &pRule, const refptr { #ifdef _DEBUG if (pRule&&g_pPrintDependencyCheck && DepDate.IsExistingFile() && TargetDate.IsExistingFile()) - cout<<"Going to build "<GetFullFileName()<<" because "<<(*pDepIt)->GetFullFileName()<<" is more recent\n"; + cout<<"Going to build "<GetQuotedFullFileName()<<" because "<<(*pDepIt)->GetQuotedFullFileName()<<" is more recent\n"; #endif MakeTarget=true; } @@ -1447,12 +1430,12 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe deque< refptr >::const_iterator pFind=find(m_TargetStack.begin(),m_TargetStack.end(),Target); if (pFind!=m_TargetStack.end()) { - cout << "Circular dependency detected.\n"<GetFullFileName()<<" depending on itself.\n"; + cout << "Circular dependency detected.\n"<GetQuotedFullFileName()<<" depending on itself.\n"; cout << "Dependency stack:\n"; deque< refptr >::const_iterator pIt=m_TargetStack.begin(); while (pIt!=m_TargetStack.end()) { - cout << " " << (*pIt)->GetFullFileName() << endl; + cout << " " << (*pIt)->GetQuotedFullFileName() << endl; pIt++; } } @@ -1471,7 +1454,7 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe { for (int i=0; iGetFullFileName()<<" : "<GetDate()<GetQuotedFullFileName()<<" : "<GetDate()<GetDate(); @@ -1479,14 +1462,14 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe #ifdef _DEBUG if (g_GenProjectTree) - cout << Target->GetFullFileName() << endl; + cout << Target->GetQuotedFullFileName() << endl; Indent++; if (g_pPrintDependencyCheck) { for (int i=0; iGetFullFileName()<GetQuotedFullFileName()< &Target,bool bChe #ifdef _DEBUG if (g_PrintAdditionalInfo) { - cout<<"Found implicit rule for "<GetFullFileName()<GetQuotedFullFileName()<PrintCommands(Target); } #endif @@ -1559,7 +1542,7 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe #ifdef _DEBUG if (g_PrintAdditionalInfo) { - cout<<"Found implicit rule for "<GetFullFileName()<<". Dependent "<first->GetFullFileName()<GetQuotedFullFileName()<<". Dependent "<first->GetQuotedFullFileName()<PrintCommands(Target); } #endif @@ -1567,7 +1550,7 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe { #ifdef _DEBUG if (pRule,g_pPrintDependencyCheck && DepDate.IsExistingFile() && TargetDate.IsExistingFile()) - cout<<"Going to build "<GetFullFileName()<<" because "<first->GetFullFileName()<<" is more recent\n"; + cout<<"Going to build "<GetQuotedFullFileName()<<" because "<first->GetQuotedFullFileName()<<" is more recent\n"; #endif MakeTarget=true; } @@ -1595,7 +1578,7 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe { for (int i=0; iGetFullFileName()<GetQuotedFullFileName()< &Target,bool bChe if (!TargetDate.DoesExist()) { if (!m_ImplicitSearch && !Target->IsPhony()) - cout<<"Building "<GetFullFileName()<<" because it does not exist yet\n"; + cout<<"Building "<GetQuotedFullFileName()<<" because it does not exist yet\n"; } else if (TargetDate.IsOlder(m_sBuildTime)) { - cout<<"Building "<GetFullFileName()<<" because need to rebuild all (-a)\n"; + cout<<"Building "<GetQuotedFullFileName()<<" because need to rebuild all (-a)\n"; } } #endif @@ -1637,7 +1620,7 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe #else if (!g_Quiet) #endif - cout << "Building " << Target->GetFullFileName()<GetQuotedFullFileName()<GetMakeDir()); @@ -1664,7 +1647,7 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe if (!pMakefile->ExecuteCommand(Command)) { cerr << "Error running command: "<GetFullFileName()<GetQuotedFullFileName()<SetCommandsMd5_32(0); /* Clear the md5 to make sure that the target is rebuild the next time mhmake is ran */ m_AutoDepsDirty=true; /* We need to update the autodeps file if the md5 has been changed */ throw(1); @@ -1705,7 +1688,7 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe { #ifdef _DEBUG if (!g_GenProjectTree) - cout << "Md5 is different for " << Target->GetFullFileName() << " Old:"<GetCommandsMd5_32()<<", New: "<GetQuotedFullFileName() << " Old:"<GetCommandsMd5_32()<<", New: "< &Target,bool bChe { for (int i=0; iGetFullFileName()<<" finished : "<< YoungestDate << endl; + cout<<"Building "<GetQuotedFullFileName()<<" finished : "<< YoungestDate << endl; } Indent--; if (g_CheckCircularDeps) @@ -1731,7 +1714,7 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe if (!m_ImplicitSearch && !Target->Exists() && !Target->IsPhony() && !g_DoNotExecute && !g_GenProjectTree) { // This is only a warning for phony messages - cout<<"Warning: don't know how to make "<GetFullFileName()<<"\nMake the rule a phony rule to avoid this warning (but only do it when it is really phony).\n";; + cout<<"Warning: don't know how to make "<GetQuotedFullFileName()<<"\nMake the rule a phony rule to avoid this warning (but only do it when it is really phony).\n";; } #endif Target->SetDate(YoungestDate); /* This is especially needed for phony targets in between real targets */ @@ -1746,7 +1729,7 @@ void mhmakefileparser::BuildIncludedMakefiles() { #ifdef _DEBUG if (g_PrintAdditionalInfo) - cout<<"Building include file "<<(*MakefileIt)->GetFullFileName()<GetQuotedFullFileName()<&NewDir) #endif if (-1==chdir(NewDir->GetFullFileName().c_str())) { - cerr<<"Error changing to directory "<GetFullFileName()<GetQuotedFullFileName()< NullFileInfo; ZEROTIME g_ZeroTime; #endif +/////////////////////////////////////////////////////////////////////////////// +string QuoteFileName(const string &Filename) +{ + string Ret(Filename); +#if OSPATHSEP=='\\' + /* Put quotes around the string if there are spaces in it */ + if (Ret.find_first_of(' ')!=string::npos && Ret[0]!='"') + { + Ret=g_QuoteString+Ret+g_QuoteString; + } +#else + int Pos=0; + /* Escape the spaces with a backslash */ + while ((Pos=Ret.find_first_of(' ',Pos))!=string::npos) + { + Ret=Ret.replace(Pos,1,"\\ "); + Pos+=2; + } +#endif + return Ret; +} + +/////////////////////////////////////////////////////////////////////////////// +string UnquoteFileName(const string &Filename) +{ + int Pos=0; + string Name(Filename); +#if OSPATHSEP=='\\' + /* Remove all the quotes from the filename */ + while ((Pos=Name.find_first_of('"',Pos))!=string::npos) + { + Name=Name.replace(Pos,1,""); + } +#else + /* Remove the escaped spaces */ + while ((Pos=Name.find_first_of("\\",Pos))!=string::npos) + { + if (Name[Pos+1]==' ') + Name=Name.replace(Pos,2," "); + Pos+=1; + } +#endif + return Name; +} + /////////////////////////////////////////////////////////////////////////////// refptr fileinfo::GetDir() const { @@ -145,7 +190,7 @@ string fileinfo::GetPrerequisits() const { Ret+=g_SpaceString; } - Ret+=(*DepIt)->GetFullFileName(); + Ret+=(*DepIt)->GetQuotedFullFileName(); } Deps.insert(*DepIt); DepIt++; @@ -185,8 +230,8 @@ bool fileinfo::IsAutoDepExtention(void) const /////////////////////////////////////////////////////////////////////////////// void fileinfo::DumpErrorMessageDuplicateRule(const refptr&pRule) { - cerr << m_AbsFileName << ": rule is defined multiple times\n"; - cerr << "First ("<GetMakefile()->GetMakeDir()->GetFullFileName()<<") :\n"; + cerr << GetQuotedFullFileName() << ": rule is defined multiple times\n"; + cerr << "First ("<GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<<") :\n"; vector::const_iterator It=m_pRule->GetCommands().begin(); while (It!=m_pRule->GetCommands().end()) @@ -194,7 +239,7 @@ void fileinfo::DumpErrorMessageDuplicateRule(const refptr&pRule) cerr << " " << m_pRule->GetMakefile()->ExpandExpression(*It) << endl; It++; } - cerr << "Second ("<GetMakefile()->GetMakeDir()->GetFullFileName()<<") :\n"; + cerr << "Second ("<GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<<") :\n"; It=pRule->GetCommands().begin(); while (It!=pRule->GetCommands().end()) { @@ -205,7 +250,7 @@ void fileinfo::DumpErrorMessageDuplicateRule(const refptr&pRule) #endif /////////////////////////////////////////////////////////////////////////////// -static inline string &GetFullLowerPathName(string &Name) +static inline string &NormalizePathName(string &Name) { const char *pPtr=Name.c_str(); const char *pBeg=pPtr; @@ -258,7 +303,11 @@ static inline string &GetFullLowerPathName(string &Name) } else { + #ifdef WIN32 *pWr++ = tolower(Char); + #else + *pWr++ = Char; + #endif } Char=*pPtr++; } @@ -272,8 +321,9 @@ static inline string &GetFullLowerPathName(string &Name) /////////////////////////////////////////////////////////////////////////////// const refptr &GetFileInfo(const string &NameIn,const refptr &RelDir) { - string Name=NameIn; + string Name=UnquoteFileName(NameIn); bool DoesExist=true; + //Only concatenate if szName is not already a full name #ifdef WIN32 if (!Name.empty() && Name[1]!=':') @@ -293,14 +343,7 @@ const refptr &GetFileInfo(const string &NameIn,const refptr } #endif } - const refptr &Ret=GetAbsFileInfo(GetFullLowerPathName(Name)); - #ifdef _DEBUG - if (Ret->GetFullFileName().find(' ')!=string::npos) - { - cerr << "Spaces are not allowed in filenames: "<< Ret->GetFullFileName() << endl; - exit(1); - } - #endif + const refptr &Ret=GetAbsFileInfo(NormalizePathName(Name)); if (!DoesExist) Ret->SetNotExist(); return Ret; @@ -313,14 +356,14 @@ void PrintFileInfos() set,less_refptrfileinfo>::iterator pIt=g_FileInfos.begin(); while (pIt!=g_FileInfos.end()) { - cout<<(*pIt)->GetFullFileName()<<" :"; + cout<<(*pIt)->GetQuotedFullFileName()<<" :"; if ((*pIt)->IsPhony()) cout<<" (phony)"; vector< refptr > &Deps=(*pIt)->GetDeps(); vector< refptr >::iterator pDepIt=Deps.begin(); while (pDepIt!=Deps.end()) { - cout<GetFullFileName(); + cout<GetQuotedFullFileName(); pDepIt++; } cout< pRule=(*pIt)->GetRule(); if (pRule) { - cout<GetMakefile()->GetMakeDir()->GetFullFileName()<GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<PrintCommands(); } pIt++; diff --git a/tools/mhmake/src/fileinfo.h b/tools/mhmake/src/fileinfo.h index c44041d30..227ba5e1f 100644 --- a/tools/mhmake/src/fileinfo.h +++ b/tools/mhmake/src/fileinfo.h @@ -53,6 +53,10 @@ extern bool g_PrintMultipleDefinedRules; extern const string g_EmptyString; extern const string g_SpaceString; +extern const string g_QuoteString; + +string QuoteFileName(const string &Filename); +string UnquoteFileName(const string &Filename); #define TIMESAFETY 3 class mh_time @@ -138,12 +142,12 @@ public: { m_IsPhony=false; m_IsBuild=false; - m_AbsFileName=AbsFileName; + m_AbsFileName=UnquoteFileName(AbsFileName); InvalidateDate(); m_CommandsMd5_32=Md5_32; #ifdef _DEBUG if (g_PrintAdditionalInfo) - cout << "Initialising Md5 of "<GetFullFileName(); + Ret+=pFile->GetQuotedFullFileName(); } return Ret; @@ -460,7 +460,7 @@ string mhmakefileparser::f_fullname(const string & Arg) const { string File=TrimString(Arg); refptr pFile=GetFileInfo(File); - return pFile->GetFullFileName(); + return pFile->GetQuotedFullFileName(); } /////////////////////////////////////////////////////////////////////////////// @@ -491,7 +491,7 @@ static string IterList(const string &List,string (*iterFunc)(const string &FileN static string basename(const string &FileName,const string &) { string Ret=FileName.substr(0,FileName.find_last_of('.')); - if (FileName[0]=='"') + if (FileName[0]=='"' && FileName.end()[-1]=='"') Ret+=s_QuoteString; return Ret; } @@ -513,7 +513,7 @@ static string notdir(const string &FileName,const string &) else { string Ret=g_EmptyString; - if (FileName[0]=='"') + if (FileName[0]=='"' && FileName.end()[-1]=='"') Ret+=s_QuoteString; Ret+=FileName.substr(Pos+1); return Ret; @@ -651,7 +651,7 @@ static string dir(const string &FileName,const string &) { string Ret=g_EmptyString; Ret+=FileName.substr(0,Pos+1); - if (FileName[0]=='"') + if (FileName[0]=='"' && FileName.end()[-1]=='"') Ret+=s_QuoteString; return Ret; } @@ -715,10 +715,8 @@ static string relpath(const string &FileName,const string &) retPath+=OSPATHSEPSTR".."; pCur++; } - if (!pPath) - return retPath; - else - return retPath+OSPATHSEPSTR+pLast; + if (pPath) + retPath=retPath+OSPATHSEPSTR+pLast; } else { @@ -731,12 +729,12 @@ static string relpath(const string &FileName,const string &) pCur++; } retPath+=pLast; - return retPath; } + return QuoteFileName(retPath); } /////////////////////////////////////////////////////////////////////////////// -// Make a path name relative to the curren directory +// Make a path name relative to the current directory string mhmakefileparser::f_relpath(const string & FileNames) const { return IterList(FileNames,relpath); diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp index cbcb33648..f8304df3f 100644 --- a/tools/mhmake/src/mhmakefileparser.cpp +++ b/tools/mhmake/src/mhmakefileparser.cpp @@ -47,14 +47,14 @@ int mhmakefileparser::ParseFile(const refptr &FileInfo,bool SetMakeDir if (SetMakeDir) { m_MakeDir=curdir::GetCurDir(); - m_Variables[CURDIR]=m_MakeDir->GetFullFileName(); + m_Variables[CURDIR]=m_MakeDir->GetQuotedFullFileName(); } theLexer.m_InputFileName=FileInfo->GetFullFileName(); theLexer.m_pParser=(mhmakeparser*)this; theLexer.yyin=::fopen(FileInfo->GetFullFileName().c_str(),"r"); if (!theLexer.yyin) { - cerr << "Error opening makefile: "<GetFullFileName()<GetQuotedFullFileName()<"; } #endif - return m_RuleThatIsBuild->GetDeps()[0]->GetFullFileName(); + return m_RuleThatIsBuild->GetDeps()[0]->GetQuotedFullFileName(); case '@': // return full target file name - return m_RuleThatIsBuild->GetFullFileName(); + return m_RuleThatIsBuild->GetQuotedFullFileName(); case '*': // return stem return m_RuleThatIsBuild->GetRule()->GetStem(); case '^': // return all prerequisits @@ -359,10 +368,6 @@ void SplitToItems(const string &String,vector< refptr > &Items,refptr< pTmp=NextItem(pTmp,Item); if (!Item.empty()) { - if (Item[0]=='"') - { - Item=Item.substr(1,Item.size()-2); - } Items.push_back(GetFileInfo(Item,Dir)); } } @@ -669,14 +674,14 @@ void mhmakefileparser::LoadAutoDepsFile(refptr &DepFile) #ifdef _DEBUG if (!pIn) { - cerr << "Error opening autodep file "<GetFullFileName()<GetQuotedFullFileName()<GetFullFileName()<<": "<GetQuotedFullFileName()<<": "< &DepFile) { #ifdef _DEBUG if (!(*pPair.first)->CompareMd5_32(Md5_32) && !(*pPair.first)->CompareMd5_32(0)) - cout << "Warning: trying to set to different md5's for Target "<<(*pPair.first)->GetFullFileName()<<" Old: "<GetCommandsMd5_32()<<" New: "<GetQuotedFullFileName()<<" Old: "<GetCommandsMd5_32()<<" New: "<GetFullFileName()<<" to "<GetQuotedFullFileName()<<" to "<SetCommandsMd5_32(Md5_32); // If it was already there, just update the md5 value } @@ -753,18 +758,19 @@ void mhmakefileparser::SaveAutoDepsFile() { return; } + refptr pDepFile=GetFileInfo(DepFile); #ifdef _DEBUG if (g_PrintAdditionalInfo) cout<<"Saving automatic dependency file "<GetFullFileName().c_str(),"wb"); if (!pOut) { /* Maybe it is because the directory does not exist, so try to create this first */ - MakeDirs(GetAbsFileInfo(DepFile.substr(0,DepFile.find_last_of(OSPATHSEP)))); - pOut=fopen(DepFile.c_str(),"wb"); + MakeDirs(pDepFile->GetDir()); + pOut=fopen(pDepFile->GetFullFileName().c_str(),"wb"); if (!pOut) { @@ -964,7 +970,7 @@ uint32 mhmakefileparser::CreateEnvMd5_32() const string Val=GetFromEnv(Var,false); transform(Var.begin(),Var.end(),Var.begin(),(int(__CDECL *)(int))toupper); transform(Val.begin(),Val.end(),Val.begin(),(int(__CDECL *)(int))toupper); - DBGOUT(cout << GetMakeDir()->GetFullFileName() << " -> Setting GetFromEnv var " << Var << " to " << Val << endl); + DBGOUT(cout << GetMakeDir()->GetQuotedFullFileName() << " -> Setting GetFromEnv var " << Var << " to " << Val << endl); Variables[Var]=Val; } } @@ -978,7 +984,7 @@ uint32 mhmakefileparser::CreateEnvMd5_32() const transform(Var.begin(),Var.end(),Var.begin(),(int(__CDECL *)(int))toupper); string Val=It->second; transform(Val.begin(),Val.end(),Val.begin(),(int(__CDECL *)(int))toupper); - DBGOUT(cout << GetMakeDir()->GetFullFileName() << " -> Setting Commandline var " << Var << " to " << Val << endl); + DBGOUT(cout << GetMakeDir()->GetQuotedFullFileName() << " -> Setting Commandline var " << Var << " to " << Val << endl); Variables[Var]=Val; } It++; @@ -987,7 +993,7 @@ uint32 mhmakefileparser::CreateEnvMd5_32() const // Now create the md5 string md5_starts( &ctx ); - DBGOUT(cout << "MD5 of " << m_MakeDir->GetFullFileName() << endl); + DBGOUT(cout << "MD5 of " << m_MakeDir->GetQuotedFullFileName() << endl); map::const_iterator VarIt=Variables.begin(); map::const_iterator VarItEnd=Variables.end(); diff --git a/tools/mhmake/src/mhmakeparser.y b/tools/mhmake/src/mhmakeparser.y index 0a8985209..ee26dd92b 100644 --- a/tools/mhmake/src/mhmakeparser.y +++ b/tools/mhmake/src/mhmakeparser.y @@ -58,7 +58,7 @@ file : statements { if (m_pCurrentItems) { - PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetFullFileName().c_str())); + PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetQuotedFullFileName().c_str())); AddRule(); } } @@ -92,7 +92,7 @@ includemak: { if (m_pCurrentItems) { - PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetFullFileName().c_str())); + PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetQuotedFullFileName().c_str())); AddRule(); } } INCLUDEMAK @@ -102,7 +102,7 @@ ruledef: expression_nocolorequal rulecolon maybeemptyexpression { if (m_pCurrentItems) { - PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetFullFileName().c_str())); + PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetQuotedFullFileName().c_str())); AddRule(); } diff --git a/tools/mhmake/src/rule.cpp b/tools/mhmake/src/rule.cpp index e8bc1b6d6..7e71ba95f 100644 --- a/tools/mhmake/src/rule.cpp +++ b/tools/mhmake/src/rule.cpp @@ -30,6 +30,7 @@ refptr NullRule; map< string, 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; /////////////////////////////////////////////////////////////////////////////// @@ -52,7 +53,7 @@ static bool FindDep(const string &DepName,vector > >&Im cerr << "Implicit Rule '"<< DepName << "' defined twice with different commands\n"; else cerr << "Implicit Rule '"<< DepName << "' defined twice with same commands\n"; - cerr << "Command 1: makedir = " << SecIt->second->GetMakefile()->GetMakeDir()->GetFullFileName()<< endl; + cerr << "Command 1: makedir = " << SecIt->second->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<< endl; vector::const_iterator It; if (bCommandsDifferent) @@ -63,7 +64,7 @@ static bool FindDep(const string &DepName,vector > >&Im cerr << " " << *It << endl; } } - cerr << "Command 2: makedir = "<< Rule->GetMakefile()->GetMakeDir()->GetFullFileName()<< endl; + cerr << "Command 2: makedir = "<< Rule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<< endl; if (bCommandsDifferent) { It=NewCommands.begin(); @@ -83,9 +84,9 @@ static bool FindDep(const string &DepName,vector > >&Im if (pOldMakefile->ExpandExpression(*OldIt)!=pNewMakefile->ExpandExpression(*NewIt)) { cerr << "Implicit Rule '"<< DepName << "' defined twice with different commands\n"; - cerr << "Command 1: makedir = " << pOldMakefile->GetMakeDir()->GetFullFileName()<< endl; + cerr << "Command 1: makedir = " << pOldMakefile->GetMakeDir()->GetQuotedFullFileName()<< endl; cerr << " " << pOldMakefile->ExpandExpression(*OldIt) << endl; - cerr << "Command 2: makedir = "<< pNewMakefile->GetMakeDir()->GetFullFileName()<< endl; + cerr << "Command 2: makedir = "<< pNewMakefile->GetMakeDir()->GetQuotedFullFileName()<< endl; cerr << " " << pNewMakefile->ExpandExpression(*NewIt) << endl; throw(1); } diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp index be0e92281..608311e94 100644 --- a/tools/mhmake/src/util.cpp +++ b/tools/mhmake/src/util.cpp @@ -265,8 +265,9 @@ loadedmakefile::loadedmakefile_statics::loadedmakefile_statics() const char *pEnv=getenv(MHMAKECONF); if (pEnv) { - m_GlobalCommandLineVars[MHMAKECONF]=pEnv; - m_MhMakeConf=GetFileInfo(pEnv); + string Env(QuoteFileName(pEnv)); + m_GlobalCommandLineVars[MHMAKECONF]=Env; + m_MhMakeConf=GetFileInfo(Env); // Get the revision of the working copy // We do it with the svn info command @@ -276,7 +277,7 @@ loadedmakefile::loadedmakefile_statics::loadedmakefile_statics() try { string SvnCommand=SearchCommand("svn",EXEEXT); - Ret=OsExeCommand(SvnCommand,string(" info ")+m_MhMakeConf->GetFullFileName(),false,&Output); + Ret=OsExeCommand(SvnCommand,string(" info ")+m_MhMakeConf->GetQuotedFullFileName(),false,&Output); } catch (int) { @@ -464,7 +465,7 @@ void loadedmakefile::LoadMakefile() #ifdef _DEBUG if (g_PrintAdditionalInfo) - cout << "Loading makefile "<GetFullFileName()<GetQuotedFullFileName()<(new mhmakeparser(m_CommandLineVars)); @@ -501,7 +502,7 @@ void loadedmakefile::LoadMakefile() int result=m_pParser->ParseFile(BeforeMakefile,true); if (result) { - printf("Error parsing %s\n",BeforeMakefile->GetFullFileName().c_str()); + printf("Error parsing %s\n",BeforeMakefile->GetQuotedFullFileName().c_str()); throw(1); } m_pParser->UpdateDate(BeforeMakefile->GetDate()); @@ -514,7 +515,7 @@ void loadedmakefile::LoadMakefile() throw(1); } DepFile=GetFileInfo(ObjDirName+OSPATHSEPSTR MAKEDEPFILE); - m_pParser->SetVariable(AUTODEPFILE,DepFile->GetFullFileName().c_str()); + m_pParser->SetVariable(AUTODEPFILE,DepFile->GetQuotedFullFileName()); } else { @@ -536,7 +537,7 @@ void loadedmakefile::LoadMakefile() sprintf(ID,"_%x",md5_finish32( &ctx)); DepFile=GetFileInfo(string(MAKEDEPFILE)+ID); - m_pParser->SetVariable(AUTODEPFILE,DepFile->GetFullFileName().c_str()); + m_pParser->SetVariable(AUTODEPFILE,DepFile->GetQuotedFullFileName()); } if (DepFile->Exists()) @@ -546,24 +547,24 @@ void loadedmakefile::LoadMakefile() int result=m_pParser->ParseFile(m_Makefile,true); if (result) { - printf("Error parsing %s\n",m_Makefile->GetFullFileName().c_str()); + printf("Error parsing %s\n",m_Makefile->GetQuotedFullFileName().c_str()); throw(1); } #ifdef _DEBUG /* Check if the makefile has changed the AUTODEPFILE variable, if so generate a warning that a * rebuild could happen for the rules defined for making included makefiles */ - if (m_pParser->ExpandVar(AUTODEPFILE)!=DepFile->GetFullFileName()) + if (m_pParser->ExpandVar(AUTODEPFILE)!=DepFile->GetQuotedFullFileName()) { - cout << "\n\nWARNING:\n makefile '"<< m_Makefile->GetFullFileName() <<"' re-defines AUTODEPFILE\n from '"<< DepFile->GetFullFileName() <<"'\n to '"<< + cout << "\n\nWARNING:\n makefile '"<< m_Makefile->GetQuotedFullFileName() <<"' re-defines AUTODEPFILE\n from '"<< DepFile->GetQuotedFullFileName() <<"'\n to '"<< m_pParser->ExpandVar(AUTODEPFILE) << "'\n (may cause needless rebuilds when having rules for included makefiles!!!!!)\n\n\n"; } if (g_PrintAdditionalInfo) { if (m_pParser->GetFirstTarget()) - cout<<"First target of "<GetFullFileName()<<" is "<GetFirstTarget()->GetFullFileName()<GetQuotedFullFileName()<<" is "<GetFirstTarget()->GetQuotedFullFileName()<GetFullFileName()<GetQuotedFullFileName()<UpdateDate(m_Makefile->GetDate()); @@ -573,7 +574,7 @@ void loadedmakefile::LoadMakefile() refptr AfterMakefile=GetFileInfo(BaseAutoMak+".after",sm_Statics.m_MhMakeConf); int result=m_pParser->ParseFile(AfterMakefile); if (result) { - printf("Error parsing %s\n",AfterMakefile->GetFullFileName().c_str()); + printf("Error parsing %s\n",AfterMakefile->GetQuotedFullFileName().c_str()); throw(1); } m_pParser->UpdateDate(AfterMakefile->GetDate()); @@ -606,7 +607,7 @@ void loadedmakefile::LoadMakefile() { #ifdef _DEBUG if (g_PrintAdditionalInfo) - cout << "Makefile already loaded: "<m_Makefile->GetFullFileName()<m_Makefile->GetQuotedFullFileName()<GetFullFileName() <<" because environment and/or command-line variables have been changed.\n"; + cout << "Rebuilding everything of "<< m_Makefile->GetQuotedFullFileName() <<" because environment and/or command-line variables have been changed.\n"; #endif m_pParser->SetRebuildAll(); } @@ -642,7 +643,7 @@ void DumpVarsAndRules() { for (i=0; i<80; i++) cout << "_"; cout << endl; - cout << "Variables of makefile " << (*LoadMakIt)->m_Makefile->GetFullFileName() << endl; + cout << "Variables of makefile " << (*LoadMakIt)->m_Makefile->GetQuotedFullFileName() << endl; for (i=0; i<80; i++) cout << "_"; cout << endl; (*LoadMakIt)->m_pParser->PrintVariables(true); diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h index 6d660fc94..5cd242d51 100644 --- a/tools/mhmake/src/util.h +++ b/tools/mhmake/src/util.h @@ -50,7 +50,7 @@ #define PLATFORM "linux" #endif -#define MHMAKEVER "1.3.22" +#define MHMAKEVER "1.4.0" #define MAKEDEPFILE ".makefile.dep" @@ -73,39 +73,49 @@ inline const char *NextItem(const char *pTmp,string &Output, const char *pToks=" const char *pStart; const char *pStop; while (strchr(pToks,*pTmp)&&*pTmp) pTmp++; - if (*pTmp=='"') + pStart=pTmp; + while (1) { - pStart=pTmp++; - while (*pTmp && *pTmp!='"') pTmp++; - if (*pTmp) pTmp++; - pStop=pTmp; - } - else if (*pTmp=='\'') - { - pStart=pTmp++; - while (*pTmp && *pTmp!='\'') pTmp++; - if (*pTmp) pTmp++; - pStop=pTmp; - } - else if (!*pTmp) - { - pStart=pStop=pTmp; - } - else - { - pStart=pTmp++; - #if OSPATHSEP=='/' - while (*pTmp) + if (*pTmp=='"') + { + pTmp++; + while (*pTmp && *pTmp!='"') pTmp++; + if (*pTmp) pTmp++; + pStop=pTmp; + if (!*pTmp || strchr(pToks,*pTmp)) + break; + } + else if (*pTmp=='\'') { - if (!strchr(pToks,*pTmp) || (*(pTmp-1)=='\\')) - pTmp++; - else + pTmp++; + while (*pTmp && *pTmp!='\'') pTmp++; + if (*pTmp) pTmp++; + pStop=pTmp; + if (!*pTmp || strchr(pToks,*pTmp)) break; } - #else - while (!strchr(pToks,*pTmp)) pTmp++; - #endif - pStop=pTmp; + else if (!*pTmp) + { + pStop=pTmp; + break; + } + else + { + pTmp++; + #if OSPATHSEP=='/' + while (*pTmp) + { + if (!strchr(pToks,*pTmp) || (*(pTmp-1)=='\\')) + pTmp++; + else + break; + } + #else + while (!strchr(pToks,*pTmp)) pTmp++; + #endif + pStop=pTmp; + break; + } } Output=string(pStart,pStop); // skip trailing space -- cgit v1.2.3