- Properly set STDCALL as default convention, previous patch incorrectly set it as...
[reactos.git] / reactos / tools / rbuild / backend / msvc / vcprojmaker.cpp
index dd2463e..0b9c67a 100644 (file)
 using std::string;\r
 using std::vector;\r
 \r
+#ifdef OUT\r
+#undef OUT\r
+#endif//OUT\r
+\r
 void\r
 MSVCBackend::_generate_vcproj ( const Module& module )\r
 {\r
@@ -43,15 +47,28 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        FILE* OUT = fopen ( vcproj_file.c_str(), "wb" );\r
 \r
        vector<string> imports;\r
-       for ( i = 0; i < module.non_if_data.libraries.size(); i++ )\r
-       {\r
-               imports.push_back ( module.non_if_data.libraries[i]->name );\r
-       }\r
-\r
        string module_type = GetExtension(module.GetTargetName());\r
-       bool lib = (module_type == ".lib") || (module_type == ".a");\r
+       bool lib = (module.type == ObjectLibrary) || (module_type == ".lib") || (module_type == ".a");\r
        bool dll = (module_type == ".dll") || (module_type == ".cpl");\r
        bool exe = (module_type == ".exe");\r
+       bool sys = (module_type == ".sys");\r
+\r
+       string path_basedir = module.GetPathToBaseDir ();\r
+       string intenv = Environment::GetIntermediatePath ();\r
+       string outenv = Environment::GetOutputPath ();\r
+       string outdir;\r
+       string intdir;\r
+       \r
+       if ( intenv == "obj-i386" )\r
+               intdir = path_basedir + "obj-i386"; /* append relative dir from project dir */\r
+       else\r
+               intdir = intenv;\r
+\r
+       if ( outenv == "output-i386" )\r
+               outdir = path_basedir + "output-i386";\r
+       else\r
+               outdir = outenv;\r
+\r
        // TODO FIXME - need more checks here for 'sys' and possibly 'drv'?\r
 \r
        bool console = exe && (module.type == Win32CUI);\r
@@ -73,16 +90,20 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        //$progress_current++;\r
        //$output->progress("$dsp_file (file $progress_current of $progress_max)");\r
 \r
-       // TODO FIXME - what's diff. betw. 'c_srcs' and 'source_files'?\r
        string vcproj_path = module.GetBasePath();\r
-       vector<string> c_srcs, source_files, resource_files, includes, libraries, defines;\r
+       vector<string> source_files, resource_files, includes, libraries, defines;\r
        vector<const IfableData*> ifs_list;\r
        ifs_list.push_back ( &module.project.non_if_data );\r
        ifs_list.push_back ( &module.non_if_data );\r
 \r
+       // MinGW doesn't have a safe-string library yet\r
+       defines.push_back ( "_CRT_SECURE_NO_DEPRECATE" );\r
+       defines.push_back ( "_CRT_NON_CONFORMING_SWPRINTFS" );\r
        // this is a define in MinGW w32api, but not Microsoft's headers\r
        defines.push_back ( "STDCALL=__stdcall" );\r
 \r
+       string baseaddr;\r
+\r
        while ( ifs_list.size() )\r
        {\r
                const IfableData& data = *ifs_list.back();\r
@@ -96,11 +117,10 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                        // TODO FIXME - do we want the full path of the file here?\r
                        string file = string(".") + &files[i]->name[vcproj_path.size()];\r
 \r
-                       source_files.push_back ( file );\r
-                       if ( !stricmp ( Right(file,2).c_str(), ".c" ) )\r
-                               c_srcs.push_back ( file );\r
                        if ( !stricmp ( Right(file,3).c_str(), ".rc" ) )\r
                                resource_files.push_back ( file );\r
+            else\r
+                               source_files.push_back ( file );\r
                }\r
                const vector<Include*>& incs = data.includes;\r
                for ( i = 0; i < incs.size(); i++ )\r
@@ -121,7 +141,19 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                const vector<Library*>& libs = data.libraries;\r
                for ( i = 0; i < libs.size(); i++ )\r
                {\r
-                       libraries.push_back ( libs[i]->name + ".lib" );\r
+#if 0\r
+                       // this code is deactivated untill the tree builds fine with msvc\r
+                       // --- is appended to each library path which is later\r
+                       // replaced by the configuration\r
+                       // i.e. ../output-i386/lib/rtl/---/rtl.lib becomes\r
+                       //      ../output-i386/lib/rtl/Debug/rtl.lib \r
+                       // etc\r
+                       libs[i]->importedModule->\r
+                       string libpath = outdir + "\\" + libs[i]->importedModule->GetBasePath() + "\\---\\" + libs[i]->name + ".lib";\r
+                       libraries.push_back ( libpath );\r
+#else\r
+               libraries.push_back ( libs[i]->name + ".lib" );\r
+#endif\r
                }\r
                const vector<Define*>& defs = data.defines;\r
                for ( i = 0; i < defs.size(); i++ )\r
@@ -131,6 +163,12 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                        else\r
                                defines.push_back ( defs[i]->name );\r
                }\r
+               for ( i = 0; i < data.properties.size(); i++ )\r
+               {\r
+                       Property& prop = *data.properties[i];\r
+                       if ( strstr ( module.baseaddress.c_str(), prop.name.c_str() ) )\r
+                               baseaddr = prop.value;\r
+               }\r
        }\r
 \r
        vector<string> header_files;\r
@@ -140,7 +178,9 @@ MSVCBackend::_generate_vcproj ( const Module& module )
 \r
        std::vector<std::string> cfgs;\r
 \r
-       cfgs.push_back ( module.name + " - Win32" );\r
+       cfgs.push_back ( "Debug" );\r
+       cfgs.push_back ( "Release" );\r
+    cfgs.push_back ( "Speed" );\r
 \r
        if (!no_cpp)\r
        {\r
@@ -167,6 +207,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        }\r
 \r
        string default_cfg = cfgs.back();\r
+       string include_string;\r
 \r
        fprintf ( OUT, "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\r\n" );\r
        fprintf ( OUT, "<VisualStudioProject\r\n" );\r
@@ -177,6 +218,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
 \r
        fprintf ( OUT, "\tVersion=\"%s\"\r\n", configuration.VSProjectVersion.c_str() );\r
        fprintf ( OUT, "\tName=\"%s\"\r\n", module.name.c_str() );\r
+       fprintf ( OUT, "\tProjectGUID=\"%s\"\r\n", module.guid.c_str() ); \r
        fprintf ( OUT, "\tKeyword=\"Win32Proj\">\r\n" );\r
 \r
        fprintf ( OUT, "\t<Platforms>\r\n" );\r
@@ -184,6 +226,15 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        fprintf ( OUT, "\t\t\tName=\"Win32\"/>\r\n" );\r
        fprintf ( OUT, "\t</Platforms>\r\n" );\r
 \r
+       fprintf ( OUT, "\t<ToolFiles>\r\n" );\r
+       fprintf ( OUT, "\t\t<ToolFile\r\n" );\r
+\r
+       string path = Path::RelativeFromDirectory ( ProjectNode.name, module.GetBasePath() );\r
+       path.erase(path.find(ProjectNode.name, 0), ProjectNode.name.size() + 1);\r
+\r
+       fprintf ( OUT, "\t\t\tRelativePath=\"%sgccasm.rules\"/>\r\n", path.c_str() );\r
+       fprintf ( OUT, "\t</ToolFiles>\r\n" );\r
+\r
        int n = 0;\r
 \r
        std::string output_dir;\r
@@ -193,19 +244,22 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        {\r
                std::string& cfg = cfgs[icfg];\r
 \r
-               bool debug = !strstr ( cfg.c_str(), "Release" );\r
+               bool debug = strstr ( cfg.c_str(), "Debug" ) != NULL;\r
+               bool speed = strstr ( cfg.c_str(), "Speed" ) != NULL;\r
+               bool release = (!debug && !speed );\r
+\r
                //bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );\r
 \r
                fprintf ( OUT, "\t\t<Configuration\r\n" );\r
                fprintf ( OUT, "\t\t\tName=\"%s|Win32\"\r\n", cfg.c_str() );\r
-               fprintf ( OUT, "\t\t\tOutputDirectory=\"%s\"\r\n", cfg.c_str() );\r
-               fprintf ( OUT, "\t\t\tIntermediateDirectory=\"%s\"\r\n", cfg.c_str() );\r
+               fprintf ( OUT, "\t\t\tOutputDirectory=\"%s\\%s\\%s\"\r\n", outdir.c_str (), module.GetBasePath ().c_str (), cfg.c_str() );\r
+               fprintf ( OUT, "\t\t\tIntermediateDirectory=\"%s\\%s\\%s\"\r\n", intdir.c_str (), module.GetBasePath ().c_str (), cfg.c_str() );\r
                fprintf ( OUT, "\t\t\tConfigurationType=\"%d\"\r\n", exe ? 1 : dll ? 2 : lib ? 4 : -1 );\r
                fprintf ( OUT, "\t\t\tCharacterSet=\"2\">\r\n" );\r
 \r
                fprintf ( OUT, "\t\t\t<Tool\r\n" );\r
                fprintf ( OUT, "\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tOptimization=\"%d\"\r\n", debug ? 0 : 2 );\r
+               fprintf ( OUT, "\t\t\t\tOptimization=\"%d\"\r\n", release ? 2 : 0 );\r
 \r
                fprintf ( OUT, "\t\t\t\tAdditionalIncludeDirectories=\"" );\r
                bool multiple_includes = false;\r
@@ -217,7 +271,9 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                        {\r
                                if ( multiple_includes )\r
                                        fprintf ( OUT, ";" );\r
+\r
                                fprintf ( OUT, "%s", include.c_str() );\r
+                               include_string += " /I " + include;\r
                                multiple_includes = true;\r
                        }\r
                }\r
@@ -226,28 +282,20 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                if ( debug )\r
                {\r
                        defines.push_back ( "_DEBUG" );\r
-                       if ( lib || exe )\r
-                       {\r
-                               defines.push_back ( "_LIB" );\r
-                       }\r
-                       else\r
-                       {\r
-                               defines.push_back ( "_WINDOWS" );\r
-                               defines.push_back ( "_USRDLL" );\r
-                       }\r
                }\r
                else\r
                {\r
                        defines.push_back ( "NDEBUG" );\r
-                       if ( lib || exe )\r
-                       {\r
-                               defines.push_back ( "_LIB" );\r
-                       }\r
-                       else\r
-                       {\r
-                               defines.push_back ( "_WINDOWS" );\r
-                               defines.push_back ( "_USRDLL" );\r
-                       }\r
+               }\r
+\r
+               if ( lib || exe )\r
+               {\r
+                       defines.push_back ( "_LIB" );\r
+               }\r
+               else\r
+               {\r
+                       defines.push_back ( "_WINDOWS" );\r
+                       defines.push_back ( "_USRDLL" );\r
                }\r
 \r
                fprintf ( OUT, "\t\t\t\tPreprocessorDefinitions=\"" );\r
@@ -255,19 +303,46 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                {\r
                        if ( i > 0 )\r
                                fprintf ( OUT, ";" );\r
+\r
+                       defines[i] = _replace_str(defines[i], "\"","&quot;"); \r
                        fprintf ( OUT, "%s", defines[i].c_str() );\r
                }\r
                fprintf ( OUT, "\"\r\n" );\r
 \r
-               fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"TRUE\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"3\"\r\n" );\r
+               fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );\r
+        fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"%s\"\r\n", sys ? 0 : (debug ? "3" : "0") );\r
                fprintf ( OUT, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );\r
+        fprintf ( OUT, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", sys ? "FALSE" : (debug ? "TRUE" : "FALSE" ));\r
                fprintf ( OUT, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );\r
-               fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tWarningLevel=\"1\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"TRUE\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"4\"/>\r\n" );\r
+               \r
+               if ( module.pch != NULL )\r
+               {\r
+                       fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"2\"\r\n" );\r
+                       string pch_path = Path::RelativeFromDirectory (\r
+                               module.pch->file.name,\r
+                               module.GetBasePath() );\r
+                       fprintf ( OUT, "\t\t\t\tPrecompiledHeaderThrough=\"%s\"\r\n", pch_path.c_str() );\r
+               }\r
+               else\r
+               {\r
+                       fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );\r
+               }\r
+\r
+               fprintf ( OUT, "\t\t\t\tWholeProgramOptimization=\"%s\"\r\n", release ? "TRUE" : "FALSE");\r
+               if ( release )\r
+               {\r
+                       fprintf ( OUT, "\t\t\t\tFavorSizeOrSpeed=\"1\"\r\n" );\r
+                       fprintf ( OUT, "\t\t\t\tStringPooling=\"true\"\r\n" );\r
+               }\r
+\r
+               fprintf ( OUT, "\t\t\t\tEnablePREfast=\"%s\"\r\n", debug ? "TRUE" : "FALSE");\r
+               fprintf ( OUT, "\t\t\t\tDisableSpecificWarnings=\"4201;4127;4214\"\r\n" );\r
+               fprintf ( OUT, "\t\t\t\tWarningLevel=\"%s\"\r\n", speed ? "0" : "4" );\r
+               fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"%s\"\r\n", speed ? "FALSE" : "TRUE");\r
+               if ( !module.cplusplus )\r
+                       fprintf ( OUT, "\t\t\t\tCompileAs=\"1\"\r\n" );\r
+        fprintf ( OUT, "\t\t\t\tCallingConvention=\"%d\"\r\n", (sys || (exe && module.type == Kernel)) ? 2: 1);\r
+               fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"%s\"/>\r\n", speed ? "0" : "4");\r
 \r
                fprintf ( OUT, "\t\t\t<Tool\r\n" );\r
                fprintf ( OUT, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );\r
@@ -276,7 +351,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                {\r
                        fprintf ( OUT, "\t\t\t<Tool\r\n" );\r
                        fprintf ( OUT, "\t\t\t\tName=\"VCLibrarianTool\"\r\n" );\r
-                       fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s.%s\"/>\r\n", module.name.c_str(), module_type.c_str() );\r
+                       fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s.lib\"/>\r\n", module.name.c_str() );\r
                }\r
                else\r
                {\r
@@ -288,18 +363,65 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                        {\r
                                if ( i > 0 )\r
                                        fprintf ( OUT, " " );\r
+#if 0 \r
+                               // this code is deactivated untill \r
+                               // msvc can build the whole tree\r
+                               string libpath = libraries[i].c_str();\r
+                               libpath.replace (libpath.find("---"), //See HACK\r
+                                                    3,\r
+                                                                cfg);\r
+                               fprintf ( OUT, "%s", libpath.c_str() );\r
+#else\r
                                fprintf ( OUT, "%s", libraries[i].c_str() );\r
+#endif\r
                        }\r
                        fprintf ( OUT, "\"\r\n" );\r
 \r
-                       fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s.%s\"\r\n", module.name.c_str(), module_type.c_str() );\r
+                       fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s%s\"\r\n", module.name.c_str(), module_type.c_str() );\r
                        fprintf ( OUT, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug ? 2 : 1 );\r
-                       fprintf ( OUT, "\t\t\t\tGenerateDebugInformation=\"TRUE\"\r\n" );\r
+                       fprintf ( OUT, "\t\t\t\tGenerateDebugInformation=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );\r
 \r
                        if ( debug )\r
                                fprintf ( OUT, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module.name.c_str() );\r
 \r
-                       fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", console ? 1 : 2 );\r
+                       if ( sys )\r
+                       {\r
+                               fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /ALIGN:0x20 /SECTION:INIT,D /IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096\"\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", 3 );\r
+                               fprintf ( OUT, "\t\t\t\tDriver=\"%d\"\r\n", 1 );\r
+                               fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint == "" ? "DriverEntry" : module.entrypoint.c_str ());\r
+                               fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", baseaddr == "" ? "0x10000" : baseaddr.c_str ());       \r
+                       }\r
+                       else if ( exe )\r
+                       {\r
+                               if ( module.type == Kernel )\r
+                               {\r
+                                       fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /SECTION:INIT,D /ALIGN:0x80\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", 3 );\r
+                                       fprintf ( OUT, "\t\t\t\tDriver=\"%d\"\r\n", 1 );\r
+                                       fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"KiSystemStartup\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", baseaddr.c_str ());    \r
+                               }\r
+                               else if ( module.type == NativeCUI )\r
+                               {\r
+                                       fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /ALIGN:0x20\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", 1 );\r
+                                       fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"NtProcessStartup\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", baseaddr.c_str ());    \r
+                               }\r
+                               else if ( module.type == Win32CUI || module.type == Win32GUI )\r
+                               {\r
+                                       fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", console ? 1 : 2 );\r
+                               }\r
+                       }\r
+                       else if ( dll )\r
+                       {\r
+                               fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint == "" ? "DllMain" : module.entrypoint.c_str ());\r
+                               fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", baseaddr == "" ? "0x40000" : baseaddr.c_str ());\r
+                       }\r
                        fprintf ( OUT, "\t\t\t\tTargetMachine=\"%d\"/>\r\n", 1 );\r
                }\r
                \r
@@ -344,12 +466,53 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        // Source files\r
        fprintf ( OUT, "\t\t<Filter\r\n" );\r
        fprintf ( OUT, "\t\t\tName=\"Source Files\"\r\n" );\r
-       fprintf ( OUT, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\">\r\n" );\r
+       fprintf ( OUT, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;S\">\r\n" );\r
        for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )\r
        {\r
-               const string& source_file = DosSeparator(source_files[isrcfile]);\r
+               string source_file = DosSeparator(source_files[isrcfile]);\r
                fprintf ( OUT, "\t\t\t<File\r\n" );\r
                fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file.c_str() );\r
+\r
+               for ( size_t iconfig = 0; iconfig < cfgs.size(); iconfig++ )\r
+               {\r
+                       std::string& config = cfgs[iconfig];\r
+\r
+                       if (( isrcfile == 0 ) && ( module.pch != NULL ))\r
+                       {\r
+                               /* little hack to speed up PCH */\r
+                               fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t\tName=\"" );\r
+                               fprintf ( OUT, config.c_str() );\r
+                               fprintf ( OUT, "|Win32\">\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );\r
+                       }\r
+\r
+                       if (configuration.VSProjectVersion < "8.00") {\r
+                               if ((source_file.find(".idl") != string::npos) || ((source_file.find(".asm") != string::npos || tolower(source_file.at(source_file.size() - 1)) == 's')))\r
+                               {\r
+                                       fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\t\tName=\"" );\r
+                                       fprintf ( OUT, config.c_str() );\r
+                                       fprintf ( OUT, "|Win32\">\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );\r
+                                       if (source_file.find(".idl") != string::npos)\r
+                                       {\r
+                                               fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );\r
+                                               fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\(InputName).obj\"/>\r\n" );\r
+                                       }\r
+                                       else if ((source_file.find(".asm") != string::npos || tolower(source_file.at(source_file.size() - 1)) == 's'))\r
+                                       {\r
+                                               fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );\r
+                                               fprintf ( OUT, "\t\t\t\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; %s /D__ASM__ | as -o &quot;$(OutDir)\\(InputName).obj&quot;\"\r\n",include_string.c_str() );\r
+                                               fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\(InputName).obj\"/>\r\n" );\r
+                                       }\r
+                                       fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );\r
+                               }\r
+                       }\r
+               }\r
                fprintf ( OUT, "\t\t\t</File>\r\n" );\r
        }\r
        fprintf ( OUT, "\t\t</Filter>\r\n" );\r
@@ -371,7 +534,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        fprintf ( OUT, "\t\t<Filter\r\n" );\r
        fprintf ( OUT, "\t\t\tName=\"Resource Files\"\r\n" );\r
        fprintf ( OUT, "\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\r\n" );\r
-       for ( i = 0; i < header_files.size(); i++ )\r
+       for ( i = 0; i < resource_files.size(); i++ )\r
        {\r
                const string& resource_file = resource_files[i];\r
                fprintf ( OUT, "\t\t\t<File\r\n" );\r
@@ -387,24 +550,69 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        fclose(OUT);\r
 }\r
 \r
-void\r
-MSVCBackend::_generate_sln_header ( FILE* OUT )\r
+std::string\r
+MSVCBackend::_replace_str(std::string string1, const std::string &find_str, const std::string &replace_str)\r
 {\r
-    if (configuration.VSProjectVersion.empty())\r
-        configuration.VSProjectVersion = MS_VS_DEF_VERSION;\r
+        std::string::size_type pos = string1.find(find_str, 0);\r
+        int intLen = find_str.length();\r
+\r
+        while(std::string::npos != pos)\r
+        {\r
+                string1.replace(pos, intLen, replace_str);\r
+                pos = string1.find(find_str, intLen + pos);\r
+        }\r
+\r
+        return string1;\r
+} \r
 \r
+std::string\r
+MSVCBackend::_get_solution_verion ( void ) {\r
     string version;\r
 \r
+    if (configuration.VSProjectVersion.empty())\r
+        configuration.VSProjectVersion = MS_VS_DEF_VERSION;\r
+\r
     if (configuration.VSProjectVersion == "7.00")\r
-       version = "7.00";\r
+               version = "7.00";\r
 \r
     if (configuration.VSProjectVersion == "7.10")\r
-       version = "8.00";\r
+               version = "8.00";\r
 \r
     if (configuration.VSProjectVersion == "8.00")\r
-       version = "9.00";\r
+               version = "9.00";\r
 \r
-    fprintf ( OUT, "Microsoft Visual Studio Solution File, Format Version %s\r\n", version.c_str() );\r
+       return version;\r
+}\r
+\r
+\r
+void\r
+MSVCBackend::_generate_rules_file ( FILE* OUT )\r
+{\r
+       fprintf ( OUT, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" );\r
+       fprintf ( OUT, "<VisualStudioToolFile\r\n" );\r
+       fprintf ( OUT, "\tName=\"GCC Assembler\"\r\n" );\r
+       fprintf ( OUT, "\tVersion=\"%s\"\r\n", _get_solution_verion().c_str() );\r
+       fprintf ( OUT, "\t>\r\n" );\r
+       fprintf ( OUT, "\t<Rules>\r\n" );\r
+       fprintf ( OUT, "\t\t<CustomBuildRule\r\n" );\r
+       fprintf ( OUT, "\t\t\tName=\"Assembler\"\r\n" );\r
+       fprintf ( OUT, "\t\t\tDisplayName=\"Assembler Files\"\r\n" );\r
+       fprintf ( OUT, "\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; | as -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n" );\r
+       fprintf ( OUT, "\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"\r\n" );   \r
+       fprintf ( OUT, "\t\t\tFileExtensions=\"*.S\"\r\n" );\r
+       fprintf ( OUT, "\t\t\tExecutionDescription=\"asm\"\r\n" );\r
+       fprintf ( OUT, "\t\t\t>\r\n" );\r
+       fprintf ( OUT, "\t\t\t<Properties>\r\n" );\r
+       fprintf ( OUT, "\t\t\t</Properties>\r\n" );\r
+       fprintf ( OUT, "\t\t</CustomBuildRule>\r\n" );\r
+       fprintf ( OUT, "\t</Rules>\r\n" );\r
+       fprintf ( OUT, "</VisualStudioToolFile>\r\n" );\r
+}\r
+\r
+void\r
+MSVCBackend::_generate_sln_header ( FILE* OUT )\r
+{\r
+    fprintf ( OUT, "Microsoft Visual Studio Solution File, Format Version %s\r\n", _get_solution_verion().c_str() );\r
     fprintf ( OUT, "# Visual Studio 2005\r\n" );\r
     fprintf ( OUT, "\r\n" );\r
 }\r
@@ -419,12 +627,22 @@ MSVCBackend::_generate_sln_project (
        std::string vcproj_guid,\r
        const std::vector<Dependency*>& dependencies )\r
 {\r
-       \r
-    vcproj_file = DosSeparator ( std::string(".\\") + vcproj_file );\r
+       vcproj_file = DosSeparator ( std::string(".\\") + vcproj_file );\r
 \r
        fprintf ( OUT, "Project(\"%s\") = \"%s\", \"%s\", \"%s\"\r\n", sln_guid.c_str() , module.name.c_str(), vcproj_file.c_str(), vcproj_guid.c_str() );\r
-       fprintf ( OUT, "        ProjectSection(ProjectDependencies) = postProject\r\n" );\r
-       fprintf ( OUT, "        EndProjectSection\r\n" );\r
+\r
+       //FIXME: only omit ProjectDependencies in VS 2005 when there are no dependencies\r
+       //NOTE: VS 2002 do not use ProjectSection; it uses GlobalSection instead\r
+       if ((configuration.VSProjectVersion == "7.10") || (dependencies.size() > 0)) {\r
+               fprintf ( OUT, "\tProjectSection(ProjectDependencies) = postProject\r\n" );\r
+               for ( size_t i = 0; i < dependencies.size(); i++ )\r
+               {\r
+                       Dependency& dependency = *dependencies[i];\r
+                       fprintf ( OUT, "\t\t%s = %s\r\n", dependency.module.guid.c_str(), dependency.module.guid.c_str() );\r
+               }\r
+               fprintf ( OUT, "\tEndProjectSection\r\n" );\r
+       }\r
+\r
        fprintf ( OUT, "EndProject\r\n" );\r
 }\r
 \r
@@ -432,39 +650,65 @@ MSVCBackend::_generate_sln_project (
 void\r
 MSVCBackend::_generate_sln_footer ( FILE* OUT )\r
 {\r
-    fprintf ( OUT, "Global\r\n" );\r
+       fprintf ( OUT, "Global\r\n" );\r
+       fprintf ( OUT, "\tGlobalSection(SolutionConfiguration) = preSolution\r\n" );\r
+       fprintf ( OUT, "\t\tDebug = Debug\r\n" );\r
+       fprintf ( OUT, "\t\tRelease = Release\r\n" );\r
+       fprintf ( OUT, "\tEndGlobalSection\r\n" );\r
+       fprintf ( OUT, "\tGlobalSection(ProjectConfiguration) = postSolution\r\n" );\r
+       for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )\r
+       {\r
+               Module& module = *ProjectNode.modules[i];\r
+               std::string guid = module.guid;\r
+               _generate_sln_configurations ( OUT, guid.c_str() );\r
+       } \r
+       fprintf ( OUT, "\tEndGlobalSection\r\n" );\r
+       fprintf ( OUT, "\tGlobalSection(ExtensibilityGlobals) = postSolution\r\n" );\r
+       fprintf ( OUT, "\tEndGlobalSection\r\n" );\r
+       fprintf ( OUT, "\tGlobalSection(ExtensibilityAddIns) = postSolution\r\n" );\r
+       fprintf ( OUT, "\tEndGlobalSection\r\n" );\r
+       \r
+       if (configuration.VSProjectVersion == "7.00") {\r
+               fprintf ( OUT, "\tGlobalSection(ProjectDependencies) = postSolution\r\n" );\r
+               //FIXME: Add dependencies for VS 2002\r
+               fprintf ( OUT, "\tEndGlobalSection\r\n" );\r
+       }\r
 \r
-       fprintf ( OUT, "        GlobalSection(SolutionConfiguration) = preSolution\r\n" );\r
-       fprintf ( OUT, "                Debug = Debug\r\n" );\r
-       fprintf ( OUT, "                Release = Release\r\n" );\r
-       fprintf ( OUT, "        EndGlobalSection\r\n" );\r
+       if (configuration.VSProjectVersion == "8.00") {\r
+               fprintf ( OUT, "\tGlobalSection(SolutionProperties) = preSolution\r\n" );\r
+               fprintf ( OUT, "\t\tHideSolutionNode = FALSE\r\n" );\r
+               fprintf ( OUT, "\tEndGlobalSection\r\n" );\r
+       }\r
 \r
-       fprintf ( OUT, "        GlobalSection(ExtensibilityGlobals) = postSolution\r\n" );\r
-       fprintf ( OUT, "        EndGlobalSection\r\n" );\r
-       fprintf ( OUT, "        GlobalSection(ExtensibilityAddIns) = postSolution\r\n" );\r
-       fprintf ( OUT, "        EndGlobalSection\r\n" );\r
        fprintf ( OUT, "EndGlobal\r\n" );\r
+       fprintf ( OUT, "\r\n" );\r
+}\r
 \r
 \r
-    fprintf ( OUT, "\r\n" );\r
+void\r
+MSVCBackend::_generate_sln_configurations ( FILE* OUT, std::string vcproj_guid )\r
+{\r
+       fprintf ( OUT, "\t\t%s.Debug.ActiveCfg = Debug|Win32\r\n", vcproj_guid.c_str() );\r
+       fprintf ( OUT, "\t\t%s.Debug.Build.0 = Debug|Win32\r\n", vcproj_guid.c_str() );\r
+       fprintf ( OUT, "\t\t%s.Debug.Release.ActiveCfg = Release|Win32\r\n", vcproj_guid.c_str() );\r
+       fprintf ( OUT, "\t\t%s.Debug.Release.Build.0 = Release|Win32\r\n", vcproj_guid.c_str() );\r
 }\r
 \r
-\r
 void\r
 MSVCBackend::_generate_sln ( FILE* OUT )\r
 {\r
        string sln_guid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";\r
+       vector<string> guids;\r
 \r
        _generate_sln_header(OUT);\r
        // TODO FIXME - is it necessary to sort them?\r
        for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )\r
        {\r
                Module& module = *ProjectNode.modules[i];\r
-\r
+               \r
                std::string vcproj_file = VcprojFileName ( module );\r
-               std::string vcproj_guid = _gen_guid();\r
-               _generate_sln_project ( OUT, module, vcproj_file, sln_guid, vcproj_guid, module.dependencies );\r
-    }\r
-    _generate_sln_footer ( OUT );\r
+               _generate_sln_project ( OUT, module, vcproj_file, sln_guid, module.guid, module.dependencies );\r
+       }\r
+       _generate_sln_footer ( OUT );\r
 }\r
 \r