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);
71 public CsprojInfo(bool isUnixMode, bool isMcsMode, string name, string guid, string csprojpath)
75 this.csprojpath = csprojpath;
77 makename = name.Replace('.','_').ToUpper();
78 makename_ext = makename + "_EXT";
79 m_bAllowUnsafeCode = false;
81 // convert backslashes to slashes
82 csprojpath = csprojpath.Replace("\\", "/");
84 // loads the file in order to deserialize and
85 // build the object graph
88 m_projObject = LoadPrjFromFile (csprojpath);
92 Console.WriteLine("CurrentDirectory={0}", Directory.GetCurrentDirectory());
94 "Could not load the file {0}\n{1}: {2}\n{3}",
103 // Establish if the allow unsafe code flag is true
104 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.Config cf in m_projObject.CSHARP.Build.Settings.Config)
106 if(cf.AllowUnsafeBlocks == true)
107 m_bAllowUnsafeCode = true;
110 switch (m_projObject.CSHARP.Build.Settings.OutputType)
113 makename_ext = makename + "_DLL";
114 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".dll";
115 switches += " -target:library";
119 makename_ext = makename + "_EXE";
120 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".exe";
121 switches += " -target:exe";
125 makename_ext = makename + "_EXE";
126 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".exe";
127 switches += " -target:winexe";
131 throw new NotSupportedException("Unsupported OutputType: " + m_projObject.CSHARP.Build.Settings.OutputType);
136 string basePath = Path.GetDirectoryName(csprojpath);
139 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.File fl in m_projObject.CSHARP.Files.Include)
141 if(fl.BuildAction == Mfconsulting.General.Prj2Make.Schema.Csproj.FileBuildAction.Compile)
148 string filePath = fl.Link;
149 if (filePath == null)
150 filePath = fl.RelPath;
152 s = System.IO.Path.Combine(basePath, filePath);
153 s = s.Replace("\\", "/");
154 if (SlnMaker.slash != "/")
155 s = s.Replace("/", SlnMaker.slash);
158 if (isUnixMode == false) {
159 // We are in win32 using a cmd.exe or other
161 if(s.IndexOf(' ') > -1) {
162 src += String.Format("\"{0}\"", s);
167 // We are in *NIX or some other
169 src += s.Replace(" ", "\\ ");
176 string rootNS = m_projObject.CSHARP.Build.Settings.RootNamespace;
178 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.File fl in m_projObject.CSHARP.Files.Include)
180 if(fl.BuildAction == Mfconsulting.General.Prj2Make.Schema.Csproj.FileBuildAction.EmbeddedResource)
186 relPath = fl.RelPath.Replace("\\", "/");
187 s = System.IO.Path.Combine(basePath, relPath);
188 if (Path.GetExtension (s) == ".resx") {
190 path = path.Replace (@"\", "/");
191 if (SlnMaker.slash != "/")
192 path = path.Replace("/", SlnMaker.slash);
193 resgen += String.Format ("{0} ", path);
194 s = Path.ChangeExtension (s, ".resources");
195 relPath = Path.ChangeExtension (relPath, ".resources");
197 s = String.Format("-resource:{0},{1}", s, rootNS + "." + relPath.Replace("/", "."));
198 s = s.Replace("\\", "/");
199 if (SlnMaker.slash != "/")
200 s = s.Replace("/", SlnMaker.slash);