Generate dependencies for kernel module type.
authorCasper Hornstrup <chorns@users.sourceforge.net>
Thu, 6 Jan 2005 20:38:14 +0000 (20:38 +0000)
committerCasper Hornstrup <chorns@users.sourceforge.net>
Thu, 6 Jan 2005 20:38:14 +0000 (20:38 +0000)
svn path=/branches/xmlbuildsystem/; revision=12855

reactos/tools/rbuild/backend/mingw/mingw.cpp
reactos/tools/rbuild/backend/mingw/mingw.h
reactos/tools/rbuild/backend/mingw/modulehandler.cpp
reactos/tools/rbuild/backend/mingw/modulehandler.h
reactos/tools/rbuild/module.cpp
reactos/tools/rbuild/rbuild.h

index b548134..3d2ea8a 100644 (file)
@@ -16,37 +16,6 @@ public:
        }\r
 } factory;\r
 \r
-#ifdef WIN32\r
-#define EXEPOSTFIX ".exe"\r
-#define SEP "\\"\r
-string\r
-FixSep ( const string& s )\r
-{\r
-       string s2(s);\r
-       char* p = strchr ( &s2[0], '/' );\r
-       while ( p )\r
-       {\r
-               *p++ = '\\';\r
-               p = strchr ( p, '/' );\r
-       }\r
-       return s2;\r
-}\r
-#else\r
-#define EXEPOSTFIX\r
-#define SEP "/"\r
-string\r
-FixSep ( const string& s )\r
-{\r
-       string s2(s);\r
-       char* p = strchr ( &s2[0], '\\' );\r
-       while ( p )\r
-       {\r
-               *p++ = '/';\r
-               p = strchr ( p, '\\' );\r
-       }\r
-       return s2;\r
-}\r
-#endif\r
 \r
 MingwBackend::MingwBackend ( Project& project )\r
        : Backend ( project )\r
@@ -58,6 +27,7 @@ MingwBackend::Process ()
 {\r
        CreateMakefile ();\r
        GenerateHeader ();\r
+       GenerateGlobalVariables ();\r
        GenerateAllTarget ();\r
        for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )\r
        {\r
@@ -88,19 +58,27 @@ MingwBackend::GenerateHeader ()
        fprintf ( fMakefile, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );\r
 }\r
 \r
+void\r
+MingwBackend::GenerateGlobalVariables ()\r
+{\r
+       fprintf ( fMakefile, "gcc = gcc\n" );\r
+       fprintf ( fMakefile, "ld = ld\n" );\r
+       fprintf ( fMakefile, "ar = ar\n" );\r
+       fprintf ( fMakefile, "\n" );\r
+}\r
+\r
 void\r
 MingwBackend::GenerateAllTarget ()\r
 {\r
-       fprintf ( fMakefile, "all: " );\r
+       fprintf ( fMakefile, "all:" );\r
        for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )\r
        {\r
                Module& module = *ProjectNode.modules[i];\r
                fprintf ( fMakefile,\r
-                         " %s" SEP "%s" EXEPOSTFIX,\r
-                         FixSep(module.path).c_str (),\r
-                         module.name.c_str () );\r
+                         " %s",\r
+                         module.GetPath ().c_str () );\r
        }\r
-       fprintf ( fMakefile, "\n\n" );\r
+       fprintf ( fMakefile, "\n\t\n\n" );\r
 }\r
 \r
 void\r
index ebdf7fb..794a7f9 100644 (file)
@@ -28,6 +28,7 @@ private:
        void CreateMakefile ();\r
        void CloseMakefile ();\r
        void GenerateHeader ();\r
+       void GenerateGlobalVariables ();\r
        void GenerateAllTarget ();\r
        FILE* fMakefile;\r
 };\r
index 23f8205..60cc98c 100644 (file)
@@ -13,20 +13,118 @@ MingwModuleHandler::MingwModuleHandler ( FILE* fMakefile )
 }\r
 \r
 string\r
-MingwModuleHandler::GetModuleDependencies ( Module& module )\r
+MingwModuleHandler::ReplaceExtension ( string filename,\r
+                                          string newExtension )\r
 {\r
-       if ( !module.libraries.size() )\r
-               return "";\r
+       size_t index = filename.find_last_of ( '.' );\r
+       if (index != string::npos)\r
+               return filename.substr ( 0, index ) + newExtension;\r
+       return filename;\r
+}\r
 \r
-       string dependencies ( module.libraries[0]->name );\r
+string\r
+MingwModuleHandler::GetModuleArchiveFilename ( Module& module )\r
+{\r
+       return ReplaceExtension ( module.GetPath ().c_str (),\r
+                                 ".a" );\r
+}\r
 \r
-       for ( size_t i = 1; i < module.libraries.size(); i++ )\r
+string\r
+MingwModuleHandler::GetModuleLibraryDependencies ( Module& module )\r
+{\r
+       if ( module.libraries.size () == 0 )\r
+               return "";\r
+       \r
+       string dependencies ( "" );\r
+       for ( size_t i = 0; i < module.libraries.size (); i++ )\r
        {\r
-               dependencies += " " + module.libraries[i]->name;\r
+               if ( dependencies.size () > 0 )\r
+                       dependencies += " ";\r
+               dependencies += module.libraries[i]->name;\r
        }\r
        return dependencies;\r
 }\r
 \r
+string\r
+MingwModuleHandler::GetSourceFilenames ( Module& module )\r
+{\r
+       if ( module.files.size () == 0 )\r
+               return "";\r
+       \r
+       string sourceFilenames ( "" );\r
+       for ( size_t i = 0; i < module.files.size (); i++ )\r
+       {\r
+               if ( sourceFilenames.size () > 0 )\r
+                       sourceFilenames += " ";\r
+               sourceFilenames += module.files[i]->name;\r
+       }\r
+       return sourceFilenames;\r
+}\r
+\r
+string\r
+MingwModuleHandler::GetObjectFilename ( string sourceFilename )\r
+{\r
+       return ReplaceExtension ( sourceFilename,\r
+                                     ".o" );\r
+}\r
+\r
+string\r
+MingwModuleHandler::GetObjectFilenames ( Module& module )\r
+{\r
+       if ( module.files.size () == 0 )\r
+               return "";\r
+       \r
+       string objectFilenames ( "" );\r
+       for ( size_t i = 0; i < module.files.size (); i++ )\r
+       {\r
+               if ( objectFilenames.size () > 0 )\r
+                       objectFilenames += " ";\r
+               objectFilenames += GetObjectFilename ( module.files[i]->name );\r
+       }\r
+       return objectFilenames;\r
+}\r
+\r
+void\r
+MingwModuleHandler::GenerateObjectFileTargets ( Module& module )\r
+{\r
+       if ( module.files.size () == 0 )\r
+               return;\r
+       \r
+       for ( size_t i = 0; i < module.files.size (); i++ )\r
+       {\r
+               string sourceFilename = module.files[i]->name;\r
+               string objectFilename = GetObjectFilename ( sourceFilename );\r
+               fprintf ( fMakefile,\r
+                         "%s: %s\n",\r
+                         sourceFilename.c_str (),\r
+                         objectFilename.c_str() );\r
+               fprintf ( fMakefile,\r
+                         "\t${gcc} -c %s -o %s\n",\r
+                         sourceFilename.c_str (),\r
+                         objectFilename.c_str () );\r
+       }\r
+       \r
+       fprintf ( fMakefile, "\n" );\r
+}\r
+\r
+void\r
+MingwModuleHandler::GenerateArchiveTarget ( Module& module )\r
+{\r
+       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string sourceFilenames = GetSourceFilenames ( module );\r
+       string objectFilenames = GetObjectFilenames ( module );\r
+       \r
+       fprintf ( fMakefile,\r
+                 "%s: %s\n",\r
+                 archiveFilename.c_str (),\r
+                 sourceFilenames.c_str ());\r
+\r
+       fprintf ( fMakefile,\r
+                "\t${ar} -rc %s %s\n\n",\r
+                archiveFilename.c_str (),\r
+                objectFilenames.c_str ());\r
+}\r
+\r
 \r
 MingwKernelModuleHandler::MingwKernelModuleHandler ( FILE* fMakefile )\r
        : MingwModuleHandler ( fMakefile )\r
@@ -48,10 +146,10 @@ MingwKernelModuleHandler::Process ( Module& module )
 void\r
 MingwKernelModuleHandler::GenerateKernelModuleTarget ( Module& module )\r
 {\r
-       fprintf ( fMakefile, "%s: %s",\r
-                 module.name.c_str (),\r
-                 GetModuleDependencies ( module ).c_str () );\r
-       fprintf ( fMakefile, "\n" );\r
-       fprintf ( fMakefile, "\t" );\r
-       fprintf ( fMakefile, "\n\n" );\r
+       fprintf ( fMakefile, "%s: %s\n",\r
+                 module.GetPath ().c_str (),\r
+                 GetModuleLibraryDependencies ( module ).c_str () );\r
+       fprintf ( fMakefile, "\t\n\n" );\r
+       GenerateArchiveTarget ( module );\r
+       GenerateObjectFileTargets ( module );\r
 }\r
index 1f827be..add4864 100644 (file)
@@ -10,8 +10,16 @@ public:
        virtual bool CanHandleModule ( Module& module ) = 0;\r
        virtual void Process ( Module& module ) = 0;\r
 protected:\r
+       std::string ReplaceExtension ( std::string filename,\r
+                                      std::string newExtension );\r
+       std::string GetModuleArchiveFilename ( Module& module );\r
+       std::string GetModuleLibraryDependencies ( Module& module );\r
+       std::string GetSourceFilenames ( Module& module );\r
+       std::string GetObjectFilename ( std::string sourceFilename );\r
+       std::string GetObjectFilenames ( Module& module );\r
+       void GenerateObjectFileTargets ( Module& module );\r
+       void GenerateArchiveTarget ( Module& module );\r
        FILE* fMakefile;\r
-       std::string GetModuleDependencies ( Module& module );\r
 };\r
 \r
 \r
index 7b6018a..1a3271a 100644 (file)
@@ -8,9 +8,41 @@
 using std::string;\r
 using std::vector;\r
 \r
+#ifdef WIN32\r
+#define EXEPOSTFIX ".exe"\r
+#define SEP "\\"\r
+string\r
+FixSeparator ( const string& s )\r
+{\r
+       string s2(s);\r
+       char* p = strchr ( &s2[0], '/' );\r
+       while ( p )\r
+       {\r
+               *p++ = '\\';\r
+               p = strchr ( p, '/' );\r
+       }\r
+       return s2;\r
+}\r
+#else\r
+#define EXEPOSTFIX\r
+#define SEP "/"\r
+string\r
+FixSeparator ( const string& s )\r
+{\r
+       string s2(s);\r
+       char* p = strchr ( &s2[0], '\\' );\r
+       while ( p )\r
+       {\r
+               *p++ = '/';\r
+               p = strchr ( p, '\\' );\r
+       }\r
+       return s2;\r
+}\r
+#endif\r
+\r
 Module::Module ( const XMLElement& moduleNode,\r
                  const string& moduleName,\r
-                 const string& modulePath)\r
+                 const string& modulePath )\r
        : node(moduleNode),\r
          name(moduleName),\r
          path(modulePath)\r
@@ -61,6 +93,12 @@ Module::GetModuleType ( const XMLAttribute& attribute )
                                               attribute.value );\r
 }\r
 \r
+string\r
+Module::GetPath ()\r
+{\r
+       return FixSeparator (path) + SEP + name + EXEPOSTFIX;\r
+}\r
+\r
 \r
 File::File ( const string& _name )\r
        : name(_name)\r
index c722078..913ec5d 100644 (file)
@@ -50,10 +50,9 @@ public:
        Module ( const XMLElement& moduleNode,\r
                 const std::string& moduleName,\r
                 const std::string& modulePath );\r
-       ModuleType GetModuleType (const XMLAttribute& attribute );\r
-\r
        ~Module();\r
-\r
+       ModuleType GetModuleType (const XMLAttribute& attribute );\r
+       std::string GetPath ();\r
        void ProcessXML ( const XMLElement& e, const std::string& path );\r
 };\r
 \r