Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.h
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h
--- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp 2005-01-06 19:22:01 UTC (rev 12854)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp 2005-01-06 20:38:14 UTC (rev 12855)
@@ -16,37 +16,6 @@
}
} factory;
-#ifdef WIN32
-#define EXEPOSTFIX ".exe"
-#define SEP "\\"
-string
-FixSep ( const string& s )
-{
- string s2(s);
- char* p = strchr ( &s2[0], '/' );
- while ( p )
- {
- *p++ = '\\';
- p = strchr ( p, '/' );
- }
- return s2;
-}
-#else
-#define EXEPOSTFIX
-#define SEP "/"
-string
-FixSep ( const string& s )
-{
- string s2(s);
- char* p = strchr ( &s2[0], '\\' );
- while ( p )
- {
- *p++ = '/';
- p = strchr ( p, '\\' );
- }
- return s2;
-}
-#endif
MingwBackend::MingwBackend ( Project& project )
: Backend ( project )
@@ -58,6 +27,7 @@
{
CreateMakefile ();
GenerateHeader ();
+ GenerateGlobalVariables ();
GenerateAllTarget ();
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
{
@@ -89,18 +59,26 @@
}
void
+MingwBackend::GenerateGlobalVariables ()
+{
+ fprintf ( fMakefile, "gcc = gcc\n" );
+ fprintf ( fMakefile, "ld = ld\n" );
+ fprintf ( fMakefile, "ar = ar\n" );
+ fprintf ( fMakefile, "\n" );
+}
+
+void
MingwBackend::GenerateAllTarget ()
{
- fprintf ( fMakefile, "all: " );
+ fprintf ( fMakefile, "all:" );
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
{
Module& module = *ProjectNode.modules[i];
fprintf ( fMakefile,
- " %s" SEP "%s" EXEPOSTFIX,
- FixSep(module.path).c_str (),
- module.name.c_str () );
+ " %s",
+ module.GetPath ().c_str () );
}
- fprintf ( fMakefile, "\n\n" );
+ fprintf ( fMakefile, "\n\t\n\n" );
}
void
--- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h 2005-01-06 19:22:01 UTC (rev 12854)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h 2005-01-06 20:38:14 UTC (rev 12855)
@@ -28,6 +28,7 @@
void CreateMakefile ();
void CloseMakefile ();
void GenerateHeader ();
+ void GenerateGlobalVariables ();
void GenerateAllTarget ();
FILE* fMakefile;
};
--- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp 2005-01-06 19:22:01 UTC (rev 12854)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp 2005-01-06 20:38:14 UTC (rev 12855)
@@ -13,21 +13,119 @@
}
string
-MingwModuleHandler::GetModuleDependencies ( Module& module )
+MingwModuleHandler::ReplaceExtension ( string filename,
+ string newExtension )
{
- if ( !module.libraries.size() )
- return "";
+ size_t index = filename.find_last_of ( '.' );
+ if (index != string::npos)
+ return filename.substr ( 0, index ) + newExtension;
+ return filename;
+}
- string dependencies ( module.libraries[0]->name );
+string
+MingwModuleHandler::GetModuleArchiveFilename ( Module& module )
+{
+ return ReplaceExtension ( module.GetPath ().c_str (),
+ ".a" );
+}
- for ( size_t i = 1; i < module.libraries.size(); i++ )
+string
+MingwModuleHandler::GetModuleLibraryDependencies ( Module& module )
+{
+ if ( module.libraries.size () == 0 )
+ return "";
+
+ string dependencies ( "" );
+ for ( size_t i = 0; i < module.libraries.size (); i++ )
{
- dependencies += " " + module.libraries[i]->name;
+ if ( dependencies.size () > 0 )
+ dependencies += " ";
+ dependencies += module.libraries[i]->name;
}
return dependencies;
}
+string
+MingwModuleHandler::GetSourceFilenames ( Module& module )
+{
+ if ( module.files.size () == 0 )
+ return "";
+
+ string sourceFilenames ( "" );
+ for ( size_t i = 0; i < module.files.size (); i++ )
+ {
+ if ( sourceFilenames.size () > 0 )
+ sourceFilenames += " ";
+ sourceFilenames += module.files[i]->name;
+ }
+ return sourceFilenames;
+}
+string
+MingwModuleHandler::GetObjectFilename ( string sourceFilename )
+{
+ return ReplaceExtension ( sourceFilename,
+ ".o" );
+}
+
+string
+MingwModuleHandler::GetObjectFilenames ( Module& module )
+{
+ if ( module.files.size () == 0 )
+ return "";
+
+ string objectFilenames ( "" );
+ for ( size_t i = 0; i < module.files.size (); i++ )
+ {
+ if ( objectFilenames.size () > 0 )
+ objectFilenames += " ";
+ objectFilenames += GetObjectFilename ( module.files[i]->name );
+ }
+ return objectFilenames;
+}
+
+void
+MingwModuleHandler::GenerateObjectFileTargets ( Module& module )
+{
+ if ( module.files.size () == 0 )
+ return;
+
+ for ( size_t i = 0; i < module.files.size (); i++ )
+ {
+ string sourceFilename = module.files[i]->name;
+ string objectFilename = GetObjectFilename ( sourceFilename );
+ fprintf ( fMakefile,
+ "%s: %s\n",
+ sourceFilename.c_str (),
+ objectFilename.c_str() );
+ fprintf ( fMakefile,
+ "\t${gcc} -c %s -o %s\n",
+ sourceFilename.c_str (),
+ objectFilename.c_str () );
+ }
+
+ fprintf ( fMakefile, "\n" );
+}
+
+void
+MingwModuleHandler::GenerateArchiveTarget ( Module& module )
+{
+ string archiveFilename = GetModuleArchiveFilename ( module );
+ string sourceFilenames = GetSourceFilenames ( module );
+ string objectFilenames = GetObjectFilenames ( module );
+
+ fprintf ( fMakefile,
+ "%s: %s\n",
+ archiveFilename.c_str (),
+ sourceFilenames.c_str ());
+
+ fprintf ( fMakefile,
+ "\t${ar} -rc %s %s\n\n",
+ archiveFilename.c_str (),
+ objectFilenames.c_str ());
+}
+
+
MingwKernelModuleHandler::MingwKernelModuleHandler ( FILE* fMakefile )
: MingwModuleHandler ( fMakefile )
{
@@ -48,10 +146,10 @@
void
MingwKernelModuleHandler::GenerateKernelModuleTarget ( Module& module )
{
- fprintf ( fMakefile, "%s: %s",
- module.name.c_str (),
- GetModuleDependencies ( module ).c_str () );
- fprintf ( fMakefile, "\n" );
- fprintf ( fMakefile, "\t" );
- fprintf ( fMakefile, "\n\n" );
+ fprintf ( fMakefile, "%s: %s\n",
+ module.GetPath ().c_str (),
+ GetModuleLibraryDependencies ( module ).c_str () );
+ fprintf ( fMakefile, "\t\n\n" );
+ GenerateArchiveTarget ( module );
+ GenerateObjectFileTargets ( module );
}
--- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.h 2005-01-06 19:22:01 UTC (rev 12854)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.h 2005-01-06 20:38:14 UTC (rev 12855)
@@ -10,8 +10,16 @@
virtual bool CanHandleModule ( Module& module ) = 0;
virtual void Process ( Module& module ) = 0;
protected:
+ std::string ReplaceExtension ( std::string filename,
+ std::string newExtension );
+ std::string GetModuleArchiveFilename ( Module& module );
+ std::string GetModuleLibraryDependencies ( Module& module );
+ std::string GetSourceFilenames ( Module& module );
+ std::string GetObjectFilename ( std::string sourceFilename );
+ std::string GetObjectFilenames ( Module& module );
+ void GenerateObjectFileTargets ( Module& module );
+ void GenerateArchiveTarget ( Module& module );
FILE* fMakefile;
- std::string GetModuleDependencies ( Module& module );
};
--- branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp 2005-01-06 19:22:01 UTC (rev 12854)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp 2005-01-06 20:38:14 UTC (rev 12855)
@@ -8,9 +8,41 @@
using std::string;
using std::vector;
+#ifdef WIN32
+#define EXEPOSTFIX ".exe"
+#define SEP "\\"
+string
+FixSeparator ( const string& s )
+{
+ string s2(s);
+ char* p = strchr ( &s2[0], '/' );
+ while ( p )
+ {
+ *p++ = '\\';
+ p = strchr ( p, '/' );
+ }
+ return s2;
+}
+#else
+#define EXEPOSTFIX
+#define SEP "/"
+string
+FixSeparator ( const string& s )
+{
+ string s2(s);
+ char* p = strchr ( &s2[0], '\\' );
+ while ( p )
+ {
+ *p++ = '/';
+ p = strchr ( p, '\\' );
+ }
+ return s2;
+}
+#endif
+
Module::Module ( const XMLElement& moduleNode,
const string& moduleName,
- const string& modulePath)
+ const string& modulePath )
: node(moduleNode),
name(moduleName),
path(modulePath)
@@ -61,7 +93,13 @@
attribute.value );
}
+string
+Module::GetPath ()
+{
+ return FixSeparator (path) + SEP + name + EXEPOSTFIX;
+}
+
File::File ( const string& _name )
: name(_name)
{
--- branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h 2005-01-06 19:22:01 UTC (rev 12854)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h 2005-01-06 20:38:14 UTC (rev 12855)
@@ -50,10 +50,9 @@
Module ( const XMLElement& moduleNode,
const std::string& moduleName,
const std::string& modulePath );
- ModuleType GetModuleType (const XMLAttribute& attribute );
-
~Module();
-
+ ModuleType GetModuleType (const XMLAttribute& attribute );
+ std::string GetPath ();
void ProcessXML ( const XMLElement& e, const std::string& path );
};