Do not use --stacktrace
[mono.git] / mcs / tools / prj2make / MainMod.cs
1 // created on 4/3/04 at 6:27 a\r
2 \r
3 // This program is free software; you can redistribute it and/or modify\r
4 // it under the terms of the GNU General Public License as published by\r
5 // the Free Software Foundation; either version 2 of the License, or\r
6 // (at your option) any later version.\r
7 // \r
8 // This program is distributed in the hope that it will be useful,\r
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
11 // GNU Library General Public License for more details.\r
12 // \r
13 // You should have received a copy of the GNU General Public License\r
14 // along with this program; if not, write to the Free Software\r
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
16 \r
17 using System;\r
18 using System.IO;\r
19 using Mfconsulting.General.Prj2Make;\r
20 \r
21 namespace Mfconsulting.General.Prj2Make.Cui\r
22 {\r
23     public class MainMod \r
24     {\r
25         public string m_AppName = "prj2make-sharp";\r
26         public string m_WorkspaceFileName;\r
27         public string m_FileNamePath;\r
28         public string m_OutputMakefile;\r
29         \r
30         private bool m_IsUnix = false;\r
31         private bool m_IsMcs = true;\r
32         \r
33         // Determines the make file type/style\r
34         public bool IsUnix\r
35         {\r
36                 get { return m_IsUnix; }\r
37                 set { m_IsUnix = value; }\r
38         }\r
39         \r
40         // Determines what compiler to use MCS or CSC\r
41         public bool IsMcs\r
42         {\r
43                 get { return m_IsMcs; }\r
44                 set { m_IsMcs = value; }\r
45         }\r
46         \r
47         protected void MyInitializeComponents()\r
48         {\r
49         }\r
50         \r
51                 public MainMod (string inputFileName)\r
52                 {\r
53                         Mfconsulting.General.Prj2Make.Maker mkObj = null;\r
54 \r
55                         MyInitializeComponents();\r
56                 \r
57                         if (inputFileName == null || inputFileName.Length < 1) \r\r
58                         {\r
59                                 Console.WriteLine ("No input file has been specified.");\r
60                                 return;            \r
61                         }\r
62 \r
63                         if (Path.GetExtension(inputFileName).ToUpper().CompareTo(".SLN") == 0)\r
64                         {\r
65                                 mkObj = new Mfconsulting.General.Prj2Make.Maker();\r
66                                 mkObj.CreateCombineFromSln(inputFileName);\r
67                                 return;\r
68                         }\r
69 \r
70                         if (Path.GetExtension(inputFileName).ToUpper().CompareTo(".CSPROJ") == 0)\r
71                         {\r
72                                 mkObj = new Mfconsulting.General.Prj2Make.Maker();\r
73                                 mkObj.CreatePrjxFromCsproj(inputFileName);\r
74                                 return;\r
75                         }\r
76                 }\r
77                 \r
78                 // For command line handling\r
79         public MainMod (bool isNmake, bool isCsc, string WorkspaceFile)\r
80         {\r
81                 MyInitializeComponents();\r
82                 this.IsMcs = (isCsc == true) ? false : true;\r
83                 this.IsUnix = (isNmake == true) ? false : true;\r
84                 IniFromCommandLine(WorkspaceFile);\r
85         }\r
86         \r
87         void IniFromCommandLine(string WorkspaceFilename)\r
88         {\r
89                 m_WorkspaceFileName = WorkspaceFilename;\r
90                 m_FileNamePath = System.IO.Path.GetDirectoryName(m_WorkspaceFileName);\r
91                 m_OutputMakefile = System.IO.Path.Combine(m_FileNamePath, "Makefile");\r
92        \r
93                 if (this.IsUnix)\r
94                         m_OutputMakefile = System.IO.Path.Combine(m_FileNamePath, "Makefile");\r
95                 else\r
96                         m_OutputMakefile = System.IO.Path.Combine(m_FileNamePath, "Makefile.Win32");\r
97      \r
98                 // Actually follow through and genrate the contents of the Makefile\r
99                 // to be placed on the textview\r
100                 CreateMakefile();\r
101         }\r
102 \r
103 \r
104         protected void CreateMakefile()\r
105         {\r
106                 Mfconsulting.General.Prj2Make.Maker mkObj = null;\r
107                 string slnFile = null;\r
108                 \r
109                 if (this.m_WorkspaceFileName.Length < 1) {\r
110                         Console.WriteLine ("No input file has been specified.");\r
111                         return;            \r
112                 }\r
113                 else\r
114                         slnFile = m_WorkspaceFileName;\r
115                 \r
116                 mkObj = new Mfconsulting.General.Prj2Make.Maker();              \r
117                 SaveMakefileToDisk(mkObj.MakerMain(IsUnix, IsMcs, slnFile));\r
118         }\r
119     \r
120         protected void SaveMakefileToDisk (string MakeFileContents)\r
121         {\r
122                 FileStream fs = null;\r
123                 StreamWriter w = null;\r
124                 \r
125                 if (MakeFileContents.StartsWith ("Error") || MakeFileContents.StartsWith ("Notice")) {\r
126                         Console.WriteLine(MakeFileContents);\r
127                         return;                 \r
128                         } \r
129                 \r
130                 if (m_OutputMakefile != null && m_OutputMakefile.Length > 1) {\r
131                         fs = new FileStream(m_OutputMakefile, FileMode.Create, FileAccess.Write);\r
132                         w = new StreamWriter(fs);\r
133                 }\r
134                 \r
135                 if (w != null) {\r
136                         w.WriteLine (MakeFileContents);\r
137                         w.Close();\r
138                 }\r
139         }\r
140     }    \r
141 }