adjust newlines around rsym command
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.cpp
index 2706f61..62f2891 100644 (file)
@@ -1,4 +1,3 @@
-\r
 #include "../../pch.h"\r
 #include <assert.h>\r
 \r
@@ -9,15 +8,34 @@
 using std::string;\r
 using std::vector;\r
 using std::map;\r
+using std::set;\r
+\r
+typedef set<string> set_string;\r
 \r
 map<ModuleType,MingwModuleHandler*>*\r
 MingwModuleHandler::handler_map = NULL;\r
+set_string\r
+MingwModuleHandler::directory_set;\r
 int\r
 MingwModuleHandler::ref = 0;\r
 \r
 FILE*\r
 MingwModuleHandler::fMakefile = NULL;\r
 \r
+string\r
+ReplaceExtension ( const string& filename,\r
+                   const string& newExtension )\r
+{\r
+       size_t index = filename.find_last_of ( '/' );\r
+       if (index == string::npos) index = 0;\r
+       string tmp = filename.substr( index, filename.size() - index );\r
+       size_t ext_index = tmp.find_last_of( '.' );\r
+       if (ext_index != string::npos) \r
+               return filename.substr ( 0, index + ext_index ) + newExtension;\r
+       return filename + newExtension;\r
+}\r
+\r
+\r
 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype )\r
 {\r
        if ( !ref++ )\r
@@ -34,6 +52,13 @@ MingwModuleHandler::~MingwModuleHandler()
        }\r
 }\r
 \r
+const string &\r
+MingwModuleHandler::PassThruCacheDirectory ( const string &file ) const \r
+{\r
+       directory_set.insert ( GetDirectory ( file ) );\r
+       return file;\r
+}\r
+\r
 void\r
 MingwModuleHandler::SetMakefile ( FILE* f )\r
 {\r
@@ -62,22 +87,25 @@ MingwModuleHandler::GetWorkingDirectory () const
 }\r
 \r
 string\r
-MingwModuleHandler::GetExtension ( const string& filename ) const\r
+MingwModuleHandler::GetBasename ( const string& filename ) const\r
 {\r
        size_t index = filename.find_last_of ( '.' );\r
-       if (index != string::npos)\r
-               return filename.substr ( index );\r
+       if ( index != string::npos )\r
+               return filename.substr ( 0, index );\r
        return "";\r
 }\r
 \r
 string\r
-MingwModuleHandler::ReplaceExtension ( const string& filename,\r
-                                          const string& newExtension ) const\r
+MingwModuleHandler::GetActualSourceFilename ( const string& filename ) const\r
 {\r
-       size_t index = filename.find_last_of ( '.' );\r
-       if (index != string::npos)\r
-               return filename.substr ( 0, index ) + newExtension;\r
-       return filename;\r
+       string extension = GetExtension ( filename );\r
+       if ( extension == ".spec" || extension == "SPEC" )\r
+       {\r
+               string basename = GetBasename ( filename );\r
+               return basename + ".stubs.c";\r
+       }\r
+       else\r
+               return filename;\r
 }\r
 \r
 string\r
@@ -87,12 +115,28 @@ MingwModuleHandler::GetModuleArchiveFilename ( const Module& module ) const
                                  ".a" );\r
 }\r
 \r
+bool\r
+MingwModuleHandler::IsGeneratedFile ( const File& file ) const\r
+{\r
+       string extension = GetExtension ( file.name );\r
+       if ( extension == ".spec" || extension == "SPEC" )\r
+               return true;\r
+       else\r
+               return false;\r
+}\r
+\r
+string\r
+MingwModuleHandler::GetImportLibraryDependency ( const Module& importedModule ) const\r
+{\r
+       if ( importedModule.type == ObjectLibrary )\r
+               return GetObjectsMacro ( importedModule );\r
+       else\r
+               return PassThruCacheDirectory ( FixupTargetFilename ( importedModule.GetDependencyPath () ) );\r
+}\r
+\r
 string\r
 MingwModuleHandler::GetImportLibraryDependencies ( const Module& module ) const\r
 {\r
-       if ( module.libraries.size () == 0 )\r
-               return "";\r
-       \r
        string dependencies ( "" );\r
        for ( size_t i = 0; i < module.libraries.size (); i++ )\r
        {\r
@@ -100,7 +144,7 @@ MingwModuleHandler::GetImportLibraryDependencies ( const Module& module ) const
                        dependencies += " ";\r
                const Module* importedModule = module.project.LocateModule ( module.libraries[i]->name );\r
                assert ( importedModule != NULL );\r
-               dependencies += FixupTargetFilename ( importedModule->GetDependencyPath () ).c_str ();\r
+               dependencies += GetImportLibraryDependency ( *importedModule );\r
        }\r
        return dependencies;\r
 }\r
@@ -120,6 +164,11 @@ MingwModuleHandler::GetModuleDependencies ( const Module& module ) const
                const Module* dependencyModule = dependency->dependencyModule;\r
                dependencies += dependencyModule->GetTargets ();\r
        }\r
+       string definitionDependencies = GetDefinitionDependencies ( module );\r
+       if ( dependencies.length () > 0 && definitionDependencies.length () > 0 )\r
+               dependencies += " " + definitionDependencies;\r
+       else if ( definitionDependencies.length () > 0 )\r
+               dependencies = definitionDependencies;\r
        return dependencies;\r
 }\r
 \r
@@ -128,7 +177,7 @@ MingwModuleHandler::GetAllDependencies ( const Module& module ) const
 {\r
        string dependencies = GetImportLibraryDependencies ( module );\r
        string s = GetModuleDependencies ( module );\r
-       if (s.length () > 0)\r
+       if ( s.length () > 0 )\r
        {\r
                dependencies += " ";\r
                dependencies += s;\r
@@ -137,37 +186,59 @@ MingwModuleHandler::GetAllDependencies ( const Module& module ) const
 }\r
 \r
 string\r
-MingwModuleHandler::GetSourceFilenames ( const Module& module ) const\r
+MingwModuleHandler::GetSourceFilenames ( const Module& module,\r
+                                            bool includeGeneratedFiles ) const\r
 {\r
        size_t i;\r
 \r
        string sourceFilenames ( "" );\r
        for ( i = 0; i < module.files.size (); i++ )\r
-               sourceFilenames += " " + module.files[i]->name;\r
+       {\r
+               if ( includeGeneratedFiles || !IsGeneratedFile ( *module.files[i] ) )\r
+                       sourceFilenames += " " + GetActualSourceFilename ( module.files[i]->name );\r
+       }\r
        vector<If*> ifs = module.ifs;\r
-       for ( i = 0; i < ifs.size(); i++ )\r
+       for ( i = 0; i < ifs.size (); i++ )\r
        {\r
                size_t j;\r
                If& rIf = *ifs[i];\r
-               for ( j = 0; j < rIf.ifs.size(); j++ )\r
+               for ( j = 0; j < rIf.ifs.size (); j++ )\r
                        ifs.push_back ( rIf.ifs[j] );\r
-               for ( j = 0; j < rIf.files.size(); j++ )\r
-                       sourceFilenames += " " + rIf.files[j]->name;\r
+               for ( j = 0; j < rIf.files.size (); j++ )\r
+               {\r
+                       if ( includeGeneratedFiles || !IsGeneratedFile ( *rIf.files[j] ) )\r
+                               sourceFilenames += " " + GetActualSourceFilename ( rIf.files[j]->name );\r
+               }\r
        }\r
        return sourceFilenames;\r
 }\r
 \r
 string\r
-MingwModuleHandler::GetObjectFilename ( const string& sourceFilename ) const\r
+MingwModuleHandler::GetSourceFilenames ( const Module& module ) const\r
+{\r
+       return GetSourceFilenames ( module,\r
+                                   true );\r
+}\r
+\r
+string\r
+MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module& module ) const\r
+{\r
+       return GetSourceFilenames ( module,\r
+                                   false );\r
+}\r
+\r
+string\r
+MingwModuleHandler::GetObjectFilename ( const string& sourceFilename )\r
 {\r
        string newExtension;\r
        string extension = GetExtension ( sourceFilename );\r
        if ( extension == ".rc" || extension == ".RC" )\r
                newExtension = ".coff";\r
+       else if ( extension == ".spec" || extension == ".SPEC" )\r
+               newExtension = ".stubs.o";\r
        else\r
                newExtension = ".o";\r
-       return FixupTargetFilename ( ReplaceExtension ( sourceFilename,\r
-                                                           newExtension ) );\r
+       return FixupTargetFilename ( ReplaceExtension ( sourceFilename, newExtension ) );\r
 }\r
 \r
 string\r
@@ -181,16 +252,66 @@ MingwModuleHandler::GetObjectFilenames ( const Module& module ) const
        {\r
                if ( objectFilenames.size () > 0 )\r
                        objectFilenames += " ";\r
-               objectFilenames += GetObjectFilename ( module.files[i]->name );\r
+               objectFilenames += PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( module.files[i]->name ) );\r
        }\r
        return objectFilenames;\r
 }\r
 \r
+bool\r
+MingwModuleHandler::IncludeDirectoryTarget ( const string& directory ) const\r
+{\r
+       if ( directory == "$(ROS_INTERMEDIATE)." SSEP "tools")\r
+               return false;\r
+       else\r
+               return true;\r
+}\r
+\r
+void\r
+MingwModuleHandler::GenerateDirectoryTargets () const\r
+{\r
+       if ( directory_set.size () == 0 )\r
+               return;\r
+       \r
+       set_string::iterator i;\r
+       fprintf ( fMakefile, "directories::" );\r
+\r
+       for ( i = directory_set.begin ();\r
+             i != directory_set.end ();\r
+             i++ )\r
+       {\r
+               if ( IncludeDirectoryTarget ( *i ) )\r
+               {\r
+                       fprintf ( fMakefile,\r
+                                 " %s",\r
+                                 i->c_str () );\r
+               }\r
+       }\r
+\r
+       fprintf ( fMakefile, "\n\n" );\r
+\r
+       for ( i = directory_set.begin ();\r
+             i != directory_set.end ();\r
+             i++ )\r
+       {\r
+               if ( IncludeDirectoryTarget ( *i ) )\r
+               {\r
+                       fprintf ( fMakefile,\r
+                                 "%s ",\r
+                                 i->c_str () );\r
+               }\r
+       }\r
+\r
+       fprintf ( fMakefile, \r
+                 "::\n\t${mkdir} $@\n\n" );\r
+\r
+       directory_set.clear ();\r
+}\r
+\r
 string\r
 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector<Define*>& defines ) const\r
 {\r
        string parameters;\r
-       for (size_t i = 0; i < defines.size (); i++)\r
+       for ( size_t i = 0; i < defines.size (); i++ )\r
        {\r
                Define& define = *defines[i];\r
                if (parameters.length () > 0)\r
@@ -211,7 +332,7 @@ MingwModuleHandler::GenerateGccDefineParameters ( const Module& module ) const
 {\r
        string parameters = GenerateGccDefineParametersFromVector ( module.project.defines );\r
        string s = GenerateGccDefineParametersFromVector ( module.defines );\r
-       if (s.length () > 0)\r
+       if ( s.length () > 0 )\r
        {\r
                parameters += " ";\r
                parameters += s;\r
@@ -238,7 +359,7 @@ MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Includ
        for ( size_t i = 0; i < includes.size (); i++ )\r
        {\r
                Include& include = *includes[i];\r
-               if (parameters.length () > 0)\r
+               if ( parameters.length () > 0 )\r
                        parameters += " ";\r
                parameters += "-I" + include.directory;\r
        }\r
@@ -259,6 +380,20 @@ MingwModuleHandler::GenerateGccIncludeParameters ( const Module& module ) const
 }\r
 \r
 \r
+string\r
+MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector<CompilerFlag*>& compilerFlags ) const\r
+{\r
+       string parameters;\r
+       for ( size_t i = 0; i < compilerFlags.size (); i++ )\r
+       {\r
+               CompilerFlag& compilerFlag = *compilerFlags[i];\r
+               if ( parameters.length () > 0 )\r
+                       parameters += " ";\r
+               parameters += compilerFlag.flag;\r
+       }\r
+       return parameters;\r
+}\r
+\r
 string\r
 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector<LinkerFlag*>& linkerFlags ) const\r
 {\r
@@ -283,15 +418,29 @@ void
 MingwModuleHandler::GenerateMacro ( const char* assignmentOperation,\r
                                     const string& macro,\r
                                     const vector<Include*>& includes,\r
-                                    const vector<Define*>& defines ) const\r
+                                    const vector<Define*>& defines,\r
+                                    const vector<CompilerFlag*>* compilerFlags ) const\r
 {\r
        size_t i;\r
-       \r
+\r
        fprintf (\r
                fMakefile,\r
                "%s %s",\r
                macro.c_str(),\r
                assignmentOperation );\r
+       \r
+       if ( compilerFlags != NULL )\r
+       {\r
+               string compilerParameters = GenerateCompilerParametersFromVector ( *compilerFlags );\r
+               if ( compilerParameters.size () > 0 )\r
+               {\r
+                       fprintf (\r
+                               fMakefile,\r
+                               " %s",\r
+                               compilerParameters.c_str () );\r
+               }\r
+       }\r
+\r
        for ( i = 0; i < includes.size(); i++ )\r
        {\r
                fprintf (\r
@@ -314,13 +463,14 @@ MingwModuleHandler::GenerateMacro ( const char* assignmentOperation,
        }\r
        fprintf ( fMakefile, "\n" );\r
 }\r
-       \r
+\r
 void\r
 MingwModuleHandler::GenerateMacros (\r
        const char* assignmentOperation,\r
        const vector<File*>& files,\r
        const vector<Include*>& includes,\r
        const vector<Define*>& defines,\r
+       const vector<CompilerFlag*>* compilerFlags,\r
        const vector<LinkerFlag*>* linkerFlags,\r
        const vector<If*>& ifs,\r
        const string& cflags_macro,\r
@@ -331,16 +481,18 @@ MingwModuleHandler::GenerateMacros (
 {\r
        size_t i;\r
 \r
-       if ( includes.size() || defines.size() )\r
+       if ( includes.size () > 0 || defines.size () > 0 )\r
        {\r
                GenerateMacro ( assignmentOperation,\r
                                cflags_macro,\r
                                includes,\r
-                               defines );\r
+                               defines,\r
+                               compilerFlags );\r
                GenerateMacro ( assignmentOperation,\r
                                windresflags_macro,\r
                                includes,\r
-                               defines );\r
+                               defines,\r
+                               compilerFlags );\r
        }\r
        \r
        if ( linkerFlags != NULL )\r
@@ -357,20 +509,34 @@ MingwModuleHandler::GenerateMacros (
                }\r
        }\r
        \r
-       if ( files.size() )\r
+       if ( files.size () > 0 )\r
        {\r
+               for ( i = 0; i < files.size (); i++ )\r
+               {\r
+                       if ( files[i]->first )\r
+                       {\r
+                               fprintf ( fMakefile,\r
+                                       "%s := %s $(%s)\n",\r
+                                       objs_macro.c_str(),\r
+                                       PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files[i]->name ) ).c_str (),\r
+                                       objs_macro.c_str() );\r
+                       }\r
+               }\r
                fprintf (\r
                        fMakefile,\r
                        "%s %s",\r
-                       objs_macro.c_str(),\r
+                       objs_macro.c_str (),\r
                        assignmentOperation );\r
                for ( i = 0; i < files.size(); i++ )\r
                {\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "%s%s",\r
-                               ( i%10 == 9 ? "\\\n\t" : " " ),\r
-                               GetObjectFilename(files[i]->name).c_str() );\r
+                       if ( !files[i]->first )\r
+                       {\r
+                               fprintf (\r
+                                       fMakefile,\r
+                                       "%s%s",\r
+                                       ( i%10 == 9 ? "\\\n\t" : " " ),\r
+                                       PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files[i]->name ) ).c_str () );\r
+                       }\r
                }\r
                fprintf ( fMakefile, "\n" );\r
        }\r
@@ -391,6 +557,7 @@ MingwModuleHandler::GenerateMacros (
                                rIf.includes,\r
                                rIf.defines,\r
                                NULL,\r
+                               NULL,\r
                                rIf.ifs,\r
                                cflags_macro,\r
                                nasmflags_macro,\r
@@ -418,6 +585,7 @@ MingwModuleHandler::GenerateMacros (
                module.files,\r
                module.includes,\r
                module.defines,\r
+               &module.compilerFlags,\r
                &module.linkerFlags,\r
                module.ifs,\r
                cflags_macro,\r
@@ -443,87 +611,184 @@ MingwModuleHandler::GenerateMacros (
                module.name.c_str () );\r
 }\r
 \r
-string\r
+void\r
 MingwModuleHandler::GenerateGccCommand ( const Module& module,\r
                                          const string& sourceFilename,\r
                                          const string& cc,\r
                                          const string& cflagsMacro ) const\r
 {\r
-       string objectFilename = GetObjectFilename ( sourceFilename );\r
-       return ssprintf ( "%s -c %s -o %s %s\n",\r
-                             cc.c_str (),\r
-                             sourceFilename.c_str (),\r
-                             objectFilename.c_str (),\r
-                             cflagsMacro.c_str () );\r
+       string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
+       fprintf ( fMakefile,\r
+                 "%s: %s\n",\r
+                 objectFilename.c_str (),\r
+                 sourceFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t%s -c %s -o %s %s\n",\r
+                cc.c_str (),\r
+                sourceFilename.c_str (),\r
+                objectFilename.c_str (),\r
+                cflagsMacro.c_str () );\r
 }\r
 \r
-string\r
+void\r
 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module& module,\r
                                                   const string& sourceFilename,\r
                                                   const string& cc,\r
                                                   const string& cflagsMacro ) const\r
 {\r
-       string objectFilename = GetObjectFilename ( sourceFilename );\r
-       return ssprintf ( "%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",\r
-                         cc.c_str (),\r
-                         sourceFilename.c_str (),\r
-                         objectFilename.c_str (),\r
-                         cflagsMacro.c_str () );\r
+       string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
+       fprintf ( fMakefile,\r
+                 "%s: %s\n",\r
+                 objectFilename.c_str (),\r
+                 sourceFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",\r
+                 cc.c_str (),\r
+                 sourceFilename.c_str (),\r
+                 objectFilename.c_str (),\r
+                 cflagsMacro.c_str () );\r
 }\r
 \r
-string\r
+void\r
 MingwModuleHandler::GenerateNasmCommand ( const Module& module,\r
                                           const string& sourceFilename,\r
                                           const string& nasmflagsMacro ) const\r
 {\r
-       string objectFilename = GetObjectFilename ( sourceFilename );\r
-       return ssprintf ( "%s -f win32 %s -o %s %s\n",\r
-                             "nasm",\r
-                             sourceFilename.c_str (),\r
-                             objectFilename.c_str (),\r
-                             nasmflagsMacro.c_str () );\r
+       string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
+       fprintf ( fMakefile,\r
+                 "%s: %s\n",\r
+                 objectFilename.c_str (),\r
+                 sourceFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t%s -f win32 %s -o %s %s\n",\r
+                 "nasm",\r
+                 sourceFilename.c_str (),\r
+                 objectFilename.c_str (),\r
+                 nasmflagsMacro.c_str () );\r
 }\r
 \r
-string\r
+void\r
 MingwModuleHandler::GenerateWindresCommand ( const Module& module,\r
                                              const string& sourceFilename,\r
                                              const string& windresflagsMacro ) const\r
 {\r
-       string objectFilename = GetObjectFilename ( sourceFilename );\r
-       return ssprintf ( "%s %s -o %s ${%s}\n",\r
-                             "${windres}",\r
-                             sourceFilename.c_str (),\r
-                             objectFilename.c_str (),\r
-                             windresflagsMacro.c_str () );\r
+       string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
+  string rciFilename = ReplaceExtension ( sourceFilename,\r
+                                          ".rci" );\r
+  string resFilename = ReplaceExtension ( sourceFilename,\r
+                                          ".res" );\r
+       fprintf ( fMakefile,\r
+                 "%s: %s\n",\r
+                 objectFilename.c_str (),\r
+                 sourceFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",\r
+                windresflagsMacro.c_str (),\r
+                sourceFilename.c_str (),\r
+                rciFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${wrc} ${%s} %s %s\n",\r
+           windresflagsMacro.c_str (),\r
+                rciFilename.c_str (),\r
+                resFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${rm} %s\n",\r
+                rciFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${windres} %s -o %s\n",\r
+                resFilename.c_str (),\r
+                objectFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${rm} %s\n",\r
+                resFilename.c_str () );\r
+}\r
+\r
+void\r
+MingwModuleHandler::GenerateWinebuildCommands ( const Module& module,\r
+                                                const string& sourceFilename ) const\r
+{\r
+       string basename = GetBasename ( sourceFilename );\r
+       fprintf ( fMakefile,\r
+                 "%s.spec.def: %s\n",\r
+                 basename.c_str (),\r
+                 sourceFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t%s --def=%s -o %s.spec.def\n",\r
+                 "${winebuild}",\r
+                 sourceFilename.c_str (),\r
+                 basename.c_str () );\r
+\r
+       fprintf ( fMakefile,\r
+                 "%s.stubs.c: %s\n",\r
+                 basename.c_str (),\r
+                 sourceFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t%s --pedll=%s -o %s.stubs.c\n",\r
+                 "${winebuild}",\r
+                 sourceFilename.c_str (),\r
+                 basename.c_str () );\r
 }\r
 \r
-string\r
-MingwModuleHandler::GenerateCommand ( const Module& module,\r
-                                      const string& sourceFilename,\r
-                                      const string& cc,\r
-                                      const string& cflagsMacro,\r
-                                      const string& nasmflagsMacro,\r
-                                      const string& windresflagsMacro ) const\r
+void\r
+MingwModuleHandler::GenerateCommands ( const Module& module,\r
+                                       const string& sourceFilename,\r
+                                       const string& cc,\r
+                                       const string& cppc,\r
+                                       const string& cflagsMacro,\r
+                                       const string& nasmflagsMacro,\r
+                                       const string& windresflagsMacro ) const\r
 {\r
        string extension = GetExtension ( sourceFilename );\r
        if ( extension == ".c" || extension == ".C" )\r
-               return GenerateGccCommand ( module,\r
-                                           sourceFilename,\r
-                                           cc,\r
-                                           cflagsMacro );\r
+       {\r
+               GenerateGccCommand ( module,\r
+                                    sourceFilename,\r
+                                    cc,\r
+                                    cflagsMacro );\r
+               return;\r
+       }\r
+       else if ( extension == ".cc" || extension == ".CC" ||\r
+                 extension == ".cpp" || extension == ".CPP" ||\r
+                 extension == ".cxx" || extension == ".CXX" )\r
+       {\r
+               GenerateGccCommand ( module,\r
+                                    sourceFilename,\r
+                                    cppc,\r
+                                    cflagsMacro );\r
+               return;\r
+       }\r
        else if ( extension == ".s" || extension == ".S" )\r
-               return GenerateGccAssemblerCommand ( module,\r
-                                                    sourceFilename,\r
-                                                    cc,\r
-                                                    cflagsMacro );\r
+       {\r
+               GenerateGccAssemblerCommand ( module,\r
+                                             sourceFilename,\r
+                                             cc,\r
+                                             cflagsMacro );\r
+               return;\r
+       }\r
        else if ( extension == ".asm" || extension == ".ASM" )\r
-               return GenerateNasmCommand ( module,\r
-                                            sourceFilename,\r
-                                            nasmflagsMacro );\r
+       {\r
+               GenerateNasmCommand ( module,\r
+                                     sourceFilename,\r
+                                     nasmflagsMacro );\r
+               return;\r
+       }\r
        else if ( extension == ".rc" || extension == ".RC" )\r
-               return GenerateWindresCommand ( module,\r
-                                               sourceFilename,\r
-                                               windresflagsMacro );\r
+       {\r
+               GenerateWindresCommand ( module,\r
+                                        sourceFilename,\r
+                                        windresflagsMacro );\r
+               return;\r
+       }\r
+       else if ( extension == ".spec" || extension == ".SPEC" )\r
+       {\r
+               GenerateWinebuildCommands ( module,\r
+                                           sourceFilename );\r
+               GenerateGccCommand ( module,\r
+                                    GetActualSourceFilename ( sourceFilename ),\r
+                                    cc,\r
+                                    cflagsMacro );\r
+               return;\r
+       }\r
 \r
        throw InvalidOperationException ( __FILE__,\r
                                          __LINE__,\r
@@ -532,21 +797,79 @@ MingwModuleHandler::GenerateCommand ( const Module& module,
                                          sourceFilename.c_str () );\r
 }\r
 \r
-string\r
+void\r
 MingwModuleHandler::GenerateLinkerCommand ( const Module& module,\r
                                             const string& linker,\r
                                             const string& linkerParameters,\r
                                             const string& objectFilenames ) const\r
 {\r
+       string targetName ( module.GetTargetName () );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
-       return ssprintf ( "%s %s -o %s %s %s %s\n",\r
-                         linker.c_str (),\r
-                             linkerParameters.c_str (),\r
-                      target.c_str (),\r
-                      objectFilenames.c_str (),\r
-                      importLibraryDependencies.c_str (),\r
-                      GetLinkerMacro ( module ).c_str () );\r
+       if ( module.importLibrary != NULL )\r
+       {\r
+               static string ros_junk ( "$(ROS_TEMPORARY)" );\r
+               string base_tmp = ros_junk + module.name + ".base.tmp";\r
+               string junk_tmp = ros_junk + module.name + ".junk.tmp";\r
+               string temp_exp = ros_junk + module.name + ".temp.exp";\r
+\r
+               fprintf ( fMakefile,\r
+                         "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",\r
+                         linker.c_str (),\r
+                         linkerParameters.c_str (),\r
+                         base_tmp.c_str (),\r
+                         junk_tmp.c_str (),\r
+                         objectFilenames.c_str (),\r
+                         importLibraryDependencies.c_str (),\r
+                         GetLinkerMacro ( module ).c_str () );\r
+\r
+               fprintf ( fMakefile,\r
+                         "\t${rm} %s\n",\r
+                         junk_tmp.c_str () );\r
+\r
+               string killAt = module.mangledSymbols ? "" : "--kill-at";\r
+               fprintf ( fMakefile,\r
+                         "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",\r
+                         targetName.c_str (),\r
+                         base_tmp.c_str (),\r
+                         ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),\r
+                         temp_exp.c_str (),\r
+                         killAt.c_str () );\r
+\r
+               fprintf ( fMakefile,\r
+                         "\t${rm} %s\n",\r
+                         base_tmp.c_str () );\r
+\r
+               fprintf ( fMakefile,\r
+                         "\t%s %s %s -o %s %s %s %s\n\n",\r
+                         linker.c_str (),\r
+                         linkerParameters.c_str (),\r
+                         temp_exp.c_str (),\r
+                         target.c_str (),\r
+                         objectFilenames.c_str (),\r
+                         importLibraryDependencies.c_str (),\r
+                         GetLinkerMacro ( module ).c_str () );\r
+\r
+               fprintf ( fMakefile,\r
+                         "\t${rm} %s\n\n",\r
+                         temp_exp.c_str () );\r
+       }\r
+       else\r
+       {\r
+               fprintf ( fMakefile,\r
+                         "\t%s %s -o %s %s %s %s\n",\r
+                         linker.c_str (),\r
+                         linkerParameters.c_str (),\r
+                         target.c_str (),\r
+                         objectFilenames.c_str (),\r
+                         importLibraryDependencies.c_str (),\r
+                         GetLinkerMacro ( module ).c_str () );\r
+       }\r
+\r
+       fprintf ( fMakefile,\r
+                     "\t${rsym} %s %s\n\n",\r
+                     target.c_str (),\r
+                     target.c_str () );\r
 }\r
 \r
 void\r
@@ -554,6 +877,7 @@ MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
                                                 const vector<File*>& files,\r
                                                 const vector<If*>& ifs,\r
                                                 const string& cc,\r
+                                                const string& cppc,\r
                                                 const string& cflagsMacro,\r
                                                 const string& nasmflagsMacro,\r
                                                 const string& windresflagsMacro ) const\r
@@ -563,34 +887,34 @@ MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
        for ( i = 0; i < files.size (); i++ )\r
        {\r
                string sourceFilename = files[i]->name;\r
-               string objectFilename = GetObjectFilename ( sourceFilename );\r
-               fprintf ( fMakefile,\r
-                         "%s: %s\n",\r
-                         objectFilename.c_str (),\r
-                         sourceFilename.c_str () );\r
+               GenerateCommands ( module,\r
+                                  sourceFilename,\r
+                                  cc,\r
+                                  cppc,\r
+                                  cflagsMacro,\r
+                                  nasmflagsMacro,\r
+                                  windresflagsMacro );\r
                fprintf ( fMakefile,\r
-                         "\t%s\n",\r
-                         GenerateCommand ( module,\r
-                                           sourceFilename,\r
-                                           cc,\r
-                                           cflagsMacro,\r
-                                           nasmflagsMacro,\r
-                                           windresflagsMacro ).c_str () );\r
+                         "\n" );\r
        }\r
 \r
        for ( i = 0; i < ifs.size(); i++ )\r
+       {\r
                GenerateObjectFileTargets ( module,\r
                                            ifs[i]->files,\r
                                            ifs[i]->ifs,\r
                                            cc,\r
+                                           cppc,\r
                                            cflagsMacro,\r
                                            nasmflagsMacro,\r
                                            windresflagsMacro );\r
+       }\r
 }\r
 \r
 void\r
 MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,\r
                                                 const string& cc,\r
+                                                const string& cppc,\r
                                                 const string& cflagsMacro,\r
                                                 const string& nasmflagsMacro,\r
                                                 const string& windresflagsMacro ) const\r
@@ -599,6 +923,7 @@ MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
                                    module.files,\r
                                    module.ifs,\r
                                    cc,\r
+                                   cppc,\r
                                    cflagsMacro,\r
                                    nasmflagsMacro,\r
                                    windresflagsMacro );\r
@@ -613,7 +938,7 @@ MingwModuleHandler::GetCleanTargets ( vector<string>& out,
        size_t i;\r
 \r
        for ( i = 0; i < files.size(); i++ )\r
-               out.push_back ( GetObjectFilename(files[i]->name) );\r
+               out.push_back ( PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files[i]->name ) ) );\r
 \r
        for ( i = 0; i < ifs.size(); i++ )\r
                GetCleanTargets ( out, ifs[i]->files, ifs[i]->ifs );\r
@@ -665,8 +990,10 @@ void
 MingwModuleHandler::GenerateMacrosAndTargets (\r
        const Module& module,\r
        const string& cc,\r
+       const string& cppc,\r
        const string& ar,\r
-       const string* cflags ) const\r
+       const string* cflags,\r
+       const string* nasmflags ) const\r
 {\r
        string cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());\r
        string nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());\r
@@ -688,13 +1015,21 @@ MingwModuleHandler::GenerateMacrosAndTargets (
                          cflagsMacro.c_str (),\r
                          cflags->c_str () );\r
        }\r
-       \r
+\r
+       if ( nasmflags != NULL )\r
+       {\r
+               fprintf ( fMakefile,\r
+                         "%s += %s\n\n",\r
+                         nasmflagsMacro.c_str (),\r
+                         nasmflags->c_str () );\r
+       }\r
+\r
        // generate phony target for module name\r
        fprintf ( fMakefile, ".PHONY: %s\n",\r
                module.name.c_str () );\r
        fprintf ( fMakefile, "%s: %s\n\n",\r
                module.name.c_str (),\r
-               module.GetPath ().c_str () );\r
+               FixupTargetFilename ( module.GetPath () ).c_str () );\r
 \r
        // future references to the macros will be to get their values\r
        cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());\r
@@ -704,6 +1039,7 @@ MingwModuleHandler::GenerateMacrosAndTargets (
        string ar_target = GenerateArchiveTarget ( module, ar, objectsMacro );\r
        GenerateObjectFileTargets ( module,\r
                                    cc,\r
+                                   cppc,\r
                                    cflagsMacro,\r
                                    nasmflagsMacro,\r
                                    windresflagsMacro );\r
@@ -713,34 +1049,48 @@ MingwModuleHandler::GenerateMacrosAndTargets (
        clean_files.push_back ( ar_target );\r
        GetCleanTargets ( clean_files, module.files, module.ifs );\r
 \r
-       fprintf ( fMakefile, "clean::\n\t-@$(rm)" );\r
+       fprintf ( fMakefile, ".PHONY: %s_clean\n", module.name.c_str() );\r
+       fprintf ( fMakefile, "%s_clean:\n\t-@$(rm)", module.name.c_str() );\r
        for ( size_t i = 0; i < clean_files.size(); i++ )\r
        {\r
                if ( 9==(i%10) )\r
-                       fprintf ( fMakefile, " 2>NUL\n\t-@$(rm)" );\r
+                       fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );\r
                fprintf ( fMakefile, " %s", clean_files[i].c_str() );\r
        }\r
-       fprintf ( fMakefile, " 2>NUL\n\n" );\r
+       fprintf ( fMakefile, " 2>$(NUL)\n" );\r
+       fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );\r
 }\r
 \r
 void\r
 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module& module ) const\r
 {\r
-       GenerateMacrosAndTargets ( module, "${host_gcc}", "${host_ar}", NULL );\r
+       GenerateMacrosAndTargets ( module,\r
+                                  "${host_gcc}",\r
+                                  "${host_gpp}",\r
+                                  "${host_ar}",\r
+                                  NULL,\r
+                                  NULL );\r
 }\r
 \r
 void\r
 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module ) const\r
 {\r
        GenerateMacrosAndTargetsTarget ( module,\r
+                                        NULL,\r
                                         NULL );\r
 }\r
 \r
 void\r
 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module,\r
-                                                        const string* clags ) const\r
+                                                        const string* cflags,\r
+                                                        const string* nasmflags ) const\r
 {\r
-       GenerateMacrosAndTargets ( module, "${gcc}", "${ar}", clags );\r
+       GenerateMacrosAndTargets ( module,\r
+                                 "${gcc}",\r
+                                 "${gpp}",\r
+                                 "${ar}",\r
+                                 cflags,\r
+                                 nasmflags );\r
 }\r
 \r
 string\r
@@ -760,40 +1110,6 @@ MingwModuleHandler::GetInvocationDependencies ( const Module& module ) const
        return dependencies;\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
@@ -805,25 +1121,27 @@ MingwModuleHandler::GenerateInvocations ( const Module& module ) const
                const Invoke& invoke = *module.invocations[i];\r
 \r
                if ( invoke.invokeModule->type != BuildTool )\r
+               {\r
                        throw InvalidBuildFileException ( module.node.location,\r
-                                                     "Only modules of type buildtool can be invoked." );\r
+                                                         "Only modules of type buildtool can be invoked." );\r
+               }\r
 \r
                string invokeTarget = module.GetInvocationTarget ( i );\r
                fprintf ( fMakefile,\r
-                         "%s: %s\n\n",\r
-                         invoke.GetTargets ().c_str (),\r
+                         ".PHONY: %s\n\n",\r
                          invokeTarget.c_str () );\r
                fprintf ( fMakefile,\r
-                         "%s: %s\n",\r
+                         "%s: %s\n\n",\r
                          invokeTarget.c_str (),\r
+                         invoke.GetTargets ().c_str () );\r
+               fprintf ( fMakefile,\r
+                         "%s: %s\n",\r
+                         invoke.GetTargets ().c_str (),\r
                          FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str () );\r
                fprintf ( fMakefile,\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
+                         invoke.GetParameters ().c_str () );\r
        }\r
 }\r
 \r
@@ -834,13 +1152,31 @@ MingwModuleHandler::GetPreconditionDependenciesName ( const Module& module ) con
                          module.name.c_str () );\r
 }\r
 \r
+string\r
+MingwModuleHandler::GetDefaultDependencies ( const Module& module ) const\r
+{\r
+       /* Avoid circular dependency */\r
+       if ( module.type == BuildTool || module.name == "zlib" )\r
+               return "$(ROS_INTERMEDIATE)." SSEP "tools $(ROS_INTERMEDIATE)." SSEP "lib" SSEP "zlib";\r
+       else\r
+               return "init";\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
+       string sourceFilenames = GetSourceFilenamesWithoutGeneratedFiles ( module );\r
+       string dependencies = GetDefaultDependencies ( module );\r
+       string s = GetModuleDependencies ( module );\r
+       if ( s.length () > 0 )\r
+       {\r
+               if ( dependencies.length () > 0 )\r
+                       dependencies += " ";\r
+               dependencies += s;\r
+       }\r
+\r
+       s = GetInvocationDependencies ( module );\r
        if ( s.length () > 0 )\r
        {\r
                if ( dependencies.length () > 0 )\r
@@ -871,10 +1207,10 @@ MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) co
                                p2 = end;\r
                }\r
                fprintf ( fMakefile,\r
-                                 "%.*s: %s\n",\r
-                                 p2-p,\r
-                                 p,\r
-                                 preconditionDependenciesName.c_str ());\r
+                         "%.*s: %s\n",\r
+                         p2-p,\r
+                         p,\r
+                         preconditionDependenciesName.c_str ());\r
                p = p2;\r
                p += strspn ( p, " \t" );\r
        }\r
@@ -886,27 +1222,84 @@ MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module& module )
 {\r
        if ( module.importLibrary != NULL )\r
        {\r
-               fprintf ( fMakefile, "%s:\n",\r
-                         module.GetDependencyPath ().c_str () );\r
+               string definitionDependencies = GetDefinitionDependencies ( module );\r
+               fprintf ( fMakefile, "%s: %s\n",\r
+                         FixupTargetFilename( module.GetDependencyPath () ).c_str (),\r
+                         definitionDependencies.c_str () );\r
 \r
+               string killAt = module.mangledSymbols ? "" : "--kill-at";\r
                fprintf ( fMakefile,\r
-                         "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",\r
+                         "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",\r
                          module.GetTargetName ().c_str (),\r
-                         FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),\r
-                         FixupTargetFilename ( module.GetDependencyPath () ).c_str () );\r
+                         ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),\r
+                         FixupTargetFilename ( module.GetDependencyPath () ).c_str (),\r
+                         killAt.c_str () );\r
        }\r
 }\r
 \r
+string\r
+MingwModuleHandler::GetSpecObjectDependencies ( const string& filename ) const\r
+{\r
+       string basename = GetBasename ( filename );\r
+       return basename + ".spec.def" + " " + basename + ".stubs.c";\r
+}\r
 \r
-static MingwBuildToolModuleHandler buildtool_handler;\r
-\r
-MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()\r
-       : MingwModuleHandler ( BuildTool )\r
+string\r
+MingwModuleHandler::GetDefinitionDependencies ( const Module& module ) const\r
 {\r
+       string dependencies;\r
+       string dkNkmLibNoFixup = "dk/nkm/lib";\r
+       dependencies += FixupTargetFilename ( dkNkmLibNoFixup );\r
+       PassThruCacheDirectory ( dkNkmLibNoFixup + SSEP );\r
+       for ( size_t i = 0; i < module.files.size (); i++ )\r
+       {\r
+               File& file = *module.files[i];\r
+               string extension = GetExtension ( file.name );\r
+               if ( extension == ".spec" || extension == ".SPEC" )\r
+               {\r
+                       if ( dependencies.length () > 0 )\r
+                               dependencies += " ";\r
+                       dependencies += GetSpecObjectDependencies ( file.name );\r
+               }\r
+       }\r
+       return dependencies;\r
 }\r
 \r
-void\r
-MingwBuildToolModuleHandler::Process ( const Module& module )\r
+string\r
+MingwModuleHandler::GetLinkingDependencies ( const Module& module ) const\r
+{\r
+       string dependencies = GetImportLibraryDependencies ( module );\r
+       string s = GetDefinitionDependencies ( module );\r
+       if ( s.length () > 0 )\r
+       {\r
+               dependencies += " ";\r
+               dependencies += s;\r
+       }\r
+       return dependencies;\r
+}\r
+\r
+bool\r
+MingwModuleHandler::IsCPlusPlusModule ( const Module& module ) const\r
+{\r
+       if ( module.HasFileWithExtensions ( ".cc", ".CC" ) )\r
+               return true;\r
+       if ( module.HasFileWithExtensions ( ".cxx", ".CXX" ) )\r
+               return true;\r
+       if ( module.HasFileWithExtensions ( ".cpp", ".CPP" ) )\r
+               return true;\r
+       return false;\r
+}\r
+\r
+\r
+static MingwBuildToolModuleHandler buildtool_handler;\r
+\r
+MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()\r
+       : MingwModuleHandler ( BuildTool )\r
+{\r
+}\r
+\r
+void\r
+MingwBuildToolModuleHandler::Process ( const Module& module )\r
 {\r
        GeneratePreconditionDependencies ( module );\r
        GenerateBuildToolModuleTarget ( module );\r
@@ -917,20 +1310,31 @@ void
 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module& module )\r
 {\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
+       string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateMacrosAndTargetsHost ( module );\r
 \r
-       fprintf ( fMakefile, "%s: %s\n",\r
+       string linker;\r
+       if ( IsCPlusPlusModule ( module ) )\r
+               linker = "${host_gpp}";\r
+       else\r
+               linker = "${host_gcc}";\r
+       \r
+       fprintf ( fMakefile, "%s: %s %s\n",\r
                  target.c_str (),\r
-                 archiveFilename.c_str () );\r
+                 objectsMacro.c_str (),\r
+                 importLibraryDependencies.c_str () );\r
        fprintf ( fMakefile,\r
-                 "\t${host_gcc} %s -o %s %s\n\n",\r
+                 "\t%s %s -o %s %s %s\n\n",\r
+                 linker.c_str (),\r
                  GetLinkerMacro ( module ).c_str (),\r
                  target.c_str (),\r
-                 archiveFilename.c_str () );\r
+                 objectsMacro.c_str (),\r
+                 importLibraryDependencies.c_str () );\r
 }\r
 \r
+\r
 static MingwKernelModuleHandler kernelmodule_handler;\r
 \r
 MingwKernelModuleHandler::MingwKernelModuleHandler ()\r
@@ -958,8 +1362,10 @@ MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )
        string base_tmp = ros_junk + module.name + ".base.tmp";\r
        string junk_tmp = ros_junk + module.name + ".junk.tmp";\r
        string temp_exp = ros_junk + module.name + ".temp.exp";\r
-       string gccOptions = ssprintf ("-Wl,-T,%s" SSEP "ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,_NtProcessStartup -Wl,--image-base,0xC0000000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
-                                     module.GetBasePath ().c_str () );\r
+       string gccOptions = ssprintf ("-Wl,-T,%s" SSEP "ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
+                                     module.GetBasePath ().c_str (),\r
+                                     module.entrypoint.c_str (),\r
+                                     module.baseaddress.c_str () );\r
 \r
        GenerateMacrosAndTargetsTarget ( module );\r
 \r
@@ -980,11 +1386,13 @@ MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )
        fprintf ( fMakefile,\r
                  "\t${rm} %s\n",\r
                  junk_tmp.c_str () );\r
+       string killAt = module.mangledSymbols ? "" : "--kill-at";\r
        fprintf ( fMakefile,\r
-                 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s --kill-at\n",\r
+                 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",\r
                  targetName.c_str (),\r
                  base_tmp.c_str (),\r
-                 temp_exp.c_str () );\r
+                 temp_exp.c_str (),\r
+                 killAt.c_str () );\r
        fprintf ( fMakefile,\r
                  "\t${rm} %s\n",\r
                  base_tmp.c_str () );\r
@@ -997,8 +1405,12 @@ MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )
                  objectsMacro.c_str (),\r
                  importLibraryDependencies.c_str () );\r
        fprintf ( fMakefile,\r
-                 "\t${rm} %s\n\n",\r
+                 "\t${rm} %s\n",\r
                  temp_exp.c_str () );\r
+       fprintf ( fMakefile,\r
+                     "\t${rsym} %s %s\n\n",\r
+                     target.c_str (),\r
+                     target.c_str () );\r
 }\r
 \r
 \r
@@ -1024,6 +1436,28 @@ MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Modul
 }\r
 \r
 \r
+static MingwObjectLibraryModuleHandler objectlibrary_handler;\r
+\r
+MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()\r
+       : MingwModuleHandler ( ObjectLibrary )\r
+{\r
+}\r
+\r
+void\r
+MingwObjectLibraryModuleHandler::Process ( const Module& module )\r
+{\r
+       GeneratePreconditionDependencies ( module );\r
+       GenerateObjectLibraryModuleTarget ( module );\r
+       GenerateInvocations ( module );\r
+}\r
+\r
+void\r
+MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module& module )\r
+{\r
+       GenerateMacrosAndTargetsTarget ( module );\r
+}\r
+\r
+\r
 static MingwKernelModeDLLModuleHandler kernelmodedll_handler;\r
 \r
 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()\r
@@ -1045,7 +1479,7 @@ MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Modul
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1056,24 +1490,23 @@ MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Modul
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         archiveFilename.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );\r
-               string linkerCommand = GenerateLinkerCommand ( module,\r
-                                                       "${gcc}",\r
-                                                       linkerParameters,\r
-                                                       archiveFilename );\r
-               fprintf ( fMakefile,\r
-                         "\t%s\n\n",\r
-                         linkerCommand.c_str () );\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
+               GenerateLinkerCommand ( module,\r
+                                       "${gcc}",\r
+                                       linkerParameters,\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
-               fprintf ( fMakefile, "%s:\n",\r
-                         target.c_str ());\r
                fprintf ( fMakefile, ".PHONY: %s\n\n",\r
                          target.c_str ());\r
+               fprintf ( fMakefile, "%s:\n",\r
+                         target.c_str ());\r
        }\r
 }\r
 \r
@@ -1093,13 +1526,14 @@ MingwKernelModeDriverModuleHandler::Process ( const Module& module )
        GenerateInvocations ( module );\r
 }\r
 \r
+\r
 void\r
 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module& module )\r
 {\r
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
-       string target ( FixupTargetFilename ( module.GetPath () ) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string target ( PassThruCacheDirectory( FixupTargetFilename ( module.GetPath () ) ) );\r
+       string workingDirectory = GetWorkingDirectory ();\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1108,29 +1542,29 @@ MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const
        {\r
                string* cflags = new string ( "-D__NTDRIVER__" );\r
                GenerateMacrosAndTargetsTarget ( module,\r
-                                                cflags );\r
+                                                cflags,\r
+                                                NULL );\r
                delete cflags;\r
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         archiveFilename.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );\r
-               string linkerCommand = GenerateLinkerCommand ( module,\r
-                                                       "${gcc}",\r
-                                                       linkerParameters,\r
-                                                       archiveFilename );\r
-               fprintf ( fMakefile,\r
-                         "\t%s\n\n",\r
-                         linkerCommand.c_str () );\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
+               GenerateLinkerCommand ( module,\r
+                                       "${gcc}",\r
+                                       linkerParameters,\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
-               fprintf ( fMakefile, "%s:\n",\r
-                         target.c_str ());\r
                fprintf ( fMakefile, ".PHONY: %s\n\n",\r
                          target.c_str ());\r
+               fprintf ( fMakefile, "%s:\n",\r
+                         target.c_str () );\r
        }\r
 }\r
 \r
@@ -1156,7 +1590,7 @@ MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module& modul
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
        \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1167,24 +1601,80 @@ MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module& modul
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         archiveFilename.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DllMainCRTStartup@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll" );\r
-               string linkerCommand = GenerateLinkerCommand ( module,\r
-                                                       "${gcc}",\r
-                                                       linkerParameters,\r
-                                                       archiveFilename );\r
-               fprintf ( fMakefile,\r
-                         "\t%s\n\n",\r
-                         linkerCommand.c_str () );\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
+               GenerateLinkerCommand ( module,\r
+                                       "${gcc}",\r
+                                       linkerParameters,\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
+               fprintf ( fMakefile, ".PHONY: %s\n\n",\r
+                         target.c_str ());\r
                fprintf ( fMakefile, "%s:\n\n",\r
                          target.c_str ());\r
+       }\r
+}\r
+\r
+\r
+static MingwNativeCUIModuleHandler nativecui_handler;\r
+\r
+MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()\r
+       : MingwModuleHandler ( NativeCUI )\r
+{\r
+}\r
+\r
+void\r
+MingwNativeCUIModuleHandler::Process ( const Module& module )\r
+{\r
+       GeneratePreconditionDependencies ( module );\r
+       GenerateNativeCUIModuleTarget ( module );\r
+       GenerateInvocations ( module );\r
+}\r
+\r
+void\r
+MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module& module )\r
+{\r
+       static string ros_junk ( "$(ROS_TEMPORARY)" );\r
+       string target ( FixupTargetFilename ( module.GetPath () ) );\r
+       string workingDirectory = GetWorkingDirectory ( );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
+       string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
+       \r
+       GenerateImportLibraryTargetIfNeeded ( module );\r
+\r
+       if ( module.files.size () > 0 )\r
+       {\r
+               string* cflags = new string ( "-D__NTAPP__" );\r
+               GenerateMacrosAndTargetsTarget ( module,\r
+                                                cflags,\r
+                                                NULL );\r
+               delete cflags;\r
+\r
+               fprintf ( fMakefile, "%s: %s %s\n",\r
+                         target.c_str (),\r
+                         objectsMacro.c_str (),\r
+                         importLibraryDependencies.c_str () );\r
+\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
+               GenerateLinkerCommand ( module,\r
+                                       "${gcc}",\r
+                                       linkerParameters,\r
+                                       objectsMacro );\r
+       }\r
+       else\r
+       {\r
                fprintf ( fMakefile, ".PHONY: %s\n\n",\r
                          target.c_str ());\r
+               fprintf ( fMakefile, "%s:\n\n",\r
+                         target.c_str ());\r
        }\r
 }\r
 \r
@@ -1199,18 +1689,98 @@ MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
 void\r
 MingwWin32DLLModuleHandler::Process ( const Module& module )\r
 {\r
+       GenerateExtractWineDLLResourcesTarget ( module );\r
        GeneratePreconditionDependencies ( module );\r
        GenerateWin32DLLModuleTarget ( module );\r
        GenerateInvocations ( module );\r
 }\r
 \r
+void\r
+MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module& module )\r
+{\r
+       fprintf ( fMakefile, ".PHONY: %s_extractresources\n\n",\r
+                 module.name.c_str () );\r
+       fprintf ( fMakefile, "%s_extractresources: bin2res\n",\r
+                 module.name.c_str () );\r
+       for ( size_t i = 0; i < module.files.size (); i++ )\r
+       {\r
+               File& file = *module.files[i];\r
+               string extension = GetExtension ( file.name );\r
+               if ( extension == ".rc" || extension == ".RC" )\r
+               {\r
+                       string resource = FixupTargetFilename ( file.name );\r
+                       fprintf ( fMakefile, "\t@echo ${bin2res} -f -x %s\n",\r
+                                 resource.c_str () );\r
+               }\r
+       }\r
+       fprintf ( fMakefile, "\n");\r
+}\r
+\r
 void\r
 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module& module )\r
 {\r
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
+       string linkingDependencies = GetLinkingDependencies ( module );\r
+\r
+       GenerateImportLibraryTargetIfNeeded ( module );\r
+       if ( module.files.size () > 0 )\r
+       {\r
+               GenerateMacrosAndTargetsTarget ( module );\r
+       \r
+               fprintf ( fMakefile, "%s: %s %s\n",\r
+                         target.c_str (),\r
+                         objectsMacro.c_str (),\r
+                         linkingDependencies.c_str () );\r
+\r
+               string linker;\r
+               if ( IsCPlusPlusModule ( module ) )\r
+                       linker = "${gpp}";\r
+               else\r
+                       linker = "${gcc}";\r
+\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
+               GenerateLinkerCommand ( module,\r
+                                       linker,\r
+                                       linkerParameters,\r
+                                       objectsMacro );\r
+       }\r
+       else\r
+       {\r
+               fprintf ( fMakefile, ".PHONY: %s\n\n",\r
+                         target.c_str () );\r
+               fprintf ( fMakefile, "%s:\n\n",\r
+                         target.c_str () );\r
+       }\r
+}\r
+\r
+\r
+static MingwWin32CUIModuleHandler win32cui_handler;\r
+\r
+MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()\r
+       : MingwModuleHandler ( Win32CUI )\r
+{\r
+}\r
+\r
+void\r
+MingwWin32CUIModuleHandler::Process ( const Module& module )\r
+{\r
+       GeneratePreconditionDependencies ( module );\r
+       GenerateWin32CUIModuleTarget ( module );\r
+       GenerateInvocations ( module );\r
+}\r
+\r
+void\r
+MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module& module )\r
+{\r
+       static string ros_junk ( "$(ROS_TEMPORARY)" );\r
+       string target ( FixupTargetFilename ( module.GetPath () ) );\r
+       string workingDirectory = GetWorkingDirectory ( );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1221,24 +1791,29 @@ MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module& module
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         archiveFilename.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters ( "-Wl,--subsystem,console -Wl,--entry,_DllMain@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll" );\r
-               string linkerCommand = GenerateLinkerCommand ( module,\r
-                                                       "${gcc}",\r
-                                                       linkerParameters,\r
-                                                       archiveFilename );\r
-               fprintf ( fMakefile,\r
-                         "\t%s\n\n",\r
-                         linkerCommand.c_str () );\r
+               string linker;\r
+               if ( IsCPlusPlusModule ( module ) )\r
+                       linker = "${gpp}";\r
+               else\r
+                       linker = "${gcc}";\r
+\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
+               GenerateLinkerCommand ( module,\r
+                                       linker,\r
+                                       linkerParameters,\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
-               fprintf ( fMakefile, "%s:\n\n",\r
-                         target.c_str ());\r
                fprintf ( fMakefile, ".PHONY: %s\n\n",\r
                          target.c_str ());\r
+               fprintf ( fMakefile, "%s:\n\n",\r
+                         target.c_str ());\r
        }\r
 }\r
 \r
@@ -1264,7 +1839,7 @@ MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module& module
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string objectFilenames = GetObjectFilenames ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1275,23 +1850,299 @@ MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module& module
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         objectFilenames.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters ( "-Wl,--subsystem,windows -Wl,--entry,_WinMainCRTStartup -Wl,--image-base,0x00400000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000" );\r
-               string linkerCommand = GenerateLinkerCommand ( module,\r
-                                                       "${gcc}",\r
-                                                       linkerParameters,\r
-                                                       objectFilenames );\r
-               fprintf ( fMakefile,\r
-                         "\t%s\n\n",\r
-                         linkerCommand.c_str () );\r
+               string linker;\r
+               if ( IsCPlusPlusModule ( module ) )\r
+                       linker = "${gpp}";\r
+               else\r
+                       linker = "${gcc}";\r
+\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
+               GenerateLinkerCommand ( module,\r
+                                       linker,\r
+                                       linkerParameters,\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
-               fprintf ( fMakefile, "%s:\n\n",\r
-                         target.c_str ());\r
                fprintf ( fMakefile, ".PHONY: %s\n\n",\r
                          target.c_str ());\r
+               fprintf ( fMakefile, "%s:\n\n",\r
+                         target.c_str ());\r
        }\r
 }\r
+\r
+\r
+static MingwBootLoaderModuleHandler bootloadermodule_handler;\r
+\r
+MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()\r
+       : MingwModuleHandler ( BootLoader )\r
+{\r
+}\r
+\r
+void\r
+MingwBootLoaderModuleHandler::Process ( const Module& module )\r
+{\r
+       GeneratePreconditionDependencies ( module );\r
+       GenerateBootLoaderModuleTarget ( module );\r
+       GenerateInvocations ( module );\r
+}\r
+\r
+void\r
+MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ( const Module& module )\r
+{\r
+       static string ros_junk ( "$(ROS_TEMPORARY)" );\r
+       string targetName ( module.GetTargetName () );\r
+       string target ( FixupTargetFilename ( module.GetPath () ) );\r
+       string workingDirectory = GetWorkingDirectory ();\r
+       string junk_tmp = ros_junk + module.name + ".junk.tmp";\r
+       string objectsMacro = GetObjectsMacro ( module );\r
+       string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
+\r
+       GenerateMacrosAndTargetsTarget ( module );\r
+\r
+       fprintf ( fMakefile, "%s: %s %s\n",\r
+                 target.c_str (),\r
+                 objectsMacro.c_str (),\r
+                 importLibraryDependencies.c_str () );\r
+\r
+       fprintf ( fMakefile,\r
+                 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",\r
+                 GetLinkerMacro ( module ).c_str (),\r
+                 junk_tmp.c_str (),\r
+                 objectsMacro.c_str (),\r
+                 importLibraryDependencies.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t${objcopy} -O binary %s %s\n",\r
+                 junk_tmp.c_str (),\r
+                 target.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t${rm} %s\n",\r
+                 junk_tmp.c_str () );\r
+}\r
+\r
+\r
+static MingwBootSectorModuleHandler bootsectormodule_handler;\r
+\r
+MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()\r
+       : MingwModuleHandler ( BootSector )\r
+{\r
+}\r
+\r
+void\r
+MingwBootSectorModuleHandler::Process ( const Module& module )\r
+{\r
+       GeneratePreconditionDependencies ( module );\r
+       GenerateBootSectorModuleTarget ( module );\r
+       GenerateInvocations ( module );\r
+}\r
+\r
+void\r
+MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module& module )\r
+{\r
+       string objectsMacro = GetObjectsMacro ( module );\r
+\r
+       string* nasmflags = new string ( "-f bin" );\r
+       GenerateMacrosAndTargetsTarget ( module,\r
+                                        NULL,\r
+                                        nasmflags);\r
+\r
+       fprintf ( fMakefile, ".PHONY: %s\n\n",\r
+                     module.name.c_str ());\r
+       fprintf ( fMakefile,\r
+                 "%s: %s\n",\r
+                 module.name.c_str (),\r
+                 objectsMacro.c_str () );\r
+}\r
+\r
+\r
+static MingwIsoModuleHandler isomodule_handler;\r
+\r
+MingwIsoModuleHandler::MingwIsoModuleHandler ()\r
+       : MingwModuleHandler ( Iso )\r
+{\r
+}\r
+\r
+void\r
+MingwIsoModuleHandler::Process ( const Module& module )\r
+{\r
+       GeneratePreconditionDependencies ( module );\r
+       GenerateIsoModuleTarget ( module );\r
+       GenerateInvocations ( module );\r
+}\r
+\r
+void\r
+MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory,\r
+                                                            const Module& module ) const\r
+{\r
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
+       {\r
+               const Module& m = *module.project.modules[i];\r
+               if ( m.bootstrap != NULL )\r
+               {\r
+                       string targetFilenameNoFixup = bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd;\r
+                       string targetFilename = PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup ) );\r
+                       fprintf ( fMakefile,\r
+                                 "\t${cp} %s %s\n",\r
+                                 m.GetPath ().c_str (),\r
+                                 targetFilename.c_str () );\r
+               }\r
+       }\r
+}\r
+\r
+void\r
+MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory,\r
+                                                     const Module& module ) const\r
+{\r
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
+       {\r
+               const CDFile& cdfile = *module.project.cdfiles[i];\r
+               string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;\r
+               string targetFilename = PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup ) );\r
+               fprintf ( fMakefile,\r
+                         "\t${cp} %s %s\n",\r
+                         cdfile.GetPath ().c_str (),\r
+                         targetFilename.c_str () );\r
+       }\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory,\r
+                                                      const Module& module ) const\r
+{\r
+       string directories;\r
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
+       {\r
+               const Module& m = *module.project.modules[i];\r
+               if ( m.bootstrap != NULL )\r
+               {\r
+                       string targetDirecctory = bootcdDirectory + SSEP + m.bootstrap->base;\r
+                       if ( directories.size () > 0 )\r
+                               directories += " ";\r
+                       directories += FixupTargetFilename ( targetDirecctory );\r
+               }\r
+       }\r
+       return directories;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory,\r
+                                                      const Module& module ) const\r
+{\r
+       string directories;\r
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
+       {\r
+               const CDFile& cdfile = *module.project.cdfiles[i];\r
+               string targetDirecctory = bootcdDirectory + SSEP + cdfile.base;\r
+               if ( directories.size () > 0 )\r
+                       directories += " ";\r
+               directories += FixupTargetFilename ( targetDirecctory );\r
+       }\r
+       return directories;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory,\r
+                                             const Module& module ) const\r
+{\r
+       string directories = GetBootstrapCdDirectories ( bootcdDirectory,\r
+                                                        module );\r
+       directories += " " + GetNonModuleCdDirectories ( bootcdDirectory,\r
+                                                        module );\r
+       return directories;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory,\r
+                                                const Module& module ) const\r
+{\r
+       string cdfiles;\r
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
+       {\r
+               const Module& m = *module.project.modules[i];\r
+               if ( m.bootstrap != NULL )\r
+               {\r
+                       if ( cdfiles.size () > 0 )\r
+                               cdfiles += " ";\r
+                       cdfiles += FixupTargetFilename ( m.GetPath () );\r
+               }\r
+       }\r
+       return cdfiles;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory,\r
+                                                const Module& module ) const\r
+{\r
+       string cdfiles;\r
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
+       {\r
+               const CDFile& cdfile = *module.project.cdfiles[i];\r
+               if ( cdfiles.size () > 0 )\r
+                       cdfiles += " ";\r
+               cdfiles += NormalizeFilename ( cdfile.GetPath () );\r
+       }\r
+       return cdfiles;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory,\r
+                                       const Module& module ) const\r
+{\r
+       string cdfiles = GetBootstrapCdFiles ( bootcdDirectory,\r
+                                              module );\r
+       cdfiles += " " + GetNonModuleCdFiles ( bootcdDirectory,\r
+                                              module );\r
+       return cdfiles;\r
+}\r
+\r
+void\r
+MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module& module )\r
+{\r
+       string bootcdDirectory = "cd";\r
+       string isoboot = FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );\r
+       string bootcdReactosNoFixup = bootcdDirectory + "/reactos";\r
+       string bootcdReactos = FixupTargetFilename ( bootcdReactosNoFixup );\r
+       PassThruCacheDirectory ( bootcdReactos + SSEP );\r
+       string reactosInf = FixupTargetFilename ( bootcdReactosNoFixup + "/reactos.inf" );\r
+       string reactosDff = NormalizeFilename ( "bootdata/packages/reactos.dff" );\r
+       string cdDirectories = bootcdReactos + " " + GetCdDirectories ( bootcdDirectory,\r
+                                                                       module );\r
+       string cdFiles = GetCdFiles ( bootcdDirectory,\r
+                                     module );\r
+\r
+       fprintf ( fMakefile, ".PHONY: %s\n\n",\r
+                     module.name.c_str ());\r
+       fprintf ( fMakefile,\r
+                 "%s: all %s %s %s\n",\r
+                 module.name.c_str (),\r
+                 isoboot.c_str (),\r
+                 cdDirectories.c_str (),\r
+                 cdFiles.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t${cabman} -C %s -L %s -I\n",\r
+                 reactosDff.c_str (),\r
+                 bootcdReactos.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t${cabman} -C %s -RC %s -L %s -N\n",\r
+                 reactosDff.c_str (),\r
+                 reactosInf.c_str (),\r
+                 bootcdReactos.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\t- ${rm} %s\n",\r
+                 reactosInf.c_str () );\r
+       OutputBootstrapfileCopyCommands ( bootcdDirectory,\r
+                                         module );\r
+       OutputCdfileCopyCommands ( bootcdDirectory,\r
+                                  module );\r
+       fprintf ( fMakefile,\r
+                 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",\r
+                 isoboot.c_str (),\r
+                 bootcdDirectory.c_str () );\r
+       fprintf ( fMakefile,\r
+                 "\n" );\r
+}\r