2007-10-19 Marek Habersack <mhabersack@novell.com>
[mono.git] / mono / wrapper / genwrapper.pl
index 7443cfd994d506fe1f97e867991bad76c5721283..15641aa59dcba3c484c5fd82ace9ffa2155e309c 100755 (executable)
@@ -8,23 +8,32 @@
 use Getopt::Long;
 init();
 
+if ($ENV{"OSTYPE"} eq "cygwin") {
 @includes = ("sys/types.h", "sys/stat.h", "unistd.h", "fcntl.h", "glib.h",
             "errno.h");
-$cflags = `gnome-config --cflags glib`;
+} else {
+@includes = ("sys/types.h", "sys/stat.h", "unistd.h", "fcntl.h", "glib.h",
+            "errno.h");
+}
+
+$cflags = `pkg-config --cflags glib-2.0`;
 $cflags =~ s/\n//;
 
 $lib = "monowrapper";
 
+if ($csmode){
+   $res_struct .= "[CLSCompliant(false)]\n";
+}
 create_struct ("MonoWrapperStat", "stat",
-              "uint", "st_dev",
-              "uint", "st_mode",
-              "uint", "st_nlink",
-              "uint", "st_uid",
-              "uint", "st_gid",
-              "long", "st_size",
-              "uint", "st_atime",
-              "uint", "st_mtime",
-              "uint", "st_ctime",
+              "uint", "mst_dev",
+              "uint", "mst_mode",
+              "uint", "mst_nlink",
+              "uint", "mst_uid",
+              "uint", "mst_gid",
+              "long", "mst_size",
+              "uint", "mst_atime",
+              "uint", "mst_mtime",
+              "uint", "mst_ctime",
               );
 
 create_func ($lib, "", "seek", "long", 
@@ -32,6 +41,13 @@ create_func ($lib, "", "seek", "long",
             "long", "offset",
             "int", "whence");
 
+create_func ($lib, "", "mkdir", "int",
+            "string", "path",
+            "int",    "mode");
+
+create_func ($lib, "", "rmdir", "int",
+            "string", "path");
+
 create_func ($lib, "", "read", "int",
             "IntPtr", "fd",
             "void *", "buf",
@@ -58,6 +74,46 @@ create_func ($lib, "", "open", "IntPtr",
 create_func ($lib, "", "close", "int",
             "IntPtr", "fd");
 
+create_func ($lib, "", "stat", "int",
+            "string", "path",
+            "stat *", "buf");
+
+create_func ($lib, "", "unlink", "int",
+            "string", "path");
+
+create_func ($lib, "", "opendir", "IntPtr",
+            "string", "path");
+
+create_func ($lib, "", "readdir", "string",
+            "IntPtr", "dir");
+
+create_func ($lib, "", "closedir", "int",
+            "IntPtr", "dir");
+
+create_func ($lib, "", "getenv", "IntPtr",
+            "string", "variable");
+
+create_func ($lib, "", "environ", "IntPtr");
+
+create_func ($lib, "", "rename", "int",
+            "string", "source",
+            "string", "target");
+
+create_func ($lib, "", "utime",  "int",
+             "string", "path",
+            "int",    "atime",
+            "int",    "mtime");
+
+create_func ($lib, "mono_glob_compile", "mono_glob_compile", "IntPtr",
+            "string", "glob");
+
+create_func ($lib, "mono_glob_match", "mono_glob_match", "int",
+            "IntPtr", "handle",
+            "string", "str");
+
+create_func ($lib, "mono_glob_dispose", "mono_glob_dispose", "void",
+            "IntPtr", "handle");
+
 map_const ("int", "%d", "SEEK_SET",
           "int", "%d", "SEEK_CUR",
           "int", "%d", "SEEK_END",
@@ -173,7 +229,6 @@ map_const ("int", "%d", "SEEK_SET",
           "int", "%d", "EMULTIHOP",
           "int", "%d", "EDOTDOT",
           "int", "%d", "EBADMSG",
-          "int", "%d", "EOVERFLOW",
           "int", "%d", "ENOTUNIQ",
           "int", "%d", "EBADFD",
           "int", "%d", "EREMCHG",
@@ -182,9 +237,6 @@ map_const ("int", "%d", "SEEK_SET",
           "int", "%d", "ELIBSCN",
           "int", "%d", "ELIBMAX",
           "int", "%d", "ELIBEXEC",
-          "int", "%d", "EILSEQ",
-          "int", "%d", "ERESTART",
-          "int", "%d", "ESTRPIPE",
           "int", "%d", "EUSERS",
           "int", "%d", "ENOTSOCK",
           "int", "%d", "EDESTADDRREQ",
@@ -215,21 +267,18 @@ map_const ("int", "%d", "SEEK_SET",
           "int", "%d", "EALREADY",
           "int", "%d", "EINPROGRESS",
           "int", "%d", "ESTALE",
-          "int", "%d", "EUCLEAN",
-          "int", "%d", "ENOTNAM",
-          "int", "%d", "ENAVAIL",
-          "int", "%d", "EISNAM",
-          "int", "%d", "EREMOTEIO",
           "int", "%d", "EDQUOT",
           "int", "%d", "ENOMEDIUM",
-          "int", "%d", "EMEDIUMTYPE",
+          "int", "%d", "ENOTDIR",
           );
 
 sub init {
 
     $csmode = 0;
+    $defmode = 0;
 
-    GetOptions ("csharp" => \$csmode) or die "cant parse options";
+    GetOptions ("c|csharp" => \$csmode,
+               "d|defmode" => \$defmode) or die "cant parse options";
 
     $CC = $env{"CC"};
 
@@ -239,7 +288,7 @@ sub init {
 
 
     %tmap = ("void" => "void",
-            "IntPtr" => "int",
+            "IntPtr" => "gpointer",
             "sbyte" => "gint8",
             "byte" => "guint8",
             "short" => "gint16",
@@ -271,14 +320,29 @@ sub create_func {
     my (@func) = @_;
     my ($i) = 0;
     my ($res) = "";
+    my ($cls) = 1;
+    my ($j) = 4;
+    while ($j <= $#func){
+       if ($func[$j] =~ /\*/){
+               $cls = 0;
+       }
+       $j+=2;
+    }
 
     if ($func[1] eq "") {
        $func[1] = "mono_wrapper_$func[2]";
     }
 
+    if ($defmode) {
+       $dlldef .= "\t$func[1]\n";
+    }
+
     if ($csmode) {
 
        $res = "\t[DllImport(\"$func[0]\", EntryPoint=\"$func[1]\", CharSet=CharSet.Ansi)]\n";
+       if ($cls == 0){
+          $res .= "\t[CLSCompliant(false)]\n";
+        }
        $res .= "\tpublic unsafe static extern $func[3] $func[2] (";
        $i +=4;
        while ($i <= $#func) {
@@ -377,12 +441,12 @@ sub map_const {
 
     close (TFN);
 
-    system ("$CC $cflags $tfn") == 0
+    system ("$CC $cflags $tfn -o conftest.exe") == 0
        or die "calling c compiler failed";
 
     system ("rm $tfn");
 
-    $res = `./a.out`;
+    $res = `./conftest.exe`;
 
     if (!$res) {
        die "calling a.out failde";
@@ -390,7 +454,7 @@ sub map_const {
 
     $res_const = $res_const . $res;
 
-    system ("rm ./a.out");     
+    system ("rm ./conftest.exe");      
 }
 
 sub etypes_end {
@@ -423,7 +487,7 @@ if ($csmode) {
     print "using System;\n";
     print "using System.Runtime.InteropServices;\n\n";
 
-    print "namespace Unix {\n\n";
+    print "namespace System.Private {\n\n";
 
     print $res_struct;
 
@@ -439,6 +503,12 @@ if ($csmode) {
 
     print "}\n";
     
+} elsif ($defmode) {
+       
+    print "LIBRARY libmonowrapper\n";
+    print "EXPORTS\n";
+    print "\tDllMain\n";
+    print $dlldef;
 
 } else {