adjust newlines around rsym command
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.cpp
index 8923afd..62f2891 100644 (file)
@@ -24,7 +24,7 @@ MingwModuleHandler::fMakefile = NULL;
 \r
 string\r
 ReplaceExtension ( const string& filename,\r
-                      const string& newExtension )\r
+                   const string& newExtension )\r
 {\r
        size_t index = filename.find_last_of ( '/' );\r
        if (index == string::npos) index = 0;\r
@@ -53,10 +53,10 @@ MingwModuleHandler::~MingwModuleHandler()
 }\r
 \r
 const string &\r
-MingwModuleHandler::PassThruCacheDirectory( const string &file ) const \r
+MingwModuleHandler::PassThruCacheDirectory ( const string &file ) const \r
 {\r
-    directory_set.insert( ReplaceExtension( GetDirectory( file ), "" ) );\r
-    return file;\r
+       directory_set.insert ( GetDirectory ( file ) );\r
+       return file;\r
 }\r
 \r
 void\r
@@ -86,21 +86,11 @@ MingwModuleHandler::GetWorkingDirectory () const
        return ".";\r
 }\r
 \r
-string\r
-MingwModuleHandler::GetDirectory ( const string& filename )\r
-{\r
-       size_t index = filename.find_last_of ( CSEP );\r
-       if (index == string::npos)\r
-               return ".";\r
-       else\r
-               return filename.substr ( 0, index );\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
+       if ( index != string::npos )\r
                return filename.substr ( 0, index );\r
        return "";\r
 }\r
@@ -111,7 +101,7 @@ MingwModuleHandler::GetActualSourceFilename ( const string& filename ) const
        string extension = GetExtension ( filename );\r
        if ( extension == ".spec" || extension == "SPEC" )\r
        {\r
-               string basename = GetBasename( filename );\r
+               string basename = GetBasename ( filename );\r
                return basename + ".stubs.c";\r
        }\r
        else\r
@@ -187,7 +177,7 @@ MingwModuleHandler::GetAllDependencies ( const Module& module ) const
 {\r
        string dependencies = GetImportLibraryDependencies ( module );\r
        string s = GetModuleDependencies ( module );\r
-       if (s.length () > 0)\r
+       if ( s.length () > 0 )\r
        {\r
                dependencies += " ";\r
                dependencies += s;\r
@@ -208,13 +198,13 @@ MingwModuleHandler::GetSourceFilenames ( const Module& module,
                        sourceFilenames += " " + GetActualSourceFilename ( module.files[i]->name );\r
        }\r
        vector<If*> ifs = module.ifs;\r
-       for ( i = 0; i < ifs.size(); i++ )\r
+       for ( i = 0; i < ifs.size (); i++ )\r
        {\r
                size_t j;\r
                If& rIf = *ifs[i];\r
-               for ( j = 0; j < rIf.ifs.size(); j++ )\r
+               for ( j = 0; j < rIf.ifs.size (); j++ )\r
                        ifs.push_back ( rIf.ifs[j] );\r
-               for ( j = 0; j < rIf.files.size(); j++ )\r
+               for ( j = 0; j < rIf.files.size (); j++ )\r
                {\r
                        if ( includeGeneratedFiles || !IsGeneratedFile ( *rIf.files[j] ) )\r
                                sourceFilenames += " " + GetActualSourceFilename ( rIf.files[j]->name );\r
@@ -248,8 +238,7 @@ MingwModuleHandler::GetObjectFilename ( const string& sourceFilename )
                newExtension = ".stubs.o";\r
        else\r
                newExtension = ".o";\r
-       return FixupTargetFilename (\r
-                       ReplaceExtension ( sourceFilename, newExtension ) );\r
+       return FixupTargetFilename ( ReplaceExtension ( sourceFilename, newExtension ) );\r
 }\r
 \r
 string\r
@@ -268,35 +257,54 @@ MingwModuleHandler::GetObjectFilenames ( const Module& module ) const
        return objectFilenames;\r
 }\r
 \r
+bool\r
+MingwModuleHandler::IncludeDirectoryTarget ( const string& directory ) const\r
+{\r
+       if ( directory == "$(ROS_INTERMEDIATE)." SSEP "tools")\r
+               return false;\r
+       else\r
+               return true;\r
+}\r
+\r
 void\r
-MingwModuleHandler::GenerateDirectoryTargets() const \r
+MingwModuleHandler::GenerateDirectoryTargets () const\r
 {\r
+       if ( directory_set.size () == 0 )\r
+               return;\r
+       \r
        set_string::iterator i;\r
-       fprintf( fMakefile, "ifneq ($(ROS_INTERMEDIATE),)\ndirectories::" );\r
+       fprintf ( fMakefile, "directories::" );\r
 \r
-       for ( i = directory_set.begin();\r
-             i != directory_set.end();\r
+       for ( i = directory_set.begin ();\r
+             i != directory_set.end ();\r
              i++ )\r
        {\r
-               fprintf ( fMakefile, " %s", i->c_str() );\r
+               if ( IncludeDirectoryTarget ( *i ) )\r
+               {\r
+                       fprintf ( fMakefile,\r
+                                 " %s",\r
+                                 i->c_str () );\r
+               }\r
        }\r
 \r
-       fprintf( fMakefile, "\n\n" );\r
+       fprintf ( fMakefile, "\n\n" );\r
 \r
-       for ( i = directory_set.begin();\r
-             i != directory_set.end();\r
+       for ( i = directory_set.begin ();\r
+             i != directory_set.end ();\r
              i++ )\r
        {\r
-               fprintf ( fMakefile, "%s ", i->c_str() );\r
+               if ( IncludeDirectoryTarget ( *i ) )\r
+               {\r
+                       fprintf ( fMakefile,\r
+                                 "%s ",\r
+                                 i->c_str () );\r
+               }\r
        }\r
 \r
        fprintf ( fMakefile, \r
-                 "::\n\t${mkdir} $@\n\n"\r
-                 "else\n"\r
-                 "directories::\n\n"\r
-                 "endif\n\n" );\r
+                 "::\n\t${mkdir} $@\n\n" );\r
 \r
-       directory_set.clear();\r
+       directory_set.clear ();\r
 }\r
 \r
 string\r
@@ -351,7 +359,7 @@ MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Includ
        for ( size_t i = 0; i < includes.size (); i++ )\r
        {\r
                Include& include = *includes[i];\r
-               if (parameters.length () > 0)\r
+               if ( parameters.length () > 0 )\r
                        parameters += " ";\r
                parameters += "-I" + include.directory;\r
        }\r
@@ -473,7 +481,7 @@ MingwModuleHandler::GenerateMacros (
 {\r
        size_t i;\r
 \r
-       if ( includes.size() || defines.size() )\r
+       if ( includes.size () > 0 || defines.size () > 0 )\r
        {\r
                GenerateMacro ( assignmentOperation,\r
                                cflags_macro,\r
@@ -501,9 +509,9 @@ MingwModuleHandler::GenerateMacros (
                }\r
        }\r
        \r
-       if ( files.size() )\r
+       if ( files.size () > 0 )\r
        {\r
-               for ( i = 0; i < files.size(); i++ )\r
+               for ( i = 0; i < files.size (); i++ )\r
                {\r
                        if ( files[i]->first )\r
                        {\r
@@ -517,14 +525,11 @@ MingwModuleHandler::GenerateMacros (
                fprintf (\r
                        fMakefile,\r
                        "%s %s",\r
-                       objs_macro.c_str(),\r
+                       objs_macro.c_str (),\r
                        assignmentOperation );\r
                for ( i = 0; i < files.size(); i++ )\r
                {\r
-                       string extension = GetExtension ( files[i]->name );\r
-                       if ( extension != ".spec"\r
-                         && extension != ".SPEC"\r
-                         && !files[i]->first )\r
+                       if ( !files[i]->first )\r
                        {\r
                                fprintf (\r
                                        fMakefile,\r
@@ -668,16 +673,34 @@ MingwModuleHandler::GenerateWindresCommand ( const Module& module,
                                              const string& windresflagsMacro ) const\r
 {\r
        string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
+  string rciFilename = ReplaceExtension ( sourceFilename,\r
+                                          ".rci" );\r
+  string resFilename = ReplaceExtension ( sourceFilename,\r
+                                          ".res" );\r
        fprintf ( fMakefile,\r
                  "%s: %s\n",\r
                  objectFilename.c_str (),\r
                  sourceFilename.c_str () );\r
        fprintf ( fMakefile,\r
-                "\t%s %s -o %s ${%s}\n",\r
-                "${windres}",\r
+                "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",\r
+                windresflagsMacro.c_str (),\r
                 sourceFilename.c_str (),\r
-                objectFilename.c_str (),\r
-                windresflagsMacro.c_str () );\r
+                rciFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${wrc} ${%s} %s %s\n",\r
+           windresflagsMacro.c_str (),\r
+                rciFilename.c_str (),\r
+                resFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${rm} %s\n",\r
+                rciFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${windres} %s -o %s\n",\r
+                resFilename.c_str (),\r
+                objectFilename.c_str () );\r
+       fprintf ( fMakefile,\r
+                "\t${rm} %s\n",\r
+                resFilename.c_str () );\r
 }\r
 \r
 void\r
@@ -724,7 +747,9 @@ MingwModuleHandler::GenerateCommands ( const Module& module,
                                     cflagsMacro );\r
                return;\r
        }\r
-       else if ( extension == ".cc" || extension == ".CC" || extension == ".cxx" || extension == ".CXX" )\r
+       else if ( extension == ".cc" || extension == ".CC" ||\r
+                 extension == ".cpp" || extension == ".CPP" ||\r
+                 extension == ".cxx" || extension == ".CXX" )\r
        {\r
                GenerateGccCommand ( module,\r
                                     sourceFilename,\r
@@ -832,7 +857,7 @@ MingwModuleHandler::GenerateLinkerCommand ( const Module& module,
        else\r
        {\r
                fprintf ( fMakefile,\r
-                         "\t%s %s -o %s %s %s %s\n\n",\r
+                         "\t%s %s -o %s %s %s %s\n",\r
                          linker.c_str (),\r
                          linkerParameters.c_str (),\r
                          target.c_str (),\r
@@ -840,6 +865,11 @@ MingwModuleHandler::GenerateLinkerCommand ( const Module& module,
                          importLibraryDependencies.c_str (),\r
                          GetLinkerMacro ( module ).c_str () );\r
        }\r
+\r
+       fprintf ( fMakefile,\r
+                     "\t${rsym} %s %s\n\n",\r
+                     target.c_str (),\r
+                     target.c_str () );\r
 }\r
 \r
 void\r
@@ -1019,14 +1049,16 @@ MingwModuleHandler::GenerateMacrosAndTargets (
        clean_files.push_back ( ar_target );\r
        GetCleanTargets ( clean_files, module.files, module.ifs );\r
 \r
-       fprintf ( fMakefile, "clean::\n\t-@$(rm)" );\r
+       fprintf ( fMakefile, ".PHONY: %s_clean\n", module.name.c_str() );\r
+       fprintf ( fMakefile, "%s_clean:\n\t-@$(rm)", module.name.c_str() );\r
        for ( size_t i = 0; i < clean_files.size(); i++ )\r
        {\r
                if ( 9==(i%10) )\r
                        fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );\r
                fprintf ( fMakefile, " %s", clean_files[i].c_str() );\r
        }\r
-       fprintf ( fMakefile, " 2>$(NUL)\n\n" );\r
+       fprintf ( fMakefile, " 2>$(NUL)\n" );\r
+       fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );\r
 }\r
 \r
 void\r
@@ -1078,40 +1110,6 @@ MingwModuleHandler::GetInvocationDependencies ( const Module& module ) const
        return dependencies;\r
 }\r
 \r
-string\r
-MingwModuleHandler::GetInvocationParameters ( const Invoke& invoke ) const\r
-{\r
-       string parameters ( "" );\r
-       size_t i;\r
-       for (i = 0; i < invoke.output.size (); i++)\r
-       {\r
-               if (parameters.length () > 0)\r
-                       parameters += " ";\r
-               InvokeFile& invokeFile = *invoke.output[i];\r
-               if (invokeFile.switches.length () > 0)\r
-               {\r
-                       parameters += invokeFile.switches;\r
-                       parameters += " ";\r
-               }\r
-               parameters += invokeFile.name;\r
-       }\r
-\r
-       for (i = 0; i < invoke.input.size (); i++)\r
-       {\r
-               if (parameters.length () > 0)\r
-                       parameters += " ";\r
-               InvokeFile& invokeFile = *invoke.input[i];\r
-               if (invokeFile.switches.length () > 0)\r
-               {\r
-                       parameters += invokeFile.switches;\r
-                       parameters += " ";\r
-               }\r
-               parameters += invokeFile.name ;\r
-       }\r
-\r
-       return parameters;\r
-}\r
-\r
 void\r
 MingwModuleHandler::GenerateInvocations ( const Module& module ) const\r
 {\r
@@ -1143,7 +1141,7 @@ MingwModuleHandler::GenerateInvocations ( const Module& module ) const
                fprintf ( fMakefile,\r
                          "\t%s %s\n\n",\r
                          FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),\r
-                         GetInvocationParameters ( invoke ).c_str () );\r
+                         invoke.GetParameters ().c_str () );\r
        }\r
 }\r
 \r
@@ -1154,13 +1152,31 @@ MingwModuleHandler::GetPreconditionDependenciesName ( const Module& module ) con
                          module.name.c_str () );\r
 }\r
 \r
+string\r
+MingwModuleHandler::GetDefaultDependencies ( const Module& module ) const\r
+{\r
+       /* Avoid circular dependency */\r
+       if ( module.type == BuildTool || module.name == "zlib" )\r
+               return "$(ROS_INTERMEDIATE)." SSEP "tools $(ROS_INTERMEDIATE)." SSEP "lib" SSEP "zlib";\r
+       else\r
+               return "init";\r
+}\r
+\r
 void\r
 MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) const\r
 {\r
        string preconditionDependenciesName = GetPreconditionDependenciesName ( module );\r
        string sourceFilenames = GetSourceFilenamesWithoutGeneratedFiles ( module );\r
-       string dependencies = GetModuleDependencies ( module );\r
-       string s = GetInvocationDependencies ( module );\r
+       string dependencies = GetDefaultDependencies ( module );\r
+       string s = GetModuleDependencies ( module );\r
+       if ( s.length () > 0 )\r
+       {\r
+               if ( dependencies.length () > 0 )\r
+                       dependencies += " ";\r
+               dependencies += s;\r
+       }\r
+\r
+       s = GetInvocationDependencies ( module );\r
        if ( s.length () > 0 )\r
        {\r
                if ( dependencies.length () > 0 )\r
@@ -1232,6 +1248,9 @@ string
 MingwModuleHandler::GetDefinitionDependencies ( const Module& module ) const\r
 {\r
        string dependencies;\r
+       string dkNkmLibNoFixup = "dk/nkm/lib";\r
+       dependencies += FixupTargetFilename ( dkNkmLibNoFixup );\r
+       PassThruCacheDirectory ( dkNkmLibNoFixup + SSEP );\r
        for ( size_t i = 0; i < module.files.size (); i++ )\r
        {\r
                File& file = *module.files[i];\r
@@ -1259,6 +1278,18 @@ MingwModuleHandler::GetLinkingDependencies ( const Module& module ) const
        return dependencies;\r
 }\r
 \r
+bool\r
+MingwModuleHandler::IsCPlusPlusModule ( const Module& module ) const\r
+{\r
+       if ( module.HasFileWithExtensions ( ".cc", ".CC" ) )\r
+               return true;\r
+       if ( module.HasFileWithExtensions ( ".cxx", ".CXX" ) )\r
+               return true;\r
+       if ( module.HasFileWithExtensions ( ".cpp", ".CPP" ) )\r
+               return true;\r
+       return false;\r
+}\r
+\r
 \r
 static MingwBuildToolModuleHandler buildtool_handler;\r
 \r
@@ -1279,27 +1310,27 @@ void
 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module& module )\r
 {\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateMacrosAndTargetsHost ( module );\r
 \r
        string linker;\r
-       if ( module.HasFileWithExtensions ( ".cxx", ".CXX" ) )\r
+       if ( IsCPlusPlusModule ( module ) )\r
                linker = "${host_gpp}";\r
        else\r
                linker = "${host_gcc}";\r
        \r
        fprintf ( fMakefile, "%s: %s %s\n",\r
                  target.c_str (),\r
-                 archiveFilename.c_str (),\r
+                 objectsMacro.c_str (),\r
                  importLibraryDependencies.c_str () );\r
        fprintf ( fMakefile,\r
                  "\t%s %s -o %s %s %s\n\n",\r
                  linker.c_str (),\r
                  GetLinkerMacro ( module ).c_str (),\r
                  target.c_str (),\r
-                 archiveFilename.c_str (),\r
+                 objectsMacro.c_str (),\r
                  importLibraryDependencies.c_str () );\r
 }\r
 \r
@@ -1331,9 +1362,10 @@ MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )
        string base_tmp = ros_junk + module.name + ".base.tmp";\r
        string junk_tmp = ros_junk + module.name + ".junk.tmp";\r
        string temp_exp = ros_junk + module.name + ".temp.exp";\r
-       string gccOptions = ssprintf ("-Wl,-T,%s" SSEP "ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,0xC0000000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\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.entrypoint.c_str (),\r
+                                     module.baseaddress.c_str () );\r
 \r
        GenerateMacrosAndTargetsTarget ( module );\r
 \r
@@ -1373,8 +1405,12 @@ MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )
                  objectsMacro.c_str (),\r
                  importLibraryDependencies.c_str () );\r
        fprintf ( fMakefile,\r
-                 "\t${rm} %s\n\n",\r
+                 "\t${rm} %s\n",\r
                  temp_exp.c_str () );\r
+       fprintf ( fMakefile,\r
+                     "\t${rsym} %s %s\n\n",\r
+                     target.c_str (),\r
+                     target.c_str () );\r
 }\r
 \r
 \r
@@ -1443,7 +1479,7 @@ MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Modul
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1454,15 +1490,16 @@ MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Modul
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         archiveFilename.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
-                                                    module.entrypoint.c_str () );\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
                GenerateLinkerCommand ( module,\r
                                        "${gcc}",\r
                                        linkerParameters,\r
-                                       archiveFilename );\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
@@ -1495,8 +1532,8 @@ MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const
 {\r
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( PassThruCacheDirectory( FixupTargetFilename ( module.GetPath () ) ) );\r
-       string workingDirectory = GetWorkingDirectory ( );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string workingDirectory = GetWorkingDirectory ();\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1511,15 +1548,16 @@ MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         archiveFilename.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
-                                                    module.entrypoint.c_str () );\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
                GenerateLinkerCommand ( module,\r
                                        "${gcc}",\r
                                        linkerParameters,\r
-                                       archiveFilename );\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
@@ -1552,8 +1590,7 @@ MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module& modul
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string objectFilenames = GetObjectFilenames ( module );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
        \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1564,15 +1601,16 @@ MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module& modul
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         archiveFilename.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",\r
-                                                    module.entrypoint.c_str () );\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
                GenerateLinkerCommand ( module,\r
                                        "${gcc}",\r
                                        linkerParameters,\r
-                                       objectFilenames );\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
@@ -1605,8 +1643,7 @@ MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module& modul
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string objectFilenames = GetObjectFilenames ( module );\r
-       string archiveFilename = GetModuleArchiveFilename ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
        \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1621,15 +1658,16 @@ MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module& modul
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         archiveFilename.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",\r
-                                                    module.entrypoint.c_str () );\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
                GenerateLinkerCommand ( module,\r
                                        "${gcc}",\r
                                        linkerParameters,\r
-                                       objectFilenames );\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
@@ -1684,7 +1722,7 @@ MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module& module
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string objectFilenames = GetObjectFilenames ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string linkingDependencies = GetLinkingDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1694,21 +1732,22 @@ MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module& module
        \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         objectFilenames.c_str (),\r
+                         objectsMacro.c_str (),\r
                          linkingDependencies.c_str () );\r
 \r
                string linker;\r
-               if ( module.HasFileWithExtensions ( ".cc", ".CC" ) || module.HasFileWithExtensions ( ".cxx", ".CXX" ) )\r
+               if ( IsCPlusPlusModule ( module ) )\r
                        linker = "${gpp}";\r
                else\r
                        linker = "${gcc}";\r
 \r
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",\r
-                                                   module.entrypoint.c_str () );\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
                GenerateLinkerCommand ( module,\r
                                        linker,\r
                                        linkerParameters,\r
-                                       objectFilenames );\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
@@ -1741,7 +1780,7 @@ MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module& module
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string objectFilenames = GetObjectFilenames ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1752,15 +1791,22 @@ MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module& module
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         objectFilenames.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,0x00400000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",\r
-                                                    module.entrypoint.c_str () );\r
+               string linker;\r
+               if ( IsCPlusPlusModule ( module ) )\r
+                       linker = "${gpp}";\r
+               else\r
+                       linker = "${gcc}";\r
+\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
                GenerateLinkerCommand ( module,\r
-                                       "${gcc}",\r
+                                       linker,\r
                                        linkerParameters,\r
-                                       objectFilenames );\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
@@ -1793,7 +1839,7 @@ MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module& module
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ( );\r
-       string objectFilenames = GetObjectFilenames ( module );\r
+       string objectsMacro = GetObjectsMacro ( module );\r
        string importLibraryDependencies = GetImportLibraryDependencies ( module );\r
 \r
        GenerateImportLibraryTargetIfNeeded ( module );\r
@@ -1804,15 +1850,22 @@ MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module& module
 \r
                fprintf ( fMakefile, "%s: %s %s\n",\r
                          target.c_str (),\r
-                         objectFilenames.c_str (),\r
+                         objectsMacro.c_str (),\r
                          importLibraryDependencies.c_str () );\r
 \r
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,0x00400000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",\r
-                                                    module.entrypoint.c_str () );\r
+               string linker;\r
+               if ( IsCPlusPlusModule ( module ) )\r
+                       linker = "${gpp}";\r
+               else\r
+                       linker = "${gcc}";\r
+\r
+               string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",\r
+                                                    module.entrypoint.c_str (),\r
+                                                    module.baseaddress.c_str () );\r
                GenerateLinkerCommand ( module,\r
-                                       "${gcc}",\r
+                                       linker,\r
                                        linkerParameters,\r
-                                       objectFilenames );\r
+                                       objectsMacro );\r
        }\r
        else\r
        {\r
@@ -1844,7 +1897,7 @@ MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ( const Module& mod
 {\r
        static string ros_junk ( "$(ROS_TEMPORARY)" );\r
        string targetName ( module.GetTargetName () );\r
-       string target ( FixupTargetFilename (module.GetPath ()) );\r
+       string target ( FixupTargetFilename ( module.GetPath () ) );\r
        string workingDirectory = GetWorkingDirectory ();\r
        string junk_tmp = ros_junk + module.name + ".junk.tmp";\r
        string objectsMacro = GetObjectsMacro ( module );\r
@@ -1922,31 +1975,174 @@ MingwIsoModuleHandler::Process ( const Module& module )
        GenerateInvocations ( module );\r
 }\r
 \r
+void\r
+MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory,\r
+                                                            const Module& module ) const\r
+{\r
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
+       {\r
+               const Module& m = *module.project.modules[i];\r
+               if ( m.bootstrap != NULL )\r
+               {\r
+                       string targetFilenameNoFixup = bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd;\r
+                       string targetFilename = PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup ) );\r
+                       fprintf ( fMakefile,\r
+                                 "\t${cp} %s %s\n",\r
+                                 m.GetPath ().c_str (),\r
+                                 targetFilename.c_str () );\r
+               }\r
+       }\r
+}\r
+\r
+void\r
+MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory,\r
+                                                     const Module& module ) const\r
+{\r
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
+       {\r
+               const CDFile& cdfile = *module.project.cdfiles[i];\r
+               string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;\r
+               string targetFilename = PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup ) );\r
+               fprintf ( fMakefile,\r
+                         "\t${cp} %s %s\n",\r
+                         cdfile.GetPath ().c_str (),\r
+                         targetFilename.c_str () );\r
+       }\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory,\r
+                                                      const Module& module ) const\r
+{\r
+       string directories;\r
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
+       {\r
+               const Module& m = *module.project.modules[i];\r
+               if ( m.bootstrap != NULL )\r
+               {\r
+                       string targetDirecctory = bootcdDirectory + SSEP + m.bootstrap->base;\r
+                       if ( directories.size () > 0 )\r
+                               directories += " ";\r
+                       directories += FixupTargetFilename ( targetDirecctory );\r
+               }\r
+       }\r
+       return directories;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory,\r
+                                                      const Module& module ) const\r
+{\r
+       string directories;\r
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
+       {\r
+               const CDFile& cdfile = *module.project.cdfiles[i];\r
+               string targetDirecctory = bootcdDirectory + SSEP + cdfile.base;\r
+               if ( directories.size () > 0 )\r
+                       directories += " ";\r
+               directories += FixupTargetFilename ( targetDirecctory );\r
+       }\r
+       return directories;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory,\r
+                                             const Module& module ) const\r
+{\r
+       string directories = GetBootstrapCdDirectories ( bootcdDirectory,\r
+                                                        module );\r
+       directories += " " + GetNonModuleCdDirectories ( bootcdDirectory,\r
+                                                        module );\r
+       return directories;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory,\r
+                                                const Module& module ) const\r
+{\r
+       string cdfiles;\r
+       for ( size_t i = 0; i < module.project.modules.size (); i++ )\r
+       {\r
+               const Module& m = *module.project.modules[i];\r
+               if ( m.bootstrap != NULL )\r
+               {\r
+                       if ( cdfiles.size () > 0 )\r
+                               cdfiles += " ";\r
+                       cdfiles += FixupTargetFilename ( m.GetPath () );\r
+               }\r
+       }\r
+       return cdfiles;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory,\r
+                                                const Module& module ) const\r
+{\r
+       string cdfiles;\r
+       for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )\r
+       {\r
+               const CDFile& cdfile = *module.project.cdfiles[i];\r
+               if ( cdfiles.size () > 0 )\r
+                       cdfiles += " ";\r
+               cdfiles += NormalizeFilename ( cdfile.GetPath () );\r
+       }\r
+       return cdfiles;\r
+}\r
+\r
+string\r
+MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory,\r
+                                       const Module& module ) const\r
+{\r
+       string cdfiles = GetBootstrapCdFiles ( bootcdDirectory,\r
+                                              module );\r
+       cdfiles += " " + GetNonModuleCdFiles ( bootcdDirectory,\r
+                                              module );\r
+       return cdfiles;\r
+}\r
+\r
 void\r
 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module& module )\r
 {\r
-       string isoboot = "$(ROS_INTERMEDIATE)" + FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );\r
+       string bootcdDirectory = "cd";\r
+       string isoboot = FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );\r
+       string bootcdReactosNoFixup = bootcdDirectory + "/reactos";\r
+       string bootcdReactos = FixupTargetFilename ( bootcdReactosNoFixup );\r
+       PassThruCacheDirectory ( bootcdReactos + SSEP );\r
+       string reactosInf = FixupTargetFilename ( bootcdReactosNoFixup + "/reactos.inf" );\r
+       string reactosDff = NormalizeFilename ( "bootdata/packages/reactos.dff" );\r
+       string cdDirectories = bootcdReactos + " " + GetCdDirectories ( bootcdDirectory,\r
+                                                                       module );\r
+       string cdFiles = GetCdFiles ( bootcdDirectory,\r
+                                     module );\r
 \r
        fprintf ( fMakefile, ".PHONY: %s\n\n",\r
                      module.name.c_str ());\r
        fprintf ( fMakefile,\r
-                 "%s: all %s\n",\r
+                 "%s: all %s %s %s\n",\r
                  module.name.c_str (),\r
-                 isoboot.c_str () );\r
+                 isoboot.c_str (),\r
+                 cdDirectories.c_str (),\r
+                 cdFiles.c_str () );\r
        fprintf ( fMakefile,\r
-                 "\t${cabman} /C %s /L $(ROS_INTERMEDIATE)%s /I\n",\r
-                 FixupTargetFilename ( "bootdata/packages/reactos.dff" ).c_str (),\r
-                 FixupTargetFilename ( "bootcd/reactos" ).c_str () );\r
+                 "\t${cabman} -C %s -L %s -I\n",\r
+                 reactosDff.c_str (),\r
+                 bootcdReactos.c_str () );\r
        fprintf ( fMakefile,\r
-                 "\t${cabman} /C %s /RC $(ROS_INTERMEDIATE)%s /L $(BOOTCD_DIR)reactos /N\n",\r
-                 FixupTargetFilename ( "bootdata/packages/reactos.dff" ).c_str (),\r
-                 FixupTargetFilename ( "bootcd/reactos/reactos.inf" ).c_str () );\r
+                 "\t${cabman} -C %s -RC %s -L %s -N\n",\r
+                 reactosDff.c_str (),\r
+                 reactosInf.c_str (),\r
+                 bootcdReactos.c_str () );\r
        fprintf ( fMakefile,\r
-                 "\t- ${rm} $(ROS_INTERMEDIATE)%s\n",\r
-                 FixupTargetFilename ( "bootcd/reactos/reactos.inf" ).c_str () );\r
+                 "\t- ${rm} %s\n",\r
+                 reactosInf.c_str () );\r
+       OutputBootstrapfileCopyCommands ( bootcdDirectory,\r
+                                         module );\r
+       OutputCdfileCopyCommands ( bootcdDirectory,\r
+                                  module );\r
        fprintf ( fMakefile,\r
-                 "\t${cdmake} -v -m -b %s $(ROS_INTERMEDIATE)bootcd REACTOS ReactOS.iso\n",\r
-                 isoboot.c_str () );\r
+                 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",\r
+                 isoboot.c_str (),\r
+                 bootcdDirectory.c_str () );\r
        fprintf ( fMakefile,\r
                  "\n" );\r
 }\r