rename net_2_1 to moonlight
[mono.git] / msvc / scripts / genproj.cs
index 3793cfeb6304cec43012b5c48b9e36749c05a880..a42fb3ec64b0555121b171dfbaa496daa16a6ec9 100644 (file)
@@ -19,6 +19,60 @@ public enum LanguageVersion
        Default         = LINQ
 }
 
+class SlnGenerator {
+       const string header = "Microsoft Visual Studio Solution File, Format Version 10.00\n" +
+               "# Visual Studio 2008";
+
+       const string project_start = "Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{0}\", \"{1}\", \"{{{2}}}\"";
+       const string project_end = "EndProject";
+
+       Dictionary<string, string> libraries = new Dictionary<string, string> ();
+
+       public void Add (string library)
+       {
+               try {
+                       libraries.Add (library, Guid.NewGuid ().ToString ().ToUpper ());
+               }
+               catch (Exception ex) {
+                       Console.WriteLine (ex);
+               }
+       }
+
+       public void Write (string filename)
+       {
+               using (var sln = new StreamWriter (filename)) {
+                       sln.WriteLine ();
+                       sln.WriteLine (header);
+                       foreach (var library in libraries) {
+                               var library_name = Path.GetFileNameWithoutExtension (library.Key);
+                               sln.WriteLine (project_start, library_name, library.Key, library.Value);
+                               sln.WriteLine (project_end);
+                       }
+                       sln.WriteLine ("Global");
+
+                       sln.WriteLine ("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
+                       sln.WriteLine ("\t\tDebug|Any CPU = Debug|Any CPU");
+                       sln.WriteLine ("\t\tRelease|Any CPU = Release|Any CPU");
+                       sln.WriteLine ("\tEndGlobalSection");
+                       
+                       sln.WriteLine ("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution");
+                       foreach (var library in libraries) {
+                               sln.WriteLine ("\t\t{{{0}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU", library.Value);
+                               sln.WriteLine ("\t\t{{{0}}}.Debug|Any CPU.Build.0 = Debug|Any CPU", library.Value);
+                               sln.WriteLine ("\t\t{{{0}}}.Release|Any CPU.ActiveCfg = Release|Any CPU", library.Value);
+                               sln.WriteLine ("\t\t{{{0}}}.Release|Any CPU.Build.0 = Release|Any CPU", library.Value);
+                       }
+                       sln.WriteLine ("\tEndGlobalSection");
+                               
+                       sln.WriteLine ("\tGlobalSection(SolutionProperties) = preSolution");
+                       sln.WriteLine ("\t\tHideSolutionNode = FALSE");
+                       sln.WriteLine ("\tEndGlobalSection");
+
+                       sln.WriteLine ("EndGlobal");
+               }
+       }
+}
+
 class MsbuildGenerator {
        static void Usage ()
        {
@@ -32,22 +86,38 @@ class MsbuildGenerator {
                        template = input.ReadToEnd ();
                }
        }
-       
-       string base_dir, dir;
-       string mcs_topdir, class_dir;
+
+       // The directory as specified in order.xml
+       string dir;
+
+       //
+       // Our base directory, this is relative to our exectution point mono/msvc/scripts
+       string base_dir;
+
+       string mcs_topdir;
+
+       // Class directory, relative to 
+       string class_dir;
        
        public MsbuildGenerator (string dir)
        {
-               mcs_topdir = "..\\";
+               this.dir = dir;
                
-               foreach (char c in dir){
-                       if (c == '/')
-                               mcs_topdir = "..\\" + mcs_topdir;
+               if (dir == "mcs"){
+                       mcs_topdir = "..\\";
+                       class_dir = "..\\class\\";
+                       base_dir = "..\\..\\..\\mcs\\mcs";
+               } else {
+                       mcs_topdir = "..\\";
+                       
+                       foreach (char c in dir){
+                               if (c == '/')
+                                       mcs_topdir = "..\\" + mcs_topdir;
+                       }
+                       class_dir = mcs_topdir.Substring (3);
+                       
+                       base_dir = "..\\..\\..\\mcs\\" + dir;
                }
-               class_dir = mcs_topdir.Substring (3);
-               
-               this.dir = dir;
-               base_dir = "..\\..\\..\\mcs\\" + dir;
        }
        
        // Currently used
@@ -453,7 +523,7 @@ class MsbuildGenerator {
                        return "";
        }
        
-       public void Generate (XElement xproject)
+       public string Generate (XElement xproject)
        {
                string library = xproject.Attribute ("library").Value;
                string boot, mcs, flags, output_name, built_sources, library_output, response;
@@ -536,20 +606,20 @@ class MsbuildGenerator {
                        mcs = mcs.Substring (10);
                
                var compiler = mcs.Substring (mcs.LastIndexOf (' ') + 1);
-               if (compiler.EndsWith ("class/lib/basic/mcs.exe"))
-                       compiler = "basic";
-               else if (compiler.EndsWith ("class/lib/net_1_1_bootstrap/mcs.exe"))
-                       compiler = "net_1_1_bootstrap";
-               else if (compiler.EndsWith ("class/lib/net_1_1/mcs.exe"))
-                       compiler = "net_1_1";
+               if (compiler.EndsWith ("class/lib/basic/gmcs.exe"))
+                       compiler = "gmcs";
                else if (compiler.EndsWith ("class/lib/net_2_0_bootstrap/gmcs.exe"))
                        compiler = "net_2_0_bootstrap";
                else if (compiler.EndsWith ("mcs/gmcs.exe"))
                        compiler = "gmcs";
-               else if (compiler.EndsWith ("class/lib/net_2_1_bootstrap/smcs.exe"))
-                       compiler = "net_2_1_bootstrap";
-               else if (compiler.EndsWith ("class/lib/net_2_1_raw/smcs.exe"))
-                       compiler = "net_2_1_raw";
+               else if (compiler.EndsWith ("class/lib/moonlight_bootstrap/smcs.exe"))
+                       compiler = "moonlight_bootstrap";
+               else if (compiler.EndsWith ("class/lib/moonlight_raw/smcs.exe"))
+                       compiler = "moonlight_raw";
+               else if (compiler.EndsWith ("class/lib/net_4_0_bootstrap/dmcs.exe"))
+                       compiler = "net_4_0_bootstrap";
+               else if (compiler.EndsWith ("class/lib/net_4_0/dmcs.exe"))
+                       compiler = "dmcs";
                else {
                        Console.WriteLine ("Can not determine compiler from {0}", compiler);
                        Environment.Exit (1);
@@ -576,13 +646,20 @@ class MsbuildGenerator {
                }
                
                var refs = new StringBuilder ();
+               //
+               // mcs is different that csc in this regard, somehow with -noconfig we still import System and System.XML
+               //
+               if (dir == "mcs" && !load_default_config){
+                       references.Add ("System.dll");
+                       references.Add ("System.Xml.dll");
+               }
                
                if (references.Count > 0 || reference_aliases.Count > 0){
                        refs.Append ("<ItemGroup>\n");
                        string last = mono_paths [0].Substring (mono_paths [0].LastIndexOf ('/') + 1);
                        
                        string hint_path = class_dir + "\\lib\\" + last;
-                       
+
                        foreach (string r in references){
                                refs.Append ("    <Reference Include=\"" + r + "\">\n");
                                refs.Append ("      <SpecificVersion>False</SpecificVersion>\n");
@@ -601,9 +678,15 @@ class MsbuildGenerator {
                                refs.Append ("      <Aliases>" + alias + "</Aliases>\n");
                                refs.Append ("    </Reference>\n");
                        }
-
+                       
                        refs.Append ("  </ItemGroup>\n");
                }
+
+               try {
+                       Path.GetDirectoryName (library_output);
+               } catch {
+                       Console.WriteLine ("Error in path: {0} while processing {1}", library_output, library);
+               }
                
                //
                // Replace the template values
@@ -624,10 +707,13 @@ class MsbuildGenerator {
 
 
                string ofile = "..\\..\\..\\mcs\\" + dir + "\\" + library + ".csproj";
+               ofile = ofile.Replace ('/', '\\');
                //Console.WriteLine ("Generated {0}", ofile.Replace ("\\", "/"));
                using (var o = new StreamWriter (ofile)){
                        o.WriteLine (output);
                }
+
+               return ofile;
        }
        
 }
@@ -641,6 +727,7 @@ public class Driver {
                        Environment.Exit (1);
                }
 
+               var sln_gen = new SlnGenerator ();
                XDocument doc = XDocument.Load ("order.xml");
                foreach (XElement project in doc.Root.Elements ()){
                        string dir = project.Attribute ("dir").Value;
@@ -652,20 +739,21 @@ public class Driver {
                        if (!(dir.StartsWith ("class") || dir.StartsWith ("mcs")))
                                continue;
 
-                       Console.WriteLine ("dir={0} lib={1}", dir, library);
                        //
-                       // Do not do 2.1 for now, it is not working yet
+                       // Do not do 2.1, it is not working yet
+                       // Do not do basic, as there is no point (requires a system mcs to be installed).
                        //
-                       if (library.Contains ("net_2_1"))
+                       if (library.Contains ("moonlight") || library.Contains ("-basic"))
                                continue;
                        
                        var gen = new MsbuildGenerator (dir);
                        try {
-                               gen.Generate (project);
+                               sln_gen.Add (gen.Generate (project));
                        } catch (Exception e) {
                                Console.WriteLine ("Error in {0}\n{1}", dir, e);
                        }
                }
-       }
+               sln_gen.Write ("mcs_full.sln");
+    }
 
-}
\ No newline at end of file
+}