mirror of
https://github.com/reactos/reactos.git
synced 2025-08-07 04:23:02 +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;
|
} 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 )
|
MingwBackend::MingwBackend ( Project& project )
|
||||||
: Backend ( project )
|
: Backend ( project )
|
||||||
|
@ -58,6 +27,7 @@ MingwBackend::Process ()
|
||||||
{
|
{
|
||||||
CreateMakefile ();
|
CreateMakefile ();
|
||||||
GenerateHeader ();
|
GenerateHeader ();
|
||||||
|
GenerateGlobalVariables ();
|
||||||
GenerateAllTarget ();
|
GenerateAllTarget ();
|
||||||
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
|
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" );
|
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
|
void
|
||||||
MingwBackend::GenerateAllTarget ()
|
MingwBackend::GenerateAllTarget ()
|
||||||
{
|
{
|
||||||
fprintf ( fMakefile, "all: " );
|
fprintf ( fMakefile, "all:" );
|
||||||
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
|
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
|
||||||
{
|
{
|
||||||
Module& module = *ProjectNode.modules[i];
|
Module& module = *ProjectNode.modules[i];
|
||||||
fprintf ( fMakefile,
|
fprintf ( fMakefile,
|
||||||
" %s" SEP "%s" EXEPOSTFIX,
|
" %s",
|
||||||
FixSep(module.path).c_str (),
|
module.GetPath ().c_str () );
|
||||||
module.name.c_str () );
|
|
||||||
}
|
}
|
||||||
fprintf ( fMakefile, "\n\n" );
|
fprintf ( fMakefile, "\n\t\n\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -28,6 +28,7 @@ private:
|
||||||
void CreateMakefile ();
|
void CreateMakefile ();
|
||||||
void CloseMakefile ();
|
void CloseMakefile ();
|
||||||
void GenerateHeader ();
|
void GenerateHeader ();
|
||||||
|
void GenerateGlobalVariables ();
|
||||||
void GenerateAllTarget ();
|
void GenerateAllTarget ();
|
||||||
FILE* fMakefile;
|
FILE* fMakefile;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,20 +13,118 @@ MingwModuleHandler::MingwModuleHandler ( FILE* fMakefile )
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
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 "";
|
return "";
|
||||||
|
|
||||||
string dependencies ( module.libraries[0]->name );
|
string dependencies ( "" );
|
||||||
|
for ( size_t i = 0; i < module.libraries.size (); i++ )
|
||||||
for ( size_t i = 1; i < module.libraries.size(); i++ )
|
|
||||||
{
|
{
|
||||||
dependencies += " " + module.libraries[i]->name;
|
if ( dependencies.size () > 0 )
|
||||||
|
dependencies += " ";
|
||||||
|
dependencies += module.libraries[i]->name;
|
||||||
}
|
}
|
||||||
return dependencies;
|
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 )
|
MingwKernelModuleHandler::MingwKernelModuleHandler ( FILE* fMakefile )
|
||||||
: MingwModuleHandler ( fMakefile )
|
: MingwModuleHandler ( fMakefile )
|
||||||
|
@ -48,10 +146,10 @@ MingwKernelModuleHandler::Process ( Module& module )
|
||||||
void
|
void
|
||||||
MingwKernelModuleHandler::GenerateKernelModuleTarget ( Module& module )
|
MingwKernelModuleHandler::GenerateKernelModuleTarget ( Module& module )
|
||||||
{
|
{
|
||||||
fprintf ( fMakefile, "%s: %s",
|
fprintf ( fMakefile, "%s: %s\n",
|
||||||
module.name.c_str (),
|
module.GetPath ().c_str (),
|
||||||
GetModuleDependencies ( module ).c_str () );
|
GetModuleLibraryDependencies ( module ).c_str () );
|
||||||
fprintf ( fMakefile, "\n" );
|
fprintf ( fMakefile, "\t\n\n" );
|
||||||
fprintf ( fMakefile, "\t" );
|
GenerateArchiveTarget ( module );
|
||||||
fprintf ( fMakefile, "\n\n" );
|
GenerateObjectFileTargets ( module );
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,16 @@ public:
|
||||||
virtual bool CanHandleModule ( Module& module ) = 0;
|
virtual bool CanHandleModule ( Module& module ) = 0;
|
||||||
virtual void Process ( Module& module ) = 0;
|
virtual void Process ( Module& module ) = 0;
|
||||||
protected:
|
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;
|
FILE* fMakefile;
|
||||||
std::string GetModuleDependencies ( Module& module );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,41 @@
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
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,
|
Module::Module ( const XMLElement& moduleNode,
|
||||||
const string& moduleName,
|
const string& moduleName,
|
||||||
const string& modulePath)
|
const string& modulePath )
|
||||||
: node(moduleNode),
|
: node(moduleNode),
|
||||||
name(moduleName),
|
name(moduleName),
|
||||||
path(modulePath)
|
path(modulePath)
|
||||||
|
@ -61,6 +93,12 @@ Module::GetModuleType ( const XMLAttribute& attribute )
|
||||||
attribute.value );
|
attribute.value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
Module::GetPath ()
|
||||||
|
{
|
||||||
|
return FixSeparator (path) + SEP + name + EXEPOSTFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
File::File ( const string& _name )
|
File::File ( const string& _name )
|
||||||
: name(_name)
|
: name(_name)
|
||||||
|
|
|
@ -50,10 +50,9 @@ public:
|
||||||
Module ( const XMLElement& moduleNode,
|
Module ( const XMLElement& moduleNode,
|
||||||
const std::string& moduleName,
|
const std::string& moduleName,
|
||||||
const std::string& modulePath );
|
const std::string& modulePath );
|
||||||
ModuleType GetModuleType (const XMLAttribute& attribute );
|
|
||||||
|
|
||||||
~Module();
|
~Module();
|
||||||
|
ModuleType GetModuleType (const XMLAttribute& attribute );
|
||||||
|
std::string GetPath ();
|
||||||
void ProcessXML ( const XMLElement& e, const std::string& path );
|
void ProcessXML ( const XMLElement& e, const std::string& path );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue