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 guid;
\r
33 public readonly string csprojpath;
\r
34 public string makename;
\r
35 public string makename_ext;
\r
36 public string assembly_name;
\r
39 private bool m_bAllowUnsafeCode;
\r
40 private Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject m_projObject;
\r
42 public string ext_refs = "";
\r
43 public string switches = "";
\r
45 public bool AllowUnsafeCode
\r
47 get { return m_bAllowUnsafeCode; }
\r
50 public ArrayList libdirs = new ArrayList();
\r
52 public Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject Proyecto
\r
54 get { return m_projObject; }
\r
57 // Project desirialization
\r
58 protected Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject LoadPrjFromFile (string strIn)
\r
60 FileStream fs = new FileStream (strIn, FileMode.Open);
\r
62 XmlSerializer xmlSer = new XmlSerializer (typeof(Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject));
\r
63 Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject prjObj = (Mfconsulting.General.Prj2Make.Schema.Csproj.VisualStudioProject) xmlSer.Deserialize (fs);
\r
70 public CsprojInfo(bool isUnixMode, bool isMcsMode, string name, string guid, string csprojpath)
\r
74 this.csprojpath = csprojpath;
\r
76 makename = name.Replace('.','_').ToUpper();
\r
77 makename_ext = makename + "_EXT";
\r
78 m_bAllowUnsafeCode = false;
\r
80 // convert backslashes to slashes
\r
81 csprojpath = csprojpath.Replace("\\", "/");
\r
83 // loads the file in order to deserialize and
\r
84 // build the object graph
\r
87 m_projObject = LoadPrjFromFile (csprojpath);
\r
89 catch (Exception exc)
\r
91 Console.WriteLine("CurrentDirectory={0}", Directory.GetCurrentDirectory());
\r
93 "Could not load the file {0}\n{1}: {2}\n{3}",
\r
102 // Establish if the allow unsafe code flag is true
\r
103 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.Config cf in m_projObject.CSHARP.Build.Settings.Config)
\r
105 if(cf.AllowUnsafeBlocks == true)
\r
106 m_bAllowUnsafeCode = true;
\r
109 switch (m_projObject.CSHARP.Build.Settings.OutputType)
\r
112 makename_ext = makename + "_DLL";
\r
113 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".dll";
\r
114 switches += " -target:library";
\r
118 makename_ext = makename + "_EXE";
\r
119 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".exe";
\r
120 switches += " -target:exe";
\r
124 makename_ext = makename + "_EXE";
\r
125 assembly_name = m_projObject.CSHARP.Build.Settings.AssemblyName + ".exe";
\r
126 switches += " -target:winexe";
\r
130 throw new NotSupportedException("Unsupported OutputType: " + m_projObject.CSHARP.Build.Settings.OutputType);
\r
135 string basePath = Path.GetDirectoryName(csprojpath);
\r
138 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.File fl in m_projObject.CSHARP.Files.Include)
\r
140 if(fl.BuildAction == Mfconsulting.General.Prj2Make.Schema.Csproj.FileBuildAction.Compile)
\r
147 string filePath = fl.Link;
\r
148 if (filePath == null)
\r
149 filePath = fl.RelPath;
\r
151 s = System.IO.Path.Combine(basePath, filePath);
\r
152 s = s.Replace("\\", "/");
\r
153 if (SlnMaker.slash != "/")
\r
154 s = s.Replace("/", SlnMaker.slash);
\r
157 if (isUnixMode == false) {
\r
158 // We are in win32 using a cmd.exe or other
\r
160 if(s.IndexOf(' ') > -1) {
\r
161 src += String.Format("\"{0}\"", s);
\r
166 // We are in *NIX or some other
\r
168 src += s.Replace(" ", "\\ ");
\r
174 string rootNS = m_projObject.CSHARP.Build.Settings.RootNamespace;
\r
176 foreach (Mfconsulting.General.Prj2Make.Schema.Csproj.File fl in m_projObject.CSHARP.Files.Include)
\r
178 if(fl.BuildAction == Mfconsulting.General.Prj2Make.Schema.Csproj.FileBuildAction.EmbeddedResource)
\r
184 relPath = fl.RelPath.Replace("\\", "/");
\r
185 s = System.IO.Path.Combine(basePath, relPath);
\r
186 s = String.Format("-resource:{0},{1}", s, rootNS + "." + relPath.Replace("/", "."));
\r
187 s = s.Replace("\\", "/");
\r
188 if (SlnMaker.slash != "/")
\r
189 s = s.Replace("/", SlnMaker.slash);
\r