aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-10-02 09:28:00 +0000
committermarha <marha@users.sourceforge.net>2009-10-02 09:28:00 +0000
commit516cdec4894096305f5002b922ba02d49cb3e816 (patch)
treee34bc97b00f6acf17b33877efb7f5ffa543d2881 /tools
parent945c71554aa1866a5286dd4b8f5b199dd7af9be9 (diff)
downloadvcxsrv-516cdec4894096305f5002b922ba02d49cb3e816.tar.gz
vcxsrv-516cdec4894096305f5002b922ba02d49cb3e816.tar.bz2
vcxsrv-516cdec4894096305f5002b922ba02d49cb3e816.zip
Optimised auto dependency generation
Added control c handler in windows Now throw string exceptions instead of integer exceptions.
Diffstat (limited to 'tools')
-rw-r--r--tools/mhmake/src/build.cpp34
-rw-r--r--tools/mhmake/src/curdir.cpp3
-rw-r--r--tools/mhmake/src/fileinfo.cpp18
-rw-r--r--tools/mhmake/src/fileinfo.h16
-rw-r--r--tools/mhmake/src/functions.cpp27
-rw-r--r--tools/mhmake/src/mhmake.cpp16
-rw-r--r--tools/mhmake/src/mhmakefileparser.cpp74
-rw-r--r--tools/mhmake/src/mhmakefileparser.h9
-rw-r--r--tools/mhmake/src/mhmakelexer.l30
-rw-r--r--tools/mhmake/src/mhmakeparser.y3
-rw-r--r--tools/mhmake/src/rule.cpp32
-rw-r--r--tools/mhmake/src/stdafx.h1
-rw-r--r--tools/mhmake/src/util.cpp16
-rw-r--r--tools/mhmake/src/util.h2
14 files changed, 152 insertions, 129 deletions
diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp
index 97366d88a..3d31b4605 100644
--- a/tools/mhmake/src/build.cpp
+++ b/tools/mhmake/src/build.cpp
@@ -287,8 +287,7 @@ found:
int CommandLen=FullCommand.size();
if (CommandLen>Len-1)
{
- cerr << "Fatal error: Command to long: "<<FullCommand<<endl;
- throw(1);
+ throw string("Command to long: ") + FullCommand;
}
strcpy(szFullCommand,FullCommand.c_str());
return 1;
@@ -915,9 +914,9 @@ string mhmakefileparser::GetFullCommand(string Command)
}
if (!bBuild)
{
- set< refptr<fileinfo> > Autodeps;
+ deps_t Autodeps;
GetAutoDeps(pPyFile, Autodeps);
- set< refptr<fileinfo> >::iterator It=Autodeps.begin();
+ deps_t::iterator It=Autodeps.begin();
while (It!=Autodeps.end())
{
if (pExeFile->GetDate().IsOlder((*It)->GetDate()))
@@ -1063,9 +1062,11 @@ bool OsExeCommand(const string &Command,const string &Params,bool IgnoreError,st
if (!CreateProcess(NULL,pFullCommand,NULL,NULL,TRUE,CREATE_NO_WINDOW,NULL,curdir::GetCurDir()->GetFullFileName().c_str(),&StartupInfo,&ProcessInfo))
{
delete[] pFullCommand;
- cerr << "Error starting command: "<<FullCommandLine<<" : "<<GetLastError()<<endl;
- if (!IgnoreError)
- throw(1);
+ string ErrorMessage=string("Error starting command: ") + FullCommandLine + " : " + stringify(GetLastError());
+ if (IgnoreError)
+ cerr << ErrorMessage << endl;
+ else
+ throw ErrorMessage;
}
delete[] pFullCommand;
if (!CloseHandle(hChildStdinRd)) return false;
@@ -1091,9 +1092,11 @@ bool OsExeCommand(const string &Command,const string &Params,bool IgnoreError,st
if (!CreateProcess(NULL,pFullCommand,NULL,NULL,TRUE,0,NULL,curdir::GetCurDir()->GetFullFileName().c_str(),&StartupInfo,&ProcessInfo))
{
delete[] pFullCommand;
- cerr << "Error starting command: "<<Command<<" : "<<GetLastError()<<endl;
- if (!IgnoreError)
- throw(1);
+ string ErrorMessage=string("Error starting command: ") + Command + " : " + stringify(GetLastError());
+ if (IgnoreError)
+ cerr << ErrorMessage << endl;
+ else
+ throw ErrorMessage;
}
delete[] pFullCommand;
CloseHandle(ProcessInfo.hThread);
@@ -1447,6 +1450,11 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr<fileinfo> &Target,bool bChe
static int Indent;
#endif
+ if (g_StopCompiling)
+ {
+ throw string("Compilation Interrupted by user.");
+ }
+
if (Target->IsBuild())
{
#ifdef _DEBUG
@@ -1646,11 +1654,11 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr<fileinfo> &Target,bool bChe
#endif
if (!pMakefile->ExecuteCommand(Command))
{
- cerr << "Error running command: "<<Command<<endl;
- cerr << "Command defined in makefile: "<<GetMakeDir()->GetQuotedFullFileName()<<endl;
+ string ErrorMessage = string("Error running command: ")+ Command +"\n";
+ ErrorMessage += "Command defined in makefile: " + GetMakeDir()->GetQuotedFullFileName();
Target->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);
+ throw ErrorMessage;
}
}
CommandIt++;
diff --git a/tools/mhmake/src/curdir.cpp b/tools/mhmake/src/curdir.cpp
index 68cf505e7..64389c993 100644
--- a/tools/mhmake/src/curdir.cpp
+++ b/tools/mhmake/src/curdir.cpp
@@ -52,8 +52,7 @@ void curdir::ChangeCurDir(const refptr<fileinfo>&NewDir)
#endif
if (-1==chdir(NewDir->GetFullFileName().c_str()))
{
- cerr<<"Error changing to directory "<<NewDir->GetQuotedFullFileName()<<endl;
- throw(1);
+ throw string("Error changing to directory ") + NewDir->GetQuotedFullFileName();
}
m_pCurrentDir=NewDir;
}
diff --git a/tools/mhmake/src/fileinfo.cpp b/tools/mhmake/src/fileinfo.cpp
index b79d51678..6ea9c158e 100644
--- a/tools/mhmake/src/fileinfo.cpp
+++ b/tools/mhmake/src/fileinfo.cpp
@@ -174,12 +174,12 @@ string fileinfo::GetPrerequisits() const
// Build a string with all prerequisits, but make sure that every dependency
// is only in there once (we do this be building a set in parallel
vector< refptr<fileinfo> >::const_iterator DepIt=m_Deps.begin();
- set< refptr<fileinfo> > Deps;
+ deps_t Deps;
bool first=true;
string Ret=g_EmptyString;
while (DepIt!=m_Deps.end())
{
- set< refptr<fileinfo> >::iterator pFound=Deps.find(*DepIt);
+ deps_t::iterator pFound=Deps.find(*DepIt);
if (pFound==Deps.end())
{
if (first)
@@ -228,24 +228,26 @@ bool fileinfo::IsAutoDepExtention(void) const
#ifdef _DEBUG
///////////////////////////////////////////////////////////////////////////////
-void fileinfo::DumpErrorMessageDuplicateRule(const refptr<rule>&pRule)
+string fileinfo::GetErrorMessageDuplicateRule(const refptr<rule>&pRule)
{
- cerr << GetQuotedFullFileName() << ": rule is defined multiple times\n";
- cerr << "First ("<<m_pRule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<<") :\n";
+ string Ret;
+ Ret = GetQuotedFullFileName() + ": rule is defined multiple times\n";
+ Ret += "First (" + m_pRule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName() + ") :\n";
vector<string>::const_iterator It=m_pRule->GetCommands().begin();
while (It!=m_pRule->GetCommands().end())
{
- cerr << " " << m_pRule->GetMakefile()->ExpandExpression(*It) << endl;
+ Ret+= " " + m_pRule->GetMakefile()->ExpandExpression(*It) + "\n";
It++;
}
- cerr << "Second ("<<pRule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<<") :\n";
+ Ret += "Second (" + pRule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName() + ") :\n";
It=pRule->GetCommands().begin();
while (It!=pRule->GetCommands().end())
{
- cerr << " " << pRule->GetMakefile()->ExpandExpression(*It) << endl;
+ Ret += " " + pRule->GetMakefile()->ExpandExpression(*It) +"\n";
It++;
}
+ return Ret;
}
#endif
diff --git a/tools/mhmake/src/fileinfo.h b/tools/mhmake/src/fileinfo.h
index 227ba5e1f..a6606b294 100644
--- a/tools/mhmake/src/fileinfo.h
+++ b/tools/mhmake/src/fileinfo.h
@@ -49,6 +49,7 @@ extern bool g_CheckCircularDeps;
extern bool g_ForceAutoDepRescan;
extern bool g_PrintLexYacc;
extern bool g_Clean;
+extern bool g_StopCompiling;
extern bool g_PrintMultipleDefinedRules;
extern const string g_EmptyString;
@@ -58,6 +59,14 @@ extern const string g_QuoteString;
string QuoteFileName(const string &Filename);
string UnquoteFileName(const string &Filename);
+template<typename T>
+inline string stringify(const T& x)
+{
+ ostringstream o;
+ o << x;
+ return o.str();
+}
+
#define TIMESAFETY 3
class mh_time
{
@@ -196,7 +205,7 @@ public:
string GetName() const;
bool IsDir() const;
- void DumpErrorMessageDuplicateRule(const refptr<rule> &pRule);
+ string GetErrorMessageDuplicateRule(const refptr<rule> &pRule);
void SetRule(refptr<rule> &pRule)
{
@@ -222,12 +231,11 @@ public:
{
if (*m_pRule!=*pRule)
{
- DumpErrorMessageDuplicateRule(pRule);
- throw(1);
+ throw(GetErrorMessageDuplicateRule(pRule));
}
else if (g_PrintMultipleDefinedRules)
{
- DumpErrorMessageDuplicateRule(pRule);
+ cerr<<GetErrorMessageDuplicateRule(pRule);
}
}
#endif
diff --git a/tools/mhmake/src/functions.cpp b/tools/mhmake/src/functions.cpp
index 2d93f59cd..5b59044c7 100644
--- a/tools/mhmake/src/functions.cpp
+++ b/tools/mhmake/src/functions.cpp
@@ -83,8 +83,7 @@ string mhmakefileparser::f_filter(const string & Arg) const
int ipos=Arg.find(',');
#ifdef _DEBUG
if (ipos==string::npos) {
- cerr << "filter func should have 2 arguments: "<<Arg<<endl;
- throw 1;
+ throw string("filter func should have 2 arguments: ")+Arg;
}
#endif
string Str=TrimString(Arg.substr(0,ipos));
@@ -123,8 +122,7 @@ string mhmakefileparser::f_filterout(const string & Arg) const
int ipos=Arg.find(',');
#ifdef _DEBUG
if (ipos==string::npos) {
- cerr << "filter func should have 2 arguments: "<<Arg<<endl;
- throw 1;
+ throw string("filter func should have 2 arguments: ")+Arg;
}
#endif
string Str=TrimString(Arg.substr(0,ipos));
@@ -170,8 +168,7 @@ string mhmakefileparser::f_call(const string & Arg) const
#ifdef _DEBUG
if (pFunc==m_Variables.end())
{
- fprintf(stderr,"call to non existing function %s\n",Func.c_str());
- throw(1);
+ throw string("call to non existing function ")+Func;
}
#endif
Func=pFunc->second;
@@ -205,8 +202,7 @@ string mhmakefileparser::f_subst(const string & Arg) const
pTmp=NextCharItem(pTmp,FromString,',');
#ifdef _DEBUG
if (!*pTmp) {
- cerr << "Wrong number of arguments in function subst" << endl;
- throw(1);
+ throw string("Wrong number of arguments in function subst");
}
#endif
@@ -242,8 +238,7 @@ string mhmakefileparser::f_patsubst(const string & Arg) const
pTmp=NextCharItem(pTmp,FromString,',');
#ifdef _DEBUG
if (!*pTmp) {
- cerr << "Wrong number of arguments in function subst" << endl;
- throw(1);
+ throw string("Wrong number of arguments in function subst");
}
#endif
@@ -408,8 +403,7 @@ string mhmakefileparser::f_filesindirs(const string & Arg) const
pTmp=NextCharItem(pTmp,strFiles,',');
#ifdef _DEBUG
if (!*pTmp) {
- cerr << "Wrong number of arguments in function filesindirs" << endl;
- throw(1);
+ throw string("Wrong number of arguments in function filesindirs");
}
#endif
string strDirs;
@@ -541,8 +535,7 @@ string mhmakefileparser::f_addprefix(const string & Arg) const
pTmp=NextCharItem(pTmp,PreFix,',');
#ifdef _DEBUG
if (!*pTmp) {
- cerr << "Wrong number of arguments in function addprefix" << endl;
- throw(1);
+ throw ("Wrong number of arguments in function addprefix");
}
#endif
string FileNames;
@@ -564,8 +557,7 @@ string mhmakefileparser::f_addsuffix(const string & Arg) const
pTmp=NextCharItem(pTmp,SufFix,',');
#ifdef _DEBUG
if (!*pTmp) {
- cerr << "Wrong number of arguments in function addsuffix" << endl;
- throw(1);
+ throw string("Wrong number of arguments in function addsuffix");
}
#endif
string FileNames;
@@ -588,8 +580,7 @@ string mhmakefileparser::f_word(const string & Arg) const
if (!WordNbr)
{
if (!WordNbr) {
- cerr << "Expecting a number bigger then 0 for the word function"<<endl;
- throw(1);
+ throw string ("Expecting a number bigger then 0 for the word function");
}
}
#endif
diff --git a/tools/mhmake/src/mhmake.cpp b/tools/mhmake/src/mhmake.cpp
index 375621fb4..9f2699f91 100644
--- a/tools/mhmake/src/mhmake.cpp
+++ b/tools/mhmake/src/mhmake.cpp
@@ -25,6 +25,15 @@
#include "util.h"
bool g_Clean=false;
+bool g_StopCompiling=false;
+
+#ifdef WIN32
+BOOL WINAPI ControlCHandler(DWORD dwCtrlType)
+{
+ g_StopCompiling=true;
+ return TRUE;
+}
+#endif
int __CDECL main(int argc, char* argv[])
{
@@ -57,6 +66,9 @@ int __CDECL main(int argc, char* argv[])
* output to fail.
*/
putenv("VS_UNICODE_OUTPUT=");
+
+ SetConsoleCtrlHandler(ControlCHandler, TRUE);
+
#endif
try
@@ -120,9 +132,9 @@ int __CDECL main(int argc, char* argv[])
}
}
- catch (int Error)
+ catch (string Message)
{
- printf("Error occured %d\n",Error);
+ cerr << "Error occured: " << Message << endl;
#ifdef _DEBUG
if (g_DumpOnError)
{
diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp
index af7d75dfe..e3434e312 100644
--- a/tools/mhmake/src/mhmakefileparser.cpp
+++ b/tools/mhmake/src/mhmakefileparser.cpp
@@ -268,8 +268,7 @@ string mhmakefileparser::ExpandMacro(const string &Expr) const
}
else
{
- cerr << "Unknown function specified in macro: "<<Func<<endl;
- throw 1;
+ throw string("Unknown function specified in macro: ")+Func;
}
#else
return (this->*pFunc)(Arg);
@@ -278,8 +277,7 @@ string mhmakefileparser::ExpandMacro(const string &Expr) const
else
{
#ifdef _DEBUG
- cerr << "Fatal error in ExpandMacro (bug in mhmake ? ? ?)";
- throw 1;
+ throw string("Fatal error in ExpandMacro (bug in mhmake ? ? ?)");
#else
return g_EmptyString;
#endif
@@ -382,8 +380,7 @@ void mhmakefileparser::ParseBuildedIncludeFiles()
int result=ParseFile(GetFileInfo(*It));
if (result)
{
- fprintf(stderr,"Error parsing %s\n",It->c_str());
- throw(1);
+ throw string("Error parsing ")+*It;
}
It++;
}
@@ -461,7 +458,7 @@ void mhmakefileparser::AddRule()
}
///////////////////////////////////////////////////////////////////////////////
-void mhmakefileparser::GetAutoDeps(const refptr<fileinfo> &FirstDep,set< refptr<fileinfo> > &Autodeps)
+void mhmakefileparser::GetAutoDeps(const refptr<fileinfo> &FirstDep, deps_t &Autodeps)
{
/* Here we have to scan only c/c++ headers so skip certain extensions */
const char *pFullName=FirstDep->GetFullFileName().c_str();
@@ -553,11 +550,11 @@ void mhmakefileparser::GetAutoDeps(const refptr<fileinfo> &FirstDep,set< refptr<
/* Add the dependency when the file alrady exist or there is a rule available to be build */
if (BuildTarget(pInclude).DoesExist()) // Try to build the target, and add it if it exists after building
{
- set< refptr<fileinfo> >::iterator pFind=Autodeps.find(pInclude);
+ deps_t::const_iterator pFind=Autodeps.find(pInclude);
if (pFind==Autodeps.end())
{
Autodeps.insert(pInclude);
- GetAutoDeps(pInclude,Autodeps);
+ GetAutoDepsIfNeeded(pInclude,pInclude);
}
}
}
@@ -568,11 +565,11 @@ void mhmakefileparser::GetAutoDeps(const refptr<fileinfo> &FirstDep,set< refptr<
refptr<fileinfo> pInclude=GetFileInfo(IncludeFile,*It);
if (BuildTarget(pInclude).DoesExist()) // Try to build the target, and add it if it exists after building
{
- set< refptr<fileinfo> >::iterator pFind=Autodeps.find(pInclude);
+ deps_t::const_iterator pFind=Autodeps.find(pInclude);
if (pFind==Autodeps.end())
{
Autodeps.insert(pInclude);
- GetAutoDeps(pInclude,Autodeps);
+ GetAutoDepsIfNeeded(pInclude,pInclude);
}
break;
}
@@ -591,6 +588,28 @@ void mhmakefileparser::GetAutoDeps(const refptr<fileinfo> &FirstDep,set< refptr<
}
///////////////////////////////////////////////////////////////////////////////
+
+void mhmakefileparser::GetAutoDepsIfNeeded(const refptr<fileinfo> &Target, const refptr<fileinfo>&FirstDep)
+{
+ autodeps_entry_t &Autodeps=m_AutoDeps[Target];
+ if (!Autodeps.first)
+ {
+ Autodeps.first=true;
+ /* We are going to rescan, so throw away the old. */
+ Autodeps.second.clear();
+ GetAutoDeps(FirstDep,Autodeps.second);
+ // Now add these dependencies also to the rules
+ deps_t::iterator It=Autodeps.second.begin();
+ while (It!=Autodeps.second.end())
+ {
+ Target->AddDep(*It);
+ It++;
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
void mhmakefileparser::UpdateAutomaticDependencies(const refptr<fileinfo> &Target)
{
m_AutoDepsDirty=true; /* Always assume dirty since in the autodeps file, the md5 strings are also saved. */
@@ -601,17 +620,7 @@ void mhmakefileparser::UpdateAutomaticDependencies(const refptr<fileinfo> &Targe
if (!Deps.size())
return; // There is no first dep
refptr<fileinfo> FirstDep=Deps[0];
-
- set< refptr<fileinfo> > &Autodeps=m_AutoDeps[Target];
- Autodeps.clear(); // We are going to scan again, so clear the list
- GetAutoDeps(FirstDep,Autodeps);
- // Now add these dependencies also to the rules
- set< refptr<fileinfo> >::iterator It=Autodeps.begin();
- while (It!=Autodeps.end())
- {
- Target->AddDep(*It);
- It++;
- }
+ GetAutoDepsIfNeeded(Target,FirstDep);
}
}
@@ -688,14 +697,14 @@ void mhmakefileparser::LoadAutoDepsFile(refptr<fileinfo> &DepFile)
while (FileName[0])
{
refptr<fileinfo> Target=GetFileInfo(FileName);
- set< refptr<fileinfo> > &Autodeps=m_AutoDeps[Target];
+ autodeps_entry_t &Autodeps=m_AutoDeps[Target];
ReadStr(pIn,FileName);
while (FileName[0])
{
if (!g_ForceAutoDepRescan) /* If we are forcing the autodepscan we do not have to load the dependencies. */
{
refptr<fileinfo> Dep=GetFileInfo(FileName);
- Autodeps.insert(Dep);
+ Autodeps.second.insert(Dep);
Target->AddDep(Dep);
}
ReadStr(pIn,FileName);
@@ -783,17 +792,20 @@ void mhmakefileparser::SaveAutoDepsFile()
fwrite(&Md5_32,sizeof(Md5_32),1,pOut);
fprintf(pOut,"%s\n",m_Variables[USED_ENVVARS].c_str());
- map< refptr<fileinfo>, set< refptr<fileinfo> > >::const_iterator It=m_AutoDeps.begin();
+ autodeps_t::const_iterator It=m_AutoDeps.begin();
while (It!=m_AutoDeps.end())
{
- fprintf(pOut,"%s\n",It->first->GetFullFileName().c_str());
- set< refptr<fileinfo> >::const_iterator DepIt=It->second.begin();
- while (DepIt!=It->second.end())
+ if (!It->second.second.empty())
{
- fprintf(pOut,"%s\n",(*DepIt)->GetFullFileName().c_str());
- DepIt++;
+ fprintf(pOut,"%s\n",It->first->GetFullFileName().c_str());
+ deps_t::const_iterator DepIt=It->second.second.begin();
+ while (DepIt!=It->second.second.end())
+ {
+ fprintf(pOut,"%s\n",(*DepIt)->GetFullFileName().c_str());
+ DepIt++;
+ }
+ fprintf(pOut,"\n");
}
- fprintf(pOut,"\n");
It++;
}
/* Now save the Md5 strings */
diff --git a/tools/mhmake/src/mhmakefileparser.h b/tools/mhmake/src/mhmakefileparser.h
index 84d69a878..e5c435cec 100644
--- a/tools/mhmake/src/mhmakefileparser.h
+++ b/tools/mhmake/src/mhmakefileparser.h
@@ -47,6 +47,10 @@ class fileinfoarray : public refbase,public vector<refptr<fileinfo> >
{
};
+typedef set< refptr<fileinfo> > deps_t;
+typedef pair< bool, deps_t > autodeps_entry_t;
+typedef map< refptr<fileinfo>, autodeps_entry_t > autodeps_t;
+
class mhmakefileparser : public refbase
{
@@ -77,7 +81,7 @@ protected:
fileinfoarray m_IncludedMakefiles;
refptr< fileinfoarray > m_pIncludeDirs;
string m_IncludeDirs;
- map< refptr<fileinfo>, set< refptr<fileinfo> > > m_AutoDeps;
+ autodeps_t m_AutoDeps;
set< const fileinfo* , less_fileinfo > m_Targets; // List of targets that are build by this makefile
bool m_DoubleColonRule;
bool m_AutoDepsDirty;
@@ -153,9 +157,10 @@ public:
{
m_RuleThatIsBuild=NULL;
}
+ void GetAutoDepsIfNeeded(const refptr<fileinfo> &Target, const refptr<fileinfo>&FirstDep);
void UpdateAutomaticDependencies(const refptr<fileinfo> &Target);
const refptr<fileinfoarray> GetIncludeDirs() const;
- void GetAutoDeps(const refptr<fileinfo> &FirstDep,set< refptr<fileinfo> > &Autodeps);
+ void GetAutoDeps(const refptr<fileinfo> &FirstDep, deps_t &Autodeps);
void SaveAutoDepsFile();
void LoadAutoDepsFile(refptr<fileinfo> &DepFile);
bool SkipHeaderFile(const string &FileName);
diff --git a/tools/mhmake/src/mhmakelexer.l b/tools/mhmake/src/mhmakelexer.l
index b9484159a..0b25d4c74 100644
--- a/tools/mhmake/src/mhmakelexer.l
+++ b/tools/mhmake/src/mhmakelexer.l
@@ -47,8 +47,7 @@ static void SaveMakMd5(refptr<fileinfo> &Target)
FILE *pFile=fopen(FileName.c_str(),"wb");
if (!pFile)
{
- cout << "Error creating file "<<FileName<<endl;
- throw(1);
+ throw string("Error creating file ")+FileName;
}
Target->WriteMd5_32(pFile);
fclose(pFile);
@@ -189,8 +188,7 @@ load_makefile {
pTmp=NextCharItem(pTmp,Item,';');
if (Item.empty())
{
- cerr << m_InputFileName << "("<<m_Line<<"): Error in load_makefile statement\n";
- throw(1);
+ throw m_InputFileName + "(" + stringify(m_Line) + "): Error in load_makefile statement";
}
GetParser()->AddMakefileToMakefilesToLoad(Item);
}
@@ -319,8 +317,7 @@ load_makefile {
}
else
{
- cerr << "Unexpected endif at line "<<m_Line<<" of "<<m_InputFileName.c_str()<<endl;
- throw(1);
+ throw string("Unexpected endif at line ") + stringify(m_Line) + " of " + m_InputFileName;
}
}
@@ -399,8 +396,7 @@ load_makefile {
}
else
{
- cerr << "Unexpected else at line "<<m_Line<<" of file "<< m_InputFileName.c_str() << endl;
- throw(1);
+ throw string("Unexpected else at line ") + stringify(m_Line) + " of file " + m_InputFileName;
}
}
@@ -501,8 +497,7 @@ load_makefile {
m_Line++;
if (!m_IndentStack.size())
{
- cerr << "Unexpected endif at line "<<m_Line<<" of "<<m_InputFileName.c_str()<<endl;
- throw(1);
+ throw string("Unexpected endif at line ") + stringify(m_Line) + " of " + m_InputFileName;
}
else
{
@@ -518,8 +513,7 @@ load_makefile {
PRINTF(("%s %d: else: depth %d\n",m_InputFileName.c_str(),m_Line,m_IndentStack.size()));
if (m_IndentStack.top())
{
- cerr << "Unexpected else at line "<<m_Line<<" of file "<< m_InputFileName.c_str() << endl;
- throw(1);
+ throw string("Unexpected else at line ") + stringify(m_Line) + " of file " + m_InputFileName;
}
m_IndentStack.top()=1;
if (m_IndentStack.size()==m_IndentSkip)
@@ -794,8 +788,7 @@ export {
{
PRINTF(("%s %d: ERRORMACRO: %s\n",m_InputFileName.c_str(),m_Line,yytext));
yyless(0);
- cerr<<GetParser()->ExpandExpression((const char*)yytext)<<endl;
- throw(1);
+ throw GetParser()->ExpandExpression((const char*)yytext);
} else {
yymore();
}
@@ -876,22 +869,19 @@ export {
}
<SKIPUNTILELSEORENDIF><<EOF>> {
- cerr << "Missing endif or else statement. #else or #endif used?\n";
- throw(1);
+ throw string("Missing endif or else statement. #else or #endif used?");
}
<<EOF>> {
if (m_BraceIndent)
{
- cerr << "Missing closing ) of macro usage in "<<m_InputFileName.c_str()<<".\n";
- throw(1);
+ throw string("Missing closing ) of macro usage in ") + m_InputFileName;
}
if (!m_IncludeStack.size())
{
if (m_IndentStack.size())
{
- cerr << "Missing endif or else statement in "<<m_InputFileName.c_str()<<". #else or #endif used?\n";
- throw(1);
+ throw string("Missing endif or else statement in ") + m_InputFileName + ". #else or #endif used";
}
yyterminate();
}
diff --git a/tools/mhmake/src/mhmakeparser.y b/tools/mhmake/src/mhmakeparser.y
index ee26dd92b..68b0a489e 100644
--- a/tools/mhmake/src/mhmakeparser.y
+++ b/tools/mhmake/src/mhmakeparser.y
@@ -111,8 +111,7 @@ ruledef: expression_nocolorequal rulecolon maybeemptyexpression
#ifdef _DEBUG
if (!ExpandExpression($1).size())
{
- printf("Empty left hand side in rule: %s : %s\n",$1.c_str(),$3.c_str());
- throw(1);
+ throw string("Empty left hand side in rule: ") + $1 + " : " + $3;
}
#endif
SplitToItems(ExpandExpression($1),*m_pCurrentItems,m_MakeDir);
diff --git a/tools/mhmake/src/rule.cpp b/tools/mhmake/src/rule.cpp
index 7e71ba95f..90fee8a91 100644
--- a/tools/mhmake/src/rule.cpp
+++ b/tools/mhmake/src/rule.cpp
@@ -49,11 +49,12 @@ static bool FindDep(const string &DepName,vector<pair<string,refptr<rule> > >&Im
bool bCommandsDifferent=OldCommands.size()!=NewCommands.size();
if (g_PrintMultipleDefinedRules || bCommandsDifferent)
{
+ string ErrorMessage;
if (bCommandsDifferent)
- cerr << "Implicit Rule '"<< DepName << "' defined twice with different commands\n";
+ ErrorMessage += "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()->GetQuotedFullFileName()<< endl;
+ ErrorMessage += "Implicit Rule '"+ DepName + "' defined twice with same commands\n";
+ ErrorMessage += "Command 1: makedir = " + SecIt->second->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()+ "\n";
vector<string>::const_iterator It;
if (bCommandsDifferent)
@@ -61,19 +62,21 @@ static bool FindDep(const string &DepName,vector<pair<string,refptr<rule> > >&Im
It=OldCommands.begin();
while (It!=OldCommands.end())
{
- cerr << " " << *It << endl;
+ ErrorMessage += " " + *It + "\n";
}
}
- cerr << "Command 2: makedir = "<< Rule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()<< endl;
+ cerr << "Command 2: makedir = "+ Rule->GetMakefile()->GetMakeDir()->GetQuotedFullFileName()+ "\n";
if (bCommandsDifferent)
{
It=NewCommands.begin();
while (It!=NewCommands.end())
{
- cerr << " " << *It << endl;
+ ErrorMessage += " " + *It + "\n";
}
- throw(1);
+ throw ErrorMessage;
}
+ else
+ cerr << ErrorMessage << endl;
}
mhmakeparser *pOldMakefile=SecIt->second->GetMakefile();
mhmakeparser *pNewMakefile=Rule->GetMakefile();
@@ -83,12 +86,12 @@ static bool FindDep(const string &DepName,vector<pair<string,refptr<rule> > >&Im
{
if (pOldMakefile->ExpandExpression(*OldIt)!=pNewMakefile->ExpandExpression(*NewIt))
{
- cerr << "Implicit Rule '"<< DepName << "' defined twice with different commands\n";
- cerr << "Command 1: makedir = " << pOldMakefile->GetMakeDir()->GetQuotedFullFileName()<< endl;
- cerr << " " << pOldMakefile->ExpandExpression(*OldIt) << endl;
- cerr << "Command 2: makedir = "<< pNewMakefile->GetMakeDir()->GetQuotedFullFileName()<< endl;
- cerr << " " << pNewMakefile->ExpandExpression(*NewIt) << endl;
- throw(1);
+ string ErrorMessage = string("Implicit Rule '") + DepName + "' 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";
+ ErrorMessage += " " + pNewMakefile->ExpandExpression(*NewIt);
+ throw ErrorMessage;
}
OldIt++;
NewIt++;
@@ -141,8 +144,7 @@ void IMPLICITRULE::SearchImplicitRule(const refptr<fileinfo> &Target,vector< pai
#ifdef _DEBUG
if (!ResIt->second)
{
- cerr << "No rhs for implicit rule : "<< ImpRegExIt->first << endl;
- throw(1);
+ throw string("No rhs for implicit rule : ") + ImpRegExIt->first;
}
#endif
ResIt->second->SetStem(Res.m_Stem);
diff --git a/tools/mhmake/src/stdafx.h b/tools/mhmake/src/stdafx.h
index d7e7bf4b7..bc686e03e 100644
--- a/tools/mhmake/src/stdafx.h
+++ b/tools/mhmake/src/stdafx.h
@@ -42,6 +42,7 @@
#include <set>
#include <stack>
#include <algorithm>
+#include <sstream>
#ifdef _MSC_VER
#include <io.h>
diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp
index 608311e94..f89009206 100644
--- a/tools/mhmake/src/util.cpp
+++ b/tools/mhmake/src/util.cpp
@@ -406,9 +406,7 @@ loadedmakefile::loadedmakefile(vector<string> &Args,const string&Makefile)
break;
#endif
default:
- cerr << "\nUnknown option: "<<*ArgIt<<endl<<endl;
- cerr << s_UsageString;
- throw(1);
+ throw string("\nUnknown option: ")+*ArgIt+"\n\n"+ s_UsageString;
}
}
else
@@ -502,8 +500,7 @@ void loadedmakefile::LoadMakefile()
int result=m_pParser->ParseFile(BeforeMakefile,true);
if (result)
{
- printf("Error parsing %s\n",BeforeMakefile->GetQuotedFullFileName().c_str());
- throw(1);
+ throw string("Error parsing ")+BeforeMakefile->GetQuotedFullFileName();
}
m_pParser->UpdateDate(BeforeMakefile->GetDate());
@@ -511,8 +508,7 @@ void loadedmakefile::LoadMakefile()
string ObjDirName=m_pParser->ExpandExpression("$(OBJDIR)");
if (!ObjDirName.size())
{
- printf("When making use of MHMAKECONF, you have to define OBJDIR in makefile.before");
- throw(1);
+ throw string("When making use of MHMAKECONF, you have to define OBJDIR in makefile.before");
}
DepFile=GetFileInfo(ObjDirName+OSPATHSEPSTR MAKEDEPFILE);
m_pParser->SetVariable(AUTODEPFILE,DepFile->GetQuotedFullFileName());
@@ -547,8 +543,7 @@ void loadedmakefile::LoadMakefile()
int result=m_pParser->ParseFile(m_Makefile,true);
if (result)
{
- printf("Error parsing %s\n",m_Makefile->GetQuotedFullFileName().c_str());
- throw(1);
+ throw string("Error parsing ")+m_Makefile->GetQuotedFullFileName();
}
#ifdef _DEBUG
/* Check if the makefile has changed the AUTODEPFILE variable, if so generate a warning that a
@@ -574,8 +569,7 @@ void loadedmakefile::LoadMakefile()
refptr<fileinfo> AfterMakefile=GetFileInfo(BaseAutoMak+".after",sm_Statics.m_MhMakeConf);
int result=m_pParser->ParseFile(AfterMakefile);
if (result) {
- printf("Error parsing %s\n",AfterMakefile->GetQuotedFullFileName().c_str());
- throw(1);
+ throw string("Error parsing ")+AfterMakefile->GetQuotedFullFileName();
}
m_pParser->UpdateDate(AfterMakefile->GetDate());
}
diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h
index 5cd242d51..607c1cb37 100644
--- a/tools/mhmake/src/util.h
+++ b/tools/mhmake/src/util.h
@@ -50,7 +50,7 @@
#define PLATFORM "linux"
#endif
-#define MHMAKEVER "1.4.0"
+#define MHMAKEVER "1.4.1"
#define MAKEDEPFILE ".makefile.dep"