Add new PEFIXUP tool and use it in the build system.
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.cpp
index 03e2514..7b6a9e6 100644 (file)
-#include "../../pch.h"\r
-#include <assert.h>\r
-\r
-#include "../../rbuild.h"\r
-#include "mingw.h"\r
-#include "modulehandler.h"\r
-\r
-using std::string;\r
-using std::vector;\r
-\r
-#define CLEAN_FILE(f) clean_files.push_back ( f ); /*if ( module.name == "crt" ) printf ( "%s(%i): clean: %s\n", __FILE__, __LINE__, f.c_str() )*/\r
-\r
-static string ros_temp = "$(TEMPORARY)";\r
-MingwBackend*\r
-MingwModuleHandler::backend = NULL;\r
-FILE*\r
-MingwModuleHandler::fMakefile = NULL;\r
-bool\r
-MingwModuleHandler::use_pch = false;\r
-\r
-string\r
-PrefixFilename (\r
-       const string& filename,\r
-       const string& prefix )\r
-{\r
-       if ( !prefix.length() )\r
-               return filename;\r
-       string out;\r
-       const char* pfilename = filename.c_str();\r
-       const char* p1 = strrchr ( pfilename, '/' );\r
-       const char* p2 = strrchr ( pfilename, '\\' );\r
-       if ( p1 || p2 )\r
-       {\r
-               if ( p2 > p1 )\r
-                       p1 = p2;\r
-               out += string(pfilename,p1-pfilename) + CSEP;\r
-               pfilename = p1 + 1;\r
-       }\r
-       out += prefix + pfilename;\r
-       return out;\r
-}\r
-\r
-string\r
-GetTargetMacro ( const Module& module, bool with_dollar )\r
-{\r
-       string s ( module.name );\r
-       strupr ( &s[0] );\r
-       s += "_TARGET";\r
-       if ( with_dollar )\r
-               return ssprintf ( "$(%s)", s.c_str() );\r
-       return s;\r
-}\r
-\r
-MingwModuleHandler::MingwModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : module(module_)\r
-{\r
-}\r
-\r
-MingwModuleHandler::~MingwModuleHandler()\r
-{\r
-}\r
-\r
-/*static*/ void\r
-MingwModuleHandler::SetBackend ( MingwBackend* backend_ )\r
-{\r
-       backend = backend_;\r
-}\r
-\r
-/*static*/ void\r
-MingwModuleHandler::SetMakefile ( FILE* f )\r
-{\r
-       fMakefile = f;\r
-}\r
-\r
-/*static*/ void\r
-MingwModuleHandler::SetUsePch ( bool b )\r
-{\r
-       use_pch = b;\r
-}\r
-\r
-/* static*/ string\r
-MingwModuleHandler::RemoveVariables ( string path)\r
-{\r
-       size_t i = path.find ( '$' );\r
-       if ( i != string::npos )\r
-       {\r
-               size_t j = path.find ( ')', i );\r
-               if ( j != string::npos )\r
-               {\r
-                       if ( j + 2 < path.length () && path[j + 1] == CSEP )\r
-                               return path.substr ( j + 2);\r
-                       else\r
-                               return path.substr ( j + 1);\r
-               }\r
-       }\r
-       return path;\r
-}\r
-\r
-/*static*/ string\r
-MingwModuleHandler::PassThruCacheDirectory (\r
-       const string &file,\r
-       Directory* directoryTree )\r
-{\r
-       string directory ( GetDirectory ( RemoveVariables ( file ) ) );\r
-       string generatedFilesDirectory = backend->AddDirectoryTarget ( directory,\r
-                                                                      directoryTree );\r
-       if ( directory.find ( generatedFilesDirectory ) != string::npos )\r
-               /* This path already includes the generated files directory variable */\r
-               return file;\r
-       else\r
-               return generatedFilesDirectory + SSEP + file;\r
-}\r
-\r
-/*static*/ string\r
-MingwModuleHandler::GetTargetFilename (\r
-       const Module& module,\r
-       string_list* pclean_files )\r
-{\r
-       string target = PassThruCacheDirectory (\r
-               NormalizeFilename ( module.GetPath () ),\r
-               backend->outputDirectory );\r
-       if ( pclean_files )\r
-       {\r
-               string_list& clean_files = *pclean_files;\r
-               CLEAN_FILE ( target );\r
-       }\r
-       return target;\r
-}\r
-\r
-/*static*/ string\r
-MingwModuleHandler::GetImportLibraryFilename (\r
-       const Module& module,\r
-       string_list* pclean_files )\r
-{\r
-       string target = PassThruCacheDirectory (\r
-               NormalizeFilename ( module.GetDependencyPath () ),\r
-               backend->outputDirectory );\r
-       if ( pclean_files )\r
-       {\r
-               string_list& clean_files = *pclean_files;\r
-               CLEAN_FILE ( target );\r
-       }\r
-       return target;\r
-}\r
-\r
-/*static*/ MingwModuleHandler*\r
-MingwModuleHandler::InstanciateHandler (\r
-       const Module& module,\r
-       MingwBackend* backend )\r
-{\r
-       MingwModuleHandler* handler;\r
-       switch ( module.type )\r
-       {\r
-               case BuildTool:\r
-                       handler = new MingwBuildToolModuleHandler ( module );\r
-                       break;\r
-               case StaticLibrary:\r
-                       handler = new MingwStaticLibraryModuleHandler ( module );\r
-                       break;\r
-               case ObjectLibrary:\r
-                       handler = new MingwObjectLibraryModuleHandler ( module );\r
-                       break;\r
-               case Kernel:\r
-                       handler = new MingwKernelModuleHandler ( module );\r
-                       break;\r
-               case NativeCUI:\r
-                       handler = new MingwNativeCUIModuleHandler ( module );\r
-                       break;\r
-               case Win32CUI:\r
-                       handler = new MingwWin32CUIModuleHandler ( module );\r
-                       break;\r
-               case Win32GUI:\r
-                       handler = new MingwWin32GUIModuleHandler ( module );\r
-                       break;\r
-               case KernelModeDLL:\r
-                       handler = new MingwKernelModeDLLModuleHandler ( module );\r
-                       break;\r
-               case NativeDLL:\r
-                       handler = new MingwNativeDLLModuleHandler ( module );\r
-                       break;\r
-               case Win32DLL:\r
-                       handler = new MingwWin32DLLModuleHandler ( module );\r
-                       break;\r
-               case KernelModeDriver:\r
-                       handler = new MingwKernelModeDriverModuleHandler ( module );\r
-                       break;\r
-               case BootLoader:\r
-                       handler = new MingwBootLoaderModuleHandler ( module );\r
-                       break;\r
-               case BootSector:\r
-                       handler = new MingwBootSectorModuleHandler ( module );\r
-                       break;\r
-               case Iso:\r
-                       handler = new MingwIsoModuleHandler ( module );\r
-                       break;\r
-               case Test:\r
-                       handler = new MingwTestModuleHandler ( module );\r
-                       break;\r
-               case RpcServer:\r
-                       handler = new MingwRpcServerModuleHandler ( module );\r
-                       break;\r
-               case RpcClient:\r
-                       handler = new MingwRpcClientModuleHandler ( module );\r
-                       break;\r
-               default:\r
-                       throw UnknownModuleTypeException (\r
-                               module.node.location,\r
-                               module.type );\r
-                       break;\r
-       }\r
-       return handler;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetWorkingDirectory () const\r
-{\r
-       return ".";\r
-}\r
-\r
-string\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 ( 0, index );\r
-       return "";\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetActualSourceFilename (\r
-       const string& filename ) const\r
-{\r
-       string extension = GetExtension ( filename );\r
-       if ( extension == ".spec" || extension == ".SPEC" )\r
-       {\r
-               string basename = GetBasename ( filename );\r
-               return PassThruCacheDirectory ( NormalizeFilename ( basename + ".stubs.c" ),\r
-                                               backend->intermediateDirectory );\r
-       }\r
-       else if ( extension == ".idl" || extension == ".IDL" )\r
-       {\r
-               string basename = GetBasename ( filename );\r
-               string newname;\r
-               if ( module.type == RpcServer )\r
-                       newname = basename + "_s.c";\r
-               else\r
-                       newname = basename + "_c.c";\r
-               return PassThruCacheDirectory ( NormalizeFilename ( newname ),\r
-                                               backend->intermediateDirectory );\r
-       }\r
-       else\r
-               return filename;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetModuleArchiveFilename () const\r
-{\r
-       if ( module.type == StaticLibrary )\r
-               return GetTargetFilename ( module, NULL );\r
-       return PassThruCacheDirectory ( ReplaceExtension (\r
-               NormalizeFilename ( module.GetPath () ),\r
-               ".temp.a" ),\r
-               backend->intermediateDirectory );\r
-}\r
-\r
-bool\r
-MingwModuleHandler::IsGeneratedFile ( const File& file ) const\r
-{\r
-       string extension = GetExtension ( file.name );\r
-       return ( extension == ".spec" || extension == ".SPEC" );\r
-}\r
-\r
-/*static*/ bool\r
-MingwModuleHandler::ReferenceObjects (\r
-       const Module& module )\r
-{\r
-       if ( module.type == ObjectLibrary )\r
-               return true;\r
-       if ( module.type == RpcServer )\r
-               return true;\r
-       if ( module.type == RpcClient )\r
-               return true;\r
-       return false;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetImportLibraryDependency (\r
-       const Module& importedModule )\r
-{\r
-       string dep;\r
-       if ( ReferenceObjects ( importedModule ) )\r
-               dep = GetTargetMacro ( importedModule );\r
-       else\r
-               dep = GetImportLibraryFilename ( importedModule, NULL );\r
-       return dep;\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetTargets ( const Module& dependencyModule,\r
-                                    string_list& targets )\r
-{\r
-       if ( dependencyModule.invocations.size () > 0 )\r
-       {\r
-               for ( size_t i = 0; i < dependencyModule.invocations.size (); i++ )\r
-               {\r
-                       Invoke& invoke = *dependencyModule.invocations[i];\r
-                       invoke.GetTargets ( targets );\r
-               }\r
-       }\r
-       else\r
-               targets.push_back ( GetImportLibraryDependency ( dependencyModule ) );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetModuleDependencies (\r
-       string_list& dependencies )\r
-{\r
-       size_t iend = module.dependencies.size ();\r
-\r
-       if ( iend == 0 )\r
-               return;\r
-       \r
-       for ( size_t i = 0; i < iend; i++ )\r
-       {\r
-               const Dependency& dependency = *module.dependencies[i];\r
-               const Module& dependencyModule = *dependency.dependencyModule;\r
-               GetTargets ( dependencyModule,\r
-                            dependencies );\r
-       }\r
-       GetDefinitionDependencies ( dependencies );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetSourceFilenames (\r
-       string_list& list,\r
-       bool includeGeneratedFiles ) const\r
-{\r
-       size_t i;\r
-\r
-       const vector<File*>& files = module.non_if_data.files;\r
-       for ( i = 0; i < files.size (); i++ )\r
-       {\r
-               if ( includeGeneratedFiles || !IsGeneratedFile ( *files[i] ) )\r
-               {\r
-                       list.push_back (\r
-                               GetActualSourceFilename ( files[i]->name ) );\r
-               }\r
-       }\r
-       // intentionally make a copy so that we can append more work in\r
-       // the middle of processing without having to go recursive\r
-       vector<If*> v = module.non_if_data.ifs;\r
-       for ( i = 0; i < v.size (); i++ )\r
-       {\r
-               size_t j;\r
-               If& rIf = *v[i];\r
-               // check for sub-ifs to add to list\r
-               const vector<If*>& ifs = rIf.data.ifs;\r
-               for ( j = 0; j < ifs.size (); j++ )\r
-                       v.push_back ( ifs[j] );\r
-               const vector<File*>& files = rIf.data.files;\r
-               for ( j = 0; j < files.size (); j++ )\r
-               {\r
-                       File& file = *files[j];\r
-                       if ( includeGeneratedFiles || !IsGeneratedFile ( file ) )\r
-                       {\r
-                               list.push_back (\r
-                                       GetActualSourceFilename ( file.name ) );\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (\r
-       string_list& list ) const\r
-{\r
-       GetSourceFilenames ( list, false );\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetObjectFilename (\r
-       const string& sourceFilename,\r
-       string_list* pclean_files ) const\r
-{\r
-       Directory* directoryTree;\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 if ( extension == ".idl" || extension == ".IDL" )\r
-       {\r
-               if ( module.type == RpcServer )\r
-                       newExtension = "_s.o";\r
-               else\r
-                       newExtension = "_c.o";\r
-       }\r
-       else\r
-               newExtension = ".o";\r
-       \r
-       if ( module.type == BootSector )\r
-               directoryTree = backend->outputDirectory;\r
-       else\r
-               directoryTree = backend->intermediateDirectory;\r
-\r
-       string obj_file = PassThruCacheDirectory (\r
-               NormalizeFilename ( ReplaceExtension (\r
-                       RemoveVariables ( sourceFilename ),\r
-                                         newExtension ) ),\r
-                       directoryTree );\r
-       if ( pclean_files )\r
-       {\r
-               string_list& clean_files = *pclean_files;\r
-               CLEAN_FILE ( obj_file );\r
-       }\r
-       return obj_file;\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateCleanTarget () const\r
-{\r
-       if ( 0 == clean_files.size() )\r
-               return;\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+1)%10) )\r
-                       fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );\r
-               fprintf ( fMakefile, " %s", clean_files[i].c_str() );\r
-       }\r
-       fprintf ( fMakefile, " 2>$(NUL)\n" );\r
-       fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetObjectFilenames ()\r
-{\r
-       const vector<File*>& files = module.non_if_data.files;\r
-       if ( files.size () == 0 )\r
-               return "";\r
-       \r
-       string objectFilenames ( "" );\r
-       for ( size_t i = 0; i < files.size (); i++ )\r
-       {\r
-               if ( objectFilenames.size () > 0 )\r
-                       objectFilenames += " ";\r
-               objectFilenames +=\r
-                       GetObjectFilename ( files[i]->name, NULL );\r
-       }\r
-       return objectFilenames;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GenerateGccDefineParametersFromVector (\r
-       const vector<Define*>& defines ) const\r
-{\r
-       string parameters;\r
-       for ( size_t i = 0; i < defines.size (); i++ )\r
-       {\r
-               Define& define = *defines[i];\r
-               if (parameters.length () > 0)\r
-                       parameters += " ";\r
-               parameters += "-D";\r
-               parameters += define.name;\r
-               if (define.value.length () > 0)\r
-               {\r
-                       parameters += "=";\r
-                       parameters += define.value;\r
-               }\r
-       }\r
-       return parameters;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GenerateGccDefineParameters () const\r
-{\r
-       string parameters = GenerateGccDefineParametersFromVector ( module.project.non_if_data.defines );\r
-       string s = GenerateGccDefineParametersFromVector ( module.non_if_data.defines );\r
-       if ( s.length () > 0 )\r
-       {\r
-               parameters += " ";\r
-               parameters += s;\r
-       }\r
-       return parameters;\r
-}\r
-\r
-string\r
-MingwModuleHandler::ConcatenatePaths (\r
-       const string& path1,\r
-       const string& path2 ) const\r
-{\r
-       if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )\r
-               return path2;\r
-       if ( path1[path1.length ()] == CSEP )\r
-               return path1 + path2;\r
-       else\r
-               return path1 + CSEP + path2;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Include*>& includes ) const\r
-{\r
-       string parameters;\r
-       for ( size_t i = 0; i < includes.size (); i++ )\r
-       {\r
-               Include& include = *includes[i];\r
-               if ( parameters.length () > 0 )\r
-                       parameters += " ";\r
-               parameters += "-I" + include.directory;\r
-       }\r
-       return parameters;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GenerateGccIncludeParameters () const\r
-{\r
-       string parameters = GenerateGccIncludeParametersFromVector ( module.non_if_data.includes );\r
-       string s = GenerateGccIncludeParametersFromVector ( module.project.non_if_data.includes );\r
-       if ( s.length () > 0 )\r
-       {\r
-               parameters += " ";\r
-               parameters += s;\r
-       }\r
-       return parameters;\r
-}\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
-       string parameters;\r
-       for ( size_t i = 0; i < linkerFlags.size (); i++ )\r
-       {\r
-               LinkerFlag& linkerFlag = *linkerFlags[i];\r
-               if ( parameters.length () > 0 )\r
-                       parameters += " ";\r
-               parameters += linkerFlag.flag;\r
-       }\r
-       return parameters;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (\r
-       const vector<Library*>& libraries )\r
-{\r
-       string dependencies ( "" );\r
-       int wrap_count = 0;\r
-       for ( size_t i = 0; i < libraries.size (); i++ )\r
-       {\r
-               if ( wrap_count++ == 5 )\r
-                       dependencies += " \\\n\t\t", wrap_count = 0;\r
-               else if ( dependencies.size () > 0 )\r
-                       dependencies += " ";\r
-               dependencies += GetImportLibraryDependency ( *libraries[i]->imported_module );\r
-       }\r
-       return dependencies;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GenerateLinkerParameters () const\r
-{\r
-       return GenerateLinkerParametersFromVector ( module.linkerFlags );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateMacro (\r
-       const char* assignmentOperation,\r
-       const string& macro,\r
-       const IfableData& data,\r
-       const vector<CompilerFlag*>* compilerFlags )\r
-{\r
-       size_t i;\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 < data.includes.size(); i++ )\r
-       {\r
-               fprintf (\r
-                       fMakefile,\r
-                       " -I%s",\r
-                       data.includes[i]->directory.c_str() );\r
-       }\r
-       for ( i = 0; i < data.defines.size(); i++ )\r
-       {\r
-               Define& d = *data.defines[i];\r
-               fprintf (\r
-                       fMakefile,\r
-                       " -D%s",\r
-                       d.name.c_str() );\r
-               if ( d.value.size() )\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "=%s",\r
-                               d.value.c_str() );\r
-       }\r
-       fprintf ( fMakefile, "\n" );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateMacros (\r
-       const char* assignmentOperation,\r
-       const IfableData& data,\r
-       const vector<CompilerFlag*>* compilerFlags,\r
-       const vector<LinkerFlag*>* linkerFlags )\r
-{\r
-       size_t i;\r
-\r
-       if ( data.includes.size () > 0 || data.defines.size () > 0 )\r
-       {\r
-               GenerateMacro ( assignmentOperation,\r
-                               cflagsMacro,\r
-                               data,\r
-                               compilerFlags );\r
-               GenerateMacro ( assignmentOperation,\r
-                               windresflagsMacro,\r
-                               data,\r
-                               compilerFlags );\r
-       }\r
-       \r
-       if ( linkerFlags != NULL )\r
-       {\r
-               string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );\r
-               if ( linkerParameters.size () > 0 )\r
-               {\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "%s %s %s\n",\r
-                               linkerflagsMacro.c_str (),\r
-                               assignmentOperation,\r
-                               linkerParameters.c_str() );\r
-               }\r
-       }\r
-\r
-       if ( data.libraries.size () > 0 )\r
-       {\r
-               string deps = GenerateImportLibraryDependenciesFromVector ( data.libraries );\r
-               if ( deps.size () > 0 )\r
-               {\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "%s %s %s\n",\r
-                               libsMacro.c_str(),\r
-                               assignmentOperation,\r
-                               deps.c_str() );\r
-               }\r
-       }\r
-\r
-       const vector<If*>& ifs = data.ifs;\r
-       for ( i = 0; i < ifs.size(); i++ )\r
-       {\r
-               If& rIf = *ifs[i];\r
-               if ( rIf.data.defines.size()\r
-                       || rIf.data.includes.size()\r
-                       || rIf.data.libraries.size()\r
-                       || rIf.data.files.size()\r
-                       || rIf.data.ifs.size() )\r
-               {\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "ifeq (\"$(%s)\",\"%s\")\n",\r
-                               rIf.property.c_str(),\r
-                               rIf.value.c_str() );\r
-                       GenerateMacros (\r
-                               "+=",\r
-                               rIf.data,\r
-                               NULL,\r
-                               NULL );\r
-                       fprintf ( \r
-                               fMakefile,\r
-                               "endif\n\n" );\r
-               }\r
-       }\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateObjectMacros (\r
-       const char* assignmentOperation,\r
-       const IfableData& data,\r
-       const vector<CompilerFlag*>* compilerFlags,\r
-       const vector<LinkerFlag*>* linkerFlags )\r
-{\r
-       size_t i;\r
-\r
-       const vector<File*>& files = data.files;\r
-       if ( files.size () > 0 )\r
-       {\r
-               for ( i = 0; i < files.size (); i++ )\r
-               {\r
-                       File& file = *files[i];\r
-                       if ( file.first )\r
-                       {\r
-                               fprintf ( fMakefile,\r
-                                       "%s := %s $(%s)\n",\r
-                                       objectsMacro.c_str(),\r
-                                       GetObjectFilename (\r
-                                               file.name, NULL ).c_str (),\r
-                                       objectsMacro.c_str() );\r
-                       }\r
-               }\r
-               fprintf (\r
-                       fMakefile,\r
-                       "%s %s",\r
-                       objectsMacro.c_str (),\r
-                       assignmentOperation );\r
-               for ( i = 0; i < files.size(); i++ )\r
-               {\r
-                       File& file = *files[i];\r
-                       if ( !file.first )\r
-                       {\r
-                               fprintf (\r
-                                       fMakefile,\r
-                                       "%s%s",\r
-                                       ( i%10 == 9 ? " \\\n\t" : " " ),\r
-                                       GetObjectFilename (\r
-                                               file.name, NULL ).c_str () );\r
-                       }\r
-               }\r
-               fprintf ( fMakefile, "\n" );\r
-       }\r
-\r
-       const vector<If*>& ifs = data.ifs;\r
-       for ( i = 0; i < ifs.size(); i++ )\r
-       {\r
-               If& rIf = *ifs[i];\r
-               if ( rIf.data.defines.size()\r
-                       || rIf.data.includes.size()\r
-                       || rIf.data.libraries.size()\r
-                       || rIf.data.files.size()\r
-                       || rIf.data.ifs.size() )\r
-               {\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "ifeq (\"$(%s)\",\"%s\")\n",\r
-                               rIf.property.c_str(),\r
-                               rIf.value.c_str() );\r
-                       GenerateObjectMacros (\r
-                               "+=",\r
-                               rIf.data,\r
-                               NULL,\r
-                               NULL );\r
-                       fprintf ( \r
-                               fMakefile,\r
-                               "endif\n\n" );\r
-               }\r
-       }\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateGccCommand (\r
-       const string& sourceFilename,\r
-       const string& cc,\r
-       const string& cflagsMacro )\r
-{\r
-       string deps = sourceFilename;\r
-       if ( module.pch && use_pch )\r
-               deps += " " + module.pch->header + ".gch";\r
-       \r
-       /* WIDL generated headers may be used */\r
-       deps += " " + GetLinkingDependenciesMacro ();\r
-\r
-       string objectFilename = GetObjectFilename (\r
-               sourceFilename, &clean_files );\r
-       fprintf ( fMakefile,\r
-                 "%s: %s | %s\n",\r
-                 objectFilename.c_str (),\r
-                 deps.c_str (),\r
-                 GetDirectory ( objectFilename ).c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_CC)\n" );\r
-       fprintf ( fMakefile,\r
-                "\t%s -c $< -o $@ %s\n",\r
-                cc.c_str (),\r
-                cflagsMacro.c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateGccAssemblerCommand (\r
-       const string& sourceFilename,\r
-       const string& cc,\r
-       const string& cflagsMacro )\r
-{\r
-       string objectFilename = GetObjectFilename (\r
-               sourceFilename, &clean_files );\r
-       fprintf ( fMakefile,\r
-                 "%s: %s | %s\n",\r
-                 objectFilename.c_str (),\r
-                 sourceFilename.c_str (),\r
-                 GetDirectory ( objectFilename ).c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_GAS)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",\r
-                 cc.c_str (),\r
-                 cflagsMacro.c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateNasmCommand (\r
-       const string& sourceFilename,\r
-       const string& nasmflagsMacro )\r
-{\r
-       string objectFilename = GetObjectFilename (\r
-               sourceFilename, &clean_files );\r
-       fprintf ( fMakefile,\r
-                 "%s: %s | %s\n",\r
-                 objectFilename.c_str (),\r
-                 sourceFilename.c_str (),\r
-                 GetDirectory ( objectFilename ).c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_NASM)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t%s -f win32 $< -o $@ %s\n",\r
-                 "$(Q)nasm",\r
-                 nasmflagsMacro.c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateWindresCommand (\r
-       const string& sourceFilename,\r
-       const string& windresflagsMacro )\r
-{\r
-       string objectFilename =\r
-               GetObjectFilename ( sourceFilename, &clean_files );\r
-       string rciFilename = ros_temp +\r
-               ReplaceExtension ( sourceFilename, ".rci" );\r
-       string resFilename = ros_temp +\r
-               ReplaceExtension ( sourceFilename, ".res" );\r
-       if ( module.useWRC )\r
-       {\r
-               fprintf ( fMakefile,\r
-                         "%s: %s $(WRC_TARGET) | %s\n",\r
-                         objectFilename.c_str (),\r
-                         sourceFilename.c_str (),\r
-                         GetDirectory ( objectFilename ).c_str () );\r
-               fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );\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$(Q)$(WRC_TARGET) ${%s} %s %s\n",\r
-                        windresflagsMacro.c_str (),\r
-                        rciFilename.c_str (),\r
-                        resFilename.c_str () );\r
-               fprintf ( fMakefile,\r
-                        "\t-@${rm} %s 2>$(NUL)\n",\r
-                        rciFilename.c_str () );\r
-               fprintf ( fMakefile,\r
-                        "\t${windres} %s -o $@\n",\r
-                        resFilename.c_str () );\r
-               fprintf ( fMakefile,\r
-                        "\t-@${rm} %s 2>$(NUL)\n",\r
-                        resFilename.c_str () );\r
-       }\r
-       else\r
-       {\r
-               fprintf ( fMakefile,\r
-                         "%s: %s $(WRC_TARGET) | %s\n",\r
-                         objectFilename.c_str (),\r
-                         sourceFilename.c_str (),\r
-                         GetDirectory ( objectFilename ).c_str () );\r
-               fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );\r
-               fprintf ( fMakefile,\r
-                        "\t${windres} $(%s) %s -o $@\n",\r
-                        windresflagsMacro.c_str (),\r
-                        sourceFilename.c_str () );\r
-       }\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateWinebuildCommands (\r
-       const string& sourceFilename )\r
-{\r
-       string basename = GetBasename ( sourceFilename );\r
-\r
-       string def_file = PassThruCacheDirectory (\r
-               basename + ".spec.def",\r
-               backend->intermediateDirectory );\r
-       CLEAN_FILE(def_file);\r
-\r
-       string stub_file = PassThruCacheDirectory (\r
-               basename + ".stubs.c",\r
-               backend->intermediateDirectory );\r
-       CLEAN_FILE(stub_file)\r
-\r
-       fprintf ( fMakefile,\r
-                 "%s: %s $(WINEBUILD_TARGET)\n",\r
-                 def_file.c_str (),\r
-                 sourceFilename.c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t%s --def=%s -o %s\n",\r
-                 "$(Q)$(WINEBUILD_TARGET)",\r
-                 sourceFilename.c_str (),\r
-                 def_file.c_str () );\r
-\r
-       fprintf ( fMakefile,\r
-                 "%s: %s $(WINEBUILD_TARGET)\n",\r
-                 stub_file.c_str (),\r
-                 sourceFilename.c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t%s --pedll=%s -o %s\n",\r
-                 "$(Q)$(WINEBUILD_TARGET)",\r
-                 sourceFilename.c_str (),\r
-                 stub_file.c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateWidlCommandsServer (\r
-       const string& sourceFilename,\r
-       const string& widlflagsMacro )\r
-{\r
-       string basename = GetBasename ( sourceFilename );\r
-\r
-       /*string generatedHeaderFilename = PassThruCacheDirectory (\r
-               basename + ".h",\r
-               backend->intermediateDirectory );\r
-       CLEAN_FILE(generatedHeaderFilename);\r
-       */\r
-       string generatedHeaderFilename = basename + "_s.h";\r
-       CLEAN_FILE(generatedHeaderFilename);\r
-\r
-       string generatedServerFilename = PassThruCacheDirectory (\r
-               basename + "_s.c",\r
-               backend->intermediateDirectory );\r
-       CLEAN_FILE(generatedServerFilename);\r
-\r
-       fprintf ( fMakefile,\r
-                 "%s %s: %s $(WIDL_TARGET) | %s\n",\r
-                 generatedServerFilename.c_str (),\r
-                 generatedHeaderFilename.c_str (),\r
-                 sourceFilename.c_str (),\r
-                 GetDirectory ( generatedServerFilename ).c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t%s %s -h -H %s -s -S %s %s\n",\r
-                 "$(Q)$(WIDL_TARGET)",\r
-                 widlflagsMacro.c_str (),\r
-                 generatedHeaderFilename.c_str (),\r
-                 generatedServerFilename.c_str (),\r
-                 sourceFilename.c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateWidlCommandsClient (\r
-       const string& sourceFilename,\r
-       const string& widlflagsMacro )\r
-{\r
-       string basename = GetBasename ( sourceFilename );\r
-\r
-       /*string generatedHeaderFilename = PassThruCacheDirectory (\r
-               basename + ".h",\r
-               backend->intermediateDirectory );\r
-       CLEAN_FILE(generatedHeaderFilename);\r
-       */\r
-       string generatedHeaderFilename = basename + "_c.h";\r
-       CLEAN_FILE(generatedHeaderFilename);\r
-\r
-       string generatedClientFilename = PassThruCacheDirectory (\r
-               basename + "_c.c",\r
-               backend->intermediateDirectory );\r
-       CLEAN_FILE(generatedClientFilename);\r
-\r
-       fprintf ( fMakefile,\r
-                 "%s %s: %s $(WIDL_TARGET) | %s\n",\r
-                 generatedClientFilename.c_str (),\r
-                 generatedHeaderFilename.c_str (),\r
-                 sourceFilename.c_str (),\r
-                 GetDirectory ( generatedClientFilename ).c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t%s %s -h -H %s -c -C %s %s\n",\r
-                 "$(Q)$(WIDL_TARGET)",\r
-                 widlflagsMacro.c_str (),\r
-                 generatedHeaderFilename.c_str (),\r
-                 generatedClientFilename.c_str (),\r
-                 sourceFilename.c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateWidlCommands (\r
-       const string& sourceFilename,\r
-       const string& widlflagsMacro )\r
-{\r
-       if ( module.type == RpcServer )\r
-               GenerateWidlCommandsServer ( sourceFilename,\r
-                                            widlflagsMacro );\r
-       else\r
-               GenerateWidlCommandsClient ( sourceFilename,\r
-                                            widlflagsMacro );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateCommands (\r
-       const string& sourceFilename,\r
-       const string& cc,\r
-       const string& cppc,\r
-       const string& cflagsMacro,\r
-       const string& nasmflagsMacro,\r
-       const string& windresflagsMacro,\r
-       const string& widlflagsMacro )\r
-{\r
-       string extension = GetExtension ( sourceFilename );\r
-       if ( extension == ".c" || extension == ".C" )\r
-       {\r
-               GenerateGccCommand ( 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 ( sourceFilename,\r
-                                    cppc,\r
-                                    cflagsMacro );\r
-               return;\r
-       }\r
-       else if ( extension == ".s" || extension == ".S" )\r
-       {\r
-               GenerateGccAssemblerCommand ( sourceFilename,\r
-                                             cc,\r
-                                             cflagsMacro );\r
-               return;\r
-       }\r
-       else if ( extension == ".asm" || extension == ".ASM" )\r
-       {\r
-               GenerateNasmCommand ( sourceFilename,\r
-                                     nasmflagsMacro );\r
-               return;\r
-       }\r
-       else if ( extension == ".rc" || extension == ".RC" )\r
-       {\r
-               GenerateWindresCommand ( sourceFilename,\r
-                                        windresflagsMacro );\r
-               return;\r
-       }\r
-       else if ( extension == ".spec" || extension == ".SPEC" )\r
-       {\r
-               GenerateWinebuildCommands ( sourceFilename );\r
-               GenerateGccCommand ( GetActualSourceFilename ( sourceFilename ),\r
-                                    cc,\r
-                                    cflagsMacro );\r
-               return;\r
-       }\r
-       else if ( extension == ".idl" || extension == ".IDL" )\r
-       {\r
-               GenerateWidlCommands ( sourceFilename,\r
-                                      widlflagsMacro );\r
-               GenerateGccCommand ( GetActualSourceFilename ( sourceFilename ),\r
-                                    cc,\r
-                                    cflagsMacro );\r
-               return;\r
-       }\r
-\r
-       throw InvalidOperationException ( __FILE__,\r
-                                         __LINE__,\r
-                                         "Unsupported filename extension '%s' in file '%s'",\r
-                                         extension.c_str (),\r
-                                         sourceFilename.c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateBuildMapCode ()\r
-{\r
-       fprintf ( fMakefile,\r
-                 "ifeq ($(ROS_BUILDMAP),full)\n" );\r
-\r
-       string mapFilename = PassThruCacheDirectory (\r
-               GetBasename ( module.GetPath () ) + ".map",\r
-               backend->outputDirectory );\r
-       CLEAN_FILE ( mapFilename );\r
-       \r
-       fprintf ( fMakefile,\r
-                 "\t$(ECHO_OBJDUMP)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t$(Q)${objdump} -d -S $@ > %s\n",\r
-                 mapFilename.c_str () );\r
-\r
-       fprintf ( fMakefile,\r
-                 "else\n" );\r
-       fprintf ( fMakefile,\r
-                 "ifeq ($(ROS_BUILDMAP),yes)\n" );\r
-\r
-       fprintf ( fMakefile,\r
-                 "\t$(ECHO_NM)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t$(Q)${nm} --numeric-sort $@ > %s\n",\r
-                 mapFilename.c_str () );\r
-\r
-       fprintf ( fMakefile,\r
-                 "endif\n" );\r
-\r
-       fprintf ( fMakefile,\r
-                 "endif\n" );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateLinkerCommand (\r
-       const string& dependencies,\r
-       const string& linker,\r
-       const string& linkerParameters,\r
-       const string& objectsMacro,\r
-       const string& libsMacro )\r
-{\r
-       string target ( GetTargetMacro ( module ) );\r
-       string target_folder ( GetDirectory ( GetTargetFilename ( module, NULL ) ) );\r
-\r
-       fprintf ( fMakefile,\r
-               "%s: %s $(RSYM_TARGET) | %s\n",\r
-               target.c_str (),\r
-               dependencies.c_str (),\r
-               target_folder.c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_LD)\n" );\r
-       string targetName ( module.GetTargetName () );\r
-       if ( module.importLibrary != NULL )\r
-       {\r
-               string base_tmp = ros_temp + module.name + ".base.tmp";\r
-               CLEAN_FILE ( base_tmp );\r
-               string junk_tmp = ros_temp + module.name + ".junk.tmp";\r
-               CLEAN_FILE ( junk_tmp );\r
-               string temp_exp = ros_temp + module.name + ".temp.exp";\r
-               CLEAN_FILE ( temp_exp );\r
-               string def_file = GetDefinitionFilename ();\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
-                         objectsMacro.c_str (),\r
-                         libsMacro.c_str (),\r
-                         GetLinkerMacro ().c_str () );\r
-\r
-               fprintf ( fMakefile,\r
-                         "\t-@${rm} %s 2>$(NUL)\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
-                         def_file.c_str (),\r
-                         temp_exp.c_str (),\r
-                         killAt.c_str () );\r
-\r
-               fprintf ( fMakefile,\r
-                         "\t-@${rm} %s 2>$(NUL)\n",\r
-                         base_tmp.c_str () );\r
-\r
-               fprintf ( fMakefile,\r
-                         "\t%s %s %s -o %s %s %s %s\n",\r
-                         linker.c_str (),\r
-                         linkerParameters.c_str (),\r
-                         temp_exp.c_str (),\r
-                         target.c_str (),\r
-                         objectsMacro.c_str (),\r
-                         libsMacro.c_str (),\r
-                         GetLinkerMacro ().c_str () );\r
-\r
-               fprintf ( fMakefile,\r
-                         "\t-@${rm} %s 2>$(NUL)\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
-                         objectsMacro.c_str (),\r
-                         libsMacro.c_str (),\r
-                         GetLinkerMacro ().c_str () );\r
-       }\r
-\r
-       GenerateBuildMapCode ();\r
-\r
-       fprintf ( fMakefile,\r
-                 "\t$(ECHO_RSYM)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GeneratePhonyTarget() const\r
-{\r
-       string targetMacro ( GetTargetMacro(module) );\r
-       fprintf ( fMakefile, ".PHONY: %s\n\n",\r
-                 targetMacro.c_str ());\r
-       fprintf ( fMakefile, "%s: | %s\n",\r
-                 targetMacro.c_str (),\r
-                 GetDirectory(GetTargetFilename(module,NULL)).c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateObjectFileTargets (\r
-       const IfableData& data,\r
-       const string& cc,\r
-       const string& cppc,\r
-       const string& cflagsMacro,\r
-       const string& nasmflagsMacro,\r
-       const string& windresflagsMacro,\r
-       const string& widlflagsMacro )\r
-{\r
-       size_t i;\r
-       \r
-       const vector<File*>& files = data.files;\r
-       for ( i = 0; i < files.size (); i++ )\r
-       {\r
-               string sourceFilename = files[i]->name;\r
-               GenerateCommands ( sourceFilename,\r
-                                  cc,\r
-                                  cppc,\r
-                                  cflagsMacro,\r
-                                  nasmflagsMacro,\r
-                                  windresflagsMacro,\r
-                                  widlflagsMacro );\r
-               fprintf ( fMakefile,\r
-                         "\n" );\r
-       }\r
-\r
-       const vector<If*>& ifs = data.ifs;\r
-       for ( i = 0; i < ifs.size(); i++ )\r
-       {\r
-               GenerateObjectFileTargets ( ifs[i]->data,\r
-                                           cc,\r
-                                           cppc,\r
-                                           cflagsMacro,\r
-                                           nasmflagsMacro,\r
-                                           windresflagsMacro,\r
-                                           widlflagsMacro );\r
-       }\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateObjectFileTargets (\r
-       const string& cc,\r
-       const string& cppc,\r
-       const string& cflagsMacro,\r
-       const string& nasmflagsMacro,\r
-       const string& windresflagsMacro,\r
-       const string& widlflagsMacro )\r
-{\r
-       if ( module.pch )\r
-       {\r
-               const string& pch_file = module.pch->header;\r
-               string gch_file = pch_file + ".gch";\r
-               CLEAN_FILE(gch_file);\r
-               if ( use_pch )\r
-               {\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "%s: %s\n",\r
-                               gch_file.c_str(),\r
-                               pch_file.c_str() );\r
-                       fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "\t%s -o %s %s -g %s\n\n",\r
-                               ( module.cplusplus ? cppc.c_str() : cc.c_str() ),\r
-                               gch_file.c_str(),\r
-                               cflagsMacro.c_str(),\r
-                               pch_file.c_str() );\r
-               }\r
-       }\r
-\r
-       GenerateObjectFileTargets ( module.non_if_data,\r
-                                   cc,\r
-                                   cppc,\r
-                                   cflagsMacro,\r
-                                   nasmflagsMacro,\r
-                                   windresflagsMacro,\r
-                                   widlflagsMacro );\r
-       fprintf ( fMakefile, "\n" );\r
-}\r
-\r
-string\r
-MingwModuleHandler::GenerateArchiveTarget ( const string& ar,\r
-                                            const string& objs_macro ) const\r
-{\r
-       string archiveFilename ( GetModuleArchiveFilename () );\r
-       \r
-       fprintf ( fMakefile,\r
-                 "%s: %s | %s\n",\r
-                 archiveFilename.c_str (),\r
-                 objs_macro.c_str (),\r
-                 GetDirectory(archiveFilename).c_str() );\r
-\r
-       fprintf ( fMakefile, "\t$(ECHO_AR)\n" );\r
-\r
-       fprintf ( fMakefile,\r
-                 "\t%s -rc $@ %s\n\n",\r
-                 ar.c_str (),\r
-                 objs_macro.c_str ());\r
-\r
-       return archiveFilename;\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetCFlagsMacro () const\r
-{\r
-       return ssprintf ( "$(%s_CFLAGS)",\r
-                         module.name.c_str () );\r
-}\r
-\r
-/*static*/ string\r
-MingwModuleHandler::GetObjectsMacro ( const Module& module )\r
-{\r
-       return ssprintf ( "$(%s_OBJS)",\r
-                         module.name.c_str () );\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetLinkingDependenciesMacro () const\r
-{\r
-       return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetLibsMacro () const\r
-{\r
-       return ssprintf ( "$(%s_LIBS)", module.name.c_str () );\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetLinkerMacro () const\r
-{\r
-       return ssprintf ( "$(%s_LFLAGS)",\r
-                         module.name.c_str () );\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetModuleTargets ( const Module& module )\r
-{\r
-       if ( ReferenceObjects ( module ) )\r
-               return GetObjectsMacro ( module );\r
-       else\r
-               return GetTargetFilename ( module, NULL );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateObjectMacro ()\r
-{\r
-       objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());\r
-\r
-       GenerateObjectMacros (\r
-               "=",\r
-               module.non_if_data,\r
-               &module.compilerFlags,\r
-               &module.linkerFlags );\r
-\r
-       // future references to the macro will be to get its values\r
-       objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateTargetMacro ()\r
-{\r
-       fprintf ( fMakefile,\r
-               "%s := %s\n",\r
-               GetTargetMacro ( module, false ).c_str (),\r
-               GetModuleTargets ( module ).c_str () );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateOtherMacros ()\r
-{\r
-       cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());\r
-       nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());\r
-       windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());\r
-       widlflagsMacro = ssprintf ("%s_WIDLFLAGS", module.name.c_str ());\r
-       linkerflagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());\r
-       libsMacro = ssprintf("%s_LIBS", module.name.c_str ());\r
-       linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());\r
-\r
-       GenerateMacros (\r
-               "=",\r
-               module.non_if_data,\r
-               &module.compilerFlags,\r
-               &module.linkerFlags );\r
-\r
-       if ( module.importLibrary )\r
-       {\r
-               string_list s;\r
-               const vector<File*>& files = module.non_if_data.files;\r
-               for ( size_t i = 0; i < files.size (); i++ )\r
-               {\r
-                       File& file = *files[i];\r
-                       string extension = GetExtension ( file.name );\r
-                       if ( extension == ".spec" || extension == ".SPEC" )\r
-                               GetSpecObjectDependencies ( s, file.name );\r
-               }\r
-               if ( s.size () > 0 )\r
-               {\r
-                       fprintf (\r
-                               fMakefile,\r
-                               "%s +=",\r
-                               linkDepsMacro.c_str() );\r
-                       for ( size_t i = 0; i < s.size(); i++ )\r
-                               fprintf ( fMakefile,\r
-                                         " %s",\r
-                                         s[i].c_str () );\r
-                       fprintf ( fMakefile, "\n" );\r
-               }\r
-       }\r
-\r
-       string globalCflags = "-g";\r
-       if ( backend->usePipe )\r
-               globalCflags += " -pipe";\r
-       \r
-       fprintf (\r
-               fMakefile,\r
-               "%s += $(PROJECT_CFLAGS) %s\n",\r
-               cflagsMacro.c_str (),\r
-               globalCflags.c_str () );\r
-\r
-       fprintf (\r
-               fMakefile,\r
-               "%s += $(PROJECT_RCFLAGS)\n",\r
-               windresflagsMacro.c_str () );\r
-\r
-       fprintf (\r
-               fMakefile,\r
-               "%s += $(PROJECT_WIDLFLAGS)\n",\r
-               widlflagsMacro.c_str () );\r
-\r
-       fprintf (\r
-               fMakefile,\r
-               "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",\r
-               module.name.c_str () );\r
-\r
-       fprintf (\r
-               fMakefile,\r
-               "%s += $(%s)\n",\r
-               linkDepsMacro.c_str (),\r
-               libsMacro.c_str () );\r
-\r
-       string cflags = TypeSpecificCFlags();\r
-       if ( cflags.size() > 0 )\r
-       {\r
-               fprintf ( fMakefile,\r
-                         "%s += %s\n\n",\r
-                         cflagsMacro.c_str (),\r
-                         cflags.c_str () );\r
-       }\r
-\r
-       string nasmflags = TypeSpecificNasmFlags();\r
-       if ( nasmflags.size () > 0 )\r
-       {\r
-               fprintf ( fMakefile,\r
-                         "%s += %s\n\n",\r
-                         nasmflagsMacro.c_str (),\r
-                         nasmflags.c_str () );\r
-       }\r
-\r
-       fprintf ( fMakefile, "\n\n" );\r
-\r
-       // future references to the macros will be to get their values\r
-       cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());\r
-       nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());\r
-       widlflagsMacro = ssprintf ("$(%s)", widlflagsMacro.c_str ());\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateRules ()\r
-{\r
-       string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );\r
-       string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );\r
-       string ar = ( module.host == HostTrue ? "${host_ar}" : "${ar}" );\r
-\r
-       string targetMacro = GetTargetMacro ( module );\r
-\r
-       CLEAN_FILE ( targetMacro );\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
-               GetTargetMacro ( module ).c_str () );\r
-\r
-       if ( !ReferenceObjects ( module ) )\r
-       {\r
-               string ar_target ( GenerateArchiveTarget ( ar, objectsMacro ) );\r
-               if ( targetMacro != ar_target )\r
-               {\r
-                       CLEAN_FILE ( ar_target );\r
-               }\r
-       }\r
-\r
-       GenerateObjectFileTargets ( cc,\r
-                                                               cppc,\r
-                                                               cflagsMacro,\r
-                                                               nasmflagsMacro,\r
-                                                               windresflagsMacro,\r
-                                                           widlflagsMacro );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetInvocationDependencies (\r
-       const Module& module,\r
-       string_list& dependencies )\r
-{\r
-       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
-               invoke.GetTargets ( dependencies );\r
-       }\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateInvocations () const\r
-{\r
-       if ( module.invocations.size () == 0 )\r
-               return;\r
-       \r
-       size_t iend = module.invocations.size ();\r
-       for ( size_t i = 0; i < iend; i++ )\r
-       {\r
-               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
-               }\r
-\r
-               string invokeTarget = module.GetInvocationTarget ( i );\r
-               string_list invoke_targets;\r
-               assert ( invoke_targets.size() );\r
-               invoke.GetTargets ( invoke_targets );\r
-               fprintf ( fMakefile,\r
-                         ".PHONY: %s\n\n",\r
-                         invokeTarget.c_str () );\r
-               fprintf ( fMakefile,\r
-                         "%s:",\r
-                         invokeTarget.c_str () );\r
-               size_t j, jend = invoke_targets.size();\r
-               for ( j = 0; j < jend; j++ )\r
-               {\r
-                       fprintf ( fMakefile,\r
-                                 " %s",\r
-                                 invoke_targets[i].c_str () );\r
-               }\r
-               fprintf ( fMakefile, "\n\n%s", invoke_targets[0].c_str () );\r
-               for ( j = 1; j < jend; j++ )\r
-                       fprintf ( fMakefile,\r
-                                 " %s",\r
-                                 invoke_targets[i].c_str () );\r
-               fprintf ( fMakefile,\r
-                         ": %s\n",\r
-                         NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str () );\r
-               fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );\r
-               fprintf ( fMakefile,\r
-                         "\t%s %s\n\n",\r
-                         NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str (),\r
-                         invoke.GetParameters ().c_str () );\r
-       }\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetPreconditionDependenciesName () const\r
-{\r
-       return module.name + "_precondition";\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetDefaultDependencies (\r
-       string_list& dependencies ) const\r
-{\r
-       /* Avoid circular dependency */\r
-       if ( module.type != BuildTool\r
-               && module.name != "zlib"\r
-               && module.name != "hostzlib" )\r
-\r
-               dependencies.push_back ( "$(INIT)" );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GeneratePreconditionDependencies ()\r
-{\r
-       string preconditionDependenciesName = GetPreconditionDependenciesName ();\r
-       string_list sourceFilenames;\r
-       GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );\r
-       string_list dependencies;\r
-       GetDefaultDependencies ( dependencies );\r
-       GetModuleDependencies ( dependencies );\r
-\r
-       GetInvocationDependencies ( module, dependencies );\r
-       \r
-       if ( dependencies.size() )\r
-       {\r
-               fprintf ( fMakefile,\r
-                         "%s =",\r
-                         preconditionDependenciesName.c_str () );\r
-               for ( size_t i = 0; i < dependencies.size(); i++ )\r
-                       fprintf ( fMakefile,\r
-                                 " %s",\r
-                                 dependencies[i].c_str () );\r
-               fprintf ( fMakefile, "\n\n" );\r
-       }\r
-\r
-       for ( size_t i = 0; i < sourceFilenames.size(); i++ )\r
-       {\r
-               fprintf ( fMakefile,\r
-                         "%s: ${%s}\n",\r
-                         sourceFilenames[i].c_str(),\r
-                         preconditionDependenciesName.c_str ());\r
-       }\r
-       fprintf ( fMakefile, "\n" );\r
-}\r
-\r
-bool\r
-MingwModuleHandler::IsWineModule () const\r
-{\r
-       if ( module.importLibrary == NULL)\r
-               return false;\r
-\r
-       size_t index = module.importLibrary->definition.rfind ( ".spec.def" );\r
-       return ( index != string::npos );\r
-}\r
-\r
-string\r
-MingwModuleHandler::GetDefinitionFilename () const\r
-{\r
-       string defFilename = module.GetBasePath () + SSEP + module.importLibrary->definition;\r
-       if ( IsWineModule () )\r
-               return PassThruCacheDirectory ( NormalizeFilename ( defFilename ),\r
-                                               backend->intermediateDirectory );\r
-       else\r
-               return defFilename;\r
-}\r
-\r
-void\r
-MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()\r
-{\r
-       if ( module.importLibrary != NULL )\r
-       {\r
-               string library_target (\r
-                       GetImportLibraryFilename ( module, &clean_files ) );\r
-\r
-               string_list deps;\r
-               GetDefinitionDependencies ( deps );\r
-\r
-               fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );\r
-\r
-               fprintf ( fMakefile, "%s:",\r
-                         library_target.c_str () );\r
-\r
-               size_t i, iend = deps.size();\r
-               for ( i = 0; i < iend; i++ )\r
-                       fprintf ( fMakefile, " %s",\r
-                                 deps[i].c_str () );\r
-\r
-               fprintf ( fMakefile, " | %s\n",\r
-                         GetDirectory ( GetTargetFilename ( module, NULL ) ).c_str () );\r
-\r
-               fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );\r
-\r
-               string killAt = module.mangledSymbols ? "" : "--kill-at";\r
-               fprintf ( fMakefile,\r
-                         "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",\r
-                         module.GetTargetName ().c_str (),\r
-                         GetDefinitionFilename ().c_str (),\r
-                         library_target.c_str (),\r
-                         killAt.c_str () );\r
-       }\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetSpecObjectDependencies (\r
-       string_list& dependencies,\r
-       const string& filename ) const\r
-{\r
-       string basename = GetBasename ( filename );\r
-       string defDependency = PassThruCacheDirectory (\r
-               NormalizeFilename ( basename + ".spec.def" ),\r
-               backend->intermediateDirectory );\r
-       dependencies.push_back ( defDependency );\r
-       string stubsDependency = PassThruCacheDirectory (\r
-               NormalizeFilename ( basename + ".stubs.c" ),\r
-               backend->intermediateDirectory );\r
-       dependencies.push_back ( stubsDependency );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetWidlObjectDependencies (\r
-       string_list& dependencies,\r
-       const string& filename ) const\r
-{\r
-       string basename = GetBasename ( filename );\r
-       string serverDependency = PassThruCacheDirectory (\r
-               NormalizeFilename ( basename + "_s.c" ),\r
-               backend->intermediateDirectory );\r
-       dependencies.push_back ( serverDependency );\r
-}\r
-\r
-void\r
-MingwModuleHandler::GetDefinitionDependencies (\r
-       string_list& dependencies ) const\r
-{\r
-       string dkNkmLibNoFixup = "dk/nkm/lib";\r
-       const vector<File*>& files = module.non_if_data.files;\r
-       for ( size_t i = 0; i < files.size (); i++ )\r
-       {\r
-               File& file = *files[i];\r
-               string extension = GetExtension ( file.name );\r
-               if ( extension == ".spec" || extension == ".SPEC" )\r
-               {\r
-                       GetSpecObjectDependencies ( dependencies, file.name );\r
-               }\r
-               if ( extension == ".idl" || extension == ".IDL" )\r
-               {\r
-                       GetWidlObjectDependencies ( dependencies, file.name );\r
-               }\r
-       }\r
-}\r
-\r
-\r
-MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwBuildToolModuleHandler::Process ()\r
-{\r
-       GenerateBuildToolModuleTarget ();\r
-}\r
-\r
-void\r
-MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()\r
-{\r
-       string targetMacro ( GetTargetMacro (module) );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-\r
-       GenerateRules ();\r
-\r
-       string linker;\r
-       if ( module.cplusplus )\r
-               linker = "${host_gpp}";\r
-       else\r
-               linker = "${host_gcc}";\r
-       \r
-       fprintf ( fMakefile, "%s: %s %s | %s\n",\r
-                 targetMacro.c_str (),\r
-                 objectsMacro.c_str (),\r
-                 linkDepsMacro.c_str (),\r
-                 GetDirectory(GetTargetFilename(module,NULL)).c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_LD)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t%s %s -o $@ %s %s\n\n",\r
-                 linker.c_str (),\r
-                 GetLinkerMacro ().c_str (),\r
-                 objectsMacro.c_str (),\r
-                 libsMacro.c_str () );\r
-}\r
-\r
-\r
-MingwKernelModuleHandler::MingwKernelModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwKernelModuleHandler::Process ()\r
-{\r
-       GenerateKernelModuleTarget ();\r
-}\r
-\r
-void\r
-MingwKernelModuleHandler::GenerateKernelModuleTarget ()\r
-{\r
-       string targetName ( module.GetTargetName () ); // i.e. "ntoskrnl.exe"\r
-       string targetMacro ( GetTargetMacro ( module ) ); // i.e. "$(NTOSKRNL_TARGET)"\r
-       string workingDirectory = GetWorkingDirectory ();\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-       string base_tmp = ros_temp + module.name + ".base.tmp";\r
-       CLEAN_FILE ( base_tmp );\r
-       string junk_tmp = ros_temp + module.name + ".junk.tmp";\r
-       CLEAN_FILE ( junk_tmp );\r
-       string temp_exp = ros_temp + module.name + ".temp.exp";\r
-       CLEAN_FILE ( temp_exp );\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
-       GenerateRules ();\r
-\r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       fprintf ( fMakefile, "%s: %s %s $(RSYM_TARGET) | %s\n",\r
-                 targetMacro.c_str (),\r
-                 objectsMacro.c_str (),\r
-                 linkDepsMacro.c_str (),\r
-                 GetDirectory(GetTargetFilename(module,NULL)).c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_LD)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",\r
-                 GetLinkerMacro ().c_str (),\r
-                 gccOptions.c_str (),\r
-                 base_tmp.c_str (),\r
-                 junk_tmp.c_str (),\r
-                 objectsMacro.c_str (),\r
-                 linkDepsMacro.c_str () );\r
-       fprintf ( fMakefile,\r
-                 "\t-@${rm} %s 2>$(NUL)\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 %s\n",\r
-                 targetName.c_str (),\r
-                 base_tmp.c_str (),\r
-                 temp_exp.c_str (),\r
-                 killAt.c_str () );\r
-       fprintf ( fMakefile,\r
-                 "\t-@${rm} %s 2>$(NUL)\n",\r
-                 base_tmp.c_str () );\r
-       fprintf ( fMakefile,\r
-                 "\t${gcc} %s %s -Wl,%s -o $@ %s %s\n",\r
-                 GetLinkerMacro ().c_str (),\r
-                 gccOptions.c_str (),\r
-                 temp_exp.c_str (),\r
-                 objectsMacro.c_str (),\r
-                 linkDepsMacro.c_str () );\r
-       fprintf ( fMakefile,\r
-                 "\t-@${rm} %s 2>$(NUL)\n",\r
-                 temp_exp.c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_RSYM)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );\r
-}\r
-\r
-\r
-MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwStaticLibraryModuleHandler::Process ()\r
-{\r
-       GenerateStaticLibraryModuleTarget ();\r
-}\r
-\r
-void\r
-MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()\r
-{\r
-       GenerateRules ();\r
-}\r
-\r
-\r
-MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwObjectLibraryModuleHandler::Process ()\r
-{\r
-       GenerateObjectLibraryModuleTarget ();\r
-}\r
-\r
-void\r
-MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()\r
-{\r
-       GenerateRules ();\r
-}\r
-\r
-\r
-MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwKernelModeDLLModuleHandler::Process ()\r
-{\r
-       GenerateKernelModeDLLModuleTarget ();\r
-}\r
-\r
-void\r
-MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()\r
-{\r
-       string targetMacro ( GetTargetMacro ( module ) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-\r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       if ( module.non_if_data.files.size () > 0 )\r
-       {\r
-               GenerateRules ();\r
-\r
-               string dependencies =\r
-                       objectsMacro + " " + linkDepsMacro;\r
-\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 ( dependencies,\r
-                                       "${gcc}",\r
-                                       linkerParameters,\r
-                                       objectsMacro,\r
-                                       libsMacro );\r
-       }\r
-       else\r
-       {\r
-               GeneratePhonyTarget();\r
-       }\r
-}\r
-\r
-\r
-MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwKernelModeDriverModuleHandler::Process ()\r
-{\r
-       GenerateKernelModeDriverModuleTarget ();\r
-}\r
-\r
-\r
-void\r
-MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()\r
-{\r
-       string targetMacro ( GetTargetMacro (module) );\r
-       string workingDirectory = GetWorkingDirectory ();\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-\r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       if ( module.non_if_data.files.size () > 0 )\r
-       {\r
-               GenerateRules ();\r
-\r
-               string dependencies = objectsMacro + " " + linkDepsMacro;\r
-\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 ( dependencies,\r
-                                       "${gcc}",\r
-                                       linkerParameters,\r
-                                       objectsMacro,\r
-                                       libsMacro );\r
-       }\r
-       else\r
-       {\r
-               GeneratePhonyTarget();\r
-       }\r
-}\r
-\r
-\r
-MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwNativeDLLModuleHandler::Process ()\r
-{\r
-       GenerateNativeDLLModuleTarget ();\r
-}\r
-\r
-void\r
-MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()\r
-{\r
-       string targetMacro ( GetTargetMacro (module) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-       \r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       if ( module.non_if_data.files.size () > 0 )\r
-       {\r
-               GenerateRules ();\r
-\r
-               string dependencies =\r
-                       objectsMacro + " " + linkDepsMacro;\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 -mdll",\r
-                                                    module.entrypoint.c_str (),\r
-                                                    module.baseaddress.c_str () );\r
-               GenerateLinkerCommand ( dependencies,\r
-                                       "${gcc}",\r
-                                       linkerParameters,\r
-                                       objectsMacro,\r
-                                       libsMacro );\r
-       }\r
-       else\r
-       {\r
-               GeneratePhonyTarget();\r
-       }\r
-}\r
-\r
-\r
-MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwNativeCUIModuleHandler::Process ()\r
-{\r
-       GenerateNativeCUIModuleTarget ();\r
-}\r
-\r
-void\r
-MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()\r
-{\r
-       string targetMacro ( GetTargetMacro (module) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-       \r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       if ( module.non_if_data.files.size () > 0 )\r
-       {\r
-               GenerateRules ();\r
-\r
-               string dependencies =\r
-                       objectsMacro + " " + linkDepsMacro;\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 ( dependencies,\r
-                                       "${gcc}",\r
-                                       linkerParameters,\r
-                                       objectsMacro,\r
-                                       libsMacro );\r
-       }\r
-       else\r
-       {\r
-               GeneratePhonyTarget();\r
-       }\r
-}\r
-\r
-\r
-MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwWin32DLLModuleHandler::Process ()\r
-{\r
-       GenerateExtractWineDLLResourcesTarget ();\r
-       GenerateWin32DLLModuleTarget ();\r
-}\r
-\r
-void\r
-MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()\r
-{\r
-       fprintf ( fMakefile, ".PHONY: %s_extractresources\n\n",\r
-                 module.name.c_str () );\r
-       fprintf ( fMakefile, "%s_extractresources: $(BIN2RES_TARGET)\n",\r
-                 module.name.c_str () );\r
-       const vector<File*>& files = module.non_if_data.files;\r
-       for ( size_t i = 0; i < files.size (); i++ )\r
-       {\r
-               File& file = *files[i];\r
-               string extension = GetExtension ( file.name );\r
-               if ( extension == ".rc" || extension == ".RC" )\r
-               {\r
-                       string resource = NormalizeFilename ( file.name );\r
-                       fprintf ( fMakefile, "\t$(ECHO_BIN2RES)\n" );\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 ()\r
-{\r
-       string targetMacro ( GetTargetMacro (module) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-\r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       if ( module.non_if_data.files.size () > 0 )\r
-       {\r
-               GenerateRules ();\r
-\r
-               string dependencies = objectsMacro + " " + linkDepsMacro;\r
-\r
-               string linker;\r
-               if ( module.cplusplus )\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 ( dependencies,\r
-                                       linker,\r
-                                       linkerParameters,\r
-                                       objectsMacro,\r
-                                       libsMacro );\r
-       }\r
-       else\r
-       {\r
-               GeneratePhonyTarget();\r
-       }\r
-}\r
-\r
-\r
-MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwWin32CUIModuleHandler::Process ()\r
-{\r
-       GenerateWin32CUIModuleTarget ();\r
-}\r
-\r
-void\r
-MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()\r
-{\r
-       string targetMacro ( GetTargetMacro (module) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-\r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       if ( module.non_if_data.files.size () > 0 )\r
-       {\r
-               GenerateRules ();\r
-\r
-               string dependencies =\r
-                       objectsMacro + " " + linkDepsMacro;\r
-\r
-               string linker;\r
-               if ( module.cplusplus )\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 ( dependencies,\r
-                                       linker,\r
-                                       linkerParameters,\r
-                                       objectsMacro,\r
-                                       libsMacro );\r
-       }\r
-       else\r
-       {\r
-               GeneratePhonyTarget();\r
-       }\r
-}\r
-\r
-\r
-MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwWin32GUIModuleHandler::Process ()\r
-{\r
-       GenerateWin32GUIModuleTarget ();\r
-}\r
-\r
-void\r
-MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()\r
-{\r
-       string targetMacro ( GetTargetMacro (module) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-\r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       if ( module.non_if_data.files.size () > 0 )\r
-       {\r
-               GenerateRules ();\r
-\r
-               string dependencies =\r
-                       objectsMacro + " " + linkDepsMacro;\r
-\r
-               string linker;\r
-               if ( module.cplusplus )\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 ( dependencies,\r
-                                       linker,\r
-                                       linkerParameters,\r
-                                       objectsMacro,\r
-                                       libsMacro );\r
-       }\r
-       else\r
-       {\r
-               GeneratePhonyTarget();\r
-       }\r
-}\r
-\r
-\r
-MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwBootLoaderModuleHandler::Process ()\r
-{\r
-       GenerateBootLoaderModuleTarget ();\r
-}\r
-\r
-void\r
-MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()\r
-{\r
-       string targetName ( module.GetTargetName () );\r
-       string targetMacro ( GetTargetMacro (module) );\r
-       string workingDirectory = GetWorkingDirectory ();\r
-       string junk_tmp = ros_temp + module.name + ".junk.tmp";\r
-       CLEAN_FILE ( junk_tmp );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-\r
-       GenerateRules ();\r
-\r
-       fprintf ( fMakefile, "%s: %s %s | %s\n",\r
-                 targetMacro.c_str (),\r
-                 objectsMacro.c_str (),\r
-                 linkDepsMacro.c_str (),\r
-                 GetDirectory(GetTargetFilename(module,NULL)).c_str () );\r
-\r
-       fprintf ( fMakefile, "\t$(ECHO_LD)\n" );\r
-\r
-       fprintf ( fMakefile,\r
-                 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",\r
-                 GetLinkerMacro ().c_str (),\r
-                 junk_tmp.c_str (),\r
-                 objectsMacro.c_str (),\r
-                 linkDepsMacro.c_str () );\r
-       fprintf ( fMakefile,\r
-                 "\t${objcopy} -O binary %s $@\n",\r
-                 junk_tmp.c_str () );\r
-       fprintf ( fMakefile,\r
-                 "\t-@${rm} %s 2>$(NUL)\n",\r
-                 junk_tmp.c_str () );\r
-}\r
-\r
-\r
-MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwBootSectorModuleHandler::Process ()\r
-{\r
-       GenerateBootSectorModuleTarget ();\r
-}\r
-\r
-void\r
-MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()\r
-{\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-\r
-       GenerateRules ();\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
-MingwIsoModuleHandler::MingwIsoModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwIsoModuleHandler::Process ()\r
-{\r
-       GenerateIsoModuleTarget ();\r
-}\r
-\r
-void\r
-MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (\r
-       const string& bootcdDirectory )\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 sourceFilename = PassThruCacheDirectory (\r
-                               NormalizeFilename ( m.GetPath () ),\r
-                               backend->outputDirectory );\r
-                       string targetFilenameNoFixup ( bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd );\r
-                       string targetFilename = MingwModuleHandler::PassThruCacheDirectory (\r
-                               NormalizeFilename ( targetFilenameNoFixup ),\r
-                               backend->outputDirectory );\r
-                       fprintf ( fMakefile,\r
-                                 "\t$(ECHO_CP)\n" );\r
-                       fprintf ( fMakefile,\r
-                                 "\t${cp} %s %s 1>$(NUL)\n",\r
-                                 sourceFilename.c_str (),\r
-                                 targetFilename.c_str () );\r
-               }\r
-       }\r
-}\r
-\r
-void\r
-MingwIsoModuleHandler::OutputCdfileCopyCommands (\r
-       const string& bootcdDirectory )\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 = MingwModuleHandler::PassThruCacheDirectory (\r
-                       NormalizeFilename ( targetFilenameNoFixup ),\r
-                       backend->outputDirectory );\r
-               fprintf ( fMakefile,\r
-                         "\t$(ECHO_CP)\n" );\r
-               fprintf ( fMakefile,\r
-                         "\t${cp} %s %s 1>$(NUL)\n",\r
-                         cdfile.GetPath ().c_str (),\r
-                         targetFilename.c_str () );\r
-       }\r
-}\r
-\r
-string\r
-MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory )\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 targetDirectory ( bootcdDirectory + SSEP + m.bootstrap->base );\r
-                       if ( directories.size () > 0 )\r
-                               directories += " ";\r
-                       directories += PassThruCacheDirectory (\r
-                               NormalizeFilename ( targetDirectory ),\r
-                               backend->outputDirectory );\r
-               }\r
-       }\r
-       return directories;\r
-}\r
-\r
-string\r
-MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory )\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 targetDirectory ( bootcdDirectory + SSEP + cdfile.base );\r
-               if ( directories.size () > 0 )\r
-                       directories += " ";\r
-               directories += PassThruCacheDirectory (\r
-                       NormalizeFilename ( targetDirectory ),\r
-                       backend->outputDirectory );\r
-       }\r
-       return directories;\r
-}\r
-\r
-string\r
-MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory )\r
-{\r
-       string directories = GetBootstrapCdDirectories ( bootcdDirectory );\r
-       directories += " " + GetNonModuleCdDirectories ( bootcdDirectory );\r
-       return directories;\r
-}\r
-\r
-void\r
-MingwIsoModuleHandler::GetBootstrapCdFiles (\r
-       vector<string>& out ) 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 filename = PassThruCacheDirectory (\r
-                               NormalizeFilename ( m.GetPath () ),\r
-                               backend->outputDirectory );\r
-                       out.push_back ( filename );\r
-               }\r
-       }\r
-}\r
-\r
-void\r
-MingwIsoModuleHandler::GetNonModuleCdFiles (\r
-       vector<string>& out ) const\r
-{\r
-       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
-       {\r
-               const CDFile& cdfile = *module.project.cdfiles[i];\r
-               out.push_back ( cdfile.GetPath () );\r
-       }\r
-}\r
-\r
-void\r
-MingwIsoModuleHandler::GetCdFiles (\r
-       vector<string>& out ) const\r
-{\r
-       GetBootstrapCdFiles ( out );\r
-       GetNonModuleCdFiles ( out );\r
-}\r
-\r
-void\r
-MingwIsoModuleHandler::GenerateIsoModuleTarget ()\r
-{\r
-       string bootcdDirectory = "cd";\r
-       string bootcd = PassThruCacheDirectory (\r
-               NormalizeFilename ( bootcdDirectory + SSEP ),\r
-               backend->outputDirectory );\r
-       string isoboot = PassThruCacheDirectory (\r
-               NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),\r
-               backend->outputDirectory );\r
-       string bootcdReactosNoFixup = bootcdDirectory + SSEP "reactos";\r
-       string bootcdReactos = PassThruCacheDirectory (\r
-               NormalizeFilename ( bootcdReactosNoFixup ),\r
-               backend->outputDirectory );\r
-       CLEAN_FILE ( bootcdReactos );\r
-       string reactosInf = PassThruCacheDirectory (\r
-               NormalizeFilename ( bootcdReactosNoFixup + SSEP "reactos.inf" ),\r
-               backend->outputDirectory );\r
-       string reactosDff = NormalizeFilename ( "bootdata" SSEP "packages" SSEP "reactos.dff" );\r
-       string cdDirectories = GetCdDirectories ( bootcdDirectory );\r
-       vector<string> vCdFiles;\r
-       GetCdFiles ( vCdFiles );\r
-       string cdFiles = v2s ( vCdFiles, 5 );\r
-\r
-       fprintf ( fMakefile, ".PHONY: %s\n\n",\r
-                 module.name.c_str ());\r
-       fprintf ( fMakefile,\r
-                 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",\r
-                 module.name.c_str (),\r
-                 isoboot.c_str (),\r
-                 bootcdReactos.c_str (),\r
-                 cdDirectories.c_str (),\r
-                 cdFiles.c_str () );\r
-       fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",\r
-                 reactosDff.c_str (),\r
-                 bootcdReactos.c_str () );\r
-       fprintf ( fMakefile,\r
-                 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",\r
-                 reactosDff.c_str (),\r
-                 reactosInf.c_str (),\r
-                 bootcdReactos.c_str ());\r
-       fprintf ( fMakefile,\r
-                 "\t-@${rm} %s 2>$(NUL)\n",\r
-                 reactosInf.c_str () );\r
-       OutputBootstrapfileCopyCommands ( bootcdDirectory );\r
-       OutputCdfileCopyCommands ( bootcdDirectory );\r
-       fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );\r
-       fprintf ( fMakefile,\r
-                 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",\r
-                 isoboot.c_str (),\r
-                 bootcd.c_str () );\r
-       fprintf ( fMakefile,\r
-                 "\n" );\r
-}\r
-\r
-\r
-MingwTestModuleHandler::MingwTestModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwTestModuleHandler::Process ()\r
-{\r
-       GenerateTestModuleTarget ();\r
-}\r
-\r
-void\r
-MingwTestModuleHandler::GenerateTestModuleTarget ()\r
-{\r
-       string targetMacro ( GetTargetMacro ( module ) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string objectsMacro = GetObjectsMacro ( module );\r
-       string linkDepsMacro = GetLinkingDependenciesMacro ();\r
-       string libsMacro = GetLibsMacro ();\r
-\r
-       GenerateImportLibraryTargetIfNeeded ();\r
-\r
-       if ( module.non_if_data.files.size () > 0 )\r
-       {\r
-               GenerateRules ();\r
-\r
-               string dependencies = objectsMacro + " " + linkDepsMacro;\r
-\r
-               string linker;\r
-               if ( module.cplusplus )\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 ( dependencies,\r
-                                       linker,\r
-                                       linkerParameters,\r
-                                       objectsMacro,\r
-                                       libsMacro );\r
-       }\r
-       else\r
-       {\r
-               GeneratePhonyTarget();\r
-       }\r
-}\r
-\r
-\r
-MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwRpcServerModuleHandler::Process ()\r
-{\r
-       GenerateRules ();\r
-}\r
-\r
-MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (\r
-       const Module& module_ )\r
-\r
-       : MingwModuleHandler ( module_ )\r
-{\r
-}\r
-\r
-void\r
-MingwRpcClientModuleHandler::Process ()\r
-{\r
-       GenerateRules ();\r
-}\r
+/*
+ * Copyright (C) 2005 Casper S. Hornstrup
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include "../../pch.h"
+#include <assert.h>
+
+#include "../../rbuild.h"
+#include "mingw.h"
+#include "modulehandler.h"
+
+using std::string;
+using std::vector;
+
+#define CLEAN_FILE(f) clean_files.push_back ( f );
+
+static string ros_temp = "$(TEMPORARY)";
+MingwBackend*
+MingwModuleHandler::backend = NULL;
+FILE*
+MingwModuleHandler::fMakefile = NULL;
+bool
+MingwModuleHandler::use_pch = false;
+
+string
+PrefixFilename (
+       const string& filename,
+       const string& prefix )
+{
+       if ( !prefix.length() )
+               return filename;
+       string out;
+       const char* pfilename = filename.c_str();
+       const char* p1 = strrchr ( pfilename, '/' );
+       const char* p2 = strrchr ( pfilename, '\\' );
+       if ( p1 || p2 )
+       {
+               if ( p2 > p1 )
+                       p1 = p2;
+               out += string(pfilename,p1-pfilename) + CSEP;
+               pfilename = p1 + 1;
+       }
+       out += prefix + pfilename;
+       return out;
+}
+
+string
+GetTargetMacro ( const Module& module, bool with_dollar )
+{
+       string s ( module.name );
+       strupr ( &s[0] );
+       s += "_TARGET";
+       if ( with_dollar )
+               return ssprintf ( "$(%s)", s.c_str() );
+       return s;
+}
+
+MingwModuleHandler::MingwModuleHandler (
+       const Module& module_ )
+
+       : module(module_)
+{
+}
+
+MingwModuleHandler::~MingwModuleHandler()
+{
+}
+
+/*static*/ void
+MingwModuleHandler::SetBackend ( MingwBackend* backend_ )
+{
+       backend = backend_;
+}
+
+/*static*/ void
+MingwModuleHandler::SetMakefile ( FILE* f )
+{
+       fMakefile = f;
+}
+
+/*static*/ void
+MingwModuleHandler::SetUsePch ( bool b )
+{
+       use_pch = b;
+}
+
+/* static*/ string
+MingwModuleHandler::RemoveVariables ( string path)
+{
+       size_t i = path.find ( '$' );
+       if ( i != string::npos )
+       {
+               size_t j = path.find ( ')', i );
+               if ( j != string::npos )
+               {
+                       if ( j + 2 < path.length () && path[j + 1] == CSEP )
+                               return path.substr ( j + 2);
+                       else
+                               return path.substr ( j + 1);
+               }
+       }
+       return path;
+}
+
+/*static*/ string
+MingwModuleHandler::PassThruCacheDirectory (
+       const string &file,
+       Directory* directoryTree )
+{
+       string directory ( GetDirectory ( RemoveVariables ( file ) ) );
+       string generatedFilesDirectory = backend->AddDirectoryTarget ( directory,
+                                                                      directoryTree );
+       if ( directory.find ( generatedFilesDirectory ) != string::npos )
+               /* This path already includes the generated files directory variable */
+               return file;
+       else
+       {
+               if ( file == "" )
+                       return generatedFilesDirectory;
+               return generatedFilesDirectory + SSEP + file;
+       }
+}
+
+/*static*/ Directory*
+MingwModuleHandler::GetTargetDirectoryTree (
+       const Module& module )
+{
+       if ( module.type == StaticLibrary )
+               return backend->intermediateDirectory;
+       return backend->outputDirectory;
+}
+
+/*static*/ string
+MingwModuleHandler::GetTargetFilename (
+       const Module& module,
+       string_list* pclean_files )
+{
+       string target = PassThruCacheDirectory (
+               NormalizeFilename ( module.GetPath () ),
+               GetTargetDirectoryTree ( module ) );
+       if ( pclean_files )
+       {
+               string_list& clean_files = *pclean_files;
+               CLEAN_FILE ( target );
+       }
+       return target;
+}
+
+/*static*/ string
+MingwModuleHandler::GetImportLibraryFilename (
+       const Module& module,
+       string_list* pclean_files )
+{
+       string target = PassThruCacheDirectory (
+               NormalizeFilename ( module.GetDependencyPath () ),
+               backend->intermediateDirectory );
+       if ( pclean_files )
+       {
+               string_list& clean_files = *pclean_files;
+               CLEAN_FILE ( target );
+       }
+       return target;
+}
+
+/*static*/ MingwModuleHandler*
+MingwModuleHandler::InstanciateHandler (
+       const Module& module,
+       MingwBackend* backend )
+{
+       MingwModuleHandler* handler;
+       switch ( module.type )
+       {
+               case BuildTool:
+                       handler = new MingwBuildToolModuleHandler ( module );
+                       break;
+               case StaticLibrary:
+                       handler = new MingwStaticLibraryModuleHandler ( module );
+                       break;
+               case ObjectLibrary:
+                       handler = new MingwObjectLibraryModuleHandler ( module );
+                       break;
+               case Kernel:
+                       handler = new MingwKernelModuleHandler ( module );
+                       break;
+               case NativeCUI:
+                       handler = new MingwNativeCUIModuleHandler ( module );
+                       break;
+               case Win32CUI:
+                       handler = new MingwWin32CUIModuleHandler ( module );
+                       break;
+               case Win32GUI:
+                       handler = new MingwWin32GUIModuleHandler ( module );
+                       break;
+               case KernelModeDLL:
+                       handler = new MingwKernelModeDLLModuleHandler ( module );
+                       break;
+               case NativeDLL:
+                       handler = new MingwNativeDLLModuleHandler ( module );
+                       break;
+               case Win32DLL:
+                       handler = new MingwWin32DLLModuleHandler ( module );
+                       break;
+               case KernelModeDriver:
+                       handler = new MingwKernelModeDriverModuleHandler ( module );
+                       break;
+               case BootLoader:
+                       handler = new MingwBootLoaderModuleHandler ( module );
+                       break;
+               case BootSector:
+                       handler = new MingwBootSectorModuleHandler ( module );
+                       break;
+               case Iso:
+                       handler = new MingwIsoModuleHandler ( module );
+                       break;
+               case LiveIso:
+                       handler = new MingwLiveIsoModuleHandler ( module );
+                       break;
+               case Test:
+                       handler = new MingwTestModuleHandler ( module );
+                       break;
+               case RpcServer:
+                       handler = new MingwRpcServerModuleHandler ( module );
+                       break;
+               case RpcClient:
+                       handler = new MingwRpcClientModuleHandler ( module );
+                       break;
+               case Alias:
+                       handler = new MingwAliasModuleHandler ( module );
+                       break;
+               default:
+                       throw UnknownModuleTypeException (
+                               module.node.location,
+                               module.type );
+                       break;
+       }
+       return handler;
+}
+
+string
+MingwModuleHandler::GetWorkingDirectory () const
+{
+       return ".";
+}
+
+string
+MingwModuleHandler::GetBasename ( const string& filename ) const
+{
+       size_t index = filename.find_last_of ( '.' );
+       if ( index != string::npos )
+               return filename.substr ( 0, index );
+       return "";
+}
+
+string
+MingwModuleHandler::GetActualSourceFilename (
+       const string& filename ) const
+{
+       string extension = GetExtension ( filename );
+       if ( extension == ".spec" || extension == ".SPEC" )
+       {
+               string basename = GetBasename ( filename );
+               return PassThruCacheDirectory ( NormalizeFilename ( basename + ".stubs.c" ),
+                                               backend->intermediateDirectory );
+       }
+       else if ( extension == ".idl" || extension == ".IDL" )
+       {
+               string basename = GetBasename ( filename );
+               string newname;
+               if ( module.type == RpcServer )
+                       newname = basename + "_s.c";
+               else
+                       newname = basename + "_c.c";
+               return PassThruCacheDirectory ( NormalizeFilename ( newname ),
+                                               backend->intermediateDirectory );
+       }
+       else
+               return filename;
+}
+
+string
+MingwModuleHandler::GetExtraDependencies (
+       const string& filename ) const
+{
+       string extension = GetExtension ( filename );
+       if ( extension == ".idl" || extension == ".IDL" )
+       {
+               string basename = GetBasename ( filename );
+               return GetRpcServerHeaderFilename ( basename ) + " " + GetRpcClientHeaderFilename ( basename );
+       }
+       else
+               return "";
+}
+
+string
+MingwModuleHandler::GetModuleArchiveFilename () const
+{
+       if ( module.type == StaticLibrary )
+               return GetTargetFilename ( module, NULL );
+       return PassThruCacheDirectory ( ReplaceExtension (
+               NormalizeFilename ( module.GetPath () ),
+               ".temp.a" ),
+               backend->intermediateDirectory );
+}
+
+bool
+MingwModuleHandler::IsGeneratedFile ( const File& file ) const
+{
+       string extension = GetExtension ( file.name );
+       return ( extension == ".spec" || extension == ".SPEC" );
+}
+
+/*static*/ bool
+MingwModuleHandler::ReferenceObjects (
+       const Module& module )
+{
+       if ( module.type == ObjectLibrary )
+               return true;
+       if ( module.type == RpcServer )
+               return true;
+       if ( module.type == RpcClient )
+               return true;
+       return false;
+}
+
+string
+MingwModuleHandler::GetImportLibraryDependency (
+       const Module& importedModule )
+{
+       string dep;
+       if ( ReferenceObjects ( importedModule ) )
+               dep = GetTargetMacro ( importedModule );
+       else
+               dep = GetImportLibraryFilename ( importedModule, NULL );
+       return dep;
+}
+
+void
+MingwModuleHandler::GetTargets ( const Module& dependencyModule,
+                                    string_list& targets )
+{
+       if ( dependencyModule.invocations.size () > 0 )
+       {
+               for ( size_t i = 0; i < dependencyModule.invocations.size (); i++ )
+               {
+                       Invoke& invoke = *dependencyModule.invocations[i];
+                       invoke.GetTargets ( targets );
+               }
+       }
+       else
+               targets.push_back ( GetImportLibraryDependency ( dependencyModule ) );
+}
+
+void
+MingwModuleHandler::GetModuleDependencies (
+       string_list& dependencies )
+{
+       size_t iend = module.dependencies.size ();
+
+       if ( iend == 0 )
+               return;
+       
+       for ( size_t i = 0; i < iend; i++ )
+       {
+               const Dependency& dependency = *module.dependencies[i];
+               const Module& dependencyModule = *dependency.dependencyModule;
+               GetTargets ( dependencyModule,
+                            dependencies );
+       }
+       GetDefinitionDependencies ( dependencies );
+}
+
+void
+MingwModuleHandler::GetSourceFilenames ( string_list& list,
+                                         bool includeGeneratedFiles ) const
+{
+       size_t i;
+
+       const vector<File*>& files = module.non_if_data.files;
+       for ( i = 0; i < files.size (); i++ )
+       {
+               if ( includeGeneratedFiles || !files[i]->IsGeneratedFile () )
+               {
+                       list.push_back (
+                               GetActualSourceFilename ( files[i]->name ) );
+               }
+       }
+       // intentionally make a copy so that we can append more work in
+       // the middle of processing without having to go recursive
+       vector<If*> v = module.non_if_data.ifs;
+       for ( i = 0; i < v.size (); i++ )
+       {
+               size_t j;
+               If& rIf = *v[i];
+               // check for sub-ifs to add to list
+               const vector<If*>& ifs = rIf.data.ifs;
+               for ( j = 0; j < ifs.size (); j++ )
+                       v.push_back ( ifs[j] );
+               const vector<File*>& files = rIf.data.files;
+               for ( j = 0; j < files.size (); j++ )
+               {
+                       File& file = *files[j];
+                       if ( includeGeneratedFiles || !file.IsGeneratedFile () )
+                       {
+                               list.push_back (
+                                       GetActualSourceFilename ( file.name ) );
+                       }
+               }
+       }
+}
+
+void
+MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
+       string_list& list ) const
+{
+       GetSourceFilenames ( list, false );
+}
+
+string
+MingwModuleHandler::GetObjectFilename (
+       const string& sourceFilename,
+       string_list* pclean_files ) const
+{
+       Directory* directoryTree;
+
+       string newExtension;
+       string extension = GetExtension ( sourceFilename );
+       if ( extension == ".rc" || extension == ".RC" )
+               newExtension = ".coff";
+       else if ( extension == ".spec" || extension == ".SPEC" )
+               newExtension = ".stubs.o";
+       else if ( extension == ".idl" || extension == ".IDL" )
+       {
+               if ( module.type == RpcServer )
+                       newExtension = "_s.o";
+               else
+                       newExtension = "_c.o";
+       }
+       else
+               newExtension = ".o";
+       
+       if ( module.type == BootSector )
+               directoryTree = backend->outputDirectory;
+       else
+               directoryTree = backend->intermediateDirectory;
+
+       string obj_file = PassThruCacheDirectory (
+               NormalizeFilename ( ReplaceExtension (
+                       RemoveVariables ( sourceFilename ),
+                                         newExtension ) ),
+                       directoryTree );
+       if ( pclean_files )
+       {
+               string_list& clean_files = *pclean_files;
+               CLEAN_FILE ( obj_file );
+       }
+       return obj_file;
+}
+
+string
+MingwModuleHandler::GetModuleCleanTarget ( const Module& module ) const
+{
+       return module.name + "_clean";
+}
+
+void
+MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector<string>& moduleNames ) const
+{
+       for ( size_t i = 0; i < module.non_if_data.libraries.size (); i++ )
+       {
+               Library& library = *module.non_if_data.libraries[i];
+               if ( library.importedModule->type == ObjectLibrary )
+                       moduleNames.push_back ( GetModuleCleanTarget ( *library.importedModule ) );
+       }
+}
+
+void
+MingwModuleHandler::GenerateCleanTarget () const
+{
+       if ( module.type == Alias )
+               return;
+       
+       fprintf ( fMakefile,
+                 ".PHONY: %s_clean\n",
+                  module.name.c_str() );
+       vector<string> referencedModuleNames;
+       GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames );
+       fprintf ( fMakefile,
+                 "%s: %s\n\t-@${rm}",
+                 GetModuleCleanTarget ( module ).c_str(),
+                 v2s ( referencedModuleNames, 10 ).c_str () );
+       for ( size_t i = 0; i < clean_files.size(); i++ )
+       {
+               if ( 9==((i+1)%10) )
+                       fprintf ( fMakefile, " 2>$(NUL)\n\t-@${rm}" );
+               fprintf ( fMakefile, " %s", clean_files[i].c_str() );
+       }
+       fprintf ( fMakefile, " 2>$(NUL)\n" );
+       fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );
+}
+
+void
+MingwModuleHandler::GenerateInstallTarget () const
+{
+       if ( module.installName.length () == 0 )
+               return;
+       fprintf ( fMakefile, ".PHONY: %s_install\n", module.name.c_str() );
+       string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
+               NormalizeFilename ( module.installBase + SSEP + module.installName ),
+               backend->installDirectory );
+       fprintf ( fMakefile,
+                 "%s_install: %s\n",
+                 module.name.c_str (),
+                 normalizedTargetFilename.c_str() );
+}
+
+void
+MingwModuleHandler::GenerateDependsTarget () const
+{
+       fprintf ( fMakefile,
+                 ".PHONY: %s_depends\n",
+                 module.name.c_str() );
+       fprintf ( fMakefile,
+                 "%s_depends: $(RBUILD_TARGET)\n",
+                 module.name.c_str () );
+       fprintf ( fMakefile,
+                 "\t$(ECHO_RBUILD)\n" );
+       fprintf ( fMakefile,
+                 "\t$(Q)$(RBUILD_TARGET) -dm%s mingw\n",
+                 module.name.c_str () );
+}
+
+string
+MingwModuleHandler::GetObjectFilenames ()
+{
+       const vector<File*>& files = module.non_if_data.files;
+       if ( files.size () == 0 )
+               return "";
+       
+       string objectFilenames ( "" );
+       for ( size_t i = 0; i < files.size (); i++ )
+       {
+               if ( objectFilenames.size () > 0 )
+                       objectFilenames += " ";
+               objectFilenames +=
+                       GetObjectFilename ( files[i]->name, NULL );
+       }
+       return objectFilenames;
+}
+
+/* static */ string
+MingwModuleHandler::GenerateGccDefineParametersFromVector (
+       const vector<Define*>& defines )
+{
+       string parameters;
+       for ( size_t i = 0; i < defines.size (); i++ )
+       {
+               Define& define = *defines[i];
+               if (parameters.length () > 0)
+                       parameters += " ";
+               parameters += "-D";
+               parameters += define.name;
+               if (define.value.length () > 0)
+               {
+                       parameters += "=";
+                       parameters += define.value;
+               }
+       }
+       return parameters;
+}
+
+string
+MingwModuleHandler::GenerateGccDefineParameters () const
+{
+       string parameters = GenerateGccDefineParametersFromVector ( module.project.non_if_data.defines );
+       string s = GenerateGccDefineParametersFromVector ( module.non_if_data.defines );
+       if ( s.length () > 0 )
+       {
+               parameters += " ";
+               parameters += s;
+       }
+       return parameters;
+}
+
+string
+MingwModuleHandler::ConcatenatePaths (
+       const string& path1,
+       const string& path2 ) const
+{
+       if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )
+               return path2;
+       if ( path1[path1.length ()] == CSEP )
+               return path1 + path2;
+       else
+               return path1 + CSEP + path2;
+}
+
+/* static */ string
+MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Include*>& includes )
+{
+       string parameters;
+       for ( size_t i = 0; i < includes.size (); i++ )
+       {
+               Include& include = *includes[i];
+               if ( parameters.length () > 0 )
+                       parameters += " ";
+               parameters += "-I" + include.directory;
+       }
+       return parameters;
+}
+
+string
+MingwModuleHandler::GenerateGccIncludeParameters () const
+{
+       string parameters = GenerateGccIncludeParametersFromVector ( module.non_if_data.includes );
+       string s = GenerateGccIncludeParametersFromVector ( module.project.non_if_data.includes );
+       if ( s.length () > 0 )
+       {
+               parameters += " ";
+               parameters += s;
+       }
+       return parameters;
+}
+
+string
+MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector<CompilerFlag*>& compilerFlags ) const
+{
+       string parameters;
+       for ( size_t i = 0; i < compilerFlags.size (); i++ )
+       {
+               CompilerFlag& compilerFlag = *compilerFlags[i];
+               if ( parameters.length () > 0 )
+                       parameters += " ";
+               parameters += compilerFlag.flag;
+       }
+       return parameters;
+}
+
+string
+MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector<LinkerFlag*>& linkerFlags ) const
+{
+       string parameters;
+       for ( size_t i = 0; i < linkerFlags.size (); i++ )
+       {
+               LinkerFlag& linkerFlag = *linkerFlags[i];
+               if ( parameters.length () > 0 )
+                       parameters += " ";
+               parameters += linkerFlag.flag;
+       }
+       return parameters;
+}
+
+string
+MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
+       const vector<Library*>& libraries )
+{
+       string dependencies ( "" );
+       int wrap_count = 0;
+       for ( size_t i = 0; i < libraries.size (); i++ )
+       {
+               if ( wrap_count++ == 5 )
+                       dependencies += " \\\n\t\t", wrap_count = 0;
+               else if ( dependencies.size () > 0 )
+                       dependencies += " ";
+               dependencies += GetImportLibraryDependency ( *libraries[i]->importedModule );
+       }
+       return dependencies;
+}
+
+string
+MingwModuleHandler::GenerateLinkerParameters () const
+{
+       return GenerateLinkerParametersFromVector ( module.linkerFlags );
+}
+
+void
+MingwModuleHandler::GenerateMacro (
+       const char* assignmentOperation,
+       const string& macro,
+       const IfableData& data )
+{
+       size_t i;
+       bool generateAssignment;
+
+       generateAssignment = (use_pch && module.pch != NULL ) || data.includes.size () > 0 || data.defines.size () > 0 || data.compilerFlags.size () > 0;
+       if ( generateAssignment )
+       {
+               fprintf ( fMakefile,
+                         "%s %s",
+                         macro.c_str(),
+                         assignmentOperation );
+       }
+
+       if ( use_pch && module.pch != NULL )
+       {
+               fprintf ( fMakefile,
+                         " -I%s",
+                         GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
+       }
+
+       string compilerParameters = GenerateCompilerParametersFromVector ( data.compilerFlags );
+       if ( compilerParameters.size () > 0 )
+       {
+               fprintf (
+                       fMakefile,
+                       " %s",
+                       compilerParameters.c_str () );
+       }
+
+       for ( i = 0; i < data.includes.size(); i++ )
+       {
+               const Include& include = *data.includes[i];
+               string includeDirectory;
+               if ( include.baseModule != NULL &&
+                    ( include.baseModule->type == RpcServer ||
+                      include.baseModule->type == RpcClient ) )
+                       includeDirectory = PassThruCacheDirectory ( NormalizeFilename ( include.directory ),
+                                                                   backend->intermediateDirectory );
+               else
+                       includeDirectory = include.directory;
+               fprintf (
+                       fMakefile,
+                       " -I%s",
+                       includeDirectory.c_str() );
+       }
+       for ( i = 0; i < data.defines.size(); i++ )
+       {
+               Define& d = *data.defines[i];
+               fprintf (
+                       fMakefile,
+                       " -D%s",
+                       d.name.c_str() );
+               if ( d.value.size() )
+                       fprintf (
+                               fMakefile,
+                               "=%s",
+                               d.value.c_str() );
+       }
+       if ( generateAssignment )
+       {
+               fprintf ( fMakefile, "\n" );
+       }
+}
+
+void
+MingwModuleHandler::GenerateMacros (
+       const char* assignmentOperation,
+       const IfableData& data,
+       const vector<LinkerFlag*>* linkerFlags )
+{
+       size_t i;
+
+       GenerateMacro ( assignmentOperation,
+                       cflagsMacro,
+                       data );
+       GenerateMacro ( assignmentOperation,
+                       windresflagsMacro,
+                       data );
+       
+       if ( linkerFlags != NULL )
+       {
+               string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );
+               if ( linkerParameters.size () > 0 )
+               {
+                       fprintf (
+                               fMakefile,
+                               "%s %s %s\n",
+                               linkerflagsMacro.c_str (),
+                               assignmentOperation,
+                               linkerParameters.c_str() );
+               }
+       }
+
+       if ( data.libraries.size () > 0 )
+       {
+               string deps = GenerateImportLibraryDependenciesFromVector ( data.libraries );
+               if ( deps.size () > 0 )
+               {
+                       fprintf (
+                               fMakefile,
+                               "%s %s %s\n",
+                               libsMacro.c_str(),
+                               assignmentOperation,
+                               deps.c_str() );
+               }
+       }
+
+       const vector<If*>& ifs = data.ifs;
+       for ( i = 0; i < ifs.size(); i++ )
+       {
+               If& rIf = *ifs[i];
+               if ( rIf.data.defines.size()
+                       || rIf.data.includes.size()
+                       || rIf.data.libraries.size()
+                       || rIf.data.files.size()
+                       || rIf.data.compilerFlags.size()
+                       || rIf.data.ifs.size() )
+               {
+                       fprintf (
+                               fMakefile,
+                               "%s (\"$(%s)\",\"%s\")\n",
+                               rIf.negated ? "ifneq" : "ifeq",
+                               rIf.property.c_str(),
+                               rIf.value.c_str() );
+                       GenerateMacros (
+                               "+=",
+                               rIf.data,
+                               NULL );
+                       fprintf ( 
+                               fMakefile,
+                               "endif\n\n" );
+               }
+       }
+}
+
+void
+MingwModuleHandler::CleanupFileVector ( vector<File*>& sourceFiles )
+{
+       for (size_t i = 0; i < sourceFiles.size (); i++)
+               delete sourceFiles[i];
+}
+
+void
+MingwModuleHandler::GetModuleSpecificSourceFiles ( vector<File*>& sourceFiles )
+{
+}
+
+void
+MingwModuleHandler::GenerateObjectMacros (
+       const char* assignmentOperation,
+       const IfableData& data,
+       const vector<LinkerFlag*>* linkerFlags )
+{
+       size_t i;
+
+       const vector<File*>& files = data.files;
+       if ( files.size () > 0 )
+       {
+               for ( i = 0; i < files.size (); i++ )
+               {
+                       File& file = *files[i];
+                       if ( file.first )
+                       {
+                               fprintf ( fMakefile,
+                                       "%s := %s $(%s)\n",
+                                       objectsMacro.c_str(),
+                                       GetObjectFilename (
+                                               file.name, NULL ).c_str (),
+                                       objectsMacro.c_str() );
+                       }
+               }
+               fprintf (
+                       fMakefile,
+                       "%s %s",
+                       objectsMacro.c_str (),
+                       assignmentOperation );
+               for ( i = 0; i < files.size(); i++ )
+               {
+                       File& file = *files[i];
+                       if ( !file.first )
+                       {
+                               fprintf (
+                                       fMakefile,
+                                       "%s%s",
+                                       ( i%10 == 9 ? " \\\n\t" : " " ),
+                                       GetObjectFilename (
+                                               file.name, NULL ).c_str () );
+                       }
+               }
+               fprintf ( fMakefile, "\n" );
+       }
+
+       const vector<If*>& ifs = data.ifs;
+       for ( i = 0; i < ifs.size(); i++ )
+       {
+               If& rIf = *ifs[i];
+               if ( rIf.data.defines.size()
+                       || rIf.data.includes.size()
+                       || rIf.data.libraries.size()
+                       || rIf.data.files.size()
+                       || rIf.data.compilerFlags.size()
+                       || rIf.data.ifs.size() )
+               {
+                       fprintf (
+                               fMakefile,
+                               "%s (\"$(%s)\",\"%s\")\n",
+                               rIf.negated ? "ifneq" : "ifeq",
+                               rIf.property.c_str(),
+                               rIf.value.c_str() );
+                       GenerateObjectMacros (
+                               "+=",
+                               rIf.data,
+                               NULL );
+                       fprintf ( 
+                               fMakefile,
+                               "endif\n\n" );
+               }
+       }
+
+       vector<File*> sourceFiles;
+       GetModuleSpecificSourceFiles ( sourceFiles );
+       for ( i = 0; i < sourceFiles.size (); i++ )
+       {
+               fprintf (
+                       fMakefile,
+                       "%s += %s\n",
+                       objectsMacro.c_str(),
+                       GetObjectFilename (
+                               sourceFiles[i]->name, NULL ).c_str () );
+       }
+       CleanupFileVector ( sourceFiles );
+}
+
+string
+MingwModuleHandler::GetPrecompiledHeaderFilename () const
+{
+       const string& basePchFilename = module.pch->file.name + ".gch";
+       return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename ),
+                                       backend->intermediateDirectory );
+}
+
+void
+MingwModuleHandler::GenerateGccCommand (
+       const string& sourceFilename,
+       const string& extraDependencies,
+       const string& cc,
+       const string& cflagsMacro )
+{
+       string dependencies = sourceFilename;
+       if ( extraDependencies != "" )
+               dependencies += " " + extraDependencies;
+       if ( module.pch && use_pch )
+               dependencies += " " + GetPrecompiledHeaderFilename ();
+       
+       /* WIDL generated headers may be used */
+       vector<string> rpcDependencies;
+       GetRpcHeaderDependencies ( rpcDependencies );
+       dependencies += " " + v2s ( rpcDependencies, 5 );
+       dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
+
+       string objectFilename = GetObjectFilename (
+               sourceFilename, &clean_files );
+       fprintf ( fMakefile,
+                 "%s: %s | %s\n",
+                 objectFilename.c_str (),
+                 dependencies.c_str (),
+                 GetDirectory ( objectFilename ).c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_CC)\n" );
+       fprintf ( fMakefile,
+                "\t%s -c $< -o $@ %s\n",
+                cc.c_str (),
+                cflagsMacro.c_str () );
+}
+
+void
+MingwModuleHandler::GenerateGccAssemblerCommand (
+       const string& sourceFilename,
+       const string& cc,
+       const string& cflagsMacro )
+{
+       string dependencies = sourceFilename;
+       dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
+       string objectFilename = GetObjectFilename (
+               sourceFilename, &clean_files );
+       fprintf ( fMakefile,
+                 "%s: %s | %s\n",
+                 objectFilename.c_str (),
+                 dependencies.c_str (),
+                 GetDirectory ( objectFilename ).c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_GAS)\n" );
+       fprintf ( fMakefile,
+                 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
+                 cc.c_str (),
+                 cflagsMacro.c_str () );
+}
+
+void
+MingwModuleHandler::GenerateNasmCommand (
+       const string& sourceFilename,
+       const string& nasmflagsMacro )
+{
+       string dependencies = sourceFilename;
+       dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
+       string objectFilename = GetObjectFilename (
+               sourceFilename, &clean_files );
+       fprintf ( fMakefile,
+                 "%s: %s | %s\n",
+                 objectFilename.c_str (),
+                 dependencies.c_str (),
+                 GetDirectory ( objectFilename ).c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_NASM)\n" );
+       fprintf ( fMakefile,
+                 "\t%s -f win32 $< -o $@ %s\n",
+                 "$(Q)${nasm}",
+                 nasmflagsMacro.c_str () );
+}
+
+void
+MingwModuleHandler::GenerateWindresCommand (
+       const string& sourceFilename,
+       const string& windresflagsMacro )
+{
+       string dependencies = sourceFilename;
+       dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
+       string objectFilename =
+               GetObjectFilename ( sourceFilename, &clean_files );
+       string sourceFilenamePart = ReplaceExtension ( GetFilename ( sourceFilename ), "" );
+       string rciFilename = ros_temp + module.name + "." + sourceFilenamePart + ".rci.tmp";
+       string resFilename = ros_temp + module.name + "." + sourceFilenamePart + ".res.tmp";
+       if ( module.useWRC )
+       {
+               fprintf ( fMakefile,
+                         "%s: %s $(WRC_TARGET) | %s\n",
+                         objectFilename.c_str (),
+                         dependencies.c_str (),
+                         GetDirectory ( objectFilename ).c_str () );
+               fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );
+               fprintf ( fMakefile,
+                        "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
+                        windresflagsMacro.c_str (),
+                        sourceFilename.c_str (),
+                        rciFilename.c_str () );
+               fprintf ( fMakefile,
+                        "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
+                        windresflagsMacro.c_str (),
+                        rciFilename.c_str (),
+                        resFilename.c_str () );
+               fprintf ( fMakefile,
+                        "\t-@${rm} %s 2>$(NUL)\n",
+                        rciFilename.c_str () );
+               fprintf ( fMakefile,
+                        "\t${windres} %s -o $@\n",
+                        resFilename.c_str () );
+               fprintf ( fMakefile,
+                        "\t-@${rm} %s 2>$(NUL)\n",
+                        resFilename.c_str () );
+       }
+       else
+       {
+               fprintf ( fMakefile,
+                         "%s: %s $(WRC_TARGET) | %s\n",
+                         objectFilename.c_str (),
+                         dependencies.c_str (),
+                         GetDirectory ( objectFilename ).c_str () );
+               fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );
+               fprintf ( fMakefile,
+                        "\t${windres} $(%s) %s -o $@\n",
+                        windresflagsMacro.c_str (),
+                        sourceFilename.c_str () );
+       }
+}
+
+void
+MingwModuleHandler::GenerateWinebuildCommands (
+       const string& sourceFilename )
+{
+       string dependencies = sourceFilename;
+       dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
+
+       string basename = GetBasename ( sourceFilename );
+       string def_file = PassThruCacheDirectory (
+               basename + ".spec.def",
+               backend->intermediateDirectory );
+       CLEAN_FILE(def_file);
+
+       string stub_file = PassThruCacheDirectory (
+               basename + ".stubs.c",
+               backend->intermediateDirectory );
+       CLEAN_FILE(stub_file)
+
+       fprintf ( fMakefile,
+                 "%s: %s $(WINEBUILD_TARGET)\n",
+                 def_file.c_str (),
+                 dependencies.c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
+       fprintf ( fMakefile,
+                 "\t%s -o %s --def -E %s\n",
+                 "$(Q)$(WINEBUILD_TARGET)",
+                 def_file.c_str (),
+                 sourceFilename.c_str () );
+       fprintf ( fMakefile,
+                 "%s: %s $(WINEBUILD_TARGET)\n",
+                 stub_file.c_str (),
+                 sourceFilename.c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
+       fprintf ( fMakefile,
+                 "\t%s -o %s --pedll %s\n",
+                 "$(Q)$(WINEBUILD_TARGET)",
+                 stub_file.c_str (),
+                 sourceFilename.c_str () );
+}
+
+string
+MingwModuleHandler::GetWidlFlags ( const File& file )
+{
+       return file.switches;
+}
+
+string
+MingwModuleHandler::GetRpcServerHeaderFilename ( string basename ) const
+{
+       return PassThruCacheDirectory ( basename + "_s.h",
+                                       backend->intermediateDirectory );
+}
+               
+void
+MingwModuleHandler::GenerateWidlCommandsServer (
+       const File& file,
+       const string& widlflagsMacro )
+{
+       string dependencies = file.name;
+       dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
+
+       string basename = GetBasename ( file.name );
+
+       string generatedHeaderFilename = GetRpcServerHeaderFilename ( basename );
+       CLEAN_FILE(generatedHeaderFilename);
+
+       string generatedServerFilename = PassThruCacheDirectory (
+               basename + "_s.c",
+               backend->intermediateDirectory );
+       CLEAN_FILE(generatedServerFilename);
+
+       fprintf ( fMakefile,
+                 "%s %s: %s $(WIDL_TARGET) | %s\n",
+                 generatedServerFilename.c_str (),
+                 generatedHeaderFilename.c_str (),
+                 dependencies.c_str (),
+                 GetDirectory ( generatedServerFilename ).c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );
+       fprintf ( fMakefile,
+                 "\t%s %s %s -h -H %s -s -S %s %s\n",
+                 "$(Q)$(WIDL_TARGET)",
+                 GetWidlFlags ( file ).c_str (),
+                 widlflagsMacro.c_str (),
+                 generatedHeaderFilename.c_str (),
+                 generatedServerFilename.c_str (),
+                 file.name.c_str () );
+}
+
+string
+MingwModuleHandler::GetRpcClientHeaderFilename ( string basename ) const
+{
+       return PassThruCacheDirectory ( basename + "_c.h",
+                                       backend->intermediateDirectory );
+}
+
+void
+MingwModuleHandler::GenerateWidlCommandsClient (
+       const File& file,
+       const string& widlflagsMacro )
+{
+       string dependencies = file.name;
+       dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
+
+       string basename = GetBasename ( file.name );
+
+       string generatedHeaderFilename = GetRpcClientHeaderFilename ( basename );
+       CLEAN_FILE(generatedHeaderFilename);
+
+       string generatedClientFilename = PassThruCacheDirectory (
+               basename + "_c.c",
+               backend->intermediateDirectory );
+       CLEAN_FILE(generatedClientFilename);
+
+       fprintf ( fMakefile,
+                 "%s %s: %s $(WIDL_TARGET) | %s\n",
+                 generatedClientFilename.c_str (),
+                 generatedHeaderFilename.c_str (),
+                 dependencies.c_str (),
+                 GetDirectory ( generatedClientFilename ).c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );
+       fprintf ( fMakefile,
+                 "\t%s %s %s -h -H %s -c -C %s %s\n",
+                 "$(Q)$(WIDL_TARGET)",
+                 GetWidlFlags ( file ).c_str (),
+                 widlflagsMacro.c_str (),
+                 generatedHeaderFilename.c_str (),
+                 generatedClientFilename.c_str (),
+                 file.name.c_str () );
+}
+
+void
+MingwModuleHandler::GenerateWidlCommands (
+       const File& file,
+       const string& widlflagsMacro )
+{
+       if ( module.type == RpcServer )
+               GenerateWidlCommandsServer ( file,
+                                            widlflagsMacro );
+       else
+               GenerateWidlCommandsClient ( file,
+                                            widlflagsMacro );
+}
+
+void
+MingwModuleHandler::GenerateCommands (
+       const File& file,
+       const string& cc,
+       const string& cppc,
+       const string& cflagsMacro,
+       const string& nasmflagsMacro,
+       const string& windresflagsMacro,
+       const string& widlflagsMacro )
+{
+       string extension = GetExtension ( file.name );
+       if ( extension == ".c" || extension == ".C" )
+       {
+               GenerateGccCommand ( file.name,
+                                    "",
+                                    cc,
+                                    cflagsMacro );
+               return;
+       }
+       else if ( extension == ".cc" || extension == ".CC" ||
+                 extension == ".cpp" || extension == ".CPP" ||
+                 extension == ".cxx" || extension == ".CXX" )
+       {
+               GenerateGccCommand ( file.name,
+                                    "",
+                                    cppc,
+                                    cflagsMacro );
+               return;
+       }
+       else if ( extension == ".s" || extension == ".S" )
+       {
+               GenerateGccAssemblerCommand ( file.name,
+                                             cc,
+                                             cflagsMacro );
+               return;
+       }
+       else if ( extension == ".asm" || extension == ".ASM" )
+       {
+               GenerateNasmCommand ( file.name,
+                                     nasmflagsMacro );
+               return;
+       }
+       else if ( extension == ".rc" || extension == ".RC" )
+       {
+               GenerateWindresCommand ( file.name,
+                                        windresflagsMacro );
+               return;
+       }
+       else if ( extension == ".spec" || extension == ".SPEC" )
+       {
+               GenerateWinebuildCommands ( file.name );
+               GenerateGccCommand ( GetActualSourceFilename ( file.name ),
+                                    "",
+                                    cc,
+                                    cflagsMacro );
+               return;
+       }
+       else if ( extension == ".idl" || extension == ".IDL" )
+       {
+               GenerateWidlCommands ( file,
+                                      widlflagsMacro );
+               GenerateGccCommand ( GetActualSourceFilename ( file.name ),
+                                    GetExtraDependencies ( file.name ),
+                                    cc,
+                                    cflagsMacro );
+               return;
+       }
+
+       throw InvalidOperationException ( __FILE__,
+                                         __LINE__,
+                                         "Unsupported filename extension '%s' in file '%s'",
+                                         extension.c_str (),
+                                         file.name.c_str () );
+}
+
+void
+MingwModuleHandler::GenerateBuildMapCode ()
+{
+       fprintf ( fMakefile,
+                 "ifeq ($(ROS_BUILDMAP),full)\n" );
+
+       string mapFilename = PassThruCacheDirectory (
+               GetBasename ( module.GetPath () ) + ".map",
+               backend->outputDirectory );
+       CLEAN_FILE ( mapFilename );
+       
+       fprintf ( fMakefile,
+                 "\t$(ECHO_OBJDUMP)\n" );
+       fprintf ( fMakefile,
+                 "\t$(Q)${objdump} -d -S $@ > %s\n",
+                 mapFilename.c_str () );
+
+       fprintf ( fMakefile,
+                 "else\n" );
+       fprintf ( fMakefile,
+                 "ifeq ($(ROS_BUILDMAP),yes)\n" );
+
+       fprintf ( fMakefile,
+                 "\t$(ECHO_NM)\n" );
+       fprintf ( fMakefile,
+                 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
+                 mapFilename.c_str () );
+
+       fprintf ( fMakefile,
+                 "endif\n" );
+
+       fprintf ( fMakefile,
+                 "endif\n" );
+}
+
+void
+MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
+{
+       fprintf ( fMakefile,
+                 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
+
+       string filename = module.GetPath ();
+       string outputFilename = PassThruCacheDirectory (
+               filename,
+               backend->outputDirectory );
+       string nostripFilename = PassThruCacheDirectory (
+               GetBasename ( filename ) + ".nostrip" + GetExtension ( filename ),
+               backend->outputDirectory );
+       CLEAN_FILE ( nostripFilename );
+       
+       fprintf ( fMakefile,
+                 "\t$(ECHO_CP)\n" );
+       fprintf ( fMakefile,
+                         "\t${cp} %s %s 1>$(NUL)\n",
+                         outputFilename.c_str (),
+                 nostripFilename.c_str () );
+       
+       fprintf ( fMakefile,
+                 "endif\n" );
+}
+
+void
+MergeStringVector ( const vector<string>& input,
+                    vector<string>& output )
+{
+       int wrap_at = 25;
+       string s;
+       int wrap_count = -1;
+       for ( size_t i = 0; i < input.size (); i++ )
+       {
+               if ( input[i].size () == 0 )
+                       continue;
+               if ( wrap_count++ == wrap_at )
+               {
+                       output.push_back ( s );
+                       s = "";
+                       wrap_count = 0;
+               }
+               else if ( s.size () > 0)
+                       s += " ";
+               s += input[i];
+       }
+       if ( s.length () > 0 )
+               output.push_back ( s );
+}
+
+void
+MingwModuleHandler::GetObjectsVector ( const IfableData& data,
+                                       vector<string>& objectFiles ) const
+{
+       for ( size_t i = 0; i < data.files.size (); i++ )
+       {
+               File& file = *data.files[i];
+               objectFiles.push_back ( GetObjectFilename ( file.name, NULL ) );
+       }
+}
+
+void
+MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
+{
+       if ( backend->configuration.CleanAsYouGo )
+       {
+               vector<string> objectFiles;
+               GetObjectsVector ( module.non_if_data,
+                           objectFiles );
+               vector<string> lines;
+               MergeStringVector ( objectFiles,
+                               lines );
+               for ( size_t i = 0; i < lines.size (); i++ )
+               {
+                       fprintf ( fMakefile,
+                                 "\t-@${rm} %s 2>$(NUL)\n",
+                                 lines[i].c_str () );
+               }
+       }
+}
+
+void
+MingwModuleHandler::GenerateRunRsymCode () const
+{
+       fprintf ( fMakefile,
+                 "\t$(ECHO_RSYM)\n" );
+       fprintf ( fMakefile,
+                 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
+}
+
+void
+MingwModuleHandler::GenerateLinkerCommand (
+       const string& dependencies,
+       const string& linker,
+       const string& linkerParameters,
+       const string& objectsMacro,
+       const string& libsMacro )
+{
+       string target ( GetTargetMacro ( module ) );
+       string target_folder ( GetDirectory ( GetTargetFilename ( module, NULL ) ) );
+       string def_file = GetDefinitionFilename ();
+
+       fprintf ( fMakefile,
+               "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
+               target.c_str (),
+               def_file.c_str (),
+               dependencies.c_str (),
+               target_folder.c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
+       string targetName ( module.GetTargetName () );
+
+       if ( module.IsDLL () )
+       {
+               string temp_exp = ros_temp + module.name + ".temp.exp";
+               CLEAN_FILE ( temp_exp );
+       
+               string killAt = module.mangledSymbols ? "" : "--kill-at";
+               fprintf ( fMakefile,
+                         "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
+                         targetName.c_str (),
+                         def_file.c_str (),
+                         temp_exp.c_str (),
+                         killAt.c_str () );
+       
+               fprintf ( fMakefile,
+                         "\t%s %s %s -o %s %s %s %s\n",
+                         linker.c_str (),
+                         linkerParameters.c_str (),
+                         temp_exp.c_str (),
+                         target.c_str (),
+                         objectsMacro.c_str (),
+                         libsMacro.c_str (),
+                         GetLinkerMacro ().c_str () );
+       
+               fprintf ( fMakefile,
+                         "\t$(Q)$(PEFIXUP_TARGET) %s -exports\n",
+                         target.c_str () );
+
+               fprintf ( fMakefile,
+                         "\t-@${rm} %s 2>$(NUL)\n",
+                         temp_exp.c_str () );
+       }
+       else
+       {
+               fprintf ( fMakefile,
+                         "\t%s %s -o %s %s %s %s\n",
+                         linker.c_str (),
+                         linkerParameters.c_str (),
+                         target.c_str (),
+                         objectsMacro.c_str (),
+                         libsMacro.c_str (),
+                         GetLinkerMacro ().c_str () );
+       }
+
+       GenerateBuildMapCode ();
+       GenerateBuildNonSymbolStrippedCode ();
+       GenerateRunRsymCode ();
+       GenerateCleanObjectsAsYouGoCode ();
+}
+
+void
+MingwModuleHandler::GeneratePhonyTarget() const
+{
+       string targetMacro ( GetTargetMacro ( module ) );
+       fprintf ( fMakefile,
+                 ".PHONY: %s\n\n",
+                 targetMacro.c_str ());
+       fprintf ( fMakefile, "%s: | %s\n",
+                 targetMacro.c_str (),
+                 GetDirectory ( GetTargetFilename ( module, NULL ) ).c_str () );
+}
+
+void
+MingwModuleHandler::GenerateObjectFileTargets (
+       const IfableData& data,
+       const string& cc,
+       const string& cppc,
+       const string& cflagsMacro,
+       const string& nasmflagsMacro,
+       const string& windresflagsMacro,
+       const string& widlflagsMacro )
+{
+       size_t i;
+       
+       const vector<File*>& files = data.files;
+       for ( i = 0; i < files.size (); i++ )
+       {
+               GenerateCommands ( *files[i],
+                                  cc,
+                                  cppc,
+                                  cflagsMacro,
+                                  nasmflagsMacro,
+                                  windresflagsMacro,
+                                  widlflagsMacro );
+               fprintf ( fMakefile,
+                         "\n" );
+       }
+
+       const vector<If*>& ifs = data.ifs;
+       for ( i = 0; i < ifs.size(); i++ )
+       {
+               GenerateObjectFileTargets ( ifs[i]->data,
+                                           cc,
+                                           cppc,
+                                           cflagsMacro,
+                                           nasmflagsMacro,
+                                           windresflagsMacro,
+                                           widlflagsMacro );
+       }
+
+       vector<File*> sourceFiles;
+       GetModuleSpecificSourceFiles ( sourceFiles );
+       for ( i = 0; i < sourceFiles.size (); i++ )
+       {
+               GenerateCommands ( *sourceFiles[i],
+                                  cc,
+                                  cppc,
+                                  cflagsMacro,
+                                  nasmflagsMacro,
+                                  windresflagsMacro,
+                                  widlflagsMacro );
+       }
+       CleanupFileVector ( sourceFiles );
+}
+
+void
+MingwModuleHandler::GenerateObjectFileTargets (
+       const string& cc,
+       const string& cppc,
+       const string& cflagsMacro,
+       const string& nasmflagsMacro,
+       const string& windresflagsMacro,
+       const string& widlflagsMacro )
+{
+       if ( module.pch && use_pch )
+       {
+               const string& baseHeaderFilename = module.pch->file.name;
+               const string& pchFilename = GetPrecompiledHeaderFilename ();
+               CLEAN_FILE(pchFilename);
+               fprintf ( fMakefile,
+                         "%s: %s\n",
+                         pchFilename.c_str(),
+                         baseHeaderFilename.c_str() );
+               fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );
+               fprintf ( fMakefile,
+                         "\t%s -o %s %s -g %s\n\n",
+                         module.cplusplus ? cppc.c_str() : cc.c_str(),
+                         pchFilename.c_str(),
+                         cflagsMacro.c_str(),
+                         baseHeaderFilename.c_str() );
+       }
+
+       GenerateObjectFileTargets ( module.non_if_data,
+                                   cc,
+                                   cppc,
+                                   cflagsMacro,
+                                   nasmflagsMacro,
+                                   windresflagsMacro,
+                                   widlflagsMacro );
+       fprintf ( fMakefile, "\n" );
+}
+
+string
+MingwModuleHandler::GenerateArchiveTarget ( const string& ar,
+                                            const string& objs_macro ) const
+{
+       string archiveFilename ( GetModuleArchiveFilename () );
+       
+       fprintf ( fMakefile,
+                 "%s: %s | %s\n",
+                 archiveFilename.c_str (),
+                 objs_macro.c_str (),
+                 GetDirectory(archiveFilename).c_str() );
+
+       fprintf ( fMakefile, "\t$(ECHO_AR)\n" );
+
+       fprintf ( fMakefile,
+                 "\t%s -rc $@ %s\n",
+                 ar.c_str (),
+                 objs_macro.c_str ());
+
+       GenerateCleanObjectsAsYouGoCode ();
+
+       fprintf ( fMakefile, "\n" );
+
+       return archiveFilename;
+}
+
+string
+MingwModuleHandler::GetCFlagsMacro () const
+{
+       return ssprintf ( "$(%s_CFLAGS)",
+                         module.name.c_str () );
+}
+
+/*static*/ string
+MingwModuleHandler::GetObjectsMacro ( const Module& module )
+{
+       return ssprintf ( "$(%s_OBJS)",
+                         module.name.c_str () );
+}
+
+string
+MingwModuleHandler::GetLinkingDependenciesMacro () const
+{
+       return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );
+}
+
+string
+MingwModuleHandler::GetLibsMacro () const
+{
+       return ssprintf ( "$(%s_LIBS)", module.name.c_str () );
+}
+
+string
+MingwModuleHandler::GetLinkerMacro () const
+{
+       return ssprintf ( "$(%s_LFLAGS)",
+                         module.name.c_str () );
+}
+
+string
+MingwModuleHandler::GetModuleTargets ( const Module& module )
+{
+       if ( ReferenceObjects ( module ) )
+               return GetObjectsMacro ( module );
+       else
+               return GetTargetFilename ( module, NULL );
+}
+
+void
+MingwModuleHandler::GenerateObjectMacro ()
+{
+       objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
+
+       GenerateObjectMacros (
+               "=",
+               module.non_if_data,
+               &module.linkerFlags );
+
+       // future references to the macro will be to get its values
+       objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());
+}
+
+void
+MingwModuleHandler::GenerateTargetMacro ()
+{
+       fprintf ( fMakefile,
+               "%s := %s\n",
+               GetTargetMacro ( module, false ).c_str (),
+               GetModuleTargets ( module ).c_str () );
+}
+
+void
+MingwModuleHandler::GetRpcHeaderDependencies (
+       vector<string>& dependencies ) const
+{
+       for ( size_t i = 0; i < module.non_if_data.libraries.size (); i++ )
+       {
+               Library& library = *module.non_if_data.libraries[i];
+               if ( library.importedModule->type == RpcServer ||
+                    library.importedModule->type == RpcClient )
+               {
+                       for ( size_t j = 0; j < library.importedModule->non_if_data.files.size (); j++ )
+                       {
+                               File& file = *library.importedModule->non_if_data.files[j];
+                               string extension = GetExtension ( file.name );
+                               if ( extension == ".idl" || extension == ".IDL" )
+                               {
+                                       string basename = GetBasename ( file.name );
+                                       if ( library.importedModule->type == RpcServer )
+                                               dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) );
+                                       if ( library.importedModule->type == RpcClient )
+                                               dependencies.push_back ( GetRpcClientHeaderFilename ( basename ) );
+                               }
+                       }
+               }
+       }
+}
+
+void
+MingwModuleHandler::GenerateOtherMacros ()
+{
+       cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
+       nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
+       windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
+       widlflagsMacro = ssprintf ("%s_WIDLFLAGS", module.name.c_str ());
+       linkerflagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
+       libsMacro = ssprintf("%s_LIBS", module.name.c_str ());
+       linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());
+
+       GenerateMacros (
+               "=",
+               module.non_if_data,
+               &module.linkerFlags );
+
+       vector<string> s;
+       if ( module.importLibrary )
+       {
+               const vector<File*>& files = module.non_if_data.files;
+               for ( size_t i = 0; i < files.size (); i++ )
+               {
+                       File& file = *files[i];
+                       string extension = GetExtension ( file.name );
+                       if ( extension == ".spec" || extension == ".SPEC" )
+                               GetSpecObjectDependencies ( s, file.name );
+               }
+       }
+       if ( s.size () > 0 )
+       {
+               fprintf (
+                       fMakefile,
+                       "%s +=",
+                       linkDepsMacro.c_str() );
+               for ( size_t i = 0; i < s.size(); i++ )
+                       fprintf ( fMakefile,
+                                 " %s",
+                                 s[i].c_str () );
+               fprintf ( fMakefile, "\n" );
+       }
+
+       string globalCflags = "-g";
+       if ( backend->usePipe )
+               globalCflags += " -pipe";
+       if ( !module.enableWarnings )
+               globalCflags += " -Werror";
+       
+       fprintf (
+               fMakefile,
+               "%s += $(PROJECT_CFLAGS) %s\n",
+               cflagsMacro.c_str (),
+               globalCflags.c_str () );
+
+       fprintf (
+               fMakefile,
+               "%s += $(PROJECT_RCFLAGS)\n",
+               windresflagsMacro.c_str () );
+
+       fprintf (
+               fMakefile,
+               "%s += $(PROJECT_WIDLFLAGS)\n",
+               widlflagsMacro.c_str () );
+
+       fprintf (
+               fMakefile,
+               "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
+               module.name.c_str () );
+
+       fprintf (
+               fMakefile,
+               "%s += $(%s)\n",
+               linkDepsMacro.c_str (),
+               libsMacro.c_str () );
+
+       string cflags = TypeSpecificCFlags();
+       if ( cflags.size() > 0 )
+       {
+               fprintf ( fMakefile,
+                         "%s += %s\n\n",
+                         cflagsMacro.c_str (),
+                         cflags.c_str () );
+       }
+
+       string nasmflags = TypeSpecificNasmFlags();
+       if ( nasmflags.size () > 0 )
+       {
+               fprintf ( fMakefile,
+                         "%s += %s\n\n",
+                         nasmflagsMacro.c_str (),
+                         nasmflags.c_str () );
+       }
+
+       string linkerflags = TypeSpecificLinkerFlags();
+       if ( linkerflags.size() > 0 )
+       {
+               fprintf ( fMakefile,
+                         "%s += %s\n\n",
+                         linkerflagsMacro.c_str (),
+                         linkerflags.c_str () );
+       }
+
+       fprintf ( fMakefile, "\n\n" );
+
+       // future references to the macros will be to get their values
+       cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
+       nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());
+       widlflagsMacro = ssprintf ("$(%s)", widlflagsMacro.c_str ());
+}
+
+void
+MingwModuleHandler::GenerateRules ()
+{
+       string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );
+       string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );
+       string ar = ( module.host == HostTrue ? "${host_ar}" : "${ar}" );
+
+       if ( module.name != "zlib" ) /* Avoid make warning */
+       {
+               string proxyMakefile = PassThruCacheDirectory (
+                       NormalizeFilename ( module.GetBasePath () + SSEP + "makefile" ),
+                       backend->outputDirectory );
+               CLEAN_FILE ( proxyMakefile );
+       }
+
+       string targetMacro = GetTargetMacro ( module );
+       CLEAN_FILE ( targetMacro );
+
+       // generate phony target for module name
+       fprintf ( fMakefile, ".PHONY: %s\n",
+               module.name.c_str () );
+       string dependencies = GetTargetMacro ( module );
+       if ( module.type == Test )
+               dependencies += " $(REGTESTS_RUN_TARGET)";
+       fprintf ( fMakefile, "%s: %s\n\n",
+               module.name.c_str (),
+               dependencies.c_str () );
+       if ( module.type == Test )
+       {
+               fprintf ( fMakefile,
+                         "\t@%s\n",
+                         targetMacro.c_str ());
+       }
+
+       if ( !ReferenceObjects ( module ) )
+       {
+               string ar_target ( GenerateArchiveTarget ( ar, objectsMacro ) );
+               if ( targetMacro != ar_target )
+                       CLEAN_FILE ( ar_target );
+       }
+
+       GenerateObjectFileTargets ( cc,
+                                   cppc,
+                                   cflagsMacro,
+                                   nasmflagsMacro,
+                                   windresflagsMacro,
+                                   widlflagsMacro );
+}
+
+void
+MingwModuleHandler::GetInvocationDependencies (
+       const Module& module,
+       string_list& dependencies )
+{
+       for ( size_t i = 0; i < module.invocations.size (); i++ )
+       {
+               Invoke& invoke = *module.invocations[i];
+               if ( invoke.invokeModule == &module )
+                       /* Protect against circular dependencies */
+                       continue;
+               invoke.GetTargets ( dependencies );
+       }
+}
+
+void
+MingwModuleHandler::GenerateInvocations () const
+{
+       if ( module.invocations.size () == 0 )
+               return;
+       
+       size_t iend = module.invocations.size ();
+       for ( size_t i = 0; i < iend; i++ )
+       {
+               const Invoke& invoke = *module.invocations[i];
+
+               if ( invoke.invokeModule->type != BuildTool )
+               {
+                       throw InvalidBuildFileException ( module.node.location,
+                                                         "Only modules of type buildtool can be invoked." );
+               }
+
+               string invokeTarget = module.GetInvocationTarget ( i );
+               string_list invoke_targets;
+               assert ( invoke_targets.size() );
+               invoke.GetTargets ( invoke_targets );
+               fprintf ( fMakefile,
+                         ".PHONY: %s\n\n",
+                         invokeTarget.c_str () );
+               fprintf ( fMakefile,
+                         "%s:",
+                         invokeTarget.c_str () );
+               size_t j, jend = invoke_targets.size();
+               for ( j = 0; j < jend; j++ )
+               {
+                       fprintf ( fMakefile,
+                                 " %s",
+                                 invoke_targets[i].c_str () );
+               }
+               fprintf ( fMakefile, "\n\n%s", invoke_targets[0].c_str () );
+               for ( j = 1; j < jend; j++ )
+                       fprintf ( fMakefile,
+                                 " %s",
+                                 invoke_targets[i].c_str () );
+               fprintf ( fMakefile,
+                         ": %s\n",
+                         NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str () );
+               fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );
+               fprintf ( fMakefile,
+                         "\t%s %s\n\n",
+                         NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str (),
+                         invoke.GetParameters ().c_str () );
+       }
+}
+
+string
+MingwModuleHandler::GetPreconditionDependenciesName () const
+{
+       return module.name + "_precondition";
+}
+
+void
+MingwModuleHandler::GetDefaultDependencies (
+       string_list& dependencies ) const
+{
+       /* Avoid circular dependency */
+       if ( module.type != BuildTool
+               && module.name != "zlib"
+               && module.name != "hostzlib" )
+
+               dependencies.push_back ( "$(INIT)" );
+}
+
+void
+MingwModuleHandler::GeneratePreconditionDependencies ()
+{
+       string preconditionDependenciesName = GetPreconditionDependenciesName ();
+       string_list sourceFilenames;
+       GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );
+       string_list dependencies;
+       GetDefaultDependencies ( dependencies );
+       GetModuleDependencies ( dependencies );
+
+       GetInvocationDependencies ( module, dependencies );
+       
+       if ( dependencies.size() )
+       {
+               fprintf ( fMakefile,
+                         "%s =",
+                         preconditionDependenciesName.c_str () );
+               for ( size_t i = 0; i < dependencies.size(); i++ )
+                       fprintf ( fMakefile,
+                                 " %s",
+                                 dependencies[i].c_str () );
+               fprintf ( fMakefile, "\n\n" );
+       }
+
+       for ( size_t i = 0; i < sourceFilenames.size(); i++ )
+       {
+               fprintf ( fMakefile,
+                         "%s: ${%s}\n",
+                         sourceFilenames[i].c_str(),
+                         preconditionDependenciesName.c_str ());
+       }
+       fprintf ( fMakefile, "\n" );
+}
+
+bool
+MingwModuleHandler::IsWineModule () const
+{
+       if ( module.importLibrary == NULL)
+               return false;
+
+       size_t index = module.importLibrary->definition.rfind ( ".spec.def" );
+       return ( index != string::npos );
+}
+
+string
+MingwModuleHandler::GetDefinitionFilename () const
+{
+       if ( module.importLibrary != NULL )
+       {
+               string defFilename = module.GetBasePath () + SSEP + module.importLibrary->definition;
+               if ( IsWineModule () )
+                       return PassThruCacheDirectory ( NormalizeFilename ( defFilename ),
+                                                       backend->intermediateDirectory );
+               else
+                       return defFilename;
+       }
+       else
+               return "tools" SSEP "rbuild" SSEP "empty.def";
+}
+
+void
+MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
+{
+       if ( module.importLibrary != NULL )
+       {
+               string library_target (
+                       GetImportLibraryFilename ( module, &clean_files ) );
+               string defFilename = GetDefinitionFilename ();
+       
+               string_list deps;
+               GetDefinitionDependencies ( deps );
+
+               fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );
+
+               fprintf ( fMakefile, "%s: %s",
+                         library_target.c_str (),
+                         defFilename.c_str () );
+
+               size_t i, iend = deps.size();
+               for ( i = 0; i < iend; i++ )
+                       fprintf ( fMakefile, " %s",
+                                 deps[i].c_str () );
+
+               fprintf ( fMakefile, " | %s\n",
+                         GetDirectory ( GetImportLibraryFilename ( module, NULL ) ).c_str () );
+
+               fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
+
+               string killAt = module.mangledSymbols ? "" : "--kill-at";
+               fprintf ( fMakefile,
+                         "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
+                         module.GetTargetName ().c_str (),
+                         defFilename.c_str (),
+                         library_target.c_str (),
+                         killAt.c_str () );
+       }
+}
+
+void
+MingwModuleHandler::GetSpecObjectDependencies (
+       string_list& dependencies,
+       const string& filename ) const
+{
+       string basename = GetBasename ( filename );
+       string defDependency = PassThruCacheDirectory (
+               NormalizeFilename ( basename + ".spec.def" ),
+               backend->intermediateDirectory );
+       dependencies.push_back ( defDependency );
+       string stubsDependency = PassThruCacheDirectory (
+               NormalizeFilename ( basename + ".stubs.c" ),
+               backend->intermediateDirectory );
+       dependencies.push_back ( stubsDependency );
+}
+
+void
+MingwModuleHandler::GetWidlObjectDependencies (
+       string_list& dependencies,
+       const string& filename ) const
+{
+       string basename = GetBasename ( filename );
+       string serverSourceDependency = PassThruCacheDirectory (
+               NormalizeFilename ( basename + "_s.c" ),
+               backend->intermediateDirectory );
+       dependencies.push_back ( serverSourceDependency );
+       dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) );
+}
+
+void
+MingwModuleHandler::GetDefinitionDependencies (
+       string_list& dependencies ) const
+{
+       string dkNkmLibNoFixup = "dk/nkm/lib";
+       const vector<File*>& files = module.non_if_data.files;
+       for ( size_t i = 0; i < files.size (); i++ )
+       {
+               File& file = *files[i];
+               string extension = GetExtension ( file.name );
+               if ( extension == ".spec" || extension == ".SPEC" )
+               {
+                       GetSpecObjectDependencies ( dependencies, file.name );
+               }
+               if ( extension == ".idl" || extension == ".IDL" )
+               {
+                       GetWidlObjectDependencies ( dependencies, file.name );
+               }
+       }
+}
+
+
+MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwBuildToolModuleHandler::Process ()
+{
+       GenerateBuildToolModuleTarget ();
+}
+
+void
+MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro (module) );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateRules ();
+
+       string linker;
+       if ( module.cplusplus )
+               linker = "${host_gpp}";
+       else
+               linker = "${host_gcc}";
+       
+       fprintf ( fMakefile, "%s: %s %s | %s\n",
+                 targetMacro.c_str (),
+                 objectsMacro.c_str (),
+                 linkDepsMacro.c_str (),
+                 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
+       fprintf ( fMakefile,
+                 "\t%s %s -o $@ %s %s\n\n",
+                 linker.c_str (),
+                 GetLinkerMacro ().c_str (),
+                 objectsMacro.c_str (),
+                 libsMacro.c_str () );
+}
+
+
+MingwKernelModuleHandler::MingwKernelModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwKernelModuleHandler::Process ()
+{
+       GenerateKernelModuleTarget ();
+}
+
+void
+MingwKernelModuleHandler::GenerateKernelModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro ( module ) );
+       string workingDirectory = GetWorkingDirectory ( );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linkerParameters = 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 -shared",
+                                                    module.GetBasePath ().c_str (),
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       "${gcc}",
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwStaticLibraryModuleHandler::Process ()
+{
+       GenerateStaticLibraryModuleTarget ();
+}
+
+void
+MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
+{
+       GenerateRules ();
+}
+
+
+MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwObjectLibraryModuleHandler::Process ()
+{
+       GenerateObjectLibraryModuleTarget ();
+}
+
+void
+MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
+{
+       GenerateRules ();
+}
+
+
+MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwKernelModeDLLModuleHandler::Process ()
+{
+       GenerateKernelModeDLLModuleTarget ();
+}
+
+void
+MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro ( module ) );
+       string workingDirectory = GetWorkingDirectory ( );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       "${gcc}",
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwKernelModeDriverModuleHandler::Process ()
+{
+       GenerateKernelModeDriverModuleTarget ();
+}
+
+
+void
+MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro (module) );
+       string workingDirectory = GetWorkingDirectory ();
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       "${gcc}",
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwNativeDLLModuleHandler::Process ()
+{
+       GenerateNativeDLLModuleTarget ();
+}
+
+void
+MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro (module) );
+       string workingDirectory = GetWorkingDirectory ( );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+       
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       "${gcc}",
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwNativeCUIModuleHandler::Process ()
+{
+       GenerateNativeCUIModuleTarget ();
+}
+
+void
+MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro (module) );
+       string workingDirectory = GetWorkingDirectory ( );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+       
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       "${gcc}",
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwWin32DLLModuleHandler::Process ()
+{
+       GenerateWin32DLLModuleTarget ();
+}
+
+void
+MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro (module) );
+       string workingDirectory = GetWorkingDirectory ( );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linker;
+               if ( module.cplusplus )
+                       linker = "${gpp}";
+               else
+                       linker = "${gcc}";
+
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       linker,
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwWin32CUIModuleHandler::Process ()
+{
+       GenerateWin32CUIModuleTarget ();
+}
+
+void
+MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro (module) );
+       string workingDirectory = GetWorkingDirectory ( );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linker;
+               if ( module.cplusplus )
+                       linker = "${gpp}";
+               else
+                       linker = "${gcc}";
+
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       linker,
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwWin32GUIModuleHandler::Process ()
+{
+       GenerateWin32GUIModuleTarget ();
+}
+
+void
+MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro (module) );
+       string workingDirectory = GetWorkingDirectory ( );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linker;
+               if ( module.cplusplus )
+                       linker = "${gpp}";
+               else
+                       linker = "${gcc}";
+
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       linker,
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwBootLoaderModuleHandler::Process ()
+{
+       GenerateBootLoaderModuleTarget ();
+}
+
+void
+MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
+{
+       string targetName ( module.GetTargetName () );
+       string targetMacro ( GetTargetMacro (module) );
+       string workingDirectory = GetWorkingDirectory ();
+       string junk_tmp = ros_temp + module.name + ".junk.tmp";
+       CLEAN_FILE ( junk_tmp );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateRules ();
+
+       fprintf ( fMakefile, "%s: %s %s | %s\n",
+                 targetMacro.c_str (),
+                 objectsMacro.c_str (),
+                 linkDepsMacro.c_str (),
+                 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
+
+       fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
+
+       fprintf ( fMakefile,
+                 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
+                 GetLinkerMacro ().c_str (),
+                 junk_tmp.c_str (),
+                 objectsMacro.c_str (),
+                 linkDepsMacro.c_str () );
+       fprintf ( fMakefile,
+                 "\t${objcopy} -O binary %s $@\n",
+                 junk_tmp.c_str () );
+       fprintf ( fMakefile,
+                 "\t-@${rm} %s 2>$(NUL)\n",
+                 junk_tmp.c_str () );
+}
+
+
+MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwBootSectorModuleHandler::Process ()
+{
+       GenerateBootSectorModuleTarget ();
+}
+
+void
+MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
+{
+       string objectsMacro = GetObjectsMacro ( module );
+
+       GenerateRules ();
+
+       fprintf ( fMakefile, ".PHONY: %s\n\n",
+                 module.name.c_str ());
+       fprintf ( fMakefile,
+                 "%s: %s\n",
+                 module.name.c_str (),
+                 objectsMacro.c_str () );
+}
+
+
+MingwIsoModuleHandler::MingwIsoModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwIsoModuleHandler::Process ()
+{
+       GenerateIsoModuleTarget ();
+}
+
+void
+MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
+       const string& bootcdDirectory )
+{
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       {
+               const Module& m = *module.project.modules[i];
+               if ( !m.enabled )
+                       continue;
+               if ( m.bootstrap != NULL )
+               {
+                       string sourceFilename = PassThruCacheDirectory (
+                               NormalizeFilename ( m.GetPath () ),
+                               backend->outputDirectory );
+                       string targetFilenameNoFixup ( bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd );
+                       string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
+                               NormalizeFilename ( targetFilenameNoFixup ),
+                               backend->outputDirectory );
+                       fprintf ( fMakefile,
+                                 "\t$(ECHO_CP)\n" );
+                       fprintf ( fMakefile,
+                                 "\t${cp} %s %s 1>$(NUL)\n",
+                                 sourceFilename.c_str (),
+                                 targetFilename.c_str () );
+               }
+       }
+}
+
+void
+MingwIsoModuleHandler::OutputCdfileCopyCommands (
+       const string& bootcdDirectory )
+{
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
+       {
+               const CDFile& cdfile = *module.project.cdfiles[i];
+               string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;
+               string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
+                       NormalizeFilename ( targetFilenameNoFixup ),
+                       backend->outputDirectory );
+               fprintf ( fMakefile,
+                         "\t$(ECHO_CP)\n" );
+               fprintf ( fMakefile,
+                         "\t${cp} %s %s 1>$(NUL)\n",
+                         cdfile.GetPath ().c_str (),
+                         targetFilename.c_str () );
+       }
+}
+
+string
+MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory )
+{
+       string directories;
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       {
+               const Module& m = *module.project.modules[i];
+               if ( !m.enabled )
+                       continue;
+               if ( m.bootstrap != NULL )
+               {
+                       string targetDirectory ( bootcdDirectory + SSEP + m.bootstrap->base );
+                       if ( directories.size () > 0 )
+                               directories += " ";
+                       directories += PassThruCacheDirectory (
+                               NormalizeFilename ( targetDirectory ),
+                               backend->outputDirectory );
+               }
+       }
+       return directories;
+}
+
+string
+MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory )
+{
+       string directories;
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
+       {
+               const CDFile& cdfile = *module.project.cdfiles[i];
+               string targetDirectory ( bootcdDirectory + SSEP + cdfile.base );
+               if ( directories.size () > 0 )
+                       directories += " ";
+               directories += PassThruCacheDirectory (
+                       NormalizeFilename ( targetDirectory ),
+                       backend->outputDirectory );
+       }
+       return directories;
+}
+
+string
+MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory )
+{
+       string directories = GetBootstrapCdDirectories ( bootcdDirectory );
+       directories += " " + GetNonModuleCdDirectories ( bootcdDirectory );
+       return directories;
+}
+
+void
+MingwIsoModuleHandler::GetBootstrapCdFiles (
+       vector<string>& out ) const
+{
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       {
+               const Module& m = *module.project.modules[i];
+               if ( !m.enabled )
+                       continue;
+               if ( m.bootstrap != NULL )
+               {
+                       string filename = PassThruCacheDirectory (
+                               NormalizeFilename ( m.GetPath () ),
+                               backend->outputDirectory );
+                       out.push_back ( filename );
+               }
+       }
+}
+
+void
+MingwIsoModuleHandler::GetNonModuleCdFiles (
+       vector<string>& out ) const
+{
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
+       {
+               const CDFile& cdfile = *module.project.cdfiles[i];
+               out.push_back ( cdfile.GetPath () );
+       }
+}
+
+void
+MingwIsoModuleHandler::GetCdFiles (
+       vector<string>& out ) const
+{
+       GetBootstrapCdFiles ( out );
+       GetNonModuleCdFiles ( out );
+}
+
+void
+MingwIsoModuleHandler::GenerateIsoModuleTarget ()
+{
+       string bootcdDirectory = "cd";
+       string bootcd = PassThruCacheDirectory (
+               NormalizeFilename ( bootcdDirectory + SSEP ),
+               backend->outputDirectory );
+       string isoboot = PassThruCacheDirectory (
+               NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
+               backend->outputDirectory );
+       string bootcdReactosNoFixup = bootcdDirectory + SSEP "reactos";
+       string bootcdReactos = PassThruCacheDirectory (
+               NormalizeFilename ( bootcdReactosNoFixup + SSEP ),
+               backend->outputDirectory );
+       CLEAN_FILE ( bootcdReactos );
+       string reactosInf = PassThruCacheDirectory (
+               NormalizeFilename ( bootcdReactosNoFixup + SSEP "reactos.inf" ),
+               backend->outputDirectory );
+       string reactosDff = NormalizeFilename ( "bootdata" SSEP "packages" SSEP "reactos.dff" );
+       string cdDirectories = GetCdDirectories ( bootcdDirectory );
+       vector<string> vCdFiles;
+       GetCdFiles ( vCdFiles );
+       string cdFiles = v2s ( vCdFiles, 5 );
+
+       fprintf ( fMakefile, ".PHONY: %s\n\n",
+                 module.name.c_str ());
+       fprintf ( fMakefile,
+                 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
+                 module.name.c_str (),
+                 isoboot.c_str (),
+                 bootcdReactos.c_str (),
+                 cdDirectories.c_str (),
+                 cdFiles.c_str () );
+       fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
+       fprintf ( fMakefile,
+                 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
+                 reactosDff.c_str (),
+                 bootcdReactos.c_str () );
+       fprintf ( fMakefile,
+                 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
+                 reactosDff.c_str (),
+                 reactosInf.c_str (),
+                 bootcdReactos.c_str ());
+       fprintf ( fMakefile,
+                 "\t-@${rm} %s 2>$(NUL)\n",
+                 reactosInf.c_str () );
+       OutputBootstrapfileCopyCommands ( bootcdDirectory );
+       OutputCdfileCopyCommands ( bootcdDirectory );
+       fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
+       fprintf ( fMakefile,
+                 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
+                 isoboot.c_str (),
+                 bootcd.c_str () );
+       fprintf ( fMakefile,
+                 "\n" );
+}
+
+
+MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwLiveIsoModuleHandler::Process ()
+{
+       GenerateLiveIsoModuleTarget ();
+}
+
+void
+MingwLiveIsoModuleHandler::CreateDirectory ( const string& directory )
+{
+       string normalizedDirectory = MingwModuleHandler::PassThruCacheDirectory (
+               NormalizeFilename ( directory ) + SSEP,
+               backend->outputDirectory );
+}
+
+void
+MingwLiveIsoModuleHandler::OutputCopyCommand ( const string& sourceFilename,
+                                               const string& targetFilename,
+                                               const string& targetDirectory )
+{
+       string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
+               NormalizeFilename ( targetDirectory + SSEP + targetFilename ),
+               backend->outputDirectory );
+       fprintf ( fMakefile,
+                 "\t$(ECHO_CP)\n" );
+       fprintf ( fMakefile,
+                 "\t${cp} %s %s 1>$(NUL)\n",
+                 sourceFilename.c_str (),
+                 normalizedTargetFilename.c_str () );
+}
+
+void
+MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string& livecdDirectory,
+                                                      string& reactosDirectory )
+{
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       {
+               const Module& m = *module.project.modules[i];
+               if ( !m.enabled )
+                       continue;
+               if ( m.installName.length () > 0 )
+               {
+                       const Module& aliasedModule = backend->GetAliasedModuleOrModule ( m  );
+                       string sourceFilename = MingwModuleHandler::PassThruCacheDirectory (
+                               NormalizeFilename ( aliasedModule.GetPath () ),
+                               backend->outputDirectory );
+                       OutputCopyCommand ( sourceFilename,
+                                           m.installName,
+                                           livecdDirectory + SSEP + reactosDirectory + SSEP + m.installBase );
+               }
+       }
+}
+
+void
+MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string& livecdDirectory,
+                                                         string& reactosDirectory )
+{
+       for ( size_t i = 0; i < module.project.installfiles.size (); i++ )
+       {
+               const InstallFile& installfile = *module.project.installfiles[i];
+               OutputCopyCommand ( installfile.GetPath (),
+                               installfile.newname,
+                               livecdDirectory + SSEP + reactosDirectory + SSEP + installfile.base );
+       }
+}
+
+void
+MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string& livecdDirectory )
+{
+       CreateDirectory ( livecdDirectory + SSEP "Profiles" );
+       CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users") ;
+       CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users" SSEP "Desktop" );
+       CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" );
+       CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "Desktop" );
+       CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "My Documents" );
+
+       string livecdIni = "bootdata" SSEP "livecd.ini";
+       OutputCopyCommand ( livecdIni,
+                        "freeldr.ini",
+                        livecdDirectory );
+}
+
+void
+MingwLiveIsoModuleHandler::OutputLoaderCommands ( string& livecdDirectory )
+{
+       string freeldr = PassThruCacheDirectory (
+               NormalizeFilename ( "boot" SSEP "freeldr" SSEP "freeldr" SSEP "freeldr.sys" ),
+               backend->outputDirectory );
+       CreateDirectory ( livecdDirectory + SSEP "loader" );
+       OutputCopyCommand ( freeldr,
+                        "setupldr.sys",
+                        livecdDirectory + SSEP + "loader" );
+}
+
+void
+MingwLiveIsoModuleHandler::OutputRegistryCommands ( string& livecdDirectory )
+{
+       string reactosSystem32ConfigDirectory = NormalizeFilename (
+               MingwModuleHandler::PassThruCacheDirectory (
+               livecdDirectory + SSEP "reactos" SSEP "system32" SSEP "config" SSEP,
+               backend->outputDirectory ) );
+       fprintf ( fMakefile,
+                 "\t$(ECHO_MKHIVE)\n" );
+       fprintf ( fMakefile,
+                 "\t$(MKHIVE_TARGET) bootdata %s bootdata" SSEP "livecd.inf bootdata" SSEP "hiveinst.inf\n",
+                 reactosSystem32ConfigDirectory.c_str () );
+}
+
+void
+MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
+{
+       string livecdDirectory = "livecd";
+       string livecd = PassThruCacheDirectory (
+               NormalizeFilename ( livecdDirectory + SSEP ),
+               backend->outputDirectory );
+       string isoboot = PassThruCacheDirectory (
+               NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
+               backend->outputDirectory );
+       string reactosDirectory = "reactos";
+       string livecdReactosNoFixup = livecdDirectory + SSEP + reactosDirectory;
+       string livecdReactos = NormalizeFilename ( PassThruCacheDirectory (
+               NormalizeFilename ( livecdReactosNoFixup + SSEP ),
+               backend->outputDirectory ) );
+       CLEAN_FILE ( livecdReactos );
+
+       fprintf ( fMakefile, ".PHONY: %s\n\n",
+                 module.name.c_str ());
+       fprintf ( fMakefile,
+                 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
+                 module.name.c_str (),
+                 isoboot.c_str (),
+                 livecdReactos.c_str () );
+       OutputModuleCopyCommands ( livecdDirectory,
+                                  reactosDirectory );
+       OutputNonModuleCopyCommands ( livecdDirectory,
+                                     reactosDirectory );
+       OutputProfilesDirectoryCommands ( livecdDirectory );
+       OutputLoaderCommands ( livecdDirectory );
+       OutputRegistryCommands ( livecdDirectory );
+       fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
+       fprintf ( fMakefile,
+                 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS ReactOS-LiveCD.iso\n",
+                 isoboot.c_str (),
+                 livecd.c_str () );
+       fprintf ( fMakefile,
+                 "\n" );
+}
+
+
+MingwTestModuleHandler::MingwTestModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwTestModuleHandler::Process ()
+{
+       GenerateTestModuleTarget ();
+}
+
+void
+MingwTestModuleHandler::GetModuleSpecificSourceFiles ( vector<File*>& sourceFiles )
+{
+       string basePath = "$(INTERMEDIATE)" SSEP + module.GetBasePath ();
+       sourceFiles.push_back ( new File ( basePath + SSEP "_hooks.c", false, "", false ) );
+       sourceFiles.push_back ( new File ( basePath + SSEP "_stubs.S", false, "", false ) );
+       sourceFiles.push_back ( new File ( basePath + SSEP "_startup.c", false, "", false ) );
+}
+
+void
+MingwTestModuleHandler::GenerateTestModuleTarget ()
+{
+       string targetMacro ( GetTargetMacro ( module ) );
+       string workingDirectory = GetWorkingDirectory ( );
+       string objectsMacro = GetObjectsMacro ( module );
+       string linkDepsMacro = GetLinkingDependenciesMacro ();
+       string libsMacro = GetLibsMacro ();
+
+       GenerateImportLibraryTargetIfNeeded ();
+
+       if ( module.non_if_data.files.size () > 0 )
+       {
+               GenerateRules ();
+
+               string dependencies = linkDepsMacro + " " + objectsMacro;
+
+               string linker;
+               if ( module.cplusplus )
+                       linker = "${gpp}";
+               else
+                       linker = "${gcc}";
+
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
+                                                    module.entrypoint.c_str (),
+                                                    module.baseaddress.c_str () );
+               GenerateLinkerCommand ( dependencies,
+                                       linker,
+                                       linkerParameters,
+                                       objectsMacro,
+                                       libsMacro );
+       }
+       else
+       {
+               GeneratePhonyTarget();
+       }
+}
+
+
+MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwRpcServerModuleHandler::Process ()
+{
+       GenerateRules ();
+}
+
+
+MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwRpcClientModuleHandler::Process ()
+{
+       GenerateRules ();
+}
+
+
+MingwAliasModuleHandler::MingwAliasModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwAliasModuleHandler::Process ()
+{
+}