diff --git a/docs/error.md b/docs/error.md
index 1db939f..2cdc6a4 100644
--- a/docs/error.md
+++ b/docs/error.md
@@ -24,6 +24,18 @@ The easiest way to get exact version information is to use the **Xamarin Studio*
The directory name specified by `-o=DIR` does not exists and could not be created. It might be an invalid name for the file system.
+
EM0002: Option `X` is not supported
+
+The tool does not support the option `X`. It is possible that another version of the tool supports it or that it does not apply in this environment.
+
+EM0003: The platform `X` is not valid.
+
+The tool does not support the platform `X`. It is possible that another version of the tool supports it or that it does not apply in this environment.
+
+EM0004: The target `X` is not valid.
+
+The tool does not support the target `X`. It is possible that another version of the tool supports it or that it does not apply in this environment.
+
EM0099: Internal error *. Please file a bug report with a test case (https://github.com/mono/Embeddinator-4000/issues).
This error message is reported when an internal consistency check in the Embeddinator-4000 fails.
diff --git a/objcgen/driver.cs b/objcgen/driver.cs
index 1f9d799..5c523c1 100644
--- a/objcgen/driver.cs
+++ b/objcgen/driver.cs
@@ -34,17 +34,20 @@ namespace Embeddinator {
public static int Main2 (string [] args)
{
- bool shared = true; // dylib
var action = Action.None;
- var debug = false;
var os = new OptionSet {
- { "c|compile", "compiles the generated output", v => CompileCode = true },
- { "o|out|outdir=", "output directory", v => OutputDirectory = v },
+ { "c|compile", "Compiles the generated output", v => CompileCode = true },
+ { "d|debug", "Build the native library with debug information.", v => Debug = true },
+ { "gen=", $"Target generator (default {Target})", v => Target = v },
+ { "o|out|outdir=", "Output directory", v => OutputDirectory = v },
+ { "p|platform=", "Target platform (macOS)", v => Platform = v },
+ { "dll|shared", "Compiles as a shared library (default)", v => Shared = true },
+ { "static", "Compiles as a static library (unsupported)", v => { throw new EmbeddinatorException (2, $"Option `--static` is not supported"); } },
+ { "vs=", $"Visual Studio version for compilation (unsupported)", v => { throw new EmbeddinatorException (2, $"Option `--vs` is not supported"); } },
{ "h|?|help", "Displays the help", v => action = Action.Help },
{ "v|verbose", "generates diagnostic verbose output", v => ErrorHelper.Verbosity++ },
{ "version", "Display the version information.", v => action = Action.Version },
- { "debug", "Build the native library with debug information.", v => debug = true },
};
var assemblies = os.Parse (args);
@@ -67,9 +70,9 @@ namespace Embeddinator {
return 0;
case Action.Generate:
try {
- var result = Generate (assemblies, shared);
+ var result = Generate (assemblies);
if (CompileCode && (result == 0))
- result = Compile (shared, debug);
+ result = Compile ();
Console.WriteLine ("Done");
return result;
} catch (NotImplementedException e) {
@@ -99,9 +102,49 @@ namespace Embeddinator {
static bool CompileCode { get; set; }
+ static bool Debug { get; set; }
+
+ static bool Shared { get; set; } = true;
+
static string LibraryName { get; set; }
- static int Generate (List args, bool shared)
+ static string platform = "macos";
+
+ public static string Platform {
+ get { return platform; }
+ set {
+ switch (value.ToLowerInvariant ()) {
+ case "osx":
+ case "macosx":
+ case "macos":
+ case "mac":
+ target = "macos";
+ break;
+ default:
+ throw new EmbeddinatorException (3, true, $"The platform `{value}` is not valid.");
+ }
+ }
+ }
+
+ static string target = "objc";
+
+ public static string Target {
+ get { return target; }
+ set {
+ switch (value.ToLowerInvariant ()) {
+ case "objc":
+ case "obj-c":
+ case "objectivec":
+ case "objective-c":
+ target = "objc";
+ break;
+ default:
+ throw new EmbeddinatorException (4, true, $"The target `{value}` is not valid.");
+ }
+ }
+ }
+
+ static int Generate (List args)
{
Console.WriteLine ("Parsing assemblies...");
@@ -128,7 +171,7 @@ namespace Embeddinator {
foreach (var res in exe.GetManifestResourceNames ()) {
if (res == "main.c") {
// no main is needed for dylib and don't re-write an existing main.c file - it's a template
- if (shared || File.Exists ("main.c"))
+ if (Shared || File.Exists ("main.c"))
continue;
}
var path = Path.Combine (OutputDirectory, res);
@@ -139,12 +182,12 @@ namespace Embeddinator {
return 0;
}
- static int Compile (bool shared, bool debug)
+ static int Compile ()
{
Console.WriteLine ("Compiling binding code...");
StringBuilder options = new StringBuilder ("clang ");
- if (debug)
+ if (Debug)
options.Append ("-g -O0 ");
options.Append ("-fobjc-arc ");
options.Append ("-DMONO_EMBEDDINATOR_DLL_EXPORT ");
@@ -152,7 +195,7 @@ namespace Embeddinator {
options.Append ("-framework Foundation ");
options.Append ("-I\"/Library/Frameworks/Mono.framework/Versions/Current/include/mono-2.0\" -L\"/Library/Frameworks/Mono.framework/Versions/Current/lib/\" -lmonosgen-2.0 ");
options.Append ("glib.c mono_embeddinator.c bindings.m ");
- if (shared)
+ if (Shared)
options.Append ($"-dynamiclib -install_name @rpath/lib{LibraryName}.dylib ");
else
options.Append ("main.c ");
diff --git a/tests/objcgentest/DriverTest.cs b/tests/objcgentest/DriverTest.cs
index 56d8522..37eeb18 100644
--- a/tests/objcgentest/DriverTest.cs
+++ b/tests/objcgentest/DriverTest.cs
@@ -28,5 +28,99 @@ namespace DriverTest {
Directory.Delete (valid);
}
}
+
+ [Test]
+ public void Target_Supported ()
+ {
+ var valid = new string [] { "ObjC", "Obj-C", "ObjectiveC", "objective-c" };
+ foreach (var t in valid) {
+ Driver.Target = t;
+ Assert.That (Driver.Target, Is.EqualTo ("objc"), t);
+ }
+ }
+
+ [Test]
+ public void Target_NotSupported ()
+ {
+ var notsupported = new string [] { "C", "C++", "Java" };
+ foreach (var t in notsupported) {
+ try {
+ Driver.Target = t;
+ }
+ catch (EmbeddinatorException ee) {
+ Assert.True (ee.Error, "Error");
+ Assert.That (ee.Code, Is.EqualTo (4), "Code");
+ }
+ }
+ }
+
+ [Test]
+ public void Target_Invalid ()
+ {
+ try {
+ Driver.Target = "invalid";
+ }
+ catch (EmbeddinatorException ee) {
+ Assert.True (ee.Error, "Error");
+ Assert.That (ee.Code, Is.EqualTo (4), "Code");
+ }
+ }
+
+ [Test]
+ public void Platform_Supported ()
+ {
+ var valid = new string [] { "OSX", "MacOSX", "MacOS", "Mac" };
+ foreach (var p in valid) {
+ Driver.Platform = p;
+ Assert.That (Driver.Platform, Is.EqualTo ("macos"), p);
+ }
+ }
+
+ [Test]
+ public void Platform_NotSupported ()
+ {
+ var notsupported = new string [] { "Windows", "Android", "iOS", "tvOS", "watchOS" };
+ foreach (var p in notsupported) {
+ try {
+ Driver.Platform = p;
+ } catch (EmbeddinatorException ee) {
+ Assert.True (ee.Error, "Error");
+ Assert.That (ee.Code, Is.EqualTo (3), "Code");
+ }
+ }
+ }
+
+ [Test]
+ public void Platform_Invalid ()
+ {
+ try {
+ Driver.Platform = "invalid";
+ } catch (EmbeddinatorException ee) {
+ Assert.True (ee.Error, "Error");
+ Assert.That (ee.Code, Is.EqualTo (3), "Code");
+ }
+ }
+
+ [Test]
+ public void Static_Unsupported ()
+ {
+ try {
+ Driver.Main2 (new [] { "--static" });
+ } catch (EmbeddinatorException ee) {
+ Assert.True (ee.Error, "Error");
+ Assert.That (ee.Code, Is.EqualTo (2), "Code");
+ }
+ }
+
+ [Test]
+ public void VS_Unsupported ()
+ {
+ try {
+ Driver.Main2 (new [] { "--vs=x" });
+ } catch (EmbeddinatorException ee) {
+ Assert.True (ee.Error, "Error");
+ Assert.That (ee.Code, Is.EqualTo (2), "Code");
+ }
+ }
}
}
\ No newline at end of file