Support for non-standard module base addresses
[reactos.git] / reactos / tools / rbuild / rbuild.h
index 1407a84..99d624f 100644 (file)
@@ -3,18 +3,33 @@
 \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 EXEPOSTFIX\r
+#define EXEPREFIX "./"\r
+#define EXEPOSTFIX ""\r
 #define CSEP '/'\r
 #define CBAD_SEP '\\'\r
 #define SSEP "/"\r
@@ -30,28 +45,53 @@ class Library;
 class Invoke;\r
 class InvokeFile;\r
 class Dependency;\r
+class ImportLibrary;\r
+class If;\r
+class CompilerFlag;\r
+class LinkerFlag;\r
+class Property;\r
+class AutomaticDependency;\r
+\r
+class SourceFileTest;\r
 \r
 class Project\r
 {\r
+       std::string xmlfile;\r
+       XMLElement *node, *head;\r
 public:\r
        std::string name;\r
        std::string makefile;\r
        std::vector<Module*> modules;\r
        std::vector<Include*> includes;\r
        std::vector<Define*> defines;\r
+       std::vector<LinkerFlag*> linkerFlags;\r
+       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
-       XMLFile xmlfile;\r
-       XMLElement* node;\r
        void ProcessXMLSubElement ( const XMLElement& e,\r
-                                   const std::string& path );\r
+                                   const std::string& path,\r
+                                   If* pIf = NULL );\r
+\r
+       // disable copy semantics\r
+       Project ( const Project& );\r
+       Project& operator = ( const Project& );\r
 };\r
 \r
 \r
@@ -59,7 +99,18 @@ enum ModuleType
 {\r
        BuildTool,\r
        StaticLibrary,\r
-       KernelModeDLL\r
+       ObjectLibrary,\r
+       Kernel,\r
+       KernelModeDLL,\r
+       KernelModeDriver,\r
+       NativeDLL,\r
+       NativeCUI,\r
+       Win32DLL,\r
+       Win32CUI,\r
+       Win32GUI,\r
+       BootLoader,\r
+       BootSector,\r
+       Iso\r
 };\r
 \r
 \r
@@ -70,14 +121,21 @@ 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
        std::vector<Define*> defines;\r
        std::vector<Invoke*> invocations;\r
        std::vector<Dependency*> dependencies;\r
+       std::vector<If*> ifs;\r
+       std::vector<CompilerFlag*> compilerFlags;\r
+       std::vector<LinkerFlag*> linkerFlags;\r
 \r
        Module ( const Project& project,\r
                 const XMLElement& moduleNode,\r
@@ -85,15 +143,25 @@ public:
        ~Module ();\r
        ModuleType GetModuleType ( const std::string& location,\r
                                   const XMLAttribute& attribute );\r
-       std::string GetBasePath() const;\r
+       bool HasImportLibrary () const;\r
+       std::string GetTargetName () const;\r
+       std::string GetDependencyPath () const;\r
+       std::string GetBasePath () const;\r
        std::string GetPath () const;\r
+       std::string GetPathWithPrefix ( const std::string& prefix ) const;\r
        std::string GetTargets () const;\r
        std::string GetInvocationTarget ( const int index ) const;\r
-       void ProcessXML();\r
+       bool HasFileWithExtensions ( const std::string& extension1,\r
+                                    const std::string& extension2 ) const;\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
+                                   const std::string& path,\r
+                                   If* pIf = NULL );\r
 };\r
 \r
 \r
@@ -104,7 +172,7 @@ public:
        const Module* module;\r
        const XMLElement& node;\r
        std::string directory;\r
-       const Module* base;\r
+       std::string basePath;\r
 \r
        Include ( const Project& project,\r
                  const XMLElement& includeNode );\r
@@ -143,8 +211,9 @@ class File
 {\r
 public:\r
        std::string name;\r
+       bool first;\r
 \r
-       File ( const std::string& _name );\r
+       File ( const std::string& _name, bool _first );\r
 \r
        void ProcessXML();\r
 };\r
@@ -179,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
@@ -213,7 +283,183 @@ public:
        void ProcessXML();\r
 };\r
 \r
+\r
+class ImportLibrary\r
+{\r
+public:\r
+       const XMLElement& node;\r
+       const Module& module;\r
+       std::string basename;\r
+       std::string definition;\r
+\r
+       ImportLibrary ( const XMLElement& _node,\r
+                       const Module& module );\r
+\r
+       void ProcessXML ();\r
+};\r
+\r
+\r
+class If\r
+{\r
+public:\r
+       const XMLElement& node;\r
+       const Project& project;\r
+       const Module* module;\r
+       std::string property, value;\r
+       std::vector<File*> files;\r
+       std::vector<Include*> includes;\r
+       std::vector<Define*> defines;\r
+       std::vector<Property*> properties;\r
+       std::vector<If*> ifs;\r
+\r
+       If ( const XMLElement& node_,\r
+            const Project& project_,\r
+            const Module* module_ );\r
+       ~If();\r
+\r
+       void ProcessXML();\r
+};\r
+\r
+\r
+class CompilerFlag\r
+{\r
+public:\r
+       const Project& project;\r
+       const Module* module;\r
+       const XMLElement& node;\r
+       std::string flag;\r
+\r
+       CompilerFlag ( const Project& project,\r
+                      const XMLElement& compilerFlagNode );\r
+       CompilerFlag ( const Project& project,\r
+                      const Module* module,\r
+                      const XMLElement& compilerFlagNode );\r
+       ~CompilerFlag ();\r
+       void ProcessXML();\r
+private:\r
+       void Initialize();\r
+};\r
+\r
+\r
+class LinkerFlag\r
+{\r
+public:\r
+       const Project& project;\r
+       const Module* module;\r
+       const XMLElement& node;\r
+       std::string flag;\r
+\r
+       LinkerFlag ( const Project& project,\r
+                    const XMLElement& linkerFlagNode );\r
+       LinkerFlag ( const Project& project,\r
+                    const Module* module,\r
+                    const XMLElement& linkerFlagNode );\r
+       ~LinkerFlag ();\r
+       void ProcessXML();\r
+private:\r
+       void Initialize();\r
+};\r
+\r
+\r
+class Property\r
+{\r
+public:\r
+       const XMLElement& node;\r
+       const Project& project;\r
+       const Module* module;\r
+       std::string name, value;\r
+\r
+       Property ( const XMLElement& node_,\r
+                  const Project& project_,\r
+                  const Module* module_ );\r
+\r
+       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
 #endif /* __RBUILD_H */\r