From 68504d1066c26aa26b73d5be549d7a95d6afd8ed Mon Sep 17 00:00:00 2001 From: marha Date: Fri, 19 Feb 2010 17:09:40 +0000 Subject: Linux compilation is ok again. --- tools/mhmake/mhmake.vcproj | 12 +- tools/mhmake/src/Makefile.am | 3 +- tools/mhmake/src/build.cpp | 201 ++++++++++++++++++++-------------- tools/mhmake/src/commandqueue.cpp | 69 ++++++++++-- tools/mhmake/src/commandqueue.h | 10 +- tools/mhmake/src/fileinfo.h | 5 +- tools/mhmake/src/functions.cpp | 7 +- tools/mhmake/src/mhmakefileparser.cpp | 61 +++++++++++ tools/mhmake/src/mhmakefileparser.h | 30 +++-- tools/mhmake/src/util.cpp | 8 +- 10 files changed, 290 insertions(+), 116 deletions(-) diff --git a/tools/mhmake/mhmake.vcproj b/tools/mhmake/mhmake.vcproj index 83ba31e6d..b8ea6a674 100644 --- a/tools/mhmake/mhmake.vcproj +++ b/tools/mhmake/mhmake.vcproj @@ -984,11 +984,19 @@ Filter="cpp;h" > + + + + diff --git a/tools/mhmake/src/Makefile.am b/tools/mhmake/src/Makefile.am index be46f3bd6..0478f1645 100644 --- a/tools/mhmake/src/Makefile.am +++ b/tools/mhmake/src/Makefile.am @@ -1,5 +1,6 @@ SRCS = mhmakeparser.y mhmakelexer.l mhmake.cpp mhmakefileparser.cpp util.cpp \ - functions.cpp fileinfo.cpp rule.cpp md5.c build.cpp curdir.cpp + functions.cpp fileinfo.cpp rule.cpp md5.c build.cpp curdir.cpp \ + commandqueue.cpp if DEBUG bin_PROGRAMS=mhmake_dbg diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp index d14f00ff3..064ffe6c9 100644 --- a/tools/mhmake/src/build.cpp +++ b/tools/mhmake/src/build.cpp @@ -333,7 +333,7 @@ static bool DeleteDir(const string &Dir,const string WildSearch="*",bool bRemove string Pattern=Dir+OSPATHSEP+WildSearch; #ifdef WIN32 WIN32_FIND_DATA FindData; - HANDLE hFind=FindFirstFile(Pattern.c_str(),&FindData); + mh_pid_t hFind=FindFirstFile(Pattern.c_str(),&FindData); if (hFind==INVALID_HANDLE_VALUE) { return Error; @@ -389,7 +389,7 @@ static bool DeleteDir(const string &Dir,const string WildSearch="*",bool bRemove } /*****************************************************************************/ -HANDLE mhmakefileparser::DeleteFiles(const string &Params) const +mh_pid_t mhmakefileparser::DeleteFiles(const string &Params) const { bool IgnoreError=false; vector< refptr > Files; @@ -405,7 +405,7 @@ HANDLE mhmakefileparser::DeleteFiles(const string &Params) const else { cerr << "Invalid option "< pDir,refptr pDest,const string Wi string Pattern=pDir->GetFullFileName()+OSPATHSEP+WildSearch; #ifdef WIN32 WIN32_FIND_DATA FindData; - HANDLE hFind=FindFirstFile(Pattern.c_str(),&FindData); + mh_pid_t hFind=FindFirstFile(Pattern.c_str(),&FindData); if (hFind==INVALID_HANDLE_VALUE) { return false; @@ -554,7 +554,7 @@ exit: for (int i=0; i pSrc=GetFileInfo(Res.gl_pathv[i]); + refptr pSrc=GetFileInfo(Res.gl_pathv[i],pDir); if (pSrc->IsDir()) { *(strrchr(Res.gl_pathv[i],'/'))='\0'; @@ -585,7 +585,7 @@ exit: } else { - Error = CopyFile(GetFileInfo(Res.gl_pathv[i]),pDest); + Error = CopyFile(GetFileInfo(Res.gl_pathv[i],pDir),pDest); if (!Error) goto exit; } } @@ -598,7 +598,7 @@ exit: } /*****************************************************************************/ -HANDLE mhmakefileparser::EchoCommand(const string &Params) const +mh_pid_t mhmakefileparser::EchoCommand(const string &Params) const { // Find the first > character size_t Pos=Params.find_first_of('>'); @@ -628,7 +628,7 @@ HANDLE mhmakefileparser::EchoCommand(const string &Params) const if (!pfFile) { cerr << "Error opening file "< > Files; @@ -662,7 +662,7 @@ HANDLE mhmakefileparser::CopyFiles(const string &Params) const if (NrSrcs>1 && !pDest->IsDir()) { cerr << "copy: Destination must be a directory when more then one source : "<GetDir(), pDest, pSrc->GetName())) { cerr << "copy: Error copying directory: " << Params << endl; - return (HANDLE)-1; + return (mh_pid_t)-1; } } else @@ -692,17 +692,17 @@ HANDLE mhmakefileparser::CopyFiles(const string &Params) const if (!CopyFile(pSrc,pDest)) { cerr << "copy: Error copying file: " << Params << endl; - return (HANDLE)-1; + return (mh_pid_t)-1; } } } - return (HANDLE)0; + return (mh_pid_t)0; } /*****************************************************************************/ -HANDLE mhmakefileparser::TouchFiles(const string &Params) const +mh_pid_t mhmakefileparser::TouchFiles(const string &Params) const { vector< refptr > Files; @@ -722,7 +722,7 @@ HANDLE mhmakefileparser::TouchFiles(const string &Params) const if (pFile->IsDir()) { cerr << "touch: Cannot touch a directory: " << FileName << endl; - return (HANDLE)-1; + return (mh_pid_t)-1; } if (pFile->Exists()) { @@ -743,7 +743,7 @@ HANDLE mhmakefileparser::TouchFiles(const string &Params) const if (fstat (fd, &st) < 0) { cerr << "touch: Cannot stat file " << FileName << endl; - return (HANDLE)-1; + return (mh_pid_t)-1; } } @@ -753,14 +753,14 @@ HANDLE mhmakefileparser::TouchFiles(const string &Params) const if (fd>=0 && close(fd) < 0) { cerr << "touch: Error closing file " << FileName << endl; - return (HANDLE)-1; + return (mh_pid_t)-1; } /*Re-Create an empty file */ pFile=fopen(FileName.c_str(),"wb"); if (!pFile) { cerr << "touch: Cannot create file: " << FileName << endl; - return (HANDLE)-1; + return (mh_pid_t)-1; } fclose(pFile); } @@ -770,22 +770,22 @@ HANDLE mhmakefileparser::TouchFiles(const string &Params) const if (Ret!=sizeof(c) && Ret!=EOF) { cerr << "touch: Cannot read file " << FileName << ": "<InvalidateDate(); } - return (HANDLE)0; + return (mh_pid_t)0; } /*****************************************************************************/ @@ -983,7 +983,7 @@ string mhmakefileparser::GetFullCommand(string Command) return pFound->second; } -HANDLE mhmakefileparser::OsExeCommand(const string &Command, const string &Params, bool IgnoreError, string *pOutput) const +mh_pid_t mhmakefileparser::OsExeCommand(const string &Command, const string &Params, bool IgnoreError, string *pOutput) const { string FullCommandLine; string ComSpec=GetComspec(); @@ -1012,12 +1012,12 @@ HANDLE mhmakefileparser::OsExeCommand(const string &Command, const string &Param if (pOutput || g_Quiet) { - HANDLE hChildStdinRd; - HANDLE hChildStdinWr; - HANDLE hChildStdoutRd; - HANDLE hChildStdoutWr; - HANDLE hChildStdinWrDup; - HANDLE hChildStdoutRdDup; + mh_pid_t hChildStdinRd; + mh_pid_t hChildStdinWr; + mh_pid_t hChildStdoutRd; + mh_pid_t hChildStdoutWr; + mh_pid_t hChildStdinWrDup; + mh_pid_t hChildStdoutRdDup; SECURITY_ATTRIBUTES saAttr; BOOL fSuccess; @@ -1026,7 +1026,7 @@ HANDLE mhmakefileparser::OsExeCommand(const string &Command, const string &Param saAttr.lpSecurityDescriptor = NULL; if (!CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) - return false; + return (mh_pid_t)-1; /* Create new output read handle and the input write handle. Set * the inheritance properties to FALSE. Otherwise, the child inherits @@ -1035,17 +1035,17 @@ HANDLE mhmakefileparser::OsExeCommand(const string &Command, const string &Param fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, GetCurrentProcess(), &hChildStdinWrDup, 0, FALSE, DUPLICATE_SAME_ACCESS); - if (!fSuccess) return false; + if (!fSuccess) return (mh_pid_t)-1; /* Close the inheritable version of ChildStdin that we're using. */ CloseHandle(hChildStdinWr); if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) - return false; + return (mh_pid_t)-1; fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, GetCurrentProcess(), &hChildStdoutRdDup, 0, FALSE, DUPLICATE_SAME_ACCESS); - if (!fSuccess) return false; + if (!fSuccess) return (mh_pid_t)-1; CloseHandle(hChildStdoutRd); int hStdIn = _open_osfhandle((long)hChildStdinWrDup, _O_WRONLY|_O_TEXT); @@ -1068,8 +1068,8 @@ HANDLE mhmakefileparser::OsExeCommand(const string &Command, const string &Param throw ErrorMessage; } delete[] pFullCommand; - if (!CloseHandle(hChildStdinRd)) return false; - if (!CloseHandle(hChildStdoutWr)) return false; + if (!CloseHandle(hChildStdinRd)) return (mh_pid_t)-1; + if (!CloseHandle(hChildStdoutWr)) return (mh_pid_t)-1; CloseHandle(ProcessInfo.hThread); char Buf[256]; @@ -1092,13 +1092,13 @@ HANDLE mhmakefileparser::OsExeCommand(const string &Command, const string &Param if (IgnoreError) { cerr << "Error running command: "<GetFullFileName().c_str()); + if (m_pEnv) + execve(pargv[0],(char *const*)pargv,m_pEnv); + else + execv(pargv[0],(char *const*)pargv); + free(pargv); + _exit (EXIT_FAILURE); + } + else { /* Close unused pipe ends. This is especially important for the * pipefrom[1] write descriptor, otherwise readFromPipe will never @@ -1183,16 +1182,16 @@ HANDLE mhmakefileparser::OsExeCommand(const string &Command, const string &Param if (IgnoreError) { cerr << "Error forking when try to run command: "<GetFullFileName().c_str()); + if (m_pEnv) + execve(pargv[0],(char *const*)pargv,m_pEnv); + else + execv(pargv[0],(char *const*)pargv); + free(pargv); + _exit (EXIT_FAILURE); + } + else + { + return (mh_pid_t)ID; } } - return true; + + return (mh_pid_t)0; #endif } @@ -1278,7 +1311,7 @@ string EscapeQuotes(const string &Params) #endif /////////////////////////////////////////////////////////////////////////////// -HANDLE mhmakefileparser::ExecuteCommand(string Command, bool &IgnoreError, string *pOutput) +mh_pid_t mhmakefileparser::ExecuteCommand(string Command, bool &IgnoreError, string *pOutput) { bool Echo=true; IgnoreError=false; @@ -1398,7 +1431,7 @@ HANDLE mhmakefileparser::ExecuteCommand(string Command, bool &IgnoreError, strin #ifdef _DEBUG } #endif - return (HANDLE)0; /* No Error */ + return (mh_pid_t)0; /* No Error */ } /////////////////////////////////////////////////////////////////////////////// diff --git a/tools/mhmake/src/commandqueue.cpp b/tools/mhmake/src/commandqueue.cpp index 484d577a5..ae7645708 100644 --- a/tools/mhmake/src/commandqueue.cpp +++ b/tools/mhmake/src/commandqueue.cpp @@ -23,14 +23,67 @@ #include "commandqueue.h" #include "mhmakeparser.h" +#ifndef WIN32 + +#define INFINITE 0 +#define FALSE 0 + +static int Status; +unsigned WaitForMultipleObjects(int Nbr, mh_pid_t *phProcesses, int, int) +{ + mh_pid_t ID=waitpid(0,&Status,0); + for (int i=0; i pTarget=pActiveEntry->pTarget; mhmakeparser *pMakefile=pTarget->GetRule()->GetMakefile(); @@ -106,8 +159,8 @@ bool commandqueue::StartExecuteNextCommand(activeentry *pActiveEntry, HANDLE *pA if (!g_GenProjectTree) { #endif - HANDLE hProcess=pMakefile->ExecuteCommand(Command,pActiveEntry->IgnoreError); - if (hProcess==(HANDLE)-1) + mh_pid_t hProcess=pMakefile->ExecuteCommand(Command,pActiveEntry->IgnoreError); + if (hProcess==(mh_pid_t)-1) { ThrowCommandExecutionError(pActiveEntry); } @@ -235,7 +288,7 @@ mh_time_t commandqueue::WaitForTarget(const refptr &pTarget) while (1) { // First wait until one of the processes that are running is finished - DWORD Ret=WaitForMultipleObjects(m_NrActiveEntries,m_pActiveProcesses,FALSE,INFINITE); + unsigned Ret=WaitForMultipleObjects(m_NrActiveEntries,m_pActiveProcesses,FALSE,INFINITE); if (Ret>=m_NrActiveEntries) throw("fatal error: unexpected return value of WaitForMultipleObjects " + stringify(Ret)); activeentry *pActiveEntry=&m_pActiveEntries[Ret]; @@ -244,7 +297,7 @@ mh_time_t commandqueue::WaitForTarget(const refptr &pTarget) // First check the error code of the command DWORD ExitCode=0; - HANDLE hProcess=m_pActiveProcesses[Ret]; + mh_pid_t hProcess=m_pActiveProcesses[Ret]; if (!GetExitCodeProcess(hProcess,&ExitCode) || ExitCode) { if (pActiveEntry->IgnoreError) diff --git a/tools/mhmake/src/commandqueue.h b/tools/mhmake/src/commandqueue.h index 1e70e3cb6..7480d63dd 100644 --- a/tools/mhmake/src/commandqueue.h +++ b/tools/mhmake/src/commandqueue.h @@ -23,6 +23,12 @@ #include "fileinfo.h" +#ifdef WIN32 +typedef HANDLE mh_pid_t; +#else +typedef pid_t mh_pid_t; +#endif + class commandqueue { struct activeentry @@ -36,7 +42,7 @@ class commandqueue private: queue< refptr > m_Queue; unsigned m_MaxNrCommandsInParallel; - HANDLE *m_pActiveProcesses; + mh_pid_t *m_pActiveProcesses; activeentry *m_pActiveEntries; unsigned m_NrActiveEntries; @@ -44,7 +50,7 @@ private: void ThrowCommandExecutionError(activeentry *pActiveEntry); void RemoveActiveEntry(unsigned Entry); bool StartExecuteCommands(const refptr &pTarget); - bool StartExecuteNextCommand(activeentry *pActiveEntry, HANDLE *pActiveProcess); + bool StartExecuteNextCommand(activeentry *pActiveEntry, mh_pid_t *pActiveProcess); void TargetBuildFinished(activeentry *pActiveEntry); public: diff --git a/tools/mhmake/src/fileinfo.h b/tools/mhmake/src/fileinfo.h index 146ade02b..16ca414e2 100644 --- a/tools/mhmake/src/fileinfo.h +++ b/tools/mhmake/src/fileinfo.h @@ -81,10 +81,7 @@ class mh_time bool operator < (const mh_time &Src); public: mh_time(){m_Time=DATENOTVALID;} -#ifdef WIN32 - mh_time(unsigned __int64 Time) : m_Time((unsigned long)(Time&0xffffffff)) {} - mh_time(__int64 Time) : m_Time((unsigned long)(Time&0xffffffff)) {} -#endif + mh_time(time_t Time) : m_Time((unsigned long)Time) {} mh_time(unsigned long Time) : m_Time(Time) {} mh_time(const mh_time &Time) : m_Time(Time.m_Time) {} diff --git a/tools/mhmake/src/functions.cpp b/tools/mhmake/src/functions.cpp index b4ea64783..b1a5f7a46 100644 --- a/tools/mhmake/src/functions.cpp +++ b/tools/mhmake/src/functions.cpp @@ -378,17 +378,18 @@ string mhmakefileparser::f_wildcard(const string & Arg) const _findclose(hFile); #else glob_t Res; - if (glob (FileSpec.c_str(), GLOB_ERR|GLOB_NOSORT|GLOB_MARK, NULL, &Res)) + if (glob (FileSpec->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(); for (int i=0; iGetQuotedFullFileName(); SepStr=g_SpaceString; } } diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp index 76e43f475..e9d50a704 100644 --- a/tools/mhmake/src/mhmakefileparser.cpp +++ b/tools/mhmake/src/mhmakefileparser.cpp @@ -415,12 +415,21 @@ void mhmakefileparser::PrintVariables(bool Expand) const if (m_pEnv) { cout << "Environment overruled:\n"; +#ifdef WIN32 char *pEnv=m_pEnv; while (*pEnv) { cout< m_pIncludeDirs; string m_IncludeDirs; - + bool m_DoubleColonRule; bool m_AutoDepsDirty; bool m_ForceAutoDepRescan; @@ -92,7 +92,11 @@ protected: bool m_RebuildAll; /* true when to rebuild all targets of this makefile */ set m_UsedEnvVars; // Array containing a list of variables that are taken from the environment (This is used for rebuild checking) +#ifdef WIN32 char *m_pEnv; // New environment in case the makefile exports variables +#else + char **m_pEnv; // New environment in case the makefile exports variables +#endif int m_EnvLen; // Current length of m_pEnv map< refptr, set< refptr > > m_AutoDeps; @@ -125,7 +129,10 @@ public: } /* Needed if you only want to use the searchcommand and execommand functions */ - mhmakefileparser(const refptr &pMakeDir) : m_MakeDir(pMakeDir), m_pEnv(NULL) + mhmakefileparser(const refptr &pMakeDir) : + m_MakeDir(pMakeDir) + , m_AutoDepsDirty(false) + , m_pEnv(NULL) {} static void SetNrParallelBuilds(int NrParallelBuilds) @@ -201,6 +208,11 @@ public: virtual ~mhmakefileparser() { SaveAutoDepsFile(); +#ifndef WIN32 + char **pEnv=m_pEnv; + if (pEnv) + while (*pEnv) free(*pEnv++); +#endif free(m_pEnv); } virtual int yylex(void); @@ -325,8 +337,8 @@ public: } void AddRule(); - HANDLE ExecuteCommand(string Command, bool &IgnoreError, string *pOutput=NULL); - HANDLE ExecuteCommand(string Command, string *pOutput=NULL) + mh_pid_t ExecuteCommand(string Command, bool &IgnoreError, string *pOutput=NULL); + mh_pid_t ExecuteCommand(string Command, string *pOutput=NULL) { bool IgnoreError; return ExecuteCommand(Command, IgnoreError, pOutput); @@ -337,14 +349,14 @@ public: static void InitBuildTime(); void SplitToItems(const string &String, vector< refptr > &Items) const; - HANDLE DeleteFiles(const string &Params) const; - HANDLE CopyFiles(const string &Params) const; - HANDLE TouchFiles(const string &Params) const; - HANDLE EchoCommand(const string &Params) 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; + mh_pid_t EchoCommand(const string &Params) const; string SearchCommand(const string &Command, const string &Extension="") const; const string &GetPythonExe() const; int SearchPath(void *NotUsed, const char *szCommand, const char *pExt, int Len, char *szFullCommand,char **pFilePart) const; - HANDLE OsExeCommand(const string &Command, const string &Params, bool IgnoreError, string *pOutput) const; + mh_pid_t OsExeCommand(const string &Command, const string &Params, bool IgnoreError, string *pOutput) const; }; diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp index 9d8b9510e..79a0424da 100644 --- a/tools/mhmake/src/util.cpp +++ b/tools/mhmake/src/util.cpp @@ -19,13 +19,15 @@ /* $Rev$ */ #include "stdafx.h" -#include #include "rule.h" #include "util.h" #include "mhmakeparser.h" #ifdef WIN32 + +#include + #define REPARSE_MOUNTPOINT_HEADER_SIZE 8 typedef struct { @@ -112,7 +114,7 @@ void PrintVersionInfo(void) static const char VersionStr[]="\ mhmake : GNU compatible make tool with extensions\n\ version: "MHMAKEVER"\n\ -Remarks and bug reports -> Marc Haesen\n\ +Remarks and bug reports -> marha@sourceforge.net\n\ "; cerr << VersionStr; exit(1); @@ -303,7 +305,7 @@ loadedmakefile::loadedmakefile_statics::loadedmakefile_statics() if (FindData.dwReserved0==IO_REPARSE_TAG_MOUNT_POINT) { HANDLE hDir = ::CreateFile(m_MhMakeConf->GetFullFileName().c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL); - + BYTE buf[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; // We need a large buffer REPARSE_MOUNTPOINT_DATA_BUFFER& ReparseBuffer = (REPARSE_MOUNTPOINT_DATA_BUFFER&)buf; DWORD dwRet; -- cgit v1.2.3