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