aboutsummaryrefslogtreecommitdiff
path: root/tools/mhmake
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-01-27 13:44:12 +0000
committermarha <marha@users.sourceforge.net>2011-01-27 13:44:12 +0000
commit11903063211dc368d03f52e090e52ab18ebe3f47 (patch)
tree71991c8ffd98ed31690190b37f39cfc6244b6595 /tools/mhmake
parent59e0042680b01d7e3cf69104921f151ceee13df4 (diff)
downloadvcxsrv-11903063211dc368d03f52e090e52ab18ebe3f47.tar.gz
vcxsrv-11903063211dc368d03f52e090e52ab18ebe3f47.tar.bz2
vcxsrv-11903063211dc368d03f52e090e52ab18ebe3f47.zip
Implemented mkdir as an internal command
Diffstat (limited to 'tools/mhmake')
-rw-r--r--tools/mhmake/src/build.cpp27
-rw-r--r--tools/mhmake/src/fileinfo.cpp9
-rw-r--r--tools/mhmake/src/fileinfo.h9
-rw-r--r--tools/mhmake/src/mhmakefileparser.cpp22
-rw-r--r--tools/mhmake/src/mhmakefileparser.h1
-rw-r--r--tools/mhmake/src/util.cpp17
-rw-r--r--tools/mhmake/src/util.h3
7 files changed, 67 insertions, 21 deletions
diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp
index d1c4a32d1..36fdefb3d 100644
--- a/tools/mhmake/src/build.cpp
+++ b/tools/mhmake/src/build.cpp
@@ -357,7 +357,7 @@ exit:
Error = false;
goto exit;
}
- if (-1==mkdir(pNewDest->GetFullFileName().c_str(),0777))
+ if (-1==mkdir(pNewDest->GetFullFileName().c_str(),S_IRWXU))
{
cerr << "Error creating directory " << pNewDest->GetQuotedFullFileName() << endl;
Error = false;
@@ -383,6 +383,23 @@ exit:
}
/*****************************************************************************/
+mh_pid_t mhmakefileparser::MakeDirsCommand(const string &Params) const
+{
+ vector<fileinfo*> Dirs;
+
+ SplitToItems(Params,Dirs);
+
+ size_t NrDirs=Dirs.size();
+ for (size_t i=0; i<NrDirs; i++)
+ {
+ fileinfo* pDir=Dirs[i];
+ if (!MakeDirs(pDir))
+ return (mh_pid_t)-1;
+ }
+ return (mh_pid_t)0;
+}
+
+/*****************************************************************************/
mh_pid_t mhmakefileparser::EchoCommand(const string &Params) const
{
// Find the first > character
@@ -440,7 +457,7 @@ mh_pid_t mhmakefileparser::CopyFiles(const string &Params) const
if (NrSrcs<1)
{
cerr << "Wrong number of arguments in copy: "<<Params<<endl;
- return false;
+ return (mh_pid_t)-1;
}
fileinfo* pDest=Files[NrSrcs];
@@ -1166,7 +1183,7 @@ mh_pid_t mhmakefileparser::ExecuteCommand(string Command, bool &IgnoreError, str
}
if (i==Params.size())
{
- if (Command!="del" && Command!="touch" && Command!="copy" && Command!="echo")
+ if (Command!="del" && Command!="touch" && Command!="copy" && Command!="echo" && Command!="mkdir")
Command=GetFullCommand(Command);
#ifndef WIN32
if (Command.substr(0,GetComspec().size())==GetComspec())
@@ -1226,6 +1243,10 @@ mh_pid_t mhmakefileparser::ExecuteCommand(string Command, bool &IgnoreError, str
{
return EchoCommand(Params);
}
+ else if (Command=="mkdir")
+ {
+ return MakeDirsCommand(Params);
+ }
return OsExeCommand(Command,Params,IgnoreError,pOutput);
#ifdef _DEBUG
diff --git a/tools/mhmake/src/fileinfo.cpp b/tools/mhmake/src/fileinfo.cpp
index 5ef044e41..f6468900d 100644
--- a/tools/mhmake/src/fileinfo.cpp
+++ b/tools/mhmake/src/fileinfo.cpp
@@ -77,7 +77,14 @@ string UnquoteFileName(const string &Filename)
///////////////////////////////////////////////////////////////////////////////
fileinfo* fileinfo::GetDir() const
{
- return GetAbsFileInfo(m_AbsFileName.substr(0,m_AbsFileName.find_last_of(OSPATHSEP)));
+ string Dir=m_AbsFileName.substr(0,m_AbsFileName.find_last_of(OSPATHSEP));
+ #ifdef WIN32
+ if (Dir.length()==2 && Dir[1]==':')
+ #else
+ if (Dir.empty())
+ #endif
+ Dir+=OSPATHSEP;
+ return GetAbsFileInfo(Dir);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/tools/mhmake/src/fileinfo.h b/tools/mhmake/src/fileinfo.h
index 1d70f0df1..b658ac677 100644
--- a/tools/mhmake/src/fileinfo.h
+++ b/tools/mhmake/src/fileinfo.h
@@ -189,11 +189,16 @@ public:
{
return QuoteFileName(m_AbsFileName);
}
+#ifdef WIN32
+#define MINPATHLENGTH 3 // The smallest dir name in windows is 3, e.g. "c:\"
+#else
+#define MINPATHLENGTH 1 // The smallest dir name in linux is 1, e.g. "/"
+#endif
void SetFullFileName(const string &strAbsName)
{
m_AbsFileName=UnquoteFileName(strAbsName);
- // If the last char is path sep strip it
- if (!m_AbsFileName.empty() && m_AbsFileName[m_AbsFileName.length()-1]==OSPATHSEP)
+ // If the last char is path sep strip it, except for the smallest dir name
+ if (m_AbsFileName.length()>MINPATHLENGTH && m_AbsFileName[m_AbsFileName.length()-1]==OSPATHSEP)
m_AbsFileName.resize(m_AbsFileName.length()-1);
}
diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp
index cf41b3c1c..b198c1ca8 100644
--- a/tools/mhmake/src/mhmakefileparser.cpp
+++ b/tools/mhmake/src/mhmakefileparser.cpp
@@ -804,19 +804,6 @@ void mhmakefileparser::LoadAutoDepsFile(fileinfo *pDepFile)
fclose(pIn);
}
-static void MakeDirs(const fileinfo *pDir)
-{
- fileinfo *pParentDir=pDir->GetDir();
- if (!pParentDir->GetDate().DoesExist())
- { /* First make parent dirs */
- MakeDirs(pParentDir);
- }
- if (!pDir->GetDate().DoesExist())
- { /* Create directory */
- mkdir(pDir->GetFullFileName().c_str(),S_IRWXU);
- }
-}
-
void mhmakefileparser::SaveAutoDepsFile()
{
if (!IsAutoDepsDirty())
@@ -845,7 +832,14 @@ void mhmakefileparser::SaveAutoDepsFile()
if (!pOut)
{
/* Maybe it is because the directory does not exist, so try to create this first */
- MakeDirs(pDepFile->GetDir());
+ if (!MakeDirs(pDepFile->GetDir()))
+ {
+ #ifdef _DEBUG
+ if (!g_DoNotExecute)
+ #endif
+ cerr << "Error creating dir "<<pDepFile->GetDir()->GetFullFileName()<<endl;
+ return;
+ }
pOut=fopen(pDepFile->GetFullFileName().c_str(),"wb");
if (!pOut)
diff --git a/tools/mhmake/src/mhmakefileparser.h b/tools/mhmake/src/mhmakefileparser.h
index 9f6cb5a96..581d243b0 100644
--- a/tools/mhmake/src/mhmakefileparser.h
+++ b/tools/mhmake/src/mhmakefileparser.h
@@ -381,6 +381,7 @@ public:
mh_pid_t CopyFiles(const string &Params) const;
mh_pid_t TouchFiles(const string &Params) const;
mh_pid_t EchoCommand(const string &Params) const;
+ mh_pid_t MakeDirsCommand(const string &Params) const;
string SearchCommand(const string &Command, const string &Extension="") const;
const string &GetPythonExe() const;
int SearchPath(const char *szCommand, const char *pExt, size_t Len, char *szFullCommand,char **pFilePart) const;
diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp
index 9b34b41ea..46f9b9edb 100644
--- a/tools/mhmake/src/util.cpp
+++ b/tools/mhmake/src/util.cpp
@@ -746,6 +746,23 @@ void loadedmakefile::LoadMakefile()
}
}
+/*****************************************************************************/
+bool MakeDirs(const fileinfo *pDir)
+{
+ fileinfo *pParentDir=pDir->GetDir();
+ if (!pParentDir->GetDate().DoesExist())
+ { /* First make parent dirs */
+ if (!MakeDirs(pParentDir))
+ return false;
+ }
+ if (!pDir->GetDate().DoesExist())
+ { /* Create directory */
+ if (-1==mkdir(pDir->GetFullFileName().c_str(),S_IRWXU))
+ return false;
+ }
+ return true;
+}
+
#ifdef _DEBUG
///////////////////////////////////////////////////////////////////////////////
void DumpVarsAndRules()
diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h
index 069effc07..aba9ec649 100644
--- a/tools/mhmake/src/util.h
+++ b/tools/mhmake/src/util.h
@@ -50,7 +50,7 @@
#define PLATFORM "linux"
#endif
-#define MHMAKEVER "2.3.30"
+#define MHMAKEVER "2.4.1"
class makecommand
{
@@ -232,6 +232,7 @@ public:
extern LOADEDMAKEFILES g_LoadedMakefiles;
+bool MakeDirs(const fileinfo *pDir); // Creates a directory tree
void DumpVarsAndRules();
#endif