Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CSharpAutotoolsSetup.cs « Autotools « CSharpBinding « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e08162ea798c3c8ff55fae578cfd6bcbe8e092d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

using System;
using System.IO;
using MonoDevelop.Core;
using MonoDevelop.Autotools;
using MonoDevelop.Projects;
using CSharpBinding;
using MonoDevelop.CSharp.Project;

namespace CSharpBinding.Autotools
{
	public class CSharpAutotoolsSetup : ISimpleAutotoolsSetup
	{
		public string GetCompilerCommand ( Project project, string configuration )
		{
			DotNetProject dp = project as DotNetProject;
			if ( !this.CanDeploy ( project ) || dp == null)
				throw new Exception ( "Not a deployable project." );
			
			switch (dp.TargetFramework.ClrVersion) {
			case ClrVersion.Net_1_1:
				return "mcs";
			case ClrVersion.Net_2_0:
				return "gmcs";
			case ClrVersion.Clr_2_1:
				return "smcs";
			case ClrVersion.Net_4_0:
			case ClrVersion.Net_4_5:
				return "dmcs";
			default:
				throw new Exception ("Cannot handle unknown runtime version ClrVersion.'" + dp.TargetFramework.ClrVersion.ToString () + "'.");
			}
		}

		public string GetCompilerFlags ( Project project, string configuration )
		{
			if ( !this.CanDeploy ( project ) )
				throw new Exception ( "Not a deployable project." );
			
			DotNetProjectConfiguration config = 
				project.Configurations [configuration] as DotNetProjectConfiguration;

			if ( config == null ) return "";
			
			CSharpCompilerParameters parameters = (CSharpCompilerParameters) config.CompilationParameters;
			CSharpProjectParameters projectParameters = (CSharpProjectParameters) config.ProjectParameters;
			
			StringWriter writer = new StringWriter();
			
			writer.Write(" -noconfig");
			writer.Write(" -codepage:utf8");
			
			if (parameters.UnsafeCode) {
				writer.Write(" -unsafe");
			}
			writer.Write(" -warn:" + parameters.WarningLevel);
			if(parameters.Optimize)
				writer.Write(" -optimize+");
			else
				writer.Write(" -optimize-");

			if(parameters.NoWarnings != null && parameters.NoWarnings != "") {
				writer.Write(" \"-nowarn:" + parameters.NoWarnings + '"');
			}

			if(config.DebugMode) {
				writer.Write(" -debug");
				//Check whether we have a DEBUG define
				bool hasDebugDefine = false;
				foreach (string define in parameters.DefineSymbols.Split (';')) {
					if (String.Compare (define, "DEBUG") == 0) {
						hasDebugDefine = true;
						break;
					}
				}
				if (!hasDebugDefine)
					writer.Write (" -define:DEBUG");
			}

			switch (parameters.LangVersion) {
			case LangVersion.Default:
				break;
			case LangVersion.ISO_1:
				writer.Write (" -langversion:ISO-1 ");
				break;
			case LangVersion.ISO_2:
				writer.Write (" -langversion:ISO-2 ");
				break;
			default:
				throw new Exception ("Invalid LangVersion enum value '" + parameters.LangVersion.ToString () + "'");
			}
			
			
			// TODO check path and add to extradist...
			//if (parameters.Win32Icon != null && parameters.Win32Icon.Length > 0) {
			//	writer.Write(" \"-win32icon:" + compilerparameters.Win32Icon + "\"");
			//}
			
			if (parameters.DefineSymbols.Length > 0) {
				writer.Write (" \"-define:" + parameters.DefineSymbols + '"');
			}
				
			if (projectParameters.MainClass != null && projectParameters.MainClass != "") {
				writer.Write (" \"-main:" + projectParameters.MainClass + '"');
			}

			if (config.SignAssembly)
				writer.Write (" \"-keyfile:" + project.GetRelativeChildPath (config.AssemblyKeyFile) + '"');
			if (config.DelaySign)
				writer.Write (" -delaySign");

			// TODO check paths and add to extradist?
			//if (parameters.GenerateXmlDocumentation) {
			//	writer.WriteLine(" \"-doc:" + Path.ChangeExtension(exe, ".xml") + '"');
			//}
		
			return writer.ToString();
		}
		
		public bool CanDeploy ( Project project )
		{
			DotNetProject csproj = project as DotNetProject;
			if ( csproj != null )
				if ( csproj.LanguageName == "C#" ) return true;
			return false;
		}
	}
}