mirror of
https://github.com/reactos/reactos.git
synced 2025-08-07 07:33:27 +00:00
Generate dependencies for kernel module type.
svn path=/branches/xmlbuildsystem/; revision=12855
This commit is contained in:
parent
505695d368
commit
b1ec82cd59
6 changed files with 176 additions and 54 deletions
|
@ -16,37 +16,6 @@ public:
|
|||
}
|
||||
} 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 @@ MingwBackend::Process ()
|
|||
{
|
||||
CreateMakefile ();
|
||||
GenerateHeader ();
|
||||
GenerateGlobalVariables ();
|
||||
GenerateAllTarget ();
|
||||
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
|
||||
{
|
||||
|
@ -88,19 +58,27 @@ MingwBackend::GenerateHeader ()
|
|||
fprintf ( fMakefile, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -28,6 +28,7 @@ private:
|
|||
void CreateMakefile ();
|
||||
void CloseMakefile ();
|
||||
void GenerateHeader ();
|
||||
void GenerateGlobalVariables ();
|
||||
void GenerateAllTarget ();
|
||||
FILE* fMakefile;
|
||||
};
|
||||
|
|
|
@ -13,20 +13,118 @@ MingwModuleHandler::MingwModuleHandler ( FILE* fMakefile )
|
|||
}
|
||||
|
||||
string
|
||||
MingwModuleHandler::GetModuleDependencies ( Module& module )
|
||||
MingwModuleHandler::ReplaceExtension ( string filename,
|
||||
string newExtension )
|
||||
{
|
||||
if ( !module.libraries.size() )
|
||||
size_t index = filename.find_last_of ( '.' );
|
||||
if (index != string::npos)
|
||||
return filename.substr ( 0, index ) + newExtension;
|
||||
return filename;
|
||||
}
|
||||
|
||||
string
|
||||
MingwModuleHandler::GetModuleArchiveFilename ( Module& module )
|
||||
{
|
||||
return ReplaceExtension ( module.GetPath ().c_str (),
|
||||
".a" );
|
||||
}
|
||||
|
||||
string
|
||||
MingwModuleHandler::GetModuleLibraryDependencies ( Module& module )
|
||||
{
|
||||
if ( module.libraries.size () == 0 )
|
||||
return "";
|
||||
|
||||
string dependencies ( module.libraries[0]->name );
|
||||
|
||||
for ( size_t i = 1; i < module.libraries.size(); i++ )
|
||||
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 @@ MingwKernelModuleHandler::Process ( Module& module )
|
|||
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 );
|
||||
}
|
||||
|
|
|
@ -10,8 +10,16 @@ public:
|
|||
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 );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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,6 +93,12 @@ Module::GetModuleType ( const XMLAttribute& attribute )
|
|||
attribute.value );
|
||||
}
|
||||
|
||||
string
|
||||
Module::GetPath ()
|
||||
{
|
||||
return FixSeparator (path) + SEP + name + EXEPOSTFIX;
|
||||
}
|
||||
|
||||
|
||||
File::File ( const string& _name )
|
||||
: name(_name)
|
||||
|
|
|
@ -50,10 +50,9 @@ public:
|
|||
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 );
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue