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/build.cpp | 194 +++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 94 deletions(-) (limited to 'tools/mhmake/src/build.cpp') diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp index bfd5d0211..525ff8c05 100644 --- a/tools/mhmake/src/build.cpp +++ b/tools/mhmake/src/build.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 @@ -242,20 +242,20 @@ void mhmakefileparser::CreatePythonExe(const string &FullCommand) /*****************************************************************************/ int mhmakefileparser::SearchPath(const char *szCommand, const char *pExt, size_t Len, char *szFullCommand,char **pFilePart) const { - static vector< refptr > vSearchPath; + static vector< fileinfo* > vSearchPath; string Command(szCommand); if (pExt) Command+=pExt; - vector< refptr >::iterator It; - vector< refptr >::iterator ItEnd; + vector< fileinfo* >::iterator It; + vector< fileinfo* >::iterator ItEnd; - refptr CommandFile=GetFileInfo(Command,m_MakeDir); - if (CommandFile->Exists()) + fileinfo* pCommandFile=GetFileInfo(Command,m_MakeDir); + if (pCommandFile->Exists()) { goto found; } - CommandFile->InvalidateDate(); // It could be created in the makefile later + pCommandFile->InvalidateDate(); // It could be created in the makefile later if (!vSearchPath.size()) { char *pPath=getenv(PATH); @@ -274,8 +274,8 @@ int mhmakefileparser::SearchPath(const char *szCommand, const char *pExt, size_t ItEnd=vSearchPath.end(); while (It!=ItEnd) { - CommandFile=GetFileInfo(Command,*It); - if (CommandFile->Exists()) + pCommandFile=GetFileInfo(Command,*It); + if (pCommandFile->Exists()) goto found; It++; } @@ -283,7 +283,7 @@ int mhmakefileparser::SearchPath(const char *szCommand, const char *pExt, size_t return 0; found: - string FullCommand=CommandFile->GetFullFileName(); + string FullCommand=pCommandFile->GetFullFileName(); size_t CommandLen=FullCommand.size(); if (CommandLen>Len-1) { @@ -392,7 +392,7 @@ static bool DeleteDir(const string &Dir,const string WildSearch="*",bool bRemove mh_pid_t mhmakefileparser::DeleteFiles(const string &Params) const { bool IgnoreError=false; - vector< refptr > Files; + vector Files; // First check if the first parameter is -e meaning don't give an error when file does not exist if (Params[1]=='-') @@ -413,10 +413,10 @@ mh_pid_t mhmakefileparser::DeleteFiles(const string &Params) const SplitToItems(Params,Files); } - vector< refptr >::const_iterator It=Files.begin(); + vector::const_iterator It=Files.begin(); while (It!=Files.end()) { - refptr pFile=*It++; + fileinfo* pFile=*It++; string DirSearch="*"; bool bRemoveDir=true; @@ -457,7 +457,7 @@ mh_pid_t mhmakefileparser::DeleteFiles(const string &Params) const /*****************************************************************************/ /* pDest can be a directory or a file */ -static bool CopyFile(refptr pSrc, refptr pDest) +static bool CopyFile(fileinfo* pSrc, fileinfo* pDest) { if (pDest->IsDir()) { @@ -494,7 +494,7 @@ static bool CopyFile(refptr pSrc, refptr pDest) /*****************************************************************************/ /* Copies a complete directory to a destination (currenlty not recursive */ -static bool CopyDir(refptr pDir,refptr pDest,const string WildSearch="*") +static bool CopyDir(fileinfo* pDir, fileinfo* pDest,const string WildSearch="*") { bool Error=true; string Pattern=pDir->GetFullFileName()+OSPATHSEP+WildSearch; @@ -513,11 +513,11 @@ static bool CopyDir(refptr pDir,refptr pDest,const string Wi { if (FindData.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) continue; - refptr pSrc=GetFileInfo(FindData.cFileName,pDir); + fileinfo* pSrc=GetFileInfo(FindData.cFileName,pDir); if (pSrc->IsDir()) { - refptr pNewDest=GetFileInfo(FindData.cFileName,pDest); + fileinfo* pNewDest=GetFileInfo(FindData.cFileName,pDest); if (!pNewDest->IsDir()) { if (pNewDest->Exists()) @@ -554,7 +554,7 @@ exit: for (int i=0; i pSrc=GetFileInfo(Res.gl_pathv[i],pDir); + fileinfo* pSrc=GetFileInfo(Res.gl_pathv[i],pDir); if (pSrc->IsDir()) { *(strrchr(Res.gl_pathv[i],'/'))='\0'; @@ -563,7 +563,7 @@ exit: if (SrcDirName[0]=='.') continue; - refptr pNewDest=GetFileInfo(SrcDirName,pDest); + fileinfo* pNewDest=GetFileInfo(SrcDirName,pDest); if (!pNewDest->IsDir()) { if (pNewDest->Exists()) @@ -615,14 +615,14 @@ mh_pid_t mhmakefileparser::EchoCommand(const string &Params) const if (Params[Pos+1]=='>') { NextItem(Params.substr(Pos+2).c_str(),Filename); - refptr pFile=GetFileInfo(Filename,m_MakeDir); + fileinfo* pFile=GetFileInfo(Filename,m_MakeDir); // Open file in append pfFile=fopen(pFile->GetFullFileName().c_str(),"a"); } else { NextItem(Params.substr(Pos+1).c_str(),Filename); - refptr pFile=GetFileInfo(Filename,m_MakeDir); + fileinfo* pFile=GetFileInfo(Filename,m_MakeDir); pfFile=fopen(pFile->GetFullFileName().c_str(),"w"); } if (!pfFile) @@ -646,7 +646,7 @@ mh_pid_t mhmakefileparser::EchoCommand(const string &Params) const /*****************************************************************************/ mh_pid_t mhmakefileparser::CopyFiles(const string &Params) const { - vector< refptr > Files; + vector Files; SplitToItems(Params,Files); @@ -658,7 +658,7 @@ mh_pid_t mhmakefileparser::CopyFiles(const string &Params) const return false; } - refptr pDest=Files[NrSrcs]; + fileinfo* pDest=Files[NrSrcs]; if (NrSrcs>1 && !pDest->IsDir()) { cerr << "copy: Destination must be a directory when more then one source : "< pSrc=Files[i]; + fileinfo* pSrc=Files[i]; string SrcFileName=pSrc->GetFullFileName(); @@ -704,14 +704,14 @@ mh_pid_t mhmakefileparser::CopyFiles(const string &Params) const /*****************************************************************************/ mh_pid_t mhmakefileparser::TouchFiles(const string &Params) const { - vector< refptr > Files; + vector Files; SplitToItems(Params,Files); - vector< refptr >::const_iterator It=Files.begin(); + vector::const_iterator It=Files.begin(); while (It!=Files.end()) { - refptr pFile=*It++; + fileinfo* pFile=*It++; const string &FileName=pFile->GetFullFileName(); /* Since this can be part of a list of commands for a certain rule, and it is possible that the file @@ -904,8 +904,8 @@ string mhmakefileparser::GetFullCommand(string Command) Command=FullCommand; if (!PythonFullCommand.empty()&&s_Py2ExeInstalled) { - refptr pExeFile=GetFileInfo(FullCommand,m_MakeDir); - refptr pPyFile=GetFileInfo(PythonFullCommand,m_MakeDir); + fileinfo* pExeFile=GetFileInfo(FullCommand,m_MakeDir); + fileinfo* pPyFile=GetFileInfo(PythonFullCommand,m_MakeDir); bool bBuild=false; if (pExeFile->GetDate().IsOlder(pPyFile->GetDate())) { @@ -950,7 +950,7 @@ string mhmakefileparser::GetFullCommand(string Command) /* Now first try to create an executable for it */ if (s_Py2ExeInstalled) { - refptr pExeFile; + fileinfo* pExeFile; CreatePythonExe(FullCommand); string ExeFullCommand=SearchCommand(Command,EXEEXT); if (!ExeFullCommand.empty()) @@ -1435,11 +1435,11 @@ mh_pid_t mhmakefileparser::ExecuteCommand(string Command, bool &IgnoreError, str } /////////////////////////////////////////////////////////////////////////////// -void mhmakefileparser::BuildDependencies(const refptr &pRule, const refptr &Target, mh_time_t TargetDate, mh_time_t &YoungestDate, bool &MakeTarget) +void mhmakefileparser::BuildDependencies(const refptr &pRule, fileinfo* pTarget, mh_time_t TargetDate, mh_time_t &YoungestDate, bool &MakeTarget) { - vector< refptr > &Deps=Target->GetDeps(); - vector< refptr >::iterator pDepIt=Deps.begin(); + vector &Deps=pTarget->GetDeps(); + vector::iterator pDepIt=Deps.begin(); while (pDepIt!=Deps.end()) { StartBuildTarget(*pDepIt); @@ -1455,7 +1455,7 @@ void mhmakefileparser::BuildDependencies(const refptr &pRule, const refptr { #ifdef _DEBUG if (pRule&&g_pPrintDependencyCheck && DepDate.IsExistingFile() && TargetDate.IsExistingFile()) - cout<<"Going to build "<GetQuotedFullFileName()<<" because "<<(*pDepIt)->GetQuotedFullFileName()<<" is more recent\n"; + cout<<"Going to build "<GetQuotedFullFileName()<<" because "<<(*pDepIt)->GetQuotedFullFileName()<<" is more recent\n"; #endif MakeTarget=true; } @@ -1464,24 +1464,24 @@ void mhmakefileparser::BuildDependencies(const refptr &pRule, const refptr } /////////////////////////////////////////////////////////////////////////////// -mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool bCheckTargetDir) +mh_time_t mhmakefileparser::StartBuildTarget(fileinfo* pTarget,bool bCheckTargetDir) { #ifdef _DEBUG if (g_CheckCircularDeps) { - deque< refptr >::const_iterator pFind=find(m_TargetStack.begin(),m_TargetStack.end(),Target); + deque::const_iterator pFind=find(m_TargetStack.begin(),m_TargetStack.end(),pTarget); if (pFind!=m_TargetStack.end()) { - cout << "Circular dependency detected.\n"<GetQuotedFullFileName()<<" 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(); + deque::const_iterator pIt=m_TargetStack.begin(); while (pIt!=m_TargetStack.end()) { cout << " " << (*pIt)->GetQuotedFullFileName() << endl; pIt++; } } - if (!Target->IsBuildStarted()) m_TargetStack.push_back(Target); + if (!pTarget->IsBuildStarted()) m_TargetStack.push_back(pTarget); } #endif @@ -1494,46 +1494,46 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool throw string("Compilation Interrupted by user."); } - if (Target->IsBuild()) + if (pTarget->IsBuild()) { #ifdef _DEBUG if (g_pPrintDependencyCheck) { for (int i=0; iGetQuotedFullFileName()<<" : "<GetDate()<GetQuotedFullFileName()<<" : "<GetDate()<GetDate(); + return pTarget->GetDate(); } - if (Target->IsBuilding()) - return mh_time_t(); // Target is still building, so we have to wait + if (pTarget->IsBuilding()) + return mh_time_t(); // pTarget is still building, so we have to wait #ifdef _DEBUG if (g_GenProjectTree) - cout << Target->GetQuotedFullFileName() << endl; + cout << pTarget->GetQuotedFullFileName() << endl; Indent++; if (g_pPrintDependencyCheck) { for (int i=0; iGetQuotedFullFileName()<GetQuotedFullFileName()<SetBuild(); + pTarget->SetBuild(); /* Optimisation: do not build target when target dir does not exist, but first build the target dir, in case there exists a rule for it*/ - refptr pRule=Target->GetRule(); + refptr pRule=pTarget->GetRule(); if (!pRule && bCheckTargetDir) { - refptr TargetDir=Target->GetDir(); - mh_time_t TargetDirDate=BuildTarget(TargetDir,false); + fileinfo *pTargetDir=pTarget->GetDir(); + mh_time_t TargetDirDate=BuildTarget(pTargetDir,false); - if (!TargetDir->Exists()) + if (!pTargetDir->Exists()) { #ifdef _DEBUG Indent--; @@ -1546,29 +1546,28 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool } } - mh_time_t TargetDate=Target->GetDate(); + mh_time_t TargetDate=pTarget->GetDate(); bool MakeTarget=false; mh_time_t YoungestDate=TargetDate; if (!pRule || !pRule->GetCommands().size()) { - vector< pair,refptr > > Result; + vector< pair > > Result; + IMPLICITRULE::SearchImplicitRule(pTarget,Result); - IMPLICITRULE::SearchImplicitRule(Target,Result); - - vector< pair,refptr > >::iterator ResultIt=Result.begin(); + vector< pair > >::iterator ResultIt=Result.begin(); while (ResultIt!=Result.end()) { - if (ResultIt->first==NullFileInfo) + if (ResultIt->first==NULL) { pRule=ResultIt->second; - Target->SetRule(pRule); + pTarget->SetRule(pRule); #ifdef _DEBUG if (g_PrintAdditionalInfo) { - cout<<"Found implicit rule for "<GetQuotedFullFileName()<PrintCommands(Target); + cout<<"Found implicit rule for "<GetQuotedFullFileName()<PrintCommands(pTarget); } #endif break; @@ -1578,28 +1577,36 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool #ifdef _DEBUG m_ImplicitSearch++; #endif - mh_time_t DepDate=BuildTarget(ResultIt->first); + fileinfo* pNewTarget=ResultIt->first; + mh_time_t DepDate=BuildTarget(pNewTarget); + if (!DepDate.DoesExist()) + { + pNewTarget=ResultIt->second->GetMakefile()->SearchvPath(pNewTarget); + if (pNewTarget!=NULL) + DepDate=pNewTarget->GetDate(); + } #ifdef _DEBUG m_ImplicitSearch--; #endif - if (DepDate.DoesExist()) { + if (DepDate.DoesExist()) + { if (DepDate.IsNewer(YoungestDate)) YoungestDate=DepDate; pRule=ResultIt->second; - Target->AddMainDep(ResultIt->first); - Target->SetRule(pRule); /* This is an implicit rule so do not add the target */ + pTarget->AddMainDep(pNewTarget); + pTarget->SetRule(pRule); /* This is an implicit rule so do not add the target */ #ifdef _DEBUG if (g_PrintAdditionalInfo) { - cout<<"Found implicit rule for "<GetQuotedFullFileName()<<". Dependent "<first->GetQuotedFullFileName()<PrintCommands(Target); + cout<<"Found implicit rule for "<GetQuotedFullFileName()<<". Dependent "<first->GetQuotedFullFileName()<PrintCommands(pTarget); } #endif if (DepDate.IsNewer(TargetDate)) { #ifdef _DEBUG if (pRule,g_pPrintDependencyCheck && DepDate.IsExistingFile() && TargetDate.IsExistingFile()) - cout<<"Going to build "<GetQuotedFullFileName()<<" because "<first->GetQuotedFullFileName()<<" is more recent\n"; + cout<<"Going to build "<GetQuotedFullFileName()<<" because "<first->GetQuotedFullFileName()<<" is more recent\n"; #endif MakeTarget=true; } @@ -1611,11 +1618,11 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool if (pRule) { #ifdef _DEBUG - Target->SetBuilding(); - Target->SetRule(pRule); - Target->ClearBuilding(); + pTarget->SetBuilding(); + pTarget->SetRule(pRule); + pTarget->ClearBuilding(); #else - Target->SetRule(pRule); + pTarget->SetRule(pRule); #endif } } @@ -1625,12 +1632,12 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool { pMakefile=pRule->GetMakefile(); if (pMakefile->ForceAutoDepRescan()||MakeTarget==true) - pMakefile->UpdateAutomaticDependencies(Target); + pMakefile->UpdateAutomaticDependencies(pTarget); } - else if (Target->GetAutoDepsMakefile()) - Target->GetAutoDepsMakefile()->UpdateNoRuleAutomaticDependencies(Target); + else if (pTarget->GetAutoDepsMakefile()) + pTarget->GetAutoDepsMakefile()->UpdateNoRuleAutomaticDependencies(pTarget); - BuildDependencies(pRule,Target,TargetDate,YoungestDate,MakeTarget); + BuildDependencies(pRule,pTarget,TargetDate,YoungestDate,MakeTarget); if (pRule) { @@ -1639,7 +1646,7 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool { for (int i=0; iGetQuotedFullFileName()<GetQuotedFullFileName()< &Target,bool { if (!TargetDate.DoesExist()) { - if (!m_ImplicitSearch && !Target->IsPhony()) - cout<<"Building "<GetQuotedFullFileName()<<" because it does not exist yet\n"; + if (!m_ImplicitSearch && !pTarget->IsPhony()) + cout<<"Building "<GetQuotedFullFileName()<<" because it does not exist yet\n"; } else if (TargetDate.IsOlder(m_sBuildTime)) { - cout<<"Building "<GetQuotedFullFileName()<<" because need to rebuild all (-a)\n"; + cout<<"Building "<GetQuotedFullFileName()<<" because need to rebuild all (-a)\n"; } } #endif @@ -1675,7 +1682,7 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool md5_starts( &ctx ); while (CommandIt!=Commands.end()) { - pMakefile->SetRuleThatIsBuild(Target); // Make sure that the command expension is correct + pMakefile->SetRuleThatIsBuild(pTarget); // Make sure that the command expension is correct string Command=pMakefile->ExpandExpression(*CommandIt); pMakefile->ClearRuleThatIsBuild(); /* Make sure that further expansion is not taking this rule into account.*/ md5_update( &ctx, (uint8 *)Command.c_str(), (unsigned long)Command.size()); @@ -1683,20 +1690,20 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool } uint32 Md5_32=md5_finish32( &ctx); - if (!Target->CompareMd5_32(Md5_32)) + if (!pTarget->CompareMd5_32(Md5_32)) { if (TargetDate.IsNewerOrSame(m_sBuildTime) || TargetDate.IsDir()) { // Only rebuild if it is not yet rebuild in this current run. This may happen for implicit rules that have multiple targets (implicit rules that build more then one target at the same time - Target->SetCommandsMd5_32(Md5_32); - pMakefile->AddTarget(Target); + pTarget->SetCommandsMd5_32(Md5_32); + pMakefile->AddTarget(pTarget); pMakefile->SetAutoDepsDirty(); /* We need to update the autodeps file if the md5 has been changed */ } else { #ifdef _DEBUG if (!g_GenProjectTree) - cout << "Md5 is different for " << Target->GetQuotedFullFileName() << " Old:"<GetCommandsMd5_32()<<", New: "<GetQuotedFullFileName() << " Old:"<GetCommandsMd5_32()<<", New: "< &Target,bool if (MakeTarget) { // Queue for execution -// Target->SetDate(YoungestDate); - if (sm_CommandQueue.QueueTarget(Target)) + if (sm_CommandQueue.QueueTarget(pTarget)) return mh_time_t(); - mh_time_t NewDate=Target->GetDate(); + mh_time_t NewDate=pTarget->GetDate(); if (NewDate.IsNewer(YoungestDate)) YoungestDate=NewDate; } @@ -1728,7 +1734,7 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool { for (int i=0; iGetQuotedFullFileName()<<" finished : "<< YoungestDate << endl; + cout<<"Building "<GetQuotedFullFileName()<<" finished : "<< YoungestDate << endl; } Indent--; if (g_CheckCircularDeps) @@ -1736,26 +1742,26 @@ mh_time_t mhmakefileparser::StartBuildTarget(const refptr &Target,bool m_TargetStack.pop_back(); } - if (!m_ImplicitSearch && !Target->Exists() && !Target->IsPhony() && !g_DoNotExecute && !g_GenProjectTree) + if (!m_ImplicitSearch && !pTarget->Exists() && !pTarget->IsPhony() && !g_DoNotExecute && !g_GenProjectTree) { // This is only a warning for phony messages - 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";; + 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 */ + pTarget->SetDate(YoungestDate); /* This is especially needed for phony targets in between real targets */ return YoungestDate; } /////////////////////////////////////////////////////////////////////////////// -mh_time_t mhmakefileparser::WaitBuildTarget(const refptr &Target) +mh_time_t mhmakefileparser::WaitBuildTarget(fileinfo* pTarget) { - return sm_CommandQueue.WaitForTarget(Target); + return sm_CommandQueue.WaitForTarget(pTarget); } /////////////////////////////////////////////////////////////////////////////// void mhmakefileparser::BuildIncludedMakefiles() { - vector< refptr >::iterator MakefileIt=m_IncludedMakefiles.begin(); + vector::iterator MakefileIt=m_IncludedMakefiles.begin(); while (MakefileIt!=m_IncludedMakefiles.end()) { #ifdef _DEBUG -- cgit v1.2.3