make_msvcX_install_[config] patch by Brezenbak
[reactos.git] / reactos / tools / rbuild / backend / msvc / vcprojmaker.cpp
index b62f796..3140229 100644 (file)
@@ -90,16 +90,16 @@ 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
-       // this is a define in MinGW w32api, but not Microsoft's headers\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
@@ -117,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
@@ -146,11 +145,10 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                        // 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
+                       // i.e. ../output-i386/lib/rtl/vcXX/---/rtl.lib becomes\r
+                       //      ../output-i386/lib/rtl/vcXX/Debug/rtl.lib \r
                        // etc\r
-                       libs[i]->importedModule->\r
-                       string libpath = outdir + "\\" + libs[i]->importedModule->GetBasePath() + "\\---\\" + libs[i]->name + ".lib";\r
+                       string libpath = outdir + "\\" + libs[i]->importedModule->GetBasePath() + "\\" + _get_vc_dir() + "\\---\\" + libs[i]->name + ".lib";\r
                        libraries.push_back ( libpath );\r
 #else\r
                libraries.push_back ( libs[i]->name + ".lib" );\r
@@ -227,14 +225,14 @@ 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
+       //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
+       //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
+       //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
@@ -245,16 +243,16 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        {\r
                std::string& cfg = cfgs[icfg];\r
 \r
-               bool debug = strstr ( cfg.c_str(), "Debug" );\r
-               bool speed = strstr ( cfg.c_str(), "Speed" );\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\\%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\tOutputDirectory=\"%s\\%s\\%s\\%s\"\r\n", outdir.c_str (), module.GetBasePath ().c_str (), _get_vc_dir().c_str (), cfg.c_str() );\r
+               fprintf ( OUT, "\t\t\tIntermediateDirectory=\"%s\\%s\\%s\\%s\"\r\n", intdir.c_str (), module.GetBasePath ().c_str (), _get_vc_dir().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
@@ -311,9 +309,9 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                fprintf ( OUT, "\"\r\n" );\r
 \r
                fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );\r
-               fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"%s\"\r\n", debug ? "3" : "0" );\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
                \r
                if ( module.pch != NULL )\r
@@ -322,6 +320,9 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                        string pch_path = Path::RelativeFromDirectory (\r
                                module.pch->file.name,\r
                                module.GetBasePath() );\r
+                       string::size_type pos = pch_path.find_last_of ("/");\r
+                       if ( pos != string::npos )\r
+                               pch_path.erase(0, pos+1);         \r
                        fprintf ( OUT, "\t\t\t\tPrecompiledHeaderThrough=\"%s\"\r\n", pch_path.c_str() );\r
                }\r
                else\r
@@ -337,11 +338,12 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                }\r
 \r
                fprintf ( OUT, "\t\t\t\tEnablePREfast=\"%s\"\r\n", debug ? "TRUE" : "FALSE");\r
-               fprintf ( OUT, "\t\t\t\tDisableSpecificWarnings=\"4201;4127\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tWarningLevel=\"%s\"\r\n", release ? "0" : "4" );\r
-               fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"%s\"\r\n", release ? "FALSE" : "TRUE");\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
@@ -386,31 +388,39 @@ MSVCBackend::_generate_vcproj ( const Module& module )
 \r
                        if ( sys )\r
                        {\r
-                               fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /DRIVER /ALIGN:0x20 /SUBSYSTEM:NATIVE /SECTION:INIT,D /NODEFAULTLIB /IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096\"\r\n" );\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\tGenerateManifest=\"FALSE\"\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=\" /SUBSYSTEM:NATIVE /NODEFAULTLIB /SECTION:INIT,D /ALIGN:0x80\"\r\n" );\r
-                                       fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );\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\tGenerateManifest=\"FALSE\"\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
+                               }\r
                                else if ( module.type == NativeCUI )\r
                                {\r
-                                       fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /NODEFAULTLIB /ALIGN:0x20\"\r\n" );\r
-                                       fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );\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\tGenerateManifest=\"FALSE\"\r\n" );\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
+                                       fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", console ? 1 : 2 );\r
+                               }\r
                        }\r
                        else if ( dll )\r
                        {\r
@@ -485,7 +495,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                                fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );\r
                        }\r
 \r
-                       if (configuration.VSProjectVersion < "8.00") {\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
@@ -506,7 +516,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                                        }\r
                                        fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );\r
                                }\r
-                       }\r
+                       //}\r
                }\r
                fprintf ( OUT, "\t\t\t</File>\r\n" );\r
        }\r
@@ -529,7 +539,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
@@ -580,29 +590,29 @@ MSVCBackend::_get_solution_verion ( void ) {
 }\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
+//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