}\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
{\r
CreateMakefile ();\r
GenerateHeader ();\r
+ GenerateGlobalVariables ();\r
GenerateAllTarget ();\r
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )\r
{\r
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
}\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
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
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
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