2010-02-13 Jb Evain <jbevain@novell.com>
[mcs.git] / tools / prj2make / PrjxInfo.cs
blobfa750e72e4c72ec9c55a832b1b36f36e08e9f7db
1 // Copyright (c) 2004 Francisco T. Martinez <paco@mfcon.com>
2 // All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 using System;
19 using System.Collections;
20 using System.IO;
21 using System.Text;
22 using System.Text.RegularExpressions;
23 using System.Xml;
24 using System.Xml.Serialization;
27 namespace Mfconsulting.General.Prj2Make
29 class PrjxInfo
31 public readonly string name;
32 public readonly string csprojpath;
33 public string makename;
34 public string makename_ext;
35 public string assembly_name;
36 public string res;
37 public string src;
38 private bool m_bAllowUnsafeCode;
39 private Mfconsulting.General.Prj2Make.Schema.Prjx.Project m_projObject;
41 public string ext_refs = "";
42 public string switches = "";
44 public bool AllowUnsafeCode
46 get { return m_bAllowUnsafeCode; }
49 public Mfconsulting.General.Prj2Make.Schema.Prjx.Project Proyecto {
50 get { return m_projObject; }
53 // Project desirialization
54 protected Mfconsulting.General.Prj2Make.Schema.Prjx.Project LoadPrjFromFile (string strIn)
56 FileStream fs = new FileStream (strIn, FileMode.Open);
58 XmlSerializer xmlSer = new XmlSerializer (typeof(Mfconsulting.General.Prj2Make.Schema.Prjx.Project));
59 Mfconsulting.General.Prj2Make.Schema.Prjx.Project prjObj = (Mfconsulting.General.Prj2Make.Schema.Prjx.Project) xmlSer.Deserialize (fs);
61 fs.Close();
63 return (prjObj);
66 public PrjxInfo(bool isUnixMode, bool isMcsMode, string csprojpath)
68 Mfconsulting.General.Prj2Make.Schema.Prjx.Configuration activeConf = null;
69 this.csprojpath = csprojpath;
71 // convert backslashes to slashes
72 csprojpath = csprojpath.Replace("\\", "/");
74 m_bAllowUnsafeCode = false;
76 // loads the file in order to deserialize and
77 // build the object graph
78 try {
79 m_projObject = LoadPrjFromFile (csprojpath);
80 } catch (Exception exc) {
82 Console.WriteLine ("Could not load the file {0}\n{1}: {2}",
83 csprojpath,
84 exc.GetType().Name,
85 exc.Message
87 return;
90 this.name = m_projObject.name;
92 makename = name.Replace('.','_').ToUpper();
93 makename_ext = makename + "_EXT";
95 // Get the configuration to be used and
96 // copy it to a local configuration object
97 foreach(Mfconsulting.General.Prj2Make.Schema.Prjx.Configuration cnfObj in m_projObject.Configurations.Configuration)
99 if(cnfObj.name.CompareTo(m_projObject.Configurations.active) == 0)
101 // Assign the active configuration
102 activeConf = cnfObj;
103 break;
107 // Establish if the allow unsafe code flag is true
108 if(activeConf.CodeGeneration.unsafecodeallowed == Mfconsulting.General.Prj2Make.Schema.Prjx.CodeGenerationUnsafecodeallowed.True)
110 m_bAllowUnsafeCode = true;
113 switch (activeConf.CodeGeneration.target)
115 case "Library":
116 makename_ext = makename + "_DLL";
117 assembly_name = activeConf.Output.assembly + ".dll";
118 switches += " -target:library";
119 break;
121 case "Exe":
122 makename_ext = makename + "_EXE";
123 assembly_name = activeConf.Output.assembly + ".exe";
124 switches += " -target:exe";
125 break;
127 case "WinExe":
128 makename_ext = makename + "_EXE";
129 assembly_name = activeConf.Output.assembly + ".exe";
130 switches += " -target:winexe";
131 break;
133 default:
134 throw new NotSupportedException("Unsupported OutputType: " + activeConf.CodeGeneration.target);
138 src = "";
139 string basePath = Path.GetDirectoryName(csprojpath);
140 string s;
142 // Process Source code files for compiling
143 foreach (Mfconsulting.General.Prj2Make.Schema.Prjx.File f in m_projObject.Contents)
145 if(f.buildaction == Mfconsulting.General.Prj2Make.Schema.Prjx.FileBuildaction.Compile)
147 if (src != "") {
148 src += " \\\n\t";
151 s = System.IO.Path.Combine(basePath, f.name);
152 s = s.Replace("\\", "/");
153 if (CmbxMaker.slash != "/")
154 s = s.Replace("/", CmbxMaker.slash);
156 // Test for spaces
157 if (isUnixMode == false)
159 // We are in win32 using a cmd.exe or other
160 // DOS shell
161 if(s.IndexOf(' ') > -1) {
162 src += String.Format("\"{0}\"", s);
163 } else {
164 src += s;
166 } else {
167 // We are in *NIX or some other
168 // GNU like shell
169 src += CsprojInfo.Quote (s);
174 // Process resources for embedding
175 res = "";
176 string rootNS = this.name;
177 string relPath;
178 foreach (Mfconsulting.General.Prj2Make.Schema.Prjx.File f in m_projObject.Contents)
180 if(f.buildaction == Mfconsulting.General.Prj2Make.Schema.Prjx.FileBuildaction.EmbedAsResource)
182 if (src != "") {
183 src += " \\\n\t";
186 relPath = f.name.Replace("\\", "/");
187 s = System.IO.Path.Combine(basePath, relPath);
188 s = String.Format(" -resource:{0},{1}", s, System.IO.Path.GetFileName(relPath));
189 s = s.Replace("\\", "/");
190 if (CmbxMaker.slash != "/")
191 s = s.Replace("/", CmbxMaker.slash);
192 res += s;