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/mhmake.kdevelop | 8 +- tools/mhmake/mhmake.sln | 9 ++ tools/mhmake/mhmake.vcxproj | 12 ++- tools/mhmake/mhmakevc10.sln | 9 ++ tools/mhmake/src/bison.cc | 2 +- tools/mhmake/src/bison.h | 2 +- tools/mhmake/src/build.cpp | 194 ++++++++++++++++++---------------- tools/mhmake/src/commandqueue.cpp | 18 ++-- tools/mhmake/src/commandqueue.h | 12 +-- tools/mhmake/src/curdir.cpp | 12 +-- tools/mhmake/src/curdir.h | 13 ++- tools/mhmake/src/fileinfo.cpp | 53 ++++++---- tools/mhmake/src/fileinfo.h | 98 ++++++++--------- tools/mhmake/src/flexskel.cc | 2 +- tools/mhmake/src/flexskel.h | 2 +- tools/mhmake/src/functions.cpp | 60 +++++------ tools/mhmake/src/md5.cpp | 2 +- tools/mhmake/src/md5.h | 2 +- tools/mhmake/src/mhmake.cpp | 10 +- tools/mhmake/src/mhmakefileparser.cpp | 192 +++++++++++++++++++++++---------- tools/mhmake/src/mhmakefileparser.h | 68 ++++++------ tools/mhmake/src/mhmakelexer.l | 61 ++++++++--- tools/mhmake/src/mhmakeparser.y | 21 ++-- tools/mhmake/src/refptr.h | 2 +- tools/mhmake/src/rule.cpp | 88 +++++++++------ tools/mhmake/src/rule.h | 11 +- tools/mhmake/src/stdafx.cpp | 2 +- tools/mhmake/src/stdafx.h | 2 +- tools/mhmake/src/util.cpp | 103 ++++++++++++++---- tools/mhmake/src/util.h | 13 +-- 30 files changed, 657 insertions(+), 426 deletions(-) diff --git a/tools/mhmake/mhmake.kdevelop b/tools/mhmake/mhmake.kdevelop index a271870fe..003b7032d 100644 --- a/tools/mhmake/mhmake.kdevelop +++ b/tools/mhmake/mhmake.kdevelop @@ -1,8 +1,8 @@ - Marc Haesen - hmca@telenet.be + marha + marc@hc-consult.be 1.1.12 KDevAutoProject C++ @@ -164,8 +164,8 @@ mhmake Mhmake MHMAKE - Marc Haesen - hmca@telenet.be + marha + marc@hc-consult.be Custom 0.1 2006 diff --git a/tools/mhmake/mhmake.sln b/tools/mhmake/mhmake.sln index 8c7fe9bc9..7121b8286 100644 --- a/tools/mhmake/mhmake.sln +++ b/tools/mhmake/mhmake.sln @@ -5,16 +5,25 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug|Win32.ActiveCfg = Debug|Win32 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug|Win32.Build.0 = Debug|Win32 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug|x64.ActiveCfg = Debug|x64 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug|x64.Build.0 = Debug|x64 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile|Win32.ActiveCfg = Profile|Win32 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile|Win32.Build.0 = Profile|Win32 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile|x64.ActiveCfg = Profile|x64 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile|x64.Build.0 = Profile|x64 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release|Win32.ActiveCfg = Release|Win32 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release|Win32.Build.0 = Release|Win32 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release|x64.ActiveCfg = Release|x64 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/tools/mhmake/mhmake.vcxproj b/tools/mhmake/mhmake.vcxproj index f5e8f2da3..8b7faed2c 100644 --- a/tools/mhmake/mhmake.vcxproj +++ b/tools/mhmake/mhmake.vcxproj @@ -114,6 +114,9 @@ $(Platform)\$(Configuration)\ false mhmake_dbg + mhmake_dbg + false + false @@ -130,7 +133,6 @@ .;src;$(OutDir);%(AdditionalIncludeDirectories) NDEBUG;WIN32;_CONSOLE;%(PreprocessorDefinitions) true - Async MultiThreaded false false @@ -158,6 +160,8 @@ MachineX86 + true + true @@ -296,8 +300,6 @@ .;src;$(OutDir);%(AdditionalIncludeDirectories) NDEBUG;WIN32;_CONSOLE;%(PreprocessorDefinitions) true - - MultiThreadedDLL false false @@ -311,13 +313,13 @@ ProgramDatabase FastCall Default + 4996;%(DisableSpecificWarnings) NDEBUG;%(PreprocessorDefinitions) 0x0409 - $(Configuration)/mhmake.exe true true $(OutDir)$(ProjectName).pdb @@ -329,6 +331,8 @@ MachineX86 + true + true diff --git a/tools/mhmake/mhmakevc10.sln b/tools/mhmake/mhmakevc10.sln index 142a822cc..aa927ed5f 100644 --- a/tools/mhmake/mhmakevc10.sln +++ b/tools/mhmake/mhmakevc10.sln @@ -5,16 +5,25 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Profile|Win32 = Profile|Win32 + Profile|x64 = Profile|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug|Win32.ActiveCfg = Debug|Win32 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug|Win32.Build.0 = Debug|Win32 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug|x64.ActiveCfg = Debug|x64 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug|x64.Build.0 = Debug|x64 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile|Win32.ActiveCfg = Profile|Win32 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile|Win32.Build.0 = Profile|Win32 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile|x64.ActiveCfg = Profile|x64 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile|x64.Build.0 = Profile|x64 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release|Win32.ActiveCfg = Release|Win32 {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release|Win32.Build.0 = Release|Win32 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release|x64.ActiveCfg = Release|x64 + {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/tools/mhmake/src/bison.cc b/tools/mhmake/src/bison.cc index e0315efd4..5a203f719 100644 --- a/tools/mhmake/src/bison.cc +++ b/tools/mhmake/src/bison.cc @@ -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 diff --git a/tools/mhmake/src/bison.h b/tools/mhmake/src/bison.h index ac5c56bf2..0724ae112 100644 --- a/tools/mhmake/src/bison.h +++ b/tools/mhmake/src/bison.h @@ -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 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 diff --git a/tools/mhmake/src/commandqueue.cpp b/tools/mhmake/src/commandqueue.cpp index c09f505d7..fca26f997 100644 --- a/tools/mhmake/src/commandqueue.cpp +++ b/tools/mhmake/src/commandqueue.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 @@ -114,7 +114,7 @@ void commandqueue::SetNrParallelBuilds(unsigned NrParallelBuilds) void commandqueue::ThrowCommandExecutionError(refptr pActiveEntry) { - refptr pTarget=pActiveEntry->pTarget; + fileinfo* pTarget=pActiveEntry->pTarget; const string &Command=pActiveEntry->Command; mhmakeparser *pMakefile=pTarget->GetRule()->GetMakefile(); @@ -166,7 +166,7 @@ void commandqueue::RemoveActiveEntry(unsigned Entry) upon return */ bool commandqueue::StartExecuteNextCommand(refptr pActiveEntry, mh_pid_t *pActiveProcess) { - refptr pTarget=pActiveEntry->pTarget; + fileinfo* pTarget=pActiveEntry->pTarget; mhmakeparser *pMakefile=pTarget->GetRule()->GetMakefile(); pMakefile->SetRuleThatIsBuild(pTarget); // Make sure that the command expension is correct @@ -208,7 +208,7 @@ bool commandqueue::StartExecuteNextCommand(refptr pActiveEntry, mh_ void commandqueue::TargetBuildFinished(refptr pActiveEntry) { - refptr pTarget=pActiveEntry->pTarget; + fileinfo* pTarget=pActiveEntry->pTarget; // Building of this target finished uint32 Md5_32=md5_finish32( &pActiveEntry->md5ctx); @@ -246,7 +246,7 @@ void commandqueue::TargetBuildFinished(refptr pActiveEntry) /* Start executing the commands of a target */ -bool commandqueue::StartExecuteCommands(const refptr &pTarget) +bool commandqueue::StartExecuteCommands(fileinfo* pTarget) { cout << "Building " << pTarget->GetQuotedFullFileName()< &pTarget) /* put the target in the execution queue or start executing immediately */ -bool commandqueue::QueueTarget(const refptr &pTarget) +bool commandqueue::QueueTarget(fileinfo* pTarget) { pTarget->SetBuilding(); // First check if there is place in the active entries @@ -306,7 +306,7 @@ bool commandqueue::QueueTarget(const refptr &pTarget) /* Wait for all the commands being executed of a target. In the mean time also continue executing all other commands in the queue */ -mh_time_t commandqueue::WaitForTarget(const refptr &pTarget) +mh_time_t commandqueue::WaitForTarget(fileinfo *pTarget) { if (!pTarget->IsBuilding()) return pTarget->GetDate(); @@ -331,7 +331,7 @@ mh_time_t commandqueue::WaitForTarget(const refptr &pTarget) throw("fatal error: unexpected return value of WaitForMultipleObjects " + stringify(Ret)); #endif refptr pActiveEntry=m_pActiveEntries[Ret]; - refptr pCurrentTarget=pActiveEntry->pTarget; + fileinfo* pCurrentTarget=pActiveEntry->pTarget; refptr pRule=pCurrentTarget->GetRule(); // First check the error code of the command @@ -391,7 +391,7 @@ mh_time_t commandqueue::WaitForTarget(const refptr &pTarget) } else { - refptr pNewTarget=m_Queue.front(); + fileinfo* pNewTarget=m_Queue.front(); m_Queue.pop(); if (StartExecuteCommands(pNewTarget)) { diff --git a/tools/mhmake/src/commandqueue.h b/tools/mhmake/src/commandqueue.h index d29057443..8b327be8c 100644 --- a/tools/mhmake/src/commandqueue.h +++ b/tools/mhmake/src/commandqueue.h @@ -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 @@ -33,14 +33,14 @@ class commandqueue { struct activeentry : public refbase { - refptr pTarget; + fileinfo* pTarget; vector::const_iterator CurrentCommandIt; string Command; md5_context md5ctx; bool IgnoreError; }; private: - queue< refptr > m_Queue; + queue m_Queue; unsigned m_MaxNrCommandsInParallel; mh_pid_t *m_pActiveProcesses; refptr *m_pActiveEntries; @@ -56,7 +56,7 @@ private: { RemoveActiveEntry(GetActiveEntryId(pActiveEntry)); } - bool StartExecuteCommands(const refptr &pTarget); + bool StartExecuteCommands(fileinfo *pTarget); bool StartExecuteNextCommand(refptr pActiveEntry, mh_pid_t *pActiveProcess); void TargetBuildFinished(refptr pActiveEntry); @@ -64,8 +64,8 @@ public: commandqueue(); ~commandqueue(); - bool QueueTarget(const refptr &pTarget); // Returns true if target has been queued, false when commands are executed upon return - mh_time_t WaitForTarget(const refptr &pTarget); + bool QueueTarget(fileinfo *pTarget); // Returns true if target has been queued, false when commands are executed upon return + mh_time_t WaitForTarget(fileinfo *pTarget); void SetNrParallelBuilds(unsigned NrParallelBuilds); }; diff --git a/tools/mhmake/src/curdir.cpp b/tools/mhmake/src/curdir.cpp index 094093a9b..4b905a327 100644 --- a/tools/mhmake/src/curdir.cpp +++ b/tools/mhmake/src/curdir.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 @@ -24,20 +24,14 @@ #include "curdir.h" #include "util.h" -set,less_refptrfileinfo> g_FileInfos; // declare here since it is important that it is constructed before m_pcurrentdir +fileinfos g_FileInfos; // declare here since it is important that it is constructed before m_pcurrentdir curdir::initcurdir curdir::m_pCurrentDir; -/////////////////////////////////////////////////////////////////////////////// -curdir::initcurdir &curdir::initcurdir::operator=(const refptr& Src) -{ - return (curdir::initcurdir&)refptr::operator=(Src); -} - /////////////////////////////////////////////////////////////////////////////// curdir::initcurdir::initcurdir() { char CurDir[MAX_PATH]; getcwd(CurDir,MAX_PATH); string strCurDir=CurDir; - *this=GetAbsFileInfo(NormalizePathName(strCurDir)); + m_pDir=GetAbsFileInfo(NormalizePathName(strCurDir)); } diff --git a/tools/mhmake/src/curdir.h b/tools/mhmake/src/curdir.h index 169dca8a7..56f835fbe 100644 --- a/tools/mhmake/src/curdir.h +++ b/tools/mhmake/src/curdir.h @@ -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 @@ -21,26 +21,25 @@ #ifndef __CURDIR_H #define __CURDIR_H -#include "refptr.h" class fileinfo; class curdir { public: - class initcurdir : public refptr + class initcurdir { + friend curdir; + const fileinfo *m_pDir; public: - initcurdir &operator=(const refptr& Src); - initcurdir(); }; private: static initcurdir m_pCurrentDir; public: - static refptr &GetCurDir() + static const fileinfo* GetCurDir() { - return m_pCurrentDir; + return m_pCurrentDir.m_pDir; } }; diff --git a/tools/mhmake/src/fileinfo.cpp b/tools/mhmake/src/fileinfo.cpp index d63724882..7174c49a4 100644 --- a/tools/mhmake/src/fileinfo.cpp +++ b/tools/mhmake/src/fileinfo.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 @@ -29,9 +29,6 @@ #define S_ISDIR(val) ((val)&_S_IFDIR) #endif -const string NullString; -refptr NullFileInfo; - /////////////////////////////////////////////////////////////////////////////// string QuoteFileName(const string &Filename) { @@ -78,7 +75,7 @@ string UnquoteFileName(const string &Filename) } /////////////////////////////////////////////////////////////////////////////// -refptr fileinfo::GetDir() const +fileinfo* fileinfo::GetDir() const { return GetAbsFileInfo(m_AbsFileName.substr(0,m_AbsFileName.find_last_of(OSPATHSEP))); } @@ -90,15 +87,15 @@ string fileinfo::GetName() const } /////////////////////////////////////////////////////////////////////////////// -mh_time_t fileinfo::realGetDate() +mh_time_t fileinfo::realGetDate() const { struct stat Buf; if (-1==stat(m_AbsFileName.c_str(),&Buf)) - m_Date.SetNotExist(); + ((fileinfo*)this)->m_Date.SetNotExist(); else if (S_ISDIR(Buf.st_mode)) - m_Date.SetDir(); + ((fileinfo*)this)->m_Date.SetDir(); else - m_Date=Buf.st_mtime; + ((fileinfo*)this)->m_Date=Buf.st_mtime; return m_Date; } @@ -145,7 +142,7 @@ 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 >::const_iterator DepIt=m_Deps.begin(); + vector::const_iterator DepIt=m_Deps.begin(); deps_t Deps; bool first=true; string Ret=g_EmptyString; @@ -171,10 +168,10 @@ string fileinfo::GetPrerequisits() const } /////////////////////////////////////////////////////////////////////////////// -void fileinfo::AddDeps(vector< refptr > &Deps) +void fileinfo::AddDeps(vector &Deps) { - vector< refptr >::iterator It=Deps.begin(); - vector< refptr >::iterator ItEnd=Deps.end(); + vector::iterator It=Deps.begin(); + vector::iterator ItEnd=Deps.end(); while (It!=ItEnd) { AddDep(*It++); @@ -293,7 +290,7 @@ string &NormalizePathName(string &Name) /////////////////////////////////////////////////////////////////////////////// -const refptr &GetFileInfo(const string &NameIn,const refptr &RelDir) +fileinfo* GetFileInfo(const string &NameIn,const fileinfo* pRelDir) { string Name=UnquoteFileName(NameIn); bool DoesExist=true; @@ -305,36 +302,36 @@ const refptr &GetFileInfo(const string &NameIn,const refptr { if (Name[0]!=OSPATHSEP) { - Name=RelDir->GetFullFileName()+OSPATHSEPSTR+Name; - if (!RelDir->Exists()) /* if the directory does not exist, the file will not exist either */ + Name=pRelDir->GetFullFileName()+OSPATHSEPSTR+Name; + if (!pRelDir->Exists()) /* if the directory does not exist, the file will not exist either */ DoesExist=false; } #ifdef WIN32 else { /* The filename is absolute but does not contain a driver letter. So add it (only on windows) */ - Name=RelDir->GetFullFileName().substr(0,2)+Name; + Name=pRelDir->GetFullFileName().substr(0,2)+Name; } #endif } - const refptr &Ret=GetAbsFileInfo(NormalizePathName(Name)); + fileinfo* pRet=GetAbsFileInfo(NormalizePathName(Name)); if (!DoesExist) - Ret->SetNotExist(); - return Ret; + pRet->SetNotExist(); + return pRet; } #ifdef _DEBUG /////////////////////////////////////////////////////////////////////////////// void PrintFileInfos() { - set,less_refptrfileinfo>::iterator pIt=g_FileInfos.begin(); + fileinfos::iterator pIt=g_FileInfos.begin(); while (pIt!=g_FileInfos.end()) { cout<<(*pIt)->GetQuotedFullFileName()<<" :"; if ((*pIt)->IsPhony()) cout<<" (phony)"; - vector< refptr > &Deps=(*pIt)->GetDeps(); - vector< refptr >::iterator pDepIt=Deps.begin(); + vector &Deps=(*pIt)->GetDeps(); + vector::iterator pDepIt=Deps.begin(); while (pDepIt!=Deps.end()) { cout<GetQuotedFullFileName(); @@ -354,3 +351,13 @@ void PrintFileInfos() } #endif +/////////////////////////////////////////////////////////////////////////////// +fileinfos::~fileinfos() +{ + fileinfos::iterator It=begin(); + while (It!=end()) + { + delete (*It); + It++; + } +} diff --git a/tools/mhmake/src/fileinfo.h b/tools/mhmake/src/fileinfo.h index 3c7917be3..8d58a1efa 100644 --- a/tools/mhmake/src/fileinfo.h +++ b/tools/mhmake/src/fileinfo.h @@ -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 @@ -130,22 +130,21 @@ inline ostream& operator<<(ostream& out,const mh_time &Src) return out; } -class fileinfo : public refbase +class fileinfo { string m_AbsFileName; bool m_IsPhony; int m_BuildStatus; /* Bit 0 means the target built is started, Bit 1 means the target is still building */ refptr m_pRule; mhmakeparser *m_pAutoDepsMakefile; - vector< refptr > m_Deps; + vector m_Deps; mh_time_t m_Date; uint32 m_CommandsMd5_32; // 32-bit Md5 checksum of commands to build this target fileinfo(const fileinfo &Src); fileinfo(void); -public: - fileinfo(const string &AbsFileName,uint32 Md5_32) + void init(const string &AbsFileName,uint32 Md5_32) { m_IsPhony=false; m_pAutoDepsMakefile=NULL; @@ -158,9 +157,15 @@ public: cout << "Initialising Md5 of "< GetDir(void) const; + fileinfo* GetDir(void) const; string GetName() const; bool IsDir() const; @@ -241,28 +238,28 @@ public: } } - refptr GetRule(void) + refptr GetRule(void) const { return m_pRule; } - void AddDep(const refptr &Dep) + void AddDep(fileinfo *pDep) { - if (&*Dep==this) + if (&*pDep==this) { #ifdef _DEBUG cout << GetQuotedFullFileName()<<" is directly dependent on itself\n"; #endif return; } - m_Deps.push_back(Dep); + m_Deps.push_back(pDep); } - void AddDeps(vector< refptr > &Deps); + void AddDeps(vector &Deps); - void InsertDeps(vector< refptr > &Deps) + void InsertDeps(vector &Deps) { - vector< refptr > NewDeps; - vector< refptr >::const_iterator It=Deps.begin(); - vector< refptr >::const_iterator ItEnd=Deps.end(); + vector NewDeps; + vector::const_iterator It=Deps.begin(); + vector::const_iterator ItEnd=Deps.end(); while (It!=ItEnd) { if (&**It==this) @@ -278,18 +275,18 @@ public: if (NewDeps.size()) m_Deps.insert(m_Deps.begin(),NewDeps.begin(),NewDeps.end()); } - void AddMainDep(refptr &MainDep) + void AddMainDep(fileinfo* pMainDep) { - if (&*MainDep==this) + if (&*pMainDep==this) { #ifdef _DEBUG cout << GetQuotedFullFileName()<<" is directly dependent on itself\n"; #endif return; } - m_Deps.insert(m_Deps.begin(),MainDep); + m_Deps.insert(m_Deps.begin(),pMainDep); } - vector< refptr > &GetDeps(void) + vector &GetDeps(void) { return m_Deps; } @@ -311,11 +308,11 @@ public: m_IsPhony=true; m_Date.SetNotExist(); // This will sure that this target will always be build (even if a corresponding file exists) } - bool IsPhony(void) + bool IsPhony(void) const { return m_IsPhony; } - mh_time_t realGetDate(void); + mh_time_t realGetDate(void) const; void SetDateToNow(void); void SetDate(mh_time_t Date) @@ -332,7 +329,7 @@ public: m_Date.Invalidate(); } - mh_time_t GetDate(void) + mh_time_t GetDate(void) const { if (m_Date.IsDateValid()) return m_Date; @@ -343,7 +340,7 @@ public: { // this is used to make sure that this item is rebuild, even if it really exists m_Date.SetNotExist(); } - bool Exists(void) + bool Exists(void) const { return GetDate().DoesExist(); } @@ -402,14 +399,6 @@ public: } }; -struct less_refptrfileinfo : public binary_function , refptr, bool> -{ - bool operator()(const refptr& _Left, const refptr& _Right) const - { - return less().operator ()(_Left->GetFullFileName(),_Right->GetFullFileName()); - } -}; - struct less_fileinfo : public binary_function { bool operator()(const fileinfo *_Left, const fileinfo *_Right) const @@ -418,31 +407,34 @@ struct less_fileinfo : public binary_function NullFileInfo; +fileinfo *GetFileInfo(const string &szName,const fileinfo* pRelDir); -const refptr &GetFileInfo(const string &szName,const refptr &pRelDir); +class fileinfos : public set +{ + public: + ~fileinfos(); +}; -extern set,less_refptrfileinfo > g_FileInfos; +extern fileinfos g_FileInfos; -inline const refptr &GetAbsFileInfo(const string &strAbsName) +inline fileinfo *GetAbsFileInfo(const string &strAbsName) { - static refptr SearchFileInfo(new fileinfo("")); - SearchFileInfo->SetFullFileName(strAbsName); + static fileinfo SearchFileInfo(""); + SearchFileInfo.SetFullFileName(strAbsName); /* Using find is just an optimalisation, you could use insert immediately */ - set,less_refptrfileinfo >::const_iterator pFind=g_FileInfos.find(SearchFileInfo); + fileinfos::const_iterator pFind=g_FileInfos.find(&SearchFileInfo); if (pFind==g_FileInfos.end()) { - pair ,less_refptrfileinfo >::iterator, bool> pPair=g_FileInfos.insert(new fileinfo(SearchFileInfo->GetFullFileName())); + pair pPair=g_FileInfos.insert(new fileinfo(SearchFileInfo.GetFullFileName())); return *(pPair.first); } else return *pFind; } -inline const refptr &GetFileInfo(const char *szName,const refptr &RelDir) +inline fileinfo *GetFileInfo(const char *szName,const fileinfo* pRelDir) { - return GetFileInfo(string(szName),RelDir); + return GetFileInfo(string(szName),pRelDir); } string &NormalizePathName(string &Name); diff --git a/tools/mhmake/src/flexskel.cc b/tools/mhmake/src/flexskel.cc index a08f23fd3..e83775372 100644 --- a/tools/mhmake/src/flexskel.cc +++ b/tools/mhmake/src/flexskel.cc @@ -1,6 +1,6 @@ /* This file is part of mhmake. * - * Copyright (C) 2001-2009 Marc Haesen + * Copyright (C) 2001-2010 marha_at_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 diff --git a/tools/mhmake/src/flexskel.h b/tools/mhmake/src/flexskel.h index 563e469c7..69d0eeeb4 100644 --- a/tools/mhmake/src/flexskel.h +++ b/tools/mhmake/src/flexskel.h @@ -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 diff --git a/tools/mhmake/src/functions.cpp b/tools/mhmake/src/functions.cpp index b1a5f7a46..97dc99c01 100644 --- a/tools/mhmake/src/functions.cpp +++ b/tools/mhmake/src/functions.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 @@ -351,45 +351,45 @@ string mhmakefileparser::f_firstword(const string & Arg) const /////////////////////////////////////////////////////////////////////////////// string mhmakefileparser::f_wildcard(const string & Arg) const { - refptr FileSpec=GetFileInfo(TrimString(Arg),m_MakeDir); /* Use GetFileInfo to make the relative path absolute */ - refptr Dir=FileSpec->GetDir(); + fileinfo *pFileSpec=GetFileInfo(TrimString(Arg),m_MakeDir); /* Use GetFileInfo to make the relative path absolute */ + fileinfo *pDir=pFileSpec->GetDir(); #ifdef WIN32 struct _finddata_t FileInfo; - intptr_t hFile=_findfirst(FileSpec->GetFullFileName().c_str(),&FileInfo); + intptr_t hFile=_findfirst(pFileSpec->GetFullFileName().c_str(),&FileInfo); if (hFile==-1) return g_EmptyString; string Ret=g_EmptyString; /* We have to verify with percentmatch since the find functions *.ext also matches the functions *.extbrol */ - string CheckSpec=FileSpec->GetName(); - if (PercentMatch(FileInfo.name,CheckSpec,NULL,'*')) + string CheckSpec=pFileSpec->GetName(); + if (PercentMatchNoCase(FileInfo.name,CheckSpec,NULL,'*')) { - Ret=GetFileInfo(FileInfo.name,Dir)->GetQuotedFullFileName(); + Ret=GetFileInfo(FileInfo.name,pDir)->GetQuotedFullFileName(); } while (-1!=_findnext(hFile,&FileInfo)) { - if (PercentMatch(FileInfo.name,CheckSpec,NULL,'*')) + if (PercentMatchNoCase(FileInfo.name,CheckSpec,NULL,'*')) { Ret+=g_SpaceString; - Ret+=GetFileInfo(FileInfo.name,Dir)->GetQuotedFullFileName(); + Ret+=GetFileInfo(FileInfo.name,pDir)->GetQuotedFullFileName(); } } _findclose(hFile); #else glob_t Res; - if (glob (FileSpec->GetFullFileName().c_str(), GLOB_ERR|GLOB_NOSORT|GLOB_MARK, NULL, &Res)) + if (glob (pFileSpec->GetFullFileName().c_str(), GLOB_ERR|GLOB_NOSORT|GLOB_MARK, NULL, &Res)) return g_EmptyString; string Ret=g_EmptyString; string SepStr=g_EmptyString; - string CheckSpec=FileSpec->GetName(); + string CheckSpec=pFileSpec->GetName(); for (int i=0; iGetQuotedFullFileName(); + Ret+=GetFileInfo(Res.gl_pathv[i],pDir)->GetQuotedFullFileName(); SepStr=g_SpaceString; } } @@ -403,7 +403,7 @@ string mhmakefileparser::f_wildcard(const string & Arg) const string mhmakefileparser::f_exist(const string & Arg) const { string File=TrimString(Arg); - refptr pFile=GetFileInfo(File,m_MakeDir); + fileinfo *pFile=GetFileInfo(File,m_MakeDir); if (pFile->Exists()) { return string("1"); @@ -427,7 +427,7 @@ string mhmakefileparser::f_filesindirs(const string & Arg) const string strDirs; NextCharItem(pTmp,strDirs,','); - vector< refptr > Dirs; + vector Dirs; SplitToItems(strDirs,Dirs); pTmp=strFiles.c_str(); @@ -436,11 +436,11 @@ string mhmakefileparser::f_filesindirs(const string & Arg) const while (*pTmp) { string File; - refptr pFile; + fileinfo *pFile; pTmp=NextItem(pTmp,File); - vector< refptr >::iterator It=Dirs.begin(); - vector< refptr >::iterator ItEnd=Dirs.end(); + vector::iterator It=Dirs.begin(); + vector::iterator ItEnd=Dirs.end(); while (It!=ItEnd) { pFile=GetFileInfo(File,*It++); @@ -448,7 +448,7 @@ string mhmakefileparser::f_filesindirs(const string & Arg) const { break; } - pFile=NullFileInfo; + pFile=NULL; } if (!pFile) continue; @@ -471,7 +471,7 @@ string mhmakefileparser::f_filesindirs(const string & Arg) const string mhmakefileparser::f_fullname(const string & Arg) const { string File=TrimString(Arg); - refptr pFile=GetFileInfo(File,m_MakeDir); + fileinfo *pFile=GetFileInfo(File,m_MakeDir); return pFile->GetQuotedFullFileName(); } @@ -674,26 +674,26 @@ string mhmakefileparser::f_shell(const string & Command) const /////////////////////////////////////////////////////////////////////////////// static string relpath(const string &FileName,void *pvDir) { - const refptr pDir=*(const refptr *)pvDir; - refptr Path=GetFileInfo(FileName,pDir); + const fileinfo *pDir=*(const fileinfo **)pvDir; + const fileinfo *pPath=GetFileInfo(FileName,pDir); const char *pCur=pDir->GetFullFileName().c_str(); - const char *pPath=Path->GetFullFileName().c_str(); + const char *pszPath=pPath->GetFullFileName().c_str(); - const char *pLast=pPath; - while (*pCur==*pPath) + const char *pLast=pszPath; + while (*pCur==*pszPath) { - char Char=*pPath; + char Char=*pszPath; if (!Char) { return "."; // Means that FileName is the same as the current directory } if (Char==OSPATHSEP) - pLast=pPath+1; + pLast=pszPath+1; pCur++; - pPath++; + pszPath++; } - if (*pPath==OSPATHSEP && !*pCur) - pLast=pPath+1; + if (*pszPath==OSPATHSEP && !*pCur) + pLast=pszPath+1; string retPath; if (*pCur==OSPATHSEP) { bool first=true; @@ -705,7 +705,7 @@ static string relpath(const string &FileName,void *pvDir) retPath+=OSPATHSEPSTR".."; pCur++; } - if (pPath) + if (pszPath) retPath=retPath+OSPATHSEPSTR+pLast; } else diff --git a/tools/mhmake/src/md5.cpp b/tools/mhmake/src/md5.cpp index 908f28134..0ffba0d48 100644 --- a/tools/mhmake/src/md5.cpp +++ b/tools/mhmake/src/md5.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 diff --git a/tools/mhmake/src/md5.h b/tools/mhmake/src/md5.h index d2e3ef62f..f16c9bd19 100644 --- a/tools/mhmake/src/md5.h +++ b/tools/mhmake/src/md5.h @@ -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 diff --git a/tools/mhmake/src/mhmake.cpp b/tools/mhmake/src/mhmake.cpp index db9a13682..6d99e5f3d 100644 --- a/tools/mhmake/src/mhmake.cpp +++ b/tools/mhmake/src/mhmake.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 @@ -120,17 +120,17 @@ int __CDECL main(int argc, char* argv[]) { g_Clean=true; } - refptr pTarget=GetFileInfo(*It,pFirstMakefile->m_MakeDir); + fileinfo *pTarget=GetFileInfo(*It,pFirstMakefile->m_MakeDir); pFirstMakefile->m_pParser->BuildTarget(pTarget); It++; } } else { - refptr FirstTarget=pFirstMakefile->m_pParser->GetFirstTarget(); - if (FirstTarget) + fileinfo *pFirstTarget=pFirstMakefile->m_pParser->GetFirstTarget(); + if (pFirstTarget) { - pFirstMakefile->m_pParser->BuildTarget(FirstTarget); + pFirstMakefile->m_pParser->BuildTarget(pFirstTarget); } else cout << "Warning: no targets in makefile. Nothing to be build.\nMHMAKECONF defined?\n"; diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp index 8c75f78f7..3d074e801 100644 --- a/tools/mhmake/src/mhmakefileparser.cpp +++ b/tools/mhmake/src/mhmakefileparser.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 @@ -42,7 +42,7 @@ void mhmakefileparser::yyerror(const char *m) } /////////////////////////////////////////////////////////////////////////////// -int mhmakefileparser::ParseFile(const refptr &FileInfo, refptr &pMakeDir) +int mhmakefileparser::ParseFile(const fileinfo *pFileInfo, const fileinfo *pMakeDir) { mhmakelexer theLexer; m_ptheLexer=&theLexer; @@ -51,12 +51,12 @@ int mhmakefileparser::ParseFile(const refptr &FileInfo, refptrGetQuotedFullFileName(); } - theLexer.m_InputFileName=FileInfo->GetFullFileName(); + theLexer.m_InputFileName=pFileInfo->GetFullFileName(); theLexer.m_pParser=(mhmakeparser*)this; - theLexer.yyin=::fopen(FileInfo->GetFullFileName().c_str(),"r"); + theLexer.yyin=::fopen(pFileInfo->GetFullFileName().c_str(),"r"); if (!theLexer.yyin) { - cerr << "Error opening makefile: "<GetQuotedFullFileName()<GetQuotedFullFileName()< > &Items) const +void mhmakefileparser::SplitToItems(const string &String,vector &Items) const { const char *pTmp=String.c_str(); while (*pTmp) @@ -453,7 +453,7 @@ void mhmakefileparser::PrintVariables(bool Expand) const /////////////////////////////////////////////////////////////////////////////// void mhmakefileparser::AddRule() { - vector< refptr >::iterator pIt=m_pCurrentItems->begin(); + fileinfoarray::iterator pIt=m_pCurrentItems->begin(); while (pIt!=m_pCurrentItems->end()) { if ((*pIt)->GetFullFileName().find('%')!=string::npos) @@ -484,10 +484,10 @@ void mhmakefileparser::AddRule() } /////////////////////////////////////////////////////////////////////////////// -void mhmakefileparser::GetAutoDeps(const refptr &FirstDep, deps_t &Autodeps) +void mhmakefileparser::GetAutoDeps(const fileinfo *pFirstDep, deps_t &Autodeps) { /* Here we have to scan only c/c++ headers so skip certain extensions */ - const char *pFullName=FirstDep->GetFullFileName().c_str(); + const char *pFullName=pFirstDep->GetFullFileName().c_str(); const char *pExt=strrchr(pFullName,'.'); bool bPython=false; if (pExt) @@ -574,7 +574,7 @@ void mhmakefileparser::GetAutoDeps(const refptr &FirstDep, deps_t &Aut #endif if (Type[0]=='"') { - refptr pInclude=GetFileInfo(IncludeFile,FirstDep->GetDir()); + fileinfo *pInclude=GetFileInfo(IncludeFile,pFirstDep->GetDir()); /* Add the dependency when the file alrady exist or there is a rule available to be build */ mh_time_t Date=BuildTarget(pInclude); if (Date.DoesExist()) // Try to build the target, and add it if it exists after building @@ -588,10 +588,10 @@ void mhmakefileparser::GetAutoDeps(const refptr &FirstDep, deps_t &Aut } } const refptr IncludeDirs=GetIncludeDirs(); - vector< refptr >::const_iterator It=IncludeDirs->begin(); + fileinfoarray::const_iterator It=IncludeDirs->begin(); while (Itend()) { - refptr pInclude=GetFileInfo(IncludeFile,*It); + fileinfo *pInclude=GetFileInfo(IncludeFile,*It); mh_time_t Date=BuildTarget(pInclude); if (Date.DoesExist()) // Try to build the target, and add it if it exists after building { @@ -618,20 +618,20 @@ void mhmakefileparser::GetAutoDeps(const refptr &FirstDep, deps_t &Aut /////////////////////////////////////////////////////////////////////////////// -void mhmakefileparser::GetAutoDepsIfNeeded(const refptr &Target, const refptr&FirstDep) +void mhmakefileparser::GetAutoDepsIfNeeded(fileinfo *pTarget, const fileinfo *pFirstDep) { - autodeps_entry_t &Autodeps=m_AutoDeps[Target]; + autodeps_entry_t &Autodeps=m_AutoDeps[pTarget]; if (!Autodeps.first) { Autodeps.first=true; /* We are going to rescan, so throw away the old. */ Autodeps.second.clear(); - GetAutoDeps(FirstDep,Autodeps.second); + GetAutoDeps(pFirstDep,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); + pTarget->AddDep(*It); It++; } } @@ -639,31 +639,31 @@ void mhmakefileparser::GetAutoDepsIfNeeded(const refptr &Target, const /////////////////////////////////////////////////////////////////////////////// -void mhmakefileparser::UpdateAutomaticDependencies(const refptr &Target) +void mhmakefileparser::UpdateAutomaticDependencies(fileinfo *pTarget) { - if (Target->IsAutoDepExtention()) + if (pTarget->IsAutoDepExtention()) { // we have to search for the include files in the first dependency of Target - vector< refptr > &Deps=Target->GetDeps(); + vector &Deps=pTarget->GetDeps(); if (!Deps.size()) return; // There is no first dep - refptr FirstDep=Deps[0]; - GetAutoDepsIfNeeded(Target,FirstDep); + fileinfo *pFirstDep=Deps[0]; + GetAutoDepsIfNeeded(pTarget,pFirstDep); SetAutoDepsDirty(); } } /////////////////////////////////////////////////////////////////////////////// -void mhmakefileparser::UpdateNoRuleAutomaticDependencies(const refptr &Target) +void mhmakefileparser::UpdateNoRuleAutomaticDependencies(fileinfo *pTarget) { // we have to search for the include files in the Target - set< refptr > Autodeps; - GetAutoDeps(Target,Autodeps); + deps_t Autodeps; + GetAutoDeps(pTarget,Autodeps); // Now add these dependencies also to the rules - set< refptr >::iterator It=Autodeps.begin(); + deps_t::iterator It=Autodeps.begin(); while (It!=Autodeps.end()) { - Target->AddDep(*It); + pTarget->AddDep(*It); It++; } } @@ -683,7 +683,7 @@ const refptr mhmakefileparser::GetIncludeDirs() const { string Item; pTmp=NextItem(pTmp,Item); - refptr pIncDir=GetFileInfo(Item,m_MakeDir); + fileinfo *pIncDir=GetFileInfo(Item,m_MakeDir); if (pIncDir->Exists() || pIncDir->GetRule()) ((mhmakefileparser*)this)->m_pIncludeDirs->push_back(pIncDir); } @@ -712,25 +712,25 @@ static void ReadStr(FILE *pFile,char *Str) Str[i]='\0'; } -void mhmakefileparser::LoadAutoDepsFile(refptr &DepFile) +void mhmakefileparser::LoadAutoDepsFile(fileinfo *pDepFile) { - if (m_AutoDepFileLoaded && m_AutoDepFileLoaded==DepFile) + if (m_AutoDepFileLoaded && m_AutoDepFileLoaded==pDepFile) return; /* This autodep file is already loaded. */ - m_AutoDepFileLoaded=DepFile; + m_AutoDepFileLoaded=pDepFile; - FILE *pIn=fopen(DepFile->GetFullFileName().c_str(),"rb"); + FILE *pIn=fopen(pDepFile->GetFullFileName().c_str(),"rb"); #ifdef _DEBUG if (!pIn) { - cerr << "Error opening autodep file "<GetQuotedFullFileName()<GetQuotedFullFileName()<GetQuotedFullFileName()<<": "<GetQuotedFullFileName()<<": "< &DepFile) ReadStr(pIn,FileName); while (FileName[0]) { - refptr Target=GetFileInfo(FileName,m_MakeDir); - autodeps_entry_t &Autodeps=m_AutoDeps[Target]; + fileinfo *pTarget=GetFileInfo(FileName,m_MakeDir); + autodeps_entry_t &Autodeps=m_AutoDeps[pTarget]; ReadStr(pIn,FileName); while (FileName[0]) { if (!g_ForceAutoDepRescan) /* If we are forcing the autodepscan we do not have to load the dependencies. */ { - refptr Dep=GetFileInfo(FileName,m_MakeDir); - Autodeps.second.insert(Dep); - Target->AddDep(Dep); + fileinfo *pDep=GetFileInfo(FileName,m_MakeDir); + Autodeps.second.insert(pDep); + pTarget->AddDep(pDep); } ReadStr(pIn,FileName); } @@ -761,20 +761,23 @@ void mhmakefileparser::LoadAutoDepsFile(refptr &DepFile) while (fread(&Md5_32,sizeof(Md5_32),1,pIn)) { ReadStr(pIn,FileName); - pair ,less_refptrfileinfo >::iterator, bool> pPair=g_FileInfos.insert(new fileinfo(FileName,Md5_32)); - if (!pPair.second) + + fileinfo *pTarget=GetAbsFileInfo(FileName); + + if (!pTarget->CompareMd5_32(0) && !pTarget->CompareMd5_32(Md5_32)) { - if (!(*pPair.first)->CompareMd5_32(Md5_32) && !(*pPair.first)->CompareMd5_32(0)) MakeNotDirty=false; /* BuildTarget had set the dirty flag, but since the md5 did not change it was a false dirty. This is for BuildTargets called before this routine */ #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)->GetQuotedFullFileName()<<" Old: "<GetCommandsMd5_32()<<" New: "<GetQuotedFullFileName()<<" to "<GetQuotedFullFileName()<<" Old: "<GetCommandsMd5_32()<<" New: "<SetCommandsMd5_32(Md5_32); // If it was already there, just update the md5 value } - AddTarget(*pPair.first); + #ifdef _DEBUG + if (g_PrintAdditionalInfo) + cout << "Setting Md5 for Target "<GetQuotedFullFileName()<<" to "<SetCommandsMd5_32(Md5_32); // If it was already there, just update the md5 value + + AddTarget(pTarget); } if (MakeNotDirty) ClearAutoDepsDirty(); @@ -782,16 +785,16 @@ void mhmakefileparser::LoadAutoDepsFile(refptr &DepFile) fclose(pIn); } -static void MakeDirs(const refptr & Dir) +static void MakeDirs(const fileinfo *pDir) { - refptr ParentDir=Dir->GetDir(); - if (!ParentDir->GetDate().DoesExist()) + fileinfo *pParentDir=pDir->GetDir(); + if (!pParentDir->GetDate().DoesExist()) { /* First make parent dirs */ - MakeDirs(ParentDir); + MakeDirs(pParentDir); } - if (!Dir->GetDate().DoesExist()) + if (!pDir->GetDate().DoesExist()) { /* Create directory */ - mkdir(Dir->GetFullFileName().c_str(),S_IRWXU); + mkdir(pDir->GetFullFileName().c_str(),S_IRWXU); } } @@ -812,7 +815,7 @@ void mhmakefileparser::SaveAutoDepsFile() { return; } - refptr pDepFile=GetFileInfo(DepFile,m_MakeDir); + fileinfo *pDepFile=GetFileInfo(DepFile,m_MakeDir); #ifdef _DEBUG if (g_PrintAdditionalInfo) @@ -860,7 +863,7 @@ void mhmakefileparser::SaveAutoDepsFile() /* Now save the Md5 strings */ fprintf(pOut,"\n"); - set< const fileinfo * , less_fileinfo>::iterator pIt=m_Targets.begin(); + set::iterator pIt=m_Targets.begin(); while (pIt!=m_Targets.end()) { if (!(*pIt)->CompareMd5_32(0)) @@ -1032,6 +1035,85 @@ void mhmakefileparser::SetExport(const string &Var, const string &Val) #endif } +/////////////////////////////////////////////////////////////////////////////// +void mhmakefileparser::SetvPath(const string &Pattern, const string &Path) +{ + // First create the array of directory from the Path parameter. For now all entries need to + // be valid directories (extra checking). This could be improved by checking if there + // is a rule for creating the directory entry, but like first said, not for now. + refptr pDirArray=new fileinfoarray; + + const char *pTmp=Path.c_str(); + while (*pTmp) + { + string Item; + pTmp=NextItem(pTmp,Item," \t:;"); + if (!Item.empty()) + { + fileinfo *pDir=GetFileInfo(Item,m_MakeDir); + if (!pDir->IsDir()) + { + #ifdef WIN32 + // On windows this could happen if a full pathname was specified, so we try together + // with the next item to check if this is not a valid directories + // but only if the the length of the item was 1 namely the driver letter + if (Item.length()==1) + { + string Rest; + pTmp=NextItem(pTmp,Rest," \t:;"); + pDir=GetFileInfo(Item+":"+Rest,m_MakeDir); + #ifdef _DEBUG + if (g_PrintAdditionalInfo && !pDir->IsDir()) + throw(pDir->GetFullFileName()+" is not a valid directory."); + #endif + } + #ifdef _DEBUG + else if (g_PrintAdditionalInfo) + cout << pDir->GetFullFileName() << " is not a valid directory.\n"; + #endif + #else + #ifdef _DEBUG + if (g_PrintAdditionalInfo) + cout << pDir->GetFullFileName() << " is not a valid directory.\n"; + #endif + #endif + } + pDirArray->push_back(pDir); + } + } + m_vPath.push_back(pair >(Pattern,pDirArray)); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Search for the target using the vPath +fileinfo* mhmakefileparser::SearchvPath(const fileinfo* pTarget) +{ + string TargetName=pTarget->GetName(); + vector< pair< string, refptr > >::iterator vPathIt=m_vPath.begin(); + while (vPathIt!=m_vPath.end()) + { + matchres Res; + + if (PercentMatch(TargetName,vPathIt->first,&Res)) + { + fileinfoarray::iterator pIt=vPathIt->second->begin(); + while (pIt!=vPathIt->second->end()) + { + fileinfo* pNewTarget=GetFileInfo(TargetName,*pIt); + mh_time_t TargetDate=StartBuildTarget(pNewTarget,false); + if (!TargetDate.IsDateValid()) + TargetDate=WaitBuildTarget(pNewTarget); + if (pNewTarget->GetDate().DoesExist()) + return pNewTarget; + pIt++; + } + } + vPathIt++; + } + return NULL; +} + /////////////////////////////////////////////////////////////////////////////// // //Checks if the variables retreived from the environment or command-line have been diff --git a/tools/mhmake/src/mhmakefileparser.h b/tools/mhmake/src/mhmakefileparser.h index 6ae19bf62..8bc0adbe9 100644 --- a/tools/mhmake/src/mhmakefileparser.h +++ b/tools/mhmake/src/mhmakefileparser.h @@ -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 @@ -44,13 +44,13 @@ struct funcdef function_f pFunc; }; -class fileinfoarray : public refbase,public vector > +class fileinfoarray : public refbase,public vector { }; -typedef set< refptr > deps_t; +typedef set deps_t; typedef pair< bool, deps_t > autodeps_entry_t; -typedef map< refptr, autodeps_entry_t > autodeps_t; +typedef map autodeps_t; class mhmakefileparser : public refbase { @@ -60,10 +60,10 @@ private: mhmakelexer *m_ptheLexer; int m_yyloc; - refptr m_RuleThatIsBuild; + fileinfo *m_RuleThatIsBuild; vector m_ToBeIncludeAfterBuild; vector m_MakefilesToLoad; - refptr m_AutoDepFileLoaded; + fileinfo* m_AutoDepFileLoaded; int m_InExpandExpression; mh_time_t m_Date; uint32 m_EnvMd5_32; /* Cached Md5_32 value of the userd environment variables */ @@ -76,11 +76,11 @@ protected: map m_Variables; map m_CommandLineVars; TOKENVALUE m_theTokenValue; - refptr m_MakeDir; + const fileinfo *m_MakeDir; refptr m_pCurrentRule; refptr m_pCurrentItems; refptr m_pCurrentDeps; - refptr m_FirstTarget; + fileinfo* m_FirstTarget; fileinfoarray m_IncludedMakefiles; refptr m_pIncludeDirs; string m_IncludeDirs; @@ -96,6 +96,7 @@ protected: set m_UsedEnvVars; // Array containing a list of variables that are taken from the environment (This is used for rebuild checking) set m_Exports; // Array containing a list of exported variables in the makefile (This is used for rebuild checking) + vector< pair< string, refptr > > m_vPath; #ifdef WIN32 char *m_pEnv; // New environment in case the makefile exports variables #else @@ -104,7 +105,7 @@ protected: size_t m_EnvLen; // Current length of m_pEnv autodeps_t m_AutoDeps; - set< const fileinfo* , less_fileinfo > m_Targets; // List of targets that are build by this makefile + set< const fileinfo* > m_Targets; // List of targets that are build by this makefile static mh_time_t m_sBuildTime; private: @@ -112,7 +113,7 @@ private: public: #ifdef _DEBUG - deque< refptr > m_TargetStack; /* Used to detect circular dependencies */ + deque m_TargetStack; /* Used to detect circular dependencies */ #endif mhmakefileparser(const map &CommandLineVars) @@ -124,6 +125,7 @@ public: ,m_RebuildAll(false) ,m_EnvMd5_32(0) ,m_pEnv(NULL) + ,m_FirstTarget(NULL) #ifdef _DEBUG ,m_ImplicitSearch(0) #endif @@ -135,7 +137,7 @@ public: } /* Needed if you only want to use the searchcommand and execommand functions */ - mhmakefileparser(const refptr &pMakeDir) : + mhmakefileparser(const fileinfo *pMakeDir) : m_MakeDir(pMakeDir) , m_AutoDepsDirty(false) , m_pEnv(NULL) @@ -152,6 +154,7 @@ public: void CreateUSED_ENVVARS(); void SetExport(const string & Var, const string & Val); + void SetvPath(const string & Pattern, const string & Path); void CheckEnv(void); @@ -195,21 +198,21 @@ public: { return m_ForceAutoDepRescan; } - void SetRuleThatIsBuild(const refptr &Target) + void SetRuleThatIsBuild(fileinfo *pTarget) { - m_RuleThatIsBuild=Target; + m_RuleThatIsBuild=pTarget; } void ClearRuleThatIsBuild() { m_RuleThatIsBuild=NULL; } - void GetAutoDepsIfNeeded(const refptr &Target, const refptr&FirstDep); - void UpdateAutomaticDependencies(const refptr &Target); - void UpdateNoRuleAutomaticDependencies(const refptr &Target); + void GetAutoDepsIfNeeded(fileinfo *pTarget, const fileinfo *pFirstDep); + void UpdateAutomaticDependencies(fileinfo *pTarget); + void UpdateNoRuleAutomaticDependencies(fileinfo *pTarget); const refptr GetIncludeDirs() const; - void GetAutoDeps(const refptr &FirstDep, deps_t &Autodeps); + void GetAutoDeps(const fileinfo *pFirstDep, deps_t &Autodeps); void SaveAutoDepsFile(); - void LoadAutoDepsFile(refptr &DepFile); + void LoadAutoDepsFile(fileinfo *pDepFile); bool SkipHeaderFile(const string &FileName); void InitEnv() const; @@ -230,7 +233,7 @@ public: throw("Please derive if you want to execute yyparse."); } - int ParseFile(const refptr &FileInfo,refptr &pMakeDir=NullFileInfo); + int ParseFile(const fileinfo *pFileInfo,const fileinfo *pMakeDir=NULL); /* Functions to handle variables */ bool IsDefined(const string &Var) const; @@ -274,12 +277,12 @@ public: string f_strip(const string & Arg) const; string f_which(const string & Arg) const; - const refptr GetFirstTarget() const + fileinfo* GetFirstTarget() const { return m_FirstTarget; } - const refptr GetMakeDir() const + const fileinfo *GetMakeDir() const { return m_MakeDir; } @@ -302,28 +305,29 @@ public: /* Starts building the target, returns 0 when target build is not finished, returns the date of the target when target is build, especially important for phony rules, since this will be the youngest date of all dependencies */ - mh_time_t StartBuildTarget(const refptr &Target, bool bCheckTargetDir=true); + mh_time_t StartBuildTarget(fileinfo* pTarget, bool bCheckTargetDir=true); /* Waits for the target being build, returns the date of the target. Not needed to be cald when StartBuildTarget returned a value different from zero */ - mh_time_t WaitBuildTarget(const refptr &Target); + mh_time_t WaitBuildTarget(fileinfo* pTarget); + + fileinfo* SearchvPath(const fileinfo* pTarget); /* Search for the target using the vPath */ /* Use the following command when you want to wait for the target is built */ - mh_time_t BuildTarget(const refptr &Target, bool bCheckTargetDir=true) + mh_time_t BuildTarget(fileinfo* pTarget, bool bCheckTargetDir=true) { - mh_time_t TargetDate=StartBuildTarget(Target,bCheckTargetDir); + mh_time_t TargetDate=StartBuildTarget(pTarget,bCheckTargetDir); if (!TargetDate.IsDateValid()) - return WaitBuildTarget(Target); - else + TargetDate=WaitBuildTarget(pTarget); return TargetDate; } - void BuildDependencies(const refptr &pRule, const refptr &Target, mh_time_t TargetDate, mh_time_t &YoungestDate, bool &MakeTarget); + void BuildDependencies(const refptr &pRule, fileinfo* pTarget, mh_time_t TargetDate, mh_time_t &YoungestDate, bool &MakeTarget); void BuildIncludedMakefiles(); - void AddIncludedMakefile(refptr &MakeInfo) + void AddIncludedMakefile(fileinfo* pMakeInfo) { - UpdateDate(MakeInfo->GetDate()); - m_IncludedMakefiles.push_back(MakeInfo); + UpdateDate(pMakeInfo->GetDate()); + m_IncludedMakefiles.push_back(pMakeInfo); } fileinfoarray &GetIncludedMakefiles() { @@ -357,7 +361,7 @@ public: static void InitBuildTime(); - void SplitToItems(const string &String, vector< refptr > &Items) const; + void SplitToItems(const string &String, vector &Items) const; mh_pid_t DeleteFiles(const string &Params) const; mh_pid_t CopyFiles(const string &Params) const; mh_pid_t TouchFiles(const string &Params) const; diff --git a/tools/mhmake/src/mhmakelexer.l b/tools/mhmake/src/mhmakelexer.l index 8796e70c4..62df687e1 100644 --- a/tools/mhmake/src/mhmakelexer.l +++ b/tools/mhmake/src/mhmakelexer.l @@ -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 @@ -26,9 +26,9 @@ #include "rule.h" #include "util.h" -static uint32 LoadMakMd5(refptr &Target) +static uint32 LoadMakMd5(fileinfo *pTarget) { - string FileName=Target->GetFullFileName(); + string FileName=pTarget->GetFullFileName(); FileName+=".md5_32"; FILE *pFile=fopen(FileName.c_str(),"rb"); if (!pFile) @@ -36,20 +36,20 @@ static uint32 LoadMakMd5(refptr &Target) uint32 Md5_32=0; fread(&Md5_32,sizeof(Md5_32),1,pFile); fclose(pFile); - Target->SetCommandsMd5_32(Md5_32); + pTarget->SetCommandsMd5_32(Md5_32); return Md5_32; } -static void SaveMakMd5(refptr &Target) +static void SaveMakMd5(fileinfo *pTarget) { - string FileName=Target->GetFullFileName(); + string FileName=pTarget->GetFullFileName(); FileName+=".md5_32"; FILE *pFile=fopen(FileName.c_str(),"wb"); if (!pFile) { throw string("Error creating file ")+FileName; } - Target->WriteMd5_32(pFile); + pTarget->WriteMd5_32(pFile); fclose(pFile); } @@ -83,12 +83,12 @@ static void SaveMakMd5(refptr &Target) /* -------------- rules section -------------- */ %x INCLUDE IFDEF IF IFNDEF SKIPUNTILELSEORENDIF QUOTE MAKEEXPRES SINGLEQUOTE COMMANDPARSE -%x IFEQ IFNEQ ERRORMACRO MESSAGEMACRO REPARSEMACRO LOAD_MAKEFILE +%x IFEQ IFNEQ ERRORMACRO MESSAGEMACRO MESSAGEINFO MESSAGEERROR REPARSEMACRO LOAD_MAKEFILE %% /*---------------------------------------------------------------------------*/ -[ \t\r]*\n[ ][ \t]* | +[ \t\r]*\n/[ ][ \t]* | [ \t\r]*\n { PRINTF(("%s %d: NEWLINE:\n",m_InputFileName.c_str(),m_Line)); m_Line++; @@ -96,10 +96,12 @@ static void SaveMakMd5(refptr &Target) } /*---------------------------------------------------------------------------*/ -^[s\-]?include { +^[ \t]*[s\-]?include { PRINTF(("%s %d: INCLUDE: ",m_InputFileName.c_str(),m_Line)); BEGIN(INCLUDE); - if (yytext[0]=='-' || yytext[0]=='s') + unsigned i=0; + while (strchr(" \t",yytext[i])) i++; + if (strchr("-s",yytext[i])) m_IgnoreIncludeError=true; else m_IgnoreIncludeError=false; @@ -123,7 +125,7 @@ static void SaveMakMd5(refptr &Target) if (!IncludeFileName.empty()) { PRINTF(("%s -> %s\n",yytext,IncludeFileName.c_str())); - refptr pInclude=GetFileInfo(IncludeFileName,pParser->GetMakeDir()); + fileinfo *pInclude=GetFileInfo(IncludeFileName,pParser->GetMakeDir()); /* Already build the include file, in case we already have a rule for it. */ if (pInclude->GetRule()) { @@ -595,6 +597,11 @@ export { return mhmakeparser::EXPORT; } + /*---------------------------------------------------------------------------*/ +^[ \t]*vpath { + PRINTF(("%s %d: vpath\n",m_InputFileName.c_str(),m_Line)); + return mhmakeparser::VPATH; +} /*---------------------------------------------------------------------------*/ [a-zA-Z]:[a-zA-Z0-9\\\._\~\-%\@<&/]+\\[ \t\r]*\n { @@ -675,6 +682,20 @@ export { m_curtoken=g_EmptyString; } + /*---------------------------------------------------------------------------*/ +[ \t]*\$\{[ \t]*info[ \t]+ { + PRINTF(("%s %d: BEGIN INFO MESSAGE ${: %d\n",m_InputFileName.c_str(),m_Line,m_BraceIndent)); + BEGIN(MESSAGEINFO); + m_curtoken=g_EmptyString; +} + + /*---------------------------------------------------------------------------*/ +[ \t]*\$\{[ \t]*error[ \t]+ { + PRINTF(("%s %d: BEGIN ERROR MESSAGE ${: %d\n",m_InputFileName.c_str(),m_Line,m_BraceIndent)); + BEGIN(MESSAGEERROR); + m_curtoken=g_EmptyString; +} + /*---------------------------------------------------------------------------*/ \$\([ \t]*reparse[ \t]+ { m_BraceIndent++; @@ -825,6 +846,22 @@ export { } } + /*****************************************************************************/ +[^\}]+ { + throw(GetParser()->ExpandExpression((const char*)yytext)); +} + + /*****************************************************************************/ +[^\}]+ { + cerr<ExpandExpression((const char*)yytext)<\} { + PRINTF(("%s %d: MESSAGEINFO: %s\n",m_InputFileName.c_str(),m_Line,yytext)); + BEGIN(INITIAL); +} + /*****************************************************************************/ \) { m_BraceIndent--; diff --git a/tools/mhmake/src/mhmakeparser.y b/tools/mhmake/src/mhmakeparser.y index 107194d70..e2312b50e 100644 --- a/tools/mhmake/src/mhmakeparser.y +++ b/tools/mhmake/src/mhmakeparser.y @@ -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 @@ -42,7 +42,7 @@ %token COMMAND %token COMMA OPENBRACE CLOSEBRACE %token STRING DOLLAREXPR EQUAL COLON DOUBLECOLON -%token IMEQUAL PEQUAL OPTEQUAL PHONY AUTODEPS EXPORT NEWLINE INCLUDEMAK SPACE +%token IMEQUAL PEQUAL OPTEQUAL PHONY AUTODEPS EXPORT NEWLINE INCLUDEMAK SPACE VPATH %type expression nonspaceexpression simpleexpression %type maybeemptyexpression @@ -69,6 +69,7 @@ statements : ; statement: NEWLINE | + SPACE | includemak | ruledef | phonyrule | @@ -78,6 +79,7 @@ statement: NEWLINE | pvarassignment | optvarassignment | exportrule | + vpathrule | COMMAND { if (!m_pCurrentRule) @@ -129,9 +131,9 @@ rulecolon: COLON {$$=0;} | phonyrule: PHONY COLON expression { - vector< refptr > Items; + vector Items; SplitToItems(ExpandExpression($3),Items); - vector< refptr >::iterator pIt=Items.begin(); + vector::iterator pIt=Items.begin(); while (pIt!=Items.end()) { (*pIt)->SetPhony(); @@ -145,9 +147,9 @@ phonyrule: PHONY COLON expression autodepsrule: AUTODEPS COLON expression { - vector< refptr > Items; + vector Items; SplitToItems(ExpandExpression($3),Items); - vector< refptr >::iterator pIt=Items.begin(); + vector::iterator pIt=Items.begin(); while (pIt!=Items.end()) { (*pIt)->SetAutoDepsScan(this); @@ -173,6 +175,13 @@ exportstring : STRING } ; +vpathrule: VPATH SPACE nonspaceexpression SPACE expression NEWLINE + { + SetvPath(ExpandExpression($3),ExpandExpression($5)); + PRINTF(("Setting vpath %s to %s\n",$3.c_str(),ExpandExpression($5).c_str())); + } +; + varassignment: STRING EQUAL maybeemptyexpression { m_Variables[$1]=$3; diff --git a/tools/mhmake/src/refptr.h b/tools/mhmake/src/refptr.h index 38b62b4ca..7223090f9 100644 --- a/tools/mhmake/src/refptr.h +++ b/tools/mhmake/src/refptr.h @@ -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 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"; } diff --git a/tools/mhmake/src/rule.h b/tools/mhmake/src/rule.h index bfc00bb15..1ec944f96 100644 --- a/tools/mhmake/src/rule.h +++ b/tools/mhmake/src/rule.h @@ -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 @@ -25,7 +25,6 @@ #include "md5.h" class mhmakeparser; class fileinfo; -extern refptr NullFileInfo; class rule: public refbase { @@ -47,7 +46,7 @@ public: { return m_Commands; } - void PrintCommands(refptr Target=NullFileInfo) const; + void PrintCommands(fileinfo *pTarget=NULL) const; void SetStem(const string &Stem) { @@ -77,10 +76,10 @@ public: class IMPLICITRULE { - static map< string, vector > > > m_ImplicitRules; + static vector > > > > m_ImplicitRules; // Use a vector and not a map because the order of the implicit rules is important public: - static void AddImplicitRule(const refptr &Target,const vector< refptr >&Deps,refptr pRule); - static void SearchImplicitRule(const refptr &Target,vector< pair,refptr > >&Result); + static void AddImplicitRule(fileinfo *pTarget,const vector &Deps,refptr pRule); + static void SearchImplicitRule(const fileinfo *pTarget,vector< pair > >&Result); static void PrintImplicitRules(); }; diff --git a/tools/mhmake/src/stdafx.cpp b/tools/mhmake/src/stdafx.cpp index feb841fea..b2168250b 100644 --- a/tools/mhmake/src/stdafx.cpp +++ b/tools/mhmake/src/stdafx.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 diff --git a/tools/mhmake/src/stdafx.h b/tools/mhmake/src/stdafx.h index b8eca6204..3a6bbb946 100644 --- a/tools/mhmake/src/stdafx.h +++ b/tools/mhmake/src/stdafx.h @@ -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 diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp index f16134551..2e26cf2e7 100644 --- a/tools/mhmake/src/util.cpp +++ b/tools/mhmake/src/util.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 @@ -235,6 +235,64 @@ bool PercentMatch(const string &String,const string &Expr,matchres *pRes,const c return true; } /////////////////////////////////////////////////////////////////////////////// +bool PercentMatchNoCase(const string &String,const string &Expr,matchres *pRes,const char Char) +{ + const char *pFirst=String.c_str(); + const char *pFirstExpr=Expr.c_str(); + while (*pFirstExpr && *pFirstExpr!=Char) + { + if (tolower(*pFirst)!=tolower(*pFirstExpr)) + return false; + pFirst++; + pFirstExpr++; + } + + if (!*pFirstExpr) + { + if (!*pFirst) + { + if (pRes) + { + pRes->m_First=String; + pRes->m_Stem=pRes->m_Last=g_EmptyString; + } + return true; + } else + return false; + } + else if (!*pFirst) + return false; + + const char *pEnd=pFirst+strlen(pFirst); + + const char *pLast=pEnd; + const char *pLastExpr=pFirstExpr+strlen(pFirstExpr)-1; + if (pLastExpr!=pFirstExpr) + { + pLast--; + + while (pLastExpr>pFirstExpr) + { + if (tolower(*pLastExpr)!=tolower(*pLast)) + return false; + pLastExpr--; + pLast--; + } + pLast++; + } + string Stem=string(pFirst,pLast-pFirst); + + if (pRes) + { + pRes->m_First=string(String.c_str(),pFirst-String.c_str()); + + pRes->m_Stem=Stem; + + pRes->m_Last=string(pLast,pEnd-pLast); + } + return true; +} +/////////////////////////////////////////////////////////////////////////////// bool PercentMatchList(const string &String,const string &ExprList,matchres *pRes) { const char *pTmp=ExprList.c_str(); @@ -365,11 +423,12 @@ loadedmakefile::loadedmakefile_statics::loadedmakefile_statics() } /////////////////////////////////////////////////////////////////////////////// -loadedmakefile::loadedmakefile(const refptr &pDir, vector &Args,const string&Makefile) +loadedmakefile::loadedmakefile(const fileinfo *pDir, vector &Args,const string&Makefile) { + m_Makefile=NULL; m_CommandLineVars=sm_Statics.m_GlobalCommandLineVars; - m_MakeDir=NullFileInfo; + m_MakeDir=NULL; vector::iterator ArgIt=Args.begin(); while (ArgIt!=Args.end()) { @@ -554,7 +613,7 @@ void loadedmakefile::LoadMakefile() string BaseAutoMak; // First parse the makefile.before makefile which is in the directory $(MHMAKECONF) environment variable - refptr DepFile; + fileinfo *pDepFile; if (sm_Statics.m_MhMakeConf) { BaseAutoMak=m_pParser->ExpandVar(BASEAUTOMAK); @@ -563,14 +622,14 @@ void loadedmakefile::LoadMakefile() BaseAutoMak="makefile"; m_pParser->SetVariable(BASEAUTOMAK,BaseAutoMak); } - refptr BeforeMakefile=GetFileInfo(BaseAutoMak+".before",sm_Statics.m_MhMakeConf); + const fileinfo *pBeforeMakefile=GetFileInfo(BaseAutoMak+".before",sm_Statics.m_MhMakeConf); - int result=m_pParser->ParseFile(BeforeMakefile,m_MakeDir); + int result=m_pParser->ParseFile(pBeforeMakefile,m_MakeDir); if (result) { - throw string("Error parsing ")+BeforeMakefile->GetQuotedFullFileName(); + throw string("Error parsing ")+pBeforeMakefile->GetQuotedFullFileName(); } - m_pParser->UpdateDate(BeforeMakefile->GetDate()); + m_pParser->UpdateDate(pBeforeMakefile->GetDate()); // Now parse the automaticly generated dependency file, which needs to be in the objdir directory string ObjDirName=m_pParser->ExpandExpression("$(OBJDIR)"); @@ -578,8 +637,8 @@ void loadedmakefile::LoadMakefile() { throw string("When making use of MHMAKECONF, you have to define OBJDIR in makefile.before"); } - DepFile=GetFileInfo(ObjDirName+OSPATHSEPSTR "." + m_Makefile->GetName()+ ".dep",m_MakeDir); - m_pParser->SetVariable(AUTODEPFILE,DepFile->GetQuotedFullFileName()); + pDepFile=GetFileInfo(ObjDirName+OSPATHSEPSTR "." + m_Makefile->GetName()+ ".dep",m_MakeDir); + m_pParser->SetVariable(AUTODEPFILE,pDepFile->GetQuotedFullFileName()); } else { @@ -603,12 +662,12 @@ void loadedmakefile::LoadMakefile() char ID[10]; sprintf(ID,"_%x",md5_finish32( &ctx)); - DepFile=GetFileInfo(string(".") + m_Makefile->GetName()+ ".dep"+ID,m_MakeDir); - m_pParser->SetVariable(AUTODEPFILE,DepFile->GetQuotedFullFileName()); + pDepFile=GetFileInfo(string(".") + m_Makefile->GetName()+ ".dep"+ID,m_MakeDir); + m_pParser->SetVariable(AUTODEPFILE,pDepFile->GetQuotedFullFileName()); } - if (DepFile->Exists()) - m_pParser->LoadAutoDepsFile(DepFile); /* Already load this autodep file before parsing of the makefile to avoid needless rebuilds. */ + if (pDepFile->Exists()) + m_pParser->LoadAutoDepsFile(pDepFile); /* Already load this autodep file before parsing of the makefile to avoid needless rebuilds. */ //m_pParser->yydebug=1; int result=m_pParser->ParseFile(m_Makefile,m_MakeDir); @@ -619,9 +678,9 @@ void loadedmakefile::LoadMakefile() #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->GetQuotedFullFileName()) + if (m_pParser->ExpandVar(AUTODEPFILE)!=pDepFile->GetQuotedFullFileName()) { - cout << "\n\nWARNING:\n makefile '"<< m_Makefile->GetQuotedFullFileName() <<"' re-defines AUTODEPFILE\n from '"<< DepFile->GetQuotedFullFileName() <<"'\n to '"<< + cout << "\n\nWARNING:\n makefile '"<< m_Makefile->GetQuotedFullFileName() <<"' re-defines AUTODEPFILE\n from '"<< pDepFile->GetQuotedFullFileName() <<"'\n to '"<< m_pParser->ExpandVar(AUTODEPFILE) << "'\n (may cause needless rebuilds when having rules for included makefiles!!!!!)\n\n\n"; } @@ -637,16 +696,16 @@ void loadedmakefile::LoadMakefile() if (sm_Statics.m_MhMakeConf) { - refptr AfterMakefile=GetFileInfo(BaseAutoMak+".after",sm_Statics.m_MhMakeConf); - int result=m_pParser->ParseFile(AfterMakefile); + fileinfo *pAfterMakefile=GetFileInfo(BaseAutoMak+".after",sm_Statics.m_MhMakeConf); + int result=m_pParser->ParseFile(pAfterMakefile); if (result) { - throw string("Error parsing ")+AfterMakefile->GetQuotedFullFileName(); + throw string("Error parsing ")+pAfterMakefile->GetQuotedFullFileName(); } - m_pParser->UpdateDate(AfterMakefile->GetDate()); + m_pParser->UpdateDate(pAfterMakefile->GetDate()); } bool ForceAutoDepRescan=g_ForceAutoDepRescan; - if (DepFile->Exists()) - m_pParser->LoadAutoDepsFile(DepFile); + if (pDepFile->Exists()) + m_pParser->LoadAutoDepsFile(pDepFile); else ForceAutoDepRescan=true; if (ForceAutoDepRescan) diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h index 9b49cf489..ff1fac9aa 100644 --- a/tools/mhmake/src/util.h +++ b/tools/mhmake/src/util.h @@ -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 @@ -50,7 +50,7 @@ #define PLATFORM "linux" #endif -#define MHMAKEVER "2.2.5" +#define MHMAKEVER "2.2.9" class makecommand { @@ -150,6 +150,7 @@ struct matchres }; bool PercentMatch(const string &String,const string &Expr,matchres *pRes=NULL,const char Char='%'); +bool PercentMatchNoCase(const string &String,const string &Expr,matchres *pRes=NULL,const char Char='%'); bool PercentMatchList(const string &String,const string &ExprList,matchres *pRes=NULL); string ReplaceWithStem(const string &String,const string &Stem); @@ -158,20 +159,20 @@ struct loadedmakefile : public refbase struct loadedmakefile_statics { map m_GlobalCommandLineVars; - refptr m_MhMakeConf; + fileinfo *m_MhMakeConf; loadedmakefile_statics(); }; static loadedmakefile_statics sm_Statics; - refptr m_Makefile; - refptr m_MakeDir; + fileinfo *m_Makefile; + const fileinfo *m_MakeDir; map m_CommandLineVars; vector m_CommandLineTargets; refptr m_pParser; - loadedmakefile(const refptr &pDir, vector &Args,const string &Makefile=g_EmptyString); + loadedmakefile(const fileinfo *pDir, vector &Args,const string &Makefile=g_EmptyString); void LoadMakefile(); void AddCommandLineVarsToEnvironment() -- cgit v1.2.3