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 csprojpath
;
33 public string makename
;
34 public string makename_ext
;
35 public string assembly_name
;
38 private bool m_bAllowUnsafeCode
;
39 private Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.Project m_projObject
;
41 public string ext_refs
= "";
42 public string switches
= "";
44 public bool AllowUnsafeCode
46 get { return m_bAllowUnsafeCode; }
49 public Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.Project Proyecto
{
50 get { return m_projObject; }
53 // Project desirialization
54 protected Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.Project
LoadPrjFromFile (string strIn
)
56 FileStream fs
= new FileStream (strIn
, FileMode
.Open
);
58 XmlSerializer xmlSer
= new XmlSerializer (typeof(Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.Project
));
59 Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.Project prjObj
= (Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.Project
) xmlSer
.Deserialize (fs
);
66 public PrjxInfo(bool isUnixMode
, bool isMcsMode
, string csprojpath
)
68 Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.Configuration activeConf
= null;
69 this.csprojpath
= csprojpath
;
71 // convert backslashes to slashes
72 csprojpath
= csprojpath
.Replace("\\", "/");
74 m_bAllowUnsafeCode
= false;
76 // loads the file in order to deserialize and
77 // build the object graph
79 m_projObject
= LoadPrjFromFile (csprojpath
);
80 } catch (Exception exc
) {
82 Console
.WriteLine ("Could not load the file {0}\n{1}: {2}",
90 this.name
= m_projObject
.name
;
92 makename
= name
.Replace('.','_').ToUpper();
93 makename_ext
= makename
+ "_EXT";
95 // Get the configuration to be used and
96 // copy it to a local configuration object
97 foreach(Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.Configuration cnfObj
in m_projObject
.Configurations
.Configuration
)
99 if(cnfObj
.name
.CompareTo(m_projObject
.Configurations
.active
) == 0)
101 // Assign the active configuration
107 // Establish if the allow unsafe code flag is true
108 if(activeConf
.CodeGeneration
.unsafecodeallowed
== Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.CodeGenerationUnsafecodeallowed
.True
)
110 m_bAllowUnsafeCode
= true;
113 switch (activeConf
.CodeGeneration
.target
)
116 makename_ext
= makename
+ "_DLL";
117 assembly_name
= activeConf
.Output
.assembly
+ ".dll";
118 switches
+= " -target:library";
122 makename_ext
= makename
+ "_EXE";
123 assembly_name
= activeConf
.Output
.assembly
+ ".exe";
124 switches
+= " -target:exe";
128 makename_ext
= makename
+ "_EXE";
129 assembly_name
= activeConf
.Output
.assembly
+ ".exe";
130 switches
+= " -target:winexe";
134 throw new NotSupportedException("Unsupported OutputType: " + activeConf
.CodeGeneration
.target
);
139 string basePath
= Path
.GetDirectoryName(csprojpath
);
142 // Process Source code files for compiling
143 foreach (Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.File f
in m_projObject
.Contents
)
145 if(f
.buildaction
== Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.FileBuildaction
.Compile
)
151 s
= System
.IO
.Path
.Combine(basePath
, f
.name
);
152 s
= s
.Replace("\\", "/");
153 if (CmbxMaker
.slash
!= "/")
154 s
= s
.Replace("/", CmbxMaker
.slash
);
157 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
+= CsprojInfo
.Quote (s
);
174 // Process resources for embedding
176 string rootNS
= this.name
;
178 foreach (Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.File f
in m_projObject
.Contents
)
180 if(f
.buildaction
== Mfconsulting
.General
.Prj2Make
.Schema
.Prjx
.FileBuildaction
.EmbedAsResource
)
186 relPath
= f
.name
.Replace("\\", "/");
187 s
= System
.IO
.Path
.Combine(basePath
, relPath
);
188 s
= String
.Format(" -resource:{0},{1}", s
, System
.IO
.Path
.GetFileName(relPath
));
189 s
= s
.Replace("\\", "/");
190 if (CmbxMaker
.slash
!= "/")
191 s
= s
.Replace("/", CmbxMaker
.slash
);