Precondition dependencies.
authorCasper Hornstrup <chorns@users.sourceforge.net>
Sun, 9 Jan 2005 01:10:43 +0000 (01:10 +0000)
committerCasper Hornstrup <chorns@users.sourceforge.net>
Sun, 9 Jan 2005 01:10:43 +0000 (01:10 +0000)
svn path=/branches/xmlbuildsystem/; revision=12897

reactos/ReactOS.xml
reactos/ntoskrnl/ntoskrnl.xml [moved from reactos/ntoskrnl/module.xml with 92% similarity]
reactos/tools/buildno.c
reactos/tools/rbuild/backend/mingw/modulehandler.cpp
reactos/tools/rbuild/backend/mingw/modulehandler.h
reactos/tools/rbuild/module.cpp
reactos/tools/rbuild/rbuild.h
reactos/tools/tools.xml
reactos/tools/wmc/wmc.xml [new file with mode: 0644]

index 78b80dc..63f491c 100644 (file)
@@ -16,6 +16,6 @@
                <xi:include href="lib/directory.xml" />\r
        </directory>\r
        <directory name="ntoskrnl">\r
-               <xi:include href="ntoskrnl/module.xml" />\r
+               <xi:include href="ntoskrnl/ntoskrnl.xml" />\r
        </directory>\r
 </project>\r
similarity index 92%
rename from reactos/ntoskrnl/module.xml
rename to reactos/ntoskrnl/ntoskrnl.xml
index 6824208..8a8fa4a 100644 (file)
@@ -1,5 +1,6 @@
 <module name="ntoskrnl" type="kernelmodedll" extension=".exe">\r
        <dependency>buildno</dependency>\r
+       <dependency>wmc</dependency>\r
        <define name="_SEH_NO_NATIVE_NLG" />\r
        <define name="_DISABLE_TIDENTS" />\r
        <define name="__NTOSKRNL__" />\r
@@ -7,6 +8,15 @@
        <include base="kjs">./include</include>\r
        <include base="ntoskrnl">include</include>\r
        <library>kjs</library>\r
+       <invoke module="wmc">\r
+               <input>\r
+                       <inputfile>ntoskrnl.mc</inputfile>\r
+               </input>\r
+               <output>\r
+                       <outputfile switches="-H">../include/reactos/bugcodes.h</outputfile>\r
+                       <outputfile switches="-o">bugcodes.rc</outputfile>\r
+               </output>\r
+       </invoke>\r
        <directory name="cc">\r
                <file>cacheman.c</file>\r
                <file>copy.c</file>\r
index ae2d1d0..72cad44 100644 (file)
 #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
                        {
index 21becd2..4a91a81 100644 (file)
@@ -106,7 +106,7 @@ string
 MingwModuleHandler::GetObjectFilename ( const string& sourceFilename ) const\r
 {\r
        return FixupTargetFilename ( ReplaceExtension ( sourceFilename,\r
-                                                           ".o" ) );\r
+                                                       ".o" ) );\r
 }\r
 \r
 string\r
@@ -221,12 +221,10 @@ MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
        {\r
                string sourceFilename = module.files[i]->name;\r
                string objectFilename = GetObjectFilename ( sourceFilename );\r
-               string dependencies = GetModuleDependencies ( module );\r
                fprintf ( fMakefile,\r
-                         "%s: %s %s\n",\r
+                         "%s: %s\n",\r
                          objectFilename.c_str (),\r
-                         sourceFilename.c_str (),\r
-                         dependencies.c_str ());\r
+                         sourceFilename.c_str () );\r
                fprintf ( fMakefile,\r
                          "\t%s -c %s -o %s %s\n",\r
                          cc.c_str (),\r
@@ -293,27 +291,64 @@ MingwModuleHandler::GetInvocationDependencies ( const Module& module ) const
        for ( size_t i = 0; i < module.invocations.size (); i++ )\r
        {\r
                Invoke& invoke = *module.invocations[i];\r
+               if (invoke.invokeModule == &module)\r
+                       /* Protect against circular dependencies */\r
+                       continue;\r
                if ( dependencies.length () > 0 )\r
                        dependencies += " ";\r
-               string invokeTarget = module.GetInvocationTarget ( i );\r
-               dependencies += invokeTarget;\r
+               dependencies += invoke.GetTargets ();\r
        }\r
        return dependencies;\r
 }\r
-       \r
+\r
+string\r
+MingwModuleHandler::GetInvocationParameters ( const Invoke& invoke ) const\r
+{\r
+       string parameters ( "" );\r
+       size_t i;\r
+       for (i = 0; i < invoke.output.size (); i++)\r
+       {\r
+               if (parameters.length () > 0)\r
+                       parameters += " ";\r
+               InvokeFile& invokeFile = *invoke.output[i];\r
+               if (invokeFile.switches.length () > 0)\r
+               {\r
+                       parameters += invokeFile.switches;\r
+                       parameters += " ";\r
+               }\r
+               parameters += invokeFile.name;\r
+       }\r
+\r
+       for (i = 0; i < invoke.input.size (); i++)\r
+       {\r
+               if (parameters.length () > 0)\r
+                       parameters += " ";\r
+               InvokeFile& invokeFile = *invoke.input[i];\r
+               if (invokeFile.switches.length () > 0)\r
+               {\r
+                       parameters += invokeFile.switches;\r
+                       parameters += " ";\r
+               }\r
+               parameters += invokeFile.name;\r
+       }\r
+\r
+       return parameters;\r
+}\r
+\r
 void\r
 MingwModuleHandler::GenerateInvocations ( const Module& module ) const\r
 {\r
        if ( module.invocations.size () == 0 )\r
                return;\r
        \r
-       if ( module.type != BuildTool )\r
-               throw InvalidBuildFileException ( module.node.location,\r
-                                                 "Only modules of type buildtool can be invoked." );\r
-\r
        for ( size_t i = 0; i < module.invocations.size (); i++ )\r
        {\r
-               Invoke& invoke = *module.invocations[i];\r
+               const Invoke& invoke = *module.invocations[i];\r
+\r
+               if ( invoke.invokeModule->type != BuildTool )\r
+                       throw InvalidBuildFileException ( module.node.location,\r
+                                                     "Only modules of type buildtool can be invoked." );\r
+\r
                string invokeTarget = module.GetInvocationTarget ( i );\r
                fprintf ( fMakefile,\r
                          "%s: %s\n\n",\r
@@ -322,16 +357,51 @@ MingwModuleHandler::GenerateInvocations ( const Module& module ) const
                fprintf ( fMakefile,\r
                          "%s: %s\n",\r
                          invokeTarget.c_str (),\r
-                         FixupTargetFilename ( module.GetPath () ).c_str () );\r
+                         FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str () );\r
                fprintf ( fMakefile,\r
-                         "\t%s\n\n",\r
-                         FixupTargetFilename ( module.GetPath () ).c_str () );\r
+                         "\t%s %s\n\n",\r
+                         FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),\r
+                         GetInvocationParameters ( invoke ).c_str () );\r
                fprintf ( fMakefile,\r
                          ".PNONY: %s\n\n",\r
                          invokeTarget.c_str () );\r
        }\r
 }\r
 \r
+string\r
+MingwModuleHandler::GetPreconditionDependenciesName ( const Module& module ) const\r
+{\r
+       return ssprintf ( "%s_precondition",\r
+                         module.name.c_str () );\r
+}\r
+\r
+void\r
+MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) const\r
+{\r
+       string preconditionDependenciesName = GetPreconditionDependenciesName ( module );\r
+       string sourceFilenames = GetSourceFilenames ( module );\r
+       string dependencies = GetModuleDependencies ( module );\r
+       string s = GetInvocationDependencies ( module );\r
+       if ( s.length () > 0 )\r
+       {\r
+               if ( dependencies.length () > 0 )\r
+                       dependencies += " ";\r
+               dependencies += s;\r
+       }\r
+       \r
+       fprintf ( fMakefile,\r
+                 "%s: %s\n\n",\r
+                 preconditionDependenciesName.c_str (),\r
+                 dependencies.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "%s: %s\n\n",\r
+                 sourceFilenames.c_str (),\r
+                 preconditionDependenciesName.c_str ());\r
+       fprintf ( fMakefile,\r
+                 ".PNONY: %s\n\n",\r
+                 preconditionDependenciesName.c_str () );\r
+}\r
+\r
 \r
 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( FILE* fMakefile )\r
        : MingwModuleHandler ( fMakefile )\r
@@ -347,6 +417,7 @@ MingwBuildToolModuleHandler::CanHandleModule ( const Module& module ) const
 void\r
 MingwBuildToolModuleHandler::Process ( const Module& module )\r
 {\r
+       GeneratePreconditionDependencies ( module );\r
        GenerateBuildToolModuleTarget ( module );\r
        GenerateInvocations ( module );\r
 }\r
@@ -382,6 +453,7 @@ MingwKernelModuleHandler::CanHandleModule ( const Module& module ) const
 void\r
 MingwKernelModuleHandler::Process ( const Module& module )\r
 {\r
+       GeneratePreconditionDependencies ( module );\r
        GenerateKernelModuleTarget ( module );\r
        GenerateInvocations ( module );\r
 }\r
@@ -448,6 +520,7 @@ MingwStaticLibraryModuleHandler::CanHandleModule ( const Module& module ) const
 void\r
 MingwStaticLibraryModuleHandler::Process ( const Module& module )\r
 {\r
+       GeneratePreconditionDependencies ( module );\r
        GenerateStaticLibraryModuleTarget ( module );\r
        GenerateInvocations ( module );\r
 }\r
index 5776b9e..2f3266c 100644 (file)
@@ -26,7 +26,9 @@ protected:
        void GenerateArchiveTargetHost ( const Module& module ) const;\r
        void GenerateArchiveTargetTarget ( const Module& module ) const;\r
        std::string GetInvocationDependencies ( const Module& module ) const;\r
+       std::string GetInvocationParameters ( const Invoke& invoke ) const;\r
        void GenerateInvocations ( const Module& module ) const;\r
+       void GeneratePreconditionDependencies ( const Module& module ) const;\r
        FILE* fMakefile;\r
 private:\r
        std::string ConcatenatePaths ( const std::string& path1,\r
@@ -40,6 +42,7 @@ private:
                                         const std::string& cc ) const;\r
        void GenerateArchiveTarget ( const Module& module,\r
                                     const std::string& ar ) const;\r
+       std::string GetPreconditionDependenciesName ( const Module& module ) const;\r
 };\r
 \r
 \r
index 68b7c9d..85a5dc2 100644 (file)
@@ -235,7 +235,7 @@ Library::ProcessXML()
        if ( !module.project.LocateModule ( name ) )\r
                throw InvalidBuildFileException (\r
                        node.location,\r
-                       "module '%s' trying to link against non-existant module '%s'",\r
+                       "module '%s' is trying to link against non-existant module '%s'",\r
                        module.name.c_str(),\r
                        name.c_str() );\r
 }\r
@@ -243,14 +243,28 @@ Library::ProcessXML()
 \r
 Invoke::Invoke ( const XMLElement& _node,\r
                  const Module& _module )\r
-       : node(_node),\r
-         module(_module)\r
+       : node (_node),\r
+         module (_module)\r
 {\r
 }\r
 \r
 void\r
 Invoke::ProcessXML()\r
 {\r
+       const XMLAttribute* att = node.GetAttribute ( "module", false );\r
+       if (att == NULL)\r
+               invokeModule = &module;\r
+       else\r
+       {\r
+               invokeModule = module.project.LocateModule ( att->value );\r
+               if ( invokeModule == NULL )\r
+                       throw InvalidBuildFileException (\r
+                               node.location,\r
+                               "module '%s' is trying to invoke non-existant module '%s'",\r
+                               module.name.c_str(),\r
+                               att->value.c_str() );\r
+       }\r
+       \r
        for ( size_t i = 0; i < node.subElements.size (); i++ )\r
                ProcessXMLSubElement ( *node.subElements[i] );\r
 }\r
@@ -259,7 +273,12 @@ void
 Invoke::ProcessXMLSubElement ( const XMLElement& e )\r
 {\r
        bool subs_invalid = false;\r
-       if ( e.name == "output" )\r
+       if ( e.name == "input" )\r
+       {\r
+               for ( size_t i = 0; i < e.subElements.size (); i++ )\r
+                       ProcessXMLSubElementInput ( *e.subElements[i] );\r
+       }\r
+       else if ( e.name == "output" )\r
        {\r
                for ( size_t i = 0; i < e.subElements.size (); i++ )\r
                        ProcessXMLSubElementOutput ( *e.subElements[i] );\r
@@ -270,13 +289,28 @@ Invoke::ProcessXMLSubElement ( const XMLElement& e )
                                                  e.name.c_str() );\r
 }\r
 \r
+void\r
+Invoke::ProcessXMLSubElementInput ( const XMLElement& e )\r
+{\r
+       bool subs_invalid = false;\r
+       if ( e.name == "inputfile" && e.value.size () > 0 )\r
+       {\r
+               input.push_back ( new InvokeFile ( e, FixSeparator ( module.path + CSEP + e.value ) ) );\r
+               subs_invalid = true;\r
+       }\r
+       if ( subs_invalid && e.subElements.size() > 0 )\r
+               throw InvalidBuildFileException ( e.location,\r
+                                                 "<%s> cannot have sub-elements",\r
+                                                 e.name.c_str() );\r
+}\r
+\r
 void\r
 Invoke::ProcessXMLSubElementOutput ( const XMLElement& e )\r
 {\r
        bool subs_invalid = false;\r
        if ( e.name == "outputfile" && e.value.size () > 0 )\r
        {\r
-               output.push_back ( new File ( FixSeparator ( module.path + CSEP + e.value ) ) );\r
+               output.push_back ( new InvokeFile ( e, FixSeparator ( module.path + CSEP + e.value ) ) );\r
                subs_invalid = true;\r
        }\r
        if ( subs_invalid && e.subElements.size() > 0 )\r
@@ -291,7 +325,7 @@ Invoke::GetTargets () const
        string targets ( "" );\r
        for ( size_t i = 0; i < output.size (); i++ )\r
        {\r
-               File& file = *output[i];\r
+               InvokeFile& file = *output[i];\r
                if ( targets.length () > 0 )\r
                        targets += " ";\r
                targets += file.name;\r
@@ -300,6 +334,24 @@ Invoke::GetTargets () const
 }\r
 \r
 \r
+InvokeFile::InvokeFile ( const XMLElement& _node,\r
+                         const string& _name )\r
+       : node (_node),\r
+      name (_name)\r
+{\r
+       const XMLAttribute* att = _node.GetAttribute ( "switches", false );\r
+       if (att != NULL)\r
+               switches = att->value;\r
+       else\r
+               switches = "";\r
+}\r
+\r
+void\r
+InvokeFile::ProcessXML()\r
+{\r
+}\r
+\r
+\r
 Dependency::Dependency ( const XMLElement& _node,\r
                          const Module& _module )\r
        : node (_node),\r
index 087c30f..dd78dfe 100644 (file)
@@ -28,6 +28,7 @@ class Define;
 class File;\r
 class Library;\r
 class Invoke;\r
+class InvokeFile;\r
 class Dependency;\r
 \r
 class Project\r
@@ -168,7 +169,9 @@ class Invoke
 public:\r
        const XMLElement& node;\r
        const Module& module;\r
-       std::vector<File*> output;\r
+       const Module* invokeModule;\r
+       std::vector<InvokeFile*> input;\r
+       std::vector<InvokeFile*> output;\r
 \r
        Invoke ( const XMLElement& _node,\r
                 const Module& _module );\r
@@ -177,10 +180,25 @@ public:
        std::string GetTargets () const;\r
 private:\r
        void ProcessXMLSubElement ( const XMLElement& e );\r
+       void ProcessXMLSubElementInput ( const XMLElement& e );\r
        void ProcessXMLSubElementOutput ( const XMLElement& e );\r
 };\r
 \r
 \r
+class InvokeFile\r
+{\r
+public:\r
+       const XMLElement& node;\r
+       std::string name;\r
+       std::string switches;\r
+\r
+       InvokeFile ( const XMLElement& _node,\r
+                    const std::string& _name );\r
+\r
+       void ProcessXML ();\r
+};\r
+\r
+\r
 class Dependency\r
 {\r
 public:\r
index 9195b30..dc4f09c 100644 (file)
@@ -7,3 +7,6 @@
                </output>\r
        </invoke>\r
 </module>\r
+<directory name="wmc">\r
+       <xi:include href="wmc/wmc.xml" />\r
+</directory>\r
diff --git a/reactos/tools/wmc/wmc.xml b/reactos/tools/wmc/wmc.xml
new file mode 100644 (file)
index 0000000..9a5f92e
--- /dev/null
@@ -0,0 +1,11 @@
+<module name="wmc" type="buildtool">\r
+       <include base="wmc">.</include>\r
+       <file>getopt.c</file>\r
+       <file>lang.c</file>\r
+       <file>mcl.c</file>\r
+       <file>misc.c</file>\r
+       <file>utils.c</file>\r
+       <file>wmc.c</file>\r
+       <file>write.c</file>\r
+       <file>y_tab.c</file>\r
+</module>\r