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