adding gccasm.rules to vcproj files
[reactos.git] / reactos / tools / rbuild / backend / msvc / vcprojmaker.cpp
index 6e5b59a..feae037 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
@@ -49,7 +53,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        }\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
        // TODO FIXME - need more checks here for 'sys' and possibly 'drv'?\r
@@ -140,7 +144,8 @@ 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
 \r
        if (!no_cpp)\r
        {\r
@@ -171,8 +176,13 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        fprintf ( OUT, "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\r\n" );\r
        fprintf ( OUT, "<VisualStudioProject\r\n" );\r
        fprintf ( OUT, "\tProjectType=\"Visual C++\"\r\n" );\r
-       fprintf ( OUT, "\tVersion=\"7.00\"\r\n" );\r
+\r
+       if (configuration.VSProjectVersion.empty())\r
+               configuration.VSProjectVersion = MS_VS_DEF_VERSION;\r
+\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
@@ -180,6 +190,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=\"%s/gccasm.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
@@ -251,6 +270,8 @@ 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
@@ -272,7 +293,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%s\"/>\r\n", module.name.c_str(), module_type.c_str() );\r
                }\r
                else\r
                {\r
@@ -288,7 +309,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                        }\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
 \r
@@ -340,7 +361,7 @@ 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
@@ -383,49 +404,165 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        fclose(OUT);\r
 }\r
 \r
+std::string\r
+MSVCBackend::_replace_str(std::string string1, const std::string &find_str, const std::string &replace_str)\r
+{\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
+\r
+    if (configuration.VSProjectVersion == "7.10")\r
+               version = "8.00";\r
+\r
+    if (configuration.VSProjectVersion == "8.00")\r
+               version = "9.00";\r
+\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 9.00\r\n" );\r
-    fprintf ( OUT, "# Visual C++ Express 2005\r\n" );\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
 \r
+\r
+void\r
+MSVCBackend::_generate_sln_project (\r
+       FILE* OUT,\r
+       const Module& module,\r
+       std::string vcproj_file,\r
+       std::string sln_guid,\r
+       std::string vcproj_guid,\r
+       const std::vector<Dependency*>& dependencies )\r
+{\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
+\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
+\r
+void\r
+MSVCBackend::_generate_sln_footer ( FILE* OUT )\r
+{\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
+       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, "EndGlobal\r\n" );\r
+       fprintf ( OUT, "\r\n" );\r
+}\r
+\r
+\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
 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
-               _generate_dsw_project ( OUT, module, vcproj_file, module.dependencies );\r
-    }\r
-//    _generate_dsw_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
-\r
-\r
-/*\r
-       m_devFile << "Microsoft Visual Studio Solution File, Format Version 9.00" << endl;\r
-       m_devFile << "# Visual C++ Express 2005" << endl;\r
-\r
-       m_devFile << "# FIXME Project listings here" << endl;\r
-       m_devFile << "EndProject" << endl;\r
-       m_devFile << "Global" << endl;\r
-       m_devFile << "  GlobalSection(SolutionConfigurationPlatforms) = preSolution" << endl;\r
-       m_devFile << "          Debug|Win32 = Debug|Win32" << endl;\r
-       m_devFile << "          Release|Win32 = Release|Win32" << endl;\r
-       m_devFile << "  EndGlobalSection" << endl;\r
-       m_devFile << "  GlobalSection(ProjectConfigurationPlatforms) = postSolution" << endl;\r
-       m_devFile << "  #FIXME Project Listings Here" << endl;\r
-       m_devFile << "  EndGlobalSection" << endl;\r
-       m_devFile << "  GlobalSection(SolutionProperties) = preSolution" << endl;\r
-       m_devFile << "          HideSolutionNode = FALSE" << endl;\r
-       m_devFile << "  EndGlobalSection" << endl;\r
-       m_devFile << "EndGlobal" << endl;\r
-\r
-       m_devFile << endl << endl;\r
-*/\r