Precondition dependencies.

svn path=/branches/xmlbuildsystem/; revision=12897
This commit is contained in:
Casper Hornstrup
2005-01-09 01:10:43 +00:00
parent 87d6ec37a6
commit 2ddad45463
9 changed files with 205 additions and 31 deletions

View File

@@ -16,6 +16,6 @@
<xi:include href="lib/directory.xml" />
</directory>
<directory name="ntoskrnl">
<xi:include href="ntoskrnl/module.xml" />
<xi:include href="ntoskrnl/ntoskrnl.xml" />
</directory>
</project>

View File

@@ -1,5 +1,6 @@
<module name="ntoskrnl" type="kernelmodedll" extension=".exe">
<dependency>buildno</dependency>
<dependency>wmc</dependency>
<define name="_SEH_NO_NATIVE_NLG" />
<define name="_DISABLE_TIDENTS" />
<define name="__NTOSKRNL__" />
@@ -7,6 +8,15 @@
<include base="kjs">./include</include>
<include base="ntoskrnl">include</include>
<library>kjs</library>
<invoke module="wmc">
<input>
<inputfile>ntoskrnl.mc</inputfile>
</input>
<output>
<outputfile switches="-H">../include/reactos/bugcodes.h</outputfile>
<outputfile switches="-o">bugcodes.rc</outputfile>
</output>
</invoke>
<directory name="cc">
<file>cacheman.c</file>
<file>copy.c</file>

View File

@@ -32,10 +32,8 @@
#define FALSE 0
#define TRUE 1
/* File to (over)write */
#define BUILDNO_INCLUDE_FILE "../include/reactos/buildno.h"
static char * argv0 = "";
static char * filename = "";
#ifdef DBG
void
@@ -157,7 +155,7 @@ write_h (int build)
s = s + sprintf (s, "-%S\"\n", KERNEL_VERSION_BUILD_TYPE);
s = s + sprintf (s, "#endif\n/* EOF */\n");
h = fopen (BUILDNO_INCLUDE_FILE, "rb");
h = fopen (filename, "rb");
if (h != NULL)
{
fseek(h, 0, SEEK_END);
@@ -178,13 +176,13 @@ write_h (int build)
fclose(h);
}
h = fopen (BUILDNO_INCLUDE_FILE, "wb");
h = fopen (filename, "wb");
if (!h)
{
fprintf (stderr,
"%s: can not create file \"%s\"!\n",
argv0,
BUILDNO_INCLUDE_FILE);
filename);
return;
}
fwrite(s1, 1, strlen(s1), h);
@@ -196,7 +194,7 @@ usage (void)
{
fprintf (
stderr,
"Usage: %s [-{p|q}]\n\n -p print version number and exit\n -q run in quiet mode\n",
"Usage: %s [-{p|q}] path-to-header\n\n -p print version number and exit\n -q run in quiet mode\n",
argv0
);
exit (EXIT_SUCCESS);
@@ -221,6 +219,7 @@ main (int argc, char * argv [])
case 1:
break;
case 2:
case 3:
if (argv[1][0] == '-')
{
if (argv[1][1] == 'q')
@@ -235,6 +234,11 @@ main (int argc, char * argv [])
{
usage ();
}
filename = argv[2];
}
else if (argc == 2)
{
filename = argv[1];
}
else
{

View File

@@ -106,7 +106,7 @@ string
MingwModuleHandler::GetObjectFilename ( const string& sourceFilename ) const
{
return FixupTargetFilename ( ReplaceExtension ( sourceFilename,
".o" ) );
".o" ) );
}
string
@@ -221,12 +221,10 @@ MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
{
string sourceFilename = module.files[i]->name;
string objectFilename = GetObjectFilename ( sourceFilename );
string dependencies = GetModuleDependencies ( module );
fprintf ( fMakefile,
"%s: %s %s\n",
"%s: %s\n",
objectFilename.c_str (),
sourceFilename.c_str (),
dependencies.c_str ());
sourceFilename.c_str () );
fprintf ( fMakefile,
"\t%s -c %s -o %s %s\n",
cc.c_str (),
@@ -293,27 +291,64 @@ MingwModuleHandler::GetInvocationDependencies ( const Module& module ) const
for ( size_t i = 0; i < module.invocations.size (); i++ )
{
Invoke& invoke = *module.invocations[i];
if (invoke.invokeModule == &module)
/* Protect against circular dependencies */
continue;
if ( dependencies.length () > 0 )
dependencies += " ";
string invokeTarget = module.GetInvocationTarget ( i );
dependencies += invokeTarget;
dependencies += invoke.GetTargets ();
}
return dependencies;
}
string
MingwModuleHandler::GetInvocationParameters ( const Invoke& invoke ) const
{
string parameters ( "" );
size_t i;
for (i = 0; i < invoke.output.size (); i++)
{
if (parameters.length () > 0)
parameters += " ";
InvokeFile& invokeFile = *invoke.output[i];
if (invokeFile.switches.length () > 0)
{
parameters += invokeFile.switches;
parameters += " ";
}
parameters += invokeFile.name;
}
for (i = 0; i < invoke.input.size (); i++)
{
if (parameters.length () > 0)
parameters += " ";
InvokeFile& invokeFile = *invoke.input[i];
if (invokeFile.switches.length () > 0)
{
parameters += invokeFile.switches;
parameters += " ";
}
parameters += invokeFile.name;
}
return parameters;
}
void
MingwModuleHandler::GenerateInvocations ( const Module& module ) const
{
if ( module.invocations.size () == 0 )
return;
if ( module.type != BuildTool )
throw InvalidBuildFileException ( module.node.location,
"Only modules of type buildtool can be invoked." );
for ( size_t i = 0; i < module.invocations.size (); i++ )
{
Invoke& invoke = *module.invocations[i];
const Invoke& invoke = *module.invocations[i];
if ( invoke.invokeModule->type != BuildTool )
throw InvalidBuildFileException ( module.node.location,
"Only modules of type buildtool can be invoked." );
string invokeTarget = module.GetInvocationTarget ( i );
fprintf ( fMakefile,
"%s: %s\n\n",
@@ -322,16 +357,51 @@ MingwModuleHandler::GenerateInvocations ( const Module& module ) const
fprintf ( fMakefile,
"%s: %s\n",
invokeTarget.c_str (),
FixupTargetFilename ( module.GetPath () ).c_str () );
FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str () );
fprintf ( fMakefile,
"\t%s\n\n",
FixupTargetFilename ( module.GetPath () ).c_str () );
"\t%s %s\n\n",
FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),
GetInvocationParameters ( invoke ).c_str () );
fprintf ( fMakefile,
".PNONY: %s\n\n",
invokeTarget.c_str () );
}
}
string
MingwModuleHandler::GetPreconditionDependenciesName ( const Module& module ) const
{
return ssprintf ( "%s_precondition",
module.name.c_str () );
}
void
MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) const
{
string preconditionDependenciesName = GetPreconditionDependenciesName ( module );
string sourceFilenames = GetSourceFilenames ( module );
string dependencies = GetModuleDependencies ( module );
string s = GetInvocationDependencies ( module );
if ( s.length () > 0 )
{
if ( dependencies.length () > 0 )
dependencies += " ";
dependencies += s;
}
fprintf ( fMakefile,
"%s: %s\n\n",
preconditionDependenciesName.c_str (),
dependencies.c_str () );
fprintf ( fMakefile,
"%s: %s\n\n",
sourceFilenames.c_str (),
preconditionDependenciesName.c_str ());
fprintf ( fMakefile,
".PNONY: %s\n\n",
preconditionDependenciesName.c_str () );
}
MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( FILE* fMakefile )
: MingwModuleHandler ( fMakefile )
@@ -347,6 +417,7 @@ MingwBuildToolModuleHandler::CanHandleModule ( const Module& module ) const
void
MingwBuildToolModuleHandler::Process ( const Module& module )
{
GeneratePreconditionDependencies ( module );
GenerateBuildToolModuleTarget ( module );
GenerateInvocations ( module );
}
@@ -382,6 +453,7 @@ MingwKernelModuleHandler::CanHandleModule ( const Module& module ) const
void
MingwKernelModuleHandler::Process ( const Module& module )
{
GeneratePreconditionDependencies ( module );
GenerateKernelModuleTarget ( module );
GenerateInvocations ( module );
}
@@ -448,6 +520,7 @@ MingwStaticLibraryModuleHandler::CanHandleModule ( const Module& module ) const
void
MingwStaticLibraryModuleHandler::Process ( const Module& module )
{
GeneratePreconditionDependencies ( module );
GenerateStaticLibraryModuleTarget ( module );
GenerateInvocations ( module );
}

View File

@@ -26,7 +26,9 @@ protected:
void GenerateArchiveTargetHost ( const Module& module ) const;
void GenerateArchiveTargetTarget ( const Module& module ) const;
std::string GetInvocationDependencies ( const Module& module ) const;
std::string GetInvocationParameters ( const Invoke& invoke ) const;
void GenerateInvocations ( const Module& module ) const;
void GeneratePreconditionDependencies ( const Module& module ) const;
FILE* fMakefile;
private:
std::string ConcatenatePaths ( const std::string& path1,
@@ -40,6 +42,7 @@ private:
const std::string& cc ) const;
void GenerateArchiveTarget ( const Module& module,
const std::string& ar ) const;
std::string GetPreconditionDependenciesName ( const Module& module ) const;
};

View File

@@ -235,7 +235,7 @@ Library::ProcessXML()
if ( !module.project.LocateModule ( name ) )
throw InvalidBuildFileException (
node.location,
"module '%s' trying to link against non-existant module '%s'",
"module '%s' is trying to link against non-existant module '%s'",
module.name.c_str(),
name.c_str() );
}
@@ -243,14 +243,28 @@ Library::ProcessXML()
Invoke::Invoke ( const XMLElement& _node,
const Module& _module )
: node(_node),
module(_module)
: node (_node),
module (_module)
{
}
void
Invoke::ProcessXML()
{
const XMLAttribute* att = node.GetAttribute ( "module", false );
if (att == NULL)
invokeModule = &module;
else
{
invokeModule = module.project.LocateModule ( att->value );
if ( invokeModule == NULL )
throw InvalidBuildFileException (
node.location,
"module '%s' is trying to invoke non-existant module '%s'",
module.name.c_str(),
att->value.c_str() );
}
for ( size_t i = 0; i < node.subElements.size (); i++ )
ProcessXMLSubElement ( *node.subElements[i] );
}
@@ -259,7 +273,12 @@ void
Invoke::ProcessXMLSubElement ( const XMLElement& e )
{
bool subs_invalid = false;
if ( e.name == "output" )
if ( e.name == "input" )
{
for ( size_t i = 0; i < e.subElements.size (); i++ )
ProcessXMLSubElementInput ( *e.subElements[i] );
}
else if ( e.name == "output" )
{
for ( size_t i = 0; i < e.subElements.size (); i++ )
ProcessXMLSubElementOutput ( *e.subElements[i] );
@@ -270,13 +289,28 @@ Invoke::ProcessXMLSubElement ( const XMLElement& e )
e.name.c_str() );
}
void
Invoke::ProcessXMLSubElementInput ( const XMLElement& e )
{
bool subs_invalid = false;
if ( e.name == "inputfile" && e.value.size () > 0 )
{
input.push_back ( new InvokeFile ( e, FixSeparator ( module.path + CSEP + e.value ) ) );
subs_invalid = true;
}
if ( subs_invalid && e.subElements.size() > 0 )
throw InvalidBuildFileException ( e.location,
"<%s> cannot have sub-elements",
e.name.c_str() );
}
void
Invoke::ProcessXMLSubElementOutput ( const XMLElement& e )
{
bool subs_invalid = false;
if ( e.name == "outputfile" && e.value.size () > 0 )
{
output.push_back ( new File ( FixSeparator ( module.path + CSEP + e.value ) ) );
output.push_back ( new InvokeFile ( e, FixSeparator ( module.path + CSEP + e.value ) ) );
subs_invalid = true;
}
if ( subs_invalid && e.subElements.size() > 0 )
@@ -291,7 +325,7 @@ Invoke::GetTargets () const
string targets ( "" );
for ( size_t i = 0; i < output.size (); i++ )
{
File& file = *output[i];
InvokeFile& file = *output[i];
if ( targets.length () > 0 )
targets += " ";
targets += file.name;
@@ -300,6 +334,24 @@ Invoke::GetTargets () const
}
InvokeFile::InvokeFile ( const XMLElement& _node,
const string& _name )
: node (_node),
name (_name)
{
const XMLAttribute* att = _node.GetAttribute ( "switches", false );
if (att != NULL)
switches = att->value;
else
switches = "";
}
void
InvokeFile::ProcessXML()
{
}
Dependency::Dependency ( const XMLElement& _node,
const Module& _module )
: node (_node),

View File

@@ -28,6 +28,7 @@ class Define;
class File;
class Library;
class Invoke;
class InvokeFile;
class Dependency;
class Project
@@ -168,7 +169,9 @@ class Invoke
public:
const XMLElement& node;
const Module& module;
std::vector<File*> output;
const Module* invokeModule;
std::vector<InvokeFile*> input;
std::vector<InvokeFile*> output;
Invoke ( const XMLElement& _node,
const Module& _module );
@@ -177,10 +180,25 @@ public:
std::string GetTargets () const;
private:
void ProcessXMLSubElement ( const XMLElement& e );
void ProcessXMLSubElementInput ( const XMLElement& e );
void ProcessXMLSubElementOutput ( const XMLElement& e );
};
class InvokeFile
{
public:
const XMLElement& node;
std::string name;
std::string switches;
InvokeFile ( const XMLElement& _node,
const std::string& _name );
void ProcessXML ();
};
class Dependency
{
public:

View File

@@ -7,3 +7,6 @@
</output>
</invoke>
</module>
<directory name="wmc">
<xi:include href="wmc/wmc.xml" />
</directory>

11
reactos/tools/wmc/wmc.xml Normal file
View File

@@ -0,0 +1,11 @@
<module name="wmc" type="buildtool">
<include base="wmc">.</include>
<file>getopt.c</file>
<file>lang.c</file>
<file>mcl.c</file>
<file>misc.c</file>
<file>utils.c</file>
<file>wmc.c</file>
<file>write.c</file>
<file>y_tab.c</file>
</module>