bool CSCParseOption (string option, ref string [] args)
{
int idx = option.IndexOf (':');
string arg, value;
if (idx == -1){
arg = option;
value = "";
} else {
arg = option.Substring (0, idx);
value = option.Substring (idx + 1);
}
switch (arg.ToLowerInvariant ()){
case "/nologo":
return true;
case "/t":
case "/target":
switch (value){
case "exe":
RootContext.Target = Target.Exe;
break;
case "winexe":
RootContext.Target = Target.WinExe;
break;
case "library":
RootContext.Target = Target.Library;
RootContext.TargetExt = ".dll";
break;
case "module":
RootContext.Target = Target.Module;
RootContext.TargetExt = ".netmodule";
break;
default:
TargetUsage ();
break;
}
return true;
case "/out":
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
RootContext.OutputFile = value;
return true;
case "/o":
case "/o+":
case "/optimize":
case "/optimize+":
RootContext.Optimize = true;
return true;
case "/o-":
case "/optimize-":
RootContext.Optimize = false;
return true;
// TODO: Not supported by csc 3.5+
case "/incremental":
case "/incremental+":
case "/incremental-":
// nothing.
return true;
case "/d":
case "/define": {
if (value.Length == 0){
Usage ();
Environment.Exit (1);
}
foreach (string d in value.Split (argument_value_separator)) {
string conditional = d.Trim ();
if (!Tokenizer.IsValidIdentifier (conditional)) {
Report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", conditional);
continue;
}
RootContext.AddConditional (conditional);
}
return true;
}
case "/bugreport":
//
// We should collect data, runtime, etc and store in the file specified
//
Console.WriteLine ("To file bug reports, please visit: http://www.mono-project.com/Bugs");
return true;
case "/pkg": {
string packages;
if (value.Length == 0){
Usage ();
Environment.Exit (1);
}
packages = String.Join (" ", value.Split (new Char [] { ';', ',', '\n', '\r'}));
string pkgout = GetPackageFlags (packages, true, Report);
if (pkgout != null){
string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}).
Split (new Char [] { ' ', '\t'});
args = AddArgs (args, xargs);
}
return true;
}
case "/linkres":
case "/linkresource":
case "/res":
case "/resource":
AssemblyResource res = null;
string[] s = value.Split (argument_value_separator, StringSplitOptions.RemoveEmptyEntries);
switch (s.Length) {
case 1:
if (s[0].Length == 0)
goto default;
res = new AssemblyResource (s [0], Path.GetFileName (s[0]));
break;
case 2:
res = new AssemblyResource (s [0], s [1]);
break;
case 3:
if (s [2] != "public" && s [2] != "private") {
Report.Error (1906, "Invalid resource visibility option `{0}'. Use either `public' or `private' instead", s [2]);
return true;
}
res = new AssemblyResource (s[0], s[1], s[2] == "private");
break;
default:
Report.Error (-2005, "Wrong number of arguments for option `{0}'", option);
break;
}
if (res != null) {
res.IsEmbeded = arg [1] == 'r' || arg [1] == 'R';
AddResource (res);
}
return true;
case "/recurse":
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
ProcessSourceFiles (value, true);
return true;
case "/r":
case "/reference": {
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
string[] refs = value.Split (argument_value_separator);
foreach (string r in refs){
if (r.Length == 0)
continue;
string val = r;
int index = val.IndexOf ('=');
if (index > -1) {
string alias = r.Substring (0, index);
string assembly = r.Substring (index + 1);
AddAssemblyReference (alias, assembly);
if (refs.Length != 1) {
Report.Error (2034, "Cannot specify multiple aliases using single /reference option");
break;
}
} else {
AddAssemblyReference (val);
}
}
return true;
}
case "/addmodule": {
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
string[] refs = value.Split (argument_value_separator);
foreach (string r in refs){
RootContext.Modules.Add (r);
}
return true;
}
case "/win32res": {
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
if (RootContext.Win32IconFile != null)
Report.Error (1565, "Cannot specify the `win32res' and the `win32ico' compiler option at the same time");
RootContext.Win32ResourceFile = value;
return true;
}
case "/win32icon": {
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
if (RootContext.Win32ResourceFile != null)
Report.Error (1565, "Cannot specify the `win32res' and the `win32ico' compiler option at the same time");
RootContext.Win32IconFile = value;
return true;
}
case "/doc": {
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
RootContext.Documentation = new Documentation (value);
return true;
}
case "/lib": {
string [] libdirs;
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
libdirs = value.Split (argument_value_separator);
foreach (string dir in libdirs)
RootContext.ReferencesLookupPaths.Add (dir);
return true;
}
case "/debug-":
RootContext.GenerateDebugInfo = false;
return true;
case "/debug":
if (value == "full" || value == "")
RootContext.GenerateDebugInfo = true;
return true;
case "/debug+":
RootContext.GenerateDebugInfo = true;
return true;
case "/checked":
case "/checked+":
RootContext.Checked = true;
return true;
case "/checked-":
RootContext.Checked = false;
return true;
case "/clscheck":
case "/clscheck+":
RootContext.VerifyClsCompliance = true;
return true;
case "/clscheck-":
RootContext.VerifyClsCompliance = false;
return true;
case "/unsafe":
case "/unsafe+":
RootContext.Unsafe = true;
return true;
case "/unsafe-":
RootContext.Unsafe = false;
return true;
case "/warnaserror":
case "/warnaserror+":
if (value.Length == 0) {
Report.WarningsAreErrors = true;
} else {
foreach (string wid in value.Split (argument_value_separator))
Report.AddWarningAsError (wid);
}
return true;
case "/warnaserror-":
if (value.Length == 0) {
Report.WarningsAreErrors = false;
} else {
foreach (string wid in value.Split (argument_value_separator))
Report.RemoveWarningAsError (wid);
}
return true;
case "/warn":
if (value.Length == 0) {
Error_RequiresArgument (option);
break;
}
SetWarningLevel (value);
return true;
case "/nowarn": {
if (value.Length == 0){
Error_RequiresArgument (option);
break;
}
var warns = value.Split (argument_value_separator);
foreach (string wc in warns){
try {
if (wc.Trim ().Length == 0)
continue;
int warn = Int32.Parse (wc);
if (warn < 1) {
throw new ArgumentOutOfRangeException("warn");
}
Report.SetIgnoreWarning (warn);
} catch {
Report.Error (1904, "`{0}' is not a valid warning number", wc);
}
}
return true;
}
case "/noconfig":
RootContext.LoadDefaultReferences = false;
return true;
case "/platform":
if (value.Length == 0) {
Error_RequiresArgument (option);
break;
}
switch (value.ToLower (CultureInfo.InvariantCulture)) {
case "anycpu":
RootContext.Platform = Platform.AnyCPU;
break;
case "x86":
RootContext.Platform = Platform.X86;
break;
case "x64":
RootContext.Platform = Platform.X64;
break;
case "itanium":
RootContext.Platform = Platform.IA64;
break;
default:
Report.Error (1672, "Invalid platform type for -platform. Valid options are `anycpu', `x86', `x64' or `itanium'");
break;
}
return true;
case "/sdk":
if (value.Length == 0) {
Error_RequiresArgument (option);
break;
}
switch (value.ToLowerInvariant ()) {
case "2":
RootContext.SdkVersion = SdkVersion.v2;
break;
case "4":
RootContext.SdkVersion = SdkVersion.v4;
break;
default:
Report.Error (-26, "Invalid sdk version name");
break;
}
return true;
// We just ignore this.
case "/errorreport":
case "/filealign":
if (value.Length == 0) {
Error_RequiresArgument (option);
break;
}
return true;
case "/helpinternal":
OtherFlags ();
Environment.Exit(0);
return true;
case "/help":
case "/?":
Usage ();
Environment.Exit (0);
return true;
case "/main":
case "/m":
if (value.Length == 0){
Error_RequiresArgument (option);
break;
}
RootContext.MainClass = value;
return true;
case "/nostdlib":
case "/nostdlib+":
RootContext.StdLib = false;
return true;
case "/nostdlib-":
RootContext.StdLib = true;
return true;
case "/fullpaths":
RootContext.ShowFullPaths = true;
return true;
case "/keyfile":
if (value.Length == 0) {
Error_RequiresFileName (option);
break;
}
RootContext.StrongNameKeyFile = value;
return true;
case "/keycontainer":
if (value.Length == 0) {
Error_RequiresArgument (option);
break;
}
RootContext.StrongNameKeyContainer = value;
return true;
case "/delaysign+":
case "/delaysign":
RootContext.StrongNameDelaySign = true;
return true;
case "/delaysign-":
RootContext.StrongNameDelaySign = false;
return true;
case "/langversion":
if (value.Length == 0) {
Error_RequiresArgument (option);
break;
}
switch (value.ToLowerInvariant ()) {
case "iso-1":
RootContext.Version = LanguageVersion.ISO_1;
return true;
case "default":
RootContext.Version = LanguageVersion.Default;
RootContext.AddConditional ("__V2__");
return true;
case "iso-2":
RootContext.Version = LanguageVersion.ISO_2;
return true;
case "3":
RootContext.Version = LanguageVersion.V_3;
return true;
case "future":
RootContext.Version = LanguageVersion.Future;
return true;
}
Report.Error (1617, "Invalid -langversion option `{0}'. It must be `ISO-1', `ISO-2', `3' or `Default'", value);
return true;
case "/codepage":
if (value.Length == 0) {
Error_RequiresArgument (option);
break;
}
switch (value) {
case "utf8":
RootContext.Encoding = new UTF8Encoding();
break;
case "reset":
RootContext.Encoding = Encoding.Default;
break;
default:
try {
RootContext.Encoding = Encoding.GetEncoding (Int32.Parse (value));
} catch {
Report.Error (2016, "Code page `{0}' is invalid or not installed", value);
}
break;
}
return true;
default:
return false;
}
return true;
}