add a 'unicode' property to modules (not yet supported by mingw, need to add a librar...
[reactos.git] / reactos / tools / rbuild / rbuild.h
index b65ea6b..87992f1 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2005 Casper S. Hornstrup
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 #ifndef __RBUILD_H
 #define __RBUILD_H
 
@@ -40,6 +57,8 @@ typedef std::vector<std::string> string_list;
 #define SBAD_SEP "\\"
 #endif
 
+#define MS_VS_DEF_VERSION "7.10"
+
 class Project;
 class IfableData;
 class Module;
@@ -55,6 +74,8 @@ class If;
 class CompilerFlag;
 class LinkerFlag;
 class Property;
+class TestSupportCode;
+class WineResource;
 class AutomaticDependency;
 class Bootstrap;
 class CDFile;
@@ -65,6 +86,40 @@ class StubbedSymbol;
 
 class SourceFileTest;
 
+
+class Configuration
+{
+public:
+       Configuration ();
+       ~Configuration ();
+       bool Verbose;
+       bool CleanAsYouGo;
+       bool AutomaticDependencies;
+       bool CheckDependenciesForModuleOnly;
+       std::string CheckDependenciesForModuleOnlyModule;
+       std::string VSProjectVersion;
+       bool MakeHandlesInstallDirectories;
+       bool GenerateProxyMakefilesInSourceTree;
+};
+
+class Environment
+{
+public:
+       static std::string GetVariable ( const std::string& name );
+       static std::string GetIntermediatePath ();
+       static std::string GetOutputPath ();
+       static std::string GetInstallPath ();
+       static std::string GetEnvironmentVariablePathOrDefault ( const std::string& name,
+                                                                const std::string& defaultValue );
+};
+
+class FileSupportCode
+{
+public:
+       static void WriteIfChanged ( char* outbuf,
+                                    std::string filename );
+};
+
 class IfableData
 {
 public:
@@ -102,15 +157,15 @@ public:
        Module* LocateModule ( const std::string& name );
        const Module* LocateModule ( const std::string& name ) const;
        std::string GetProjectFilename () const;
+       std::string ResolveProperties ( const std::string& s ) const;
 private:
+       std::string ResolveNextProperty ( std::string& s ) const;
        const Property* LookupProperty ( const std::string& name ) const;
        void SetConfigurationOption ( char* s,
                                      std::string name,
                                      std::string* alternativeName );
        void SetConfigurationOption ( char* s,
                                      std::string name );
-       void WriteIfChanged ( char* outbuf,
-                             std::string filename );
        void ReadXml ();
        void ProcessXMLSubElement ( const XMLElement& e,
                                    const std::string& path,
@@ -141,7 +196,8 @@ enum ModuleType
        LiveIso = 14,
        Test = 15,
        RpcServer = 16,
-       RpcClient = 17
+       RpcClient = 17,
+       Alias = 18
 };
 
 enum HostType
@@ -158,6 +214,7 @@ public:
        const XMLElement& node;
        std::string xmlbuildFile;
        std::string name;
+       std::string guid;
        std::string extension;
        std::string entrypoint;
        std::string baseaddress;
@@ -165,6 +222,7 @@ public:
        ModuleType type;
        ImportLibrary* importLibrary;
        bool mangledSymbols;
+       bool isUnicode;
        Bootstrap* bootstrap;
        IfableData non_if_data;
        std::vector<Invoke*> invocations;
@@ -178,8 +236,10 @@ public:
        HostType host;
        std::string installBase;
        std::string installName;
+       std::string aliasedModuleName;
        bool useWRC;
-       bool enableWarnings;
+       bool allowWarnings;
+       bool enabled;
 
        Module ( const Project& project,
                 const XMLElement& moduleNode,
@@ -189,16 +249,19 @@ public:
                                   const XMLAttribute& attribute );
        bool HasImportLibrary () const;
        bool IsDLL () const;
-       std::string GetTargetName () const;
-       std::string GetDependencyPath () const;
-       std::string GetBasePath () const;
-       std::string GetPath () const;
-       std::string GetPathWithPrefix ( const std::string& prefix ) const;
+       bool GenerateInOutputTree () const;
+       std::string GetTargetName () const; // "foo.exe"
+       std::string GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
+       std::string GetBasePath () const; // "path"
+       std::string GetPath () const; // "path/foo.exe"
+       std::string GetPathWithPrefix ( const std::string& prefix ) const; // "path/prefixfoo.exe"
        void GetTargets ( string_list& ) const;
        std::string GetInvocationTarget ( const int index ) const;
        bool HasFileWithExtension ( const IfableData&, const std::string& extension ) const;
        void InvokeModule () const;
        void ProcessXML ();
+       void GetSourceFilenames ( string_list& list,
+                                  bool includeGeneratedFiles ) const;
 private:
        std::string GetDefaultModuleExtension () const;
        std::string GetDefaultModuleEntrypoint () const;
@@ -214,19 +277,22 @@ class Include
 public:
        const Project& project;
        const Module* module;
-       const XMLElement& node;
+       const XMLElement* node;
+       const Module* baseModule;
        std::string directory;
        std::string basePath;
 
        Include ( const Project& project,
-                 const XMLElement& includeNode );
+                 const XMLElement* includeNode );
        Include ( const Project& project,
                  const Module* module,
-                 const XMLElement& includeNode );
+                 const XMLElement* includeNode );
+       Include ( const Project& project,
+                 std::string directory,
+                 std::string basePath );
        ~Include ();
        void ProcessXML();
 private:
-       void Initialize();
 };
 
 
@@ -257,12 +323,15 @@ public:
        std::string name;
        bool first;
        std::string switches;
+       bool isPreCompiledHeader;
 
        File ( const std::string& _name,
               bool _first,
-              std::string _switches );
+              std::string _switches,
+              bool _isPreCompiledHeader );
 
        void ProcessXML();
+       bool IsGeneratedFile () const;
 };
 
 
@@ -272,7 +341,7 @@ public:
        const XMLElement& node;
        const Module& module;
        std::string name;
-       const Module* imported_module;
+       const Module* importedModule;
 
        Library ( const XMLElement& _node,
                  const Module& _module,
@@ -353,12 +422,14 @@ public:
        const XMLElement& node;
        const Project& project;
        const Module* module;
+       const bool negated;
        std::string property, value;
        IfableData data;
 
        If ( const XMLElement& node_,
             const Project& project_,
-            const Module* module_ );
+            const Module* module_,
+            const bool negated_ = false );
        ~If();
 
        void ProcessXML();
@@ -421,11 +492,73 @@ public:
 };
 
 
+class TestSupportCode
+{
+public:
+       const Project& project;
+
+       TestSupportCode ( const Project& project );
+       ~TestSupportCode ();
+       void GenerateTestSupportCode ( bool verbose );
+private:
+       bool IsTestModule ( const Module& module );
+       void GenerateTestSupportCodeForModule ( Module& module,
+                                               bool verbose );
+       std::string GetHooksFilename ( Module& module );
+       char* WriteStubbedSymbolToHooksFile ( char* buffer,
+                                             const StubbedComponent& component,
+                                             const StubbedSymbol& symbol );
+       char* WriteStubbedComponentToHooksFile ( char* buffer,
+                                                const StubbedComponent& component );
+       void WriteHooksFile ( Module& module );
+       std::string GetStubsFilename ( Module& module );
+       char* WriteStubbedSymbolToStubsFile ( char* buffer,
+                                              const StubbedComponent& component,
+                                             const StubbedSymbol& symbol,
+                                             int stubIndex );
+       char* WriteStubbedComponentToStubsFile ( char* buffer,
+                                                 const StubbedComponent& component,
+                                                int* stubIndex );
+       void WriteStubsFile ( Module& module );
+       std::string GetStartupFilename ( Module& module );
+       bool IsUnknownCharacter ( char ch );
+       std::string GetTestDispatcherName ( std::string filename );
+       bool IsTestFile ( std::string& filename ) const;
+       void GetSourceFilenames ( string_list& list,
+                                  Module& module ) const;
+       char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer,
+                                                           Module& module );
+       char* WriteRegisterTestsFunctionToStartupFile ( char* buffer,
+                                                       Module& module );
+       void WriteStartupFile ( Module& module );
+};
+
+
+class WineResource
+{
+public:
+       const Project& project;
+       std::string bin2res;
+
+       WineResource ( const Project& project,
+                      std::string bin2res );
+       ~WineResource ();
+       void UnpackResources ( bool verbose );
+private:
+       bool IsSpecFile ( const File& file );
+       bool IsWineModule ( const Module& module );
+       bool IsResourceFile ( const File& file );
+       std::string GetResourceFilename ( const Module& module );
+       void UnpackResourcesInModule ( Module& module,
+                                      bool verbose );
+};
+
+
 class SourceFile
 {
 public:
        SourceFile ( AutomaticDependency* automaticDependency,
-                    Module& module,
+                    const Module& module,
                     const std::string& filename,
                     SourceFile* parent,
                     bool isNonAutomaticDependency );
@@ -434,7 +567,7 @@ public:
        std::string Location () const;
        std::vector<SourceFile*> files;
        AutomaticDependency* automaticDependency;
-       Module& module;
+       const Module& module;
        std::string filename;
        std::string filenamePart;
        std::string directoryPart;
@@ -450,6 +583,7 @@ private:
        void Open ();
        void SkipWhitespace ();
        bool ReadInclude ( std::string& filename,
+                          bool& searchCurrentDirectory,
                           bool& includeNext );
        bool IsIncludedFrom ( const std::string& normalizedFilename );
        SourceFile* GetParentSourceFile ();
@@ -470,26 +604,38 @@ public:
 
        AutomaticDependency ( const Project& project );
        ~AutomaticDependency ();
-       void Process ();
        std::string GetFilename ( const std::string& filename );
        bool LocateIncludedFile ( const std::string& directory,
                                  const std::string& includedFilename,
                                  std::string& resolvedFilename );
        bool LocateIncludedFile ( SourceFile* sourceFile,
-                                 Module& module,
+                                 const Module& module,
                                  const std::string& includedFilename,
+                                 bool searchCurrentDirectory,
                                  bool includeNext,
                                  std::string& resolvedFilename );
-       SourceFile* RetrieveFromCacheOrParse ( Module& module,
+       SourceFile* RetrieveFromCacheOrParse ( const Module& module,
                                               const std::string& filename,
                                               SourceFile* parentSourceFile );
        SourceFile* RetrieveFromCache ( const std::string& filename );
        void CheckAutomaticDependencies ( bool verbose );
-       void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile );
+       void CheckAutomaticDependenciesForModule ( Module& module,
+                                                  bool verbose );
 private:
-       void ProcessModule ( Module& module );
-       void ProcessFile ( Module& module,
-                          const File& file );
+       void GetModulesToCheck ( Module& module, std::vector<const Module*>& modules );
+       void CheckAutomaticDependencies ( const Module& module,
+                                          bool verbose );
+       void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile );
+       void GetIncludeDirectories ( std::vector<Include*>& includes,
+                                    const Module& module,
+                                     Include& currentDirectory,
+                                     bool searchCurrentDirectory );
+       void GetModuleFiles ( const Module& module,
+                              std::vector<File*>& files ) const;
+       void ParseFiles ();
+       void ParseFiles ( const Module& module );
+       void ParseFile ( const Module& module,
+                        const File& file );
        std::map<std::string, SourceFile*> sourcefile_map;
 };
 
@@ -557,12 +703,12 @@ class PchFile
 public:
        const XMLElement& node;
        const Module& module;
-       std::string header;
+       File file;
 
        PchFile (
                const XMLElement& node,
                const Module& module,
-               const std::string& header );
+               const File file );
        void ProcessXML();
 };
 
@@ -589,15 +735,27 @@ public:
        const XMLElement& node;
        std::string symbol;
        std::string newname;
+       std::string strippedName;
 
        StubbedSymbol ( const XMLElement& stubbedSymbolNode );
        ~StubbedSymbol ();
        void ProcessXML();
+private:
+       std::string StripSymbol ( std::string symbol );
 };
 
+extern std::string
+Right ( const std::string& s, size_t n );
+
+extern std::string
+Replace ( const std::string& s, const std::string& find, const std::string& with );
+
 extern std::string
 FixSeparator ( const std::string& s );
 
+extern std::string
+DosSeparator ( const std::string& s );
+
 extern std::string
 ReplaceExtension (
        const std::string& filename,
@@ -615,6 +773,9 @@ GetExtension ( const std::string& filename );
 extern std::string
 GetDirectory ( const std::string& filename );
 
+extern std::string
+GetFilename ( const std::string& filename );
+
 extern std::string
 NormalizeFilename ( const std::string& filename );