Support for non-standard module base addresses
[reactos.git] / reactos / tools / rbuild / rbuild.h
index 671dd55..99d624f 100644 (file)
@@ -3,17 +3,32 @@
 \r
 #include "pch.h"\r
 \r
+#ifdef WIN32\r
+#include <direct.h>\r
+#include <io.h>\r
+#endif\r
+#include <sys/stat.h>\r
+#include <time.h>\r
+#ifdef _MSC_VER\r
+#include <sys/utime.h>\r
+#else\r
+#include <utime.h>\r
+#include <process.h>\r
+#endif\r
+\r
 #include "ssprintf.h"\r
 #include "exception.h"\r
 #include "XML.h"\r
 \r
 #ifdef WIN32\r
+#define EXEPREFIX ""\r
 #define EXEPOSTFIX ".exe"\r
 #define CSEP '\\'\r
 #define CBAD_SEP '/'\r
 #define SSEP "\\"\r
 #define SBAD_SEP "/"\r
 #else\r
+#define EXEPREFIX "./"\r
 #define EXEPOSTFIX ""\r
 #define CSEP '/'\r
 #define CBAD_SEP '\\'\r
@@ -35,6 +50,9 @@ class If;
 class CompilerFlag;\r
 class LinkerFlag;\r
 class Property;\r
+class AutomaticDependency;\r
+\r
+class SourceFileTest;\r
 \r
 class Project\r
 {\r
@@ -50,13 +68,22 @@ public:
        std::vector<Property*> properties;\r
        std::vector<If*> ifs;\r
 \r
-       //Project ();\r
        Project ( const std::string& filename );\r
        ~Project ();\r
+       void WriteConfigurationFile ();\r
+       void ExecuteInvocations ();\r
        void ProcessXML ( const std::string& path );\r
        Module* LocateModule ( const std::string& name );\r
        const Module* LocateModule ( const std::string& name ) const;\r
 private:\r
+       const Property* LookupProperty ( const std::string& name ) const;\r
+       void SetConfigurationOption ( char* s,\r
+                                     std::string name,\r
+                                     std::string* alternativeName );\r
+       void SetConfigurationOption ( char* s,\r
+                                     std::string name );\r
+       void WriteIfChanged ( char* outbuf,\r
+                             std::string filename );\r
        void ReadXml ();\r
        void ProcessXMLSubElement ( const XMLElement& e,\r
                                    const std::string& path,\r
@@ -77,9 +104,12 @@ enum ModuleType
        KernelModeDLL,\r
        KernelModeDriver,\r
        NativeDLL,\r
+       NativeCUI,\r
        Win32DLL,\r
+       Win32CUI,\r
        Win32GUI,\r
        BootLoader,\r
+       BootSector,\r
        Iso\r
 };\r
 \r
@@ -91,9 +121,12 @@ public:
        const XMLElement& node;\r
        std::string name;\r
        std::string extension;\r
+       std::string entrypoint;\r
+       std::string baseaddress;\r
        std::string path;\r
        ModuleType type;\r
        ImportLibrary* importLibrary;\r
+       bool mangledSymbols;\r
        std::vector<File*> files;\r
        std::vector<Library*> libraries;\r
        std::vector<Include*> includes;\r
@@ -120,9 +153,12 @@ public:
        std::string GetInvocationTarget ( const int index ) const;\r
        bool HasFileWithExtensions ( const std::string& extension1,\r
                                     const std::string& extension2 ) const;\r
-       void ProcessXML();\r
+       void InvokeModule () const;\r
+       void ProcessXML ();\r
 private:\r
        std::string GetDefaultModuleExtension () const;\r
+       std::string GetDefaultModuleEntrypoint () const;\r
+       std::string GetDefaultModuleBaseaddress () const;\r
        void ProcessXMLSubElement ( const XMLElement& e,\r
                                    const std::string& path,\r
                                    If* pIf = NULL );\r
@@ -212,6 +248,7 @@ public:
 \r
        void ProcessXML();\r
        std::string GetTargets () const;\r
+       std::string GetParameters () const;\r
 private:\r
        void ProcessXMLSubElement ( const XMLElement& e );\r
        void ProcessXMLSubElementInput ( const XMLElement& e );\r
@@ -339,12 +376,89 @@ public:
        void ProcessXML();\r
 };\r
 \r
+\r
+class SourceFile\r
+{\r
+public:\r
+       SourceFile ( AutomaticDependency* automaticDependency,\r
+                    Module& module,\r
+                    const std::string& filename,\r
+                    SourceFile* parent,\r
+                    bool isNonAutomaticDependency );\r
+       SourceFile* ParseFile ( const std::string& normalizedFilename );\r
+       void Parse ();\r
+       std::string Location () const;\r
+       std::vector<SourceFile*> files;\r
+       AutomaticDependency* automaticDependency;\r
+       Module& module;\r
+       std::string filename;\r
+       std::string filenamePart;\r
+       std::string directoryPart;\r
+       std::vector<SourceFile*> parents; /* List of files, this file is included from */\r
+       bool isNonAutomaticDependency;\r
+       std::string cachedDependencies;\r
+       time_t lastWriteTime;\r
+       time_t youngestLastWriteTime; /* Youngest last write time of this file and all children */\r
+       SourceFile* youngestFile;\r
+private:\r
+       void GetDirectoryAndFilenameParts ();\r
+       void Close ();\r
+       void Open ();\r
+       void SkipWhitespace ();\r
+       bool ReadInclude ( std::string& filename,\r
+                          bool& includeNext );\r
+       bool IsIncludedFrom ( const std::string& normalizedFilename );\r
+       SourceFile* GetParentSourceFile ();\r
+       bool CanProcessFile ( const std::string& extension );\r
+       bool IsParentOf ( const SourceFile* parent,\r
+                         const SourceFile* child );\r
+       std::string buf;\r
+       const char *p;\r
+       const char *end;\r
+};\r
+\r
+\r
+class AutomaticDependency\r
+{\r
+       friend class SourceFileTest;\r
+public:\r
+       const Project& project;\r
+\r
+       AutomaticDependency ( const Project& project );\r
+       ~AutomaticDependency ();\r
+       void Process ();\r
+       std::string GetFilename ( const std::string& filename );\r
+       bool LocateIncludedFile ( const std::string& directory,\r
+                                 const std::string& includedFilename,\r
+                                 std::string& resolvedFilename );\r
+       bool LocateIncludedFile ( SourceFile* sourceFile,\r
+                                 Module& module,\r
+                                 const std::string& includedFilename,\r
+                                 bool includeNext,\r
+                                 std::string& resolvedFilename );\r
+       SourceFile* RetrieveFromCacheOrParse ( Module& module,\r
+                                              const std::string& filename,\r
+                                              SourceFile* parentSourceFile );\r
+       SourceFile* RetrieveFromCache ( const std::string& filename );\r
+       void CheckAutomaticDependencies ();\r
+       void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile );\r
+private:\r
+       void ProcessModule ( Module& module );\r
+       void ProcessFile ( Module& module,\r
+                          const File& file );\r
+       std::map<std::string, SourceFile*> sourcefile_map;\r
+};\r
+\r
+\r
 extern std::string\r
 FixSeparator ( const std::string& s );\r
 \r
 extern std::string\r
 GetExtension ( const std::string& filename );\r
 \r
+extern std::string\r
+GetDirectory ( const std::string& filename );\r
+\r
 extern std::string\r
 NormalizeFilename ( const std::string& filename );\r
 \r