1 // Copyright (c) 2004 Francisco T. Martinez <paco@mfcon.com>
2 // All rights reserved.
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.
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.
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.
19 using System.Collections;
22 using System.Text.RegularExpressions;
24 using System.Xml.Serialization;
27 namespace Mfconsulting.General.Prj2Make
31 public readonly string name;
32 public readonly string guid;
33 public readonly string csprojpath;
34 public string makename;
35 public string makename_ext;
36 public string assembly_name;
40 private bool m_bAllowUnsafeCode;
41 private Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject m_projObject;
43 public string ext_refs = "";
44 public string switches = "";
46 public bool AllowUnsafeCode
48 get { return m_bAllowUnsafeCode; }
51 public ArrayList libdirs = new ArrayList();
53 public Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject Proyecto
55 get { return m_projObject; }
58 // Project desirialization
59 protected Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject LoadPrjFromFile (string strIn)
61 FileStream fs = new FileStream (strIn, FileMode.Open, FileAccess.Read);
63 XmlSerializer xmlSer = new XmlSerializer (typeof(Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject));
64 Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject prjObj = (Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject) xmlSer.Deserialize (fs);
73 static char [] quotable = new char [] { ' ', '(', ')' };
75 static public string Quote (string s)
77 if (s.IndexOfAny (quotable) == -1)
80 StringBuilder sb = new StringBuilder ();
81 foreach (char c in s){
83 case ' ': case '(': case ')':
89 return sb.ToString ();
93 public CsprojInfo(bool isUnixMode, bool isMcsMode, string name, string guid, string csprojpath)
97 this.csprojpath = csprojpath;
99 makename = name.Replace('.','_').ToUpper();
100 makename_ext = makename + "_EXT";
101 m_bAllowUnsafeCode = false;
103 // convert backslashes to slashes
104 csprojpath = csprojpath.Replace("\\", "/");
106 // loads the file in order to deserialize and
107 // build the object graph
110 m_projObject = LoadPrjFromFile (csprojpath);
112 catch (Exception exc)
114 Console.WriteLine("CurrentDirectory={0}", Directory.GetCurrentDirectory());
116 "Could not load the file {0}\n{1}: {2}\n{3}",
125 // Establish if the allow unsafe code flag is true
126 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.Config cf in m_projObject.CSHARP.Build.Settings.Config)
128 if(cf.AllowUnsafeBlocks == true)
129 m_bAllowUnsafeCode = true;
132 switch (m_projObject.CSHARP.Build.Settings.OutputType)
135 makename_ext = makename + "_DLL";
136 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".dll";
137 switches += " -target:library";
141 makename_ext = makename + "_EXE";
142 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".exe";
143 switches += " -target:exe";
147 makename_ext = makename + "_EXE";
148 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".exe";
149 switches += " -target:winexe";
153 throw new NotSupportedException("Unsupported OutputType: " + m_projObject.CSHARP.Build.Settings.OutputType);
158 string basePath = Path.GetDirectoryName(csprojpath);
161 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.File fl in m_projObject.CSHARP.Files.Include)
163 if(fl.BuildAction == Mfconsulting.General.Prj2Make.Schema.Csproj.FileBuildAction.Compile)
170 string filePath = fl.Link;
171 if (filePath == null)
172 filePath = fl.RelPath;
174 s = System.IO.Path.Combine(basePath, filePath);
175 s = s.Replace("\\", "/");
176 if (SlnMaker.slash != "/")
177 s = s.Replace("/", SlnMaker.slash);
180 if (isUnixMode == false) {
181 // We are in win32 using a cmd.exe or other
183 if(s.IndexOf(' ') > -1) {
184 src += String.Format("\"{0}\"", s);
189 // We are in *NIX or some other
191 src += s.Replace(" ", "\\ ");
198 string rootNS = m_projObject.CSHARP.Build.Settings.RootNamespace;
200 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.File fl in m_projObject.CSHARP.Files.Include)
202 if(fl.BuildAction == Mfconsulting.General.Prj2Make.Schema.Csproj.FileBuildAction.EmbeddedResource)
208 relPath = fl.RelPath.Replace("\\", "/");
209 s = System.IO.Path.Combine(basePath, relPath);
210 if (Path.GetExtension (s) == ".resx") {
212 path = path.Replace (@"\", "/");
213 if (SlnMaker.slash != "/")
214 path = path.Replace("/", SlnMaker.slash);
215 resgen += String.Format ("{0} ", Quote (path));
216 s = Path.ChangeExtension (s, ".resources");
217 relPath = Path.ChangeExtension (relPath, ".resources");
219 s = s.Replace("\\", "/");
220 string rp = relPath.Replace ("/", ".").Replace ("\\", "/");
221 s = String.Format("-resource:{0},{1}", Quote (s), rootNS + "." + rp);
222 if (SlnMaker.slash != "/")
223 s = s.Replace("/", SlnMaker.slash);