4 # Dietmar Maurer (dietmar@ximian.com)
6 # (C) 2001 Ximian, Inc.
11 if ($ENV{"OSTYPE"} eq "cygwin") {
12 @includes = ("sys/types.h", "sys/stat.h", "unistd.h", "fcntl.h", "glib.h",
15 @includes = ("sys/types.h", "sys/stat.h", "unistd.h", "fcntl.h", "glib.h",
19 $cflags = `glib-config --cflags glib`;
24 create_struct ("MonoWrapperStat", "stat",
36 create_func ($lib, "", "seek", "long",
41 create_func ($lib, "", "read", "int",
46 create_func ($lib, "", "write", "int",
51 create_func ($lib, "", "fstat", "int",
55 create_func ($lib, "", "ftruncate", "int",
59 create_func ($lib, "", "open", "IntPtr",
64 create_func ($lib, "", "close", "int",
67 create_func ($lib, "", "stat", "int",
71 create_func ($lib, "", "unlink", "int",
74 create_func ($lib, "", "opendir", "IntPtr",
77 create_func ($lib, "", "readdir", "string",
80 create_func ($lib, "", "closedir", "int",
83 create_func ($lib, "", "getenv", "IntPtr",
84 "string", "variable");
86 create_func ($lib, "", "environ", "IntPtr");
89 map_const ("int", "%d", "SEEK_SET",
90 "int", "%d", "SEEK_CUR",
91 "int", "%d", "SEEK_END",
93 "int", "0x%08x", "O_RDONLY",
94 "int", "0x%08x", "O_WRONLY",
95 "int", "0x%08x", "O_RDWR",
96 "int", "0x%08x", "O_CREAT",
97 "int", "0x%08x", "O_EXCL",
98 "int", "0x%08x", "O_NOCTTY",
99 "int", "0x%08x", "O_TRUNC",
100 "int", "0x%08x", "O_SYNC",
101 "int", "0x%08x", "O_APPEND",
103 "int", "0x%08x", "STDIN_FILENO",
104 "int", "0x%08x", "STDOUT_FILENO",
105 "int", "0x%08x", "STDERR_FILENO",
107 "int", "0x%08x", "S_IFMT",
108 "int", "0x%08x", "S_IFSOCK",
109 "int", "0x%08x", "S_IFLNK",
110 "int", "0x%08x", "S_IFREG",
111 "int", "0x%08x", "S_IFBLK",
112 "int", "0x%08x", "S_IFDIR",
113 "int", "0x%08x", "S_IFCHR",
114 "int", "0x%08x", "S_IFIFO",
115 "int", "0x%08x", "S_ISUID",
116 "int", "0x%08x", "S_ISGID",
117 "int", "0x%08x", "S_ISVTX",
118 "int", "0x%08x", "S_IRWXU",
119 "int", "0x%08x", "S_IRUSR",
120 "int", "0x%08x", "S_IWUSR",
121 "int", "0x%08x", "S_IXUSR",
122 "int", "0x%08x", "S_IRWXG",
123 "int", "0x%08x", "S_IRGRP",
124 "int", "0x%08x", "S_IWGRP",
125 "int", "0x%08x", "S_IXGRP",
126 "int", "0x%08x", "S_IRWXO",
127 "int", "0x%08x", "S_IROTH",
128 "int", "0x%08x", "S_IWOTH",
129 "int", "0x%08x", "S_IXOTH",
131 "int", "%d", "EPERM",
132 "int", "%d", "ENOENT",
133 "int", "%d", "ESRCH",
134 "int", "%d", "EINTR",
136 "int", "%d", "ENXIO",
137 "int", "%d", "E2BIG",
138 "int", "%d", "ENOEXEC",
139 "int", "%d", "EBADF",
140 "int", "%d", "ECHILD",
141 "int", "%d", "EAGAIN",
142 "int", "%d", "ENOMEM",
143 "int", "%d", "EACCES",
144 "int", "%d", "EFAULT",
145 "int", "%d", "ENOTBLK",
146 "int", "%d", "EBUSY",
147 "int", "%d", "EEXIST",
148 "int", "%d", "EXDEV",
149 "int", "%d", "ENODEV",
150 "int", "%d", "EISDIR",
151 "int", "%d", "EINVAL",
152 "int", "%d", "ENFILE",
153 "int", "%d", "EMFILE",
154 "int", "%d", "ENOTTY",
155 "int", "%d", "ETXTBSY",
156 "int", "%d", "EFBIG",
157 "int", "%d", "ENOSPC",
158 "int", "%d", "ESPIPE",
159 "int", "%d", "EROFS",
160 "int", "%d", "EMLINK",
161 "int", "%d", "EPIPE",
163 "int", "%d", "ERANGE",
164 "int", "%d", "EDEADLK",
165 "int", "%d", "ENAMETOOLONG",
166 "int", "%d", "ENOLCK",
167 "int", "%d", "ENOSYS",
168 "int", "%d", "ENOTEMPTY",
169 "int", "%d", "ELOOP",
170 "int", "%d", "EWOULDBLOCK",
171 "int", "%d", "ENOMSG",
172 "int", "%d", "EIDRM",
173 "int", "%d", "ECHRNG",
174 "int", "%d", "EL2NSYNC",
175 "int", "%d", "EL3HLT",
176 "int", "%d", "EL3RST",
177 "int", "%d", "ELNRNG",
178 "int", "%d", "EUNATCH",
179 "int", "%d", "ENOCSI",
180 "int", "%d", "EL2HLT",
181 "int", "%d", "EBADE",
182 "int", "%d", "EBADR",
183 "int", "%d", "EXFULL",
184 "int", "%d", "ENOANO",
185 "int", "%d", "EBADRQC",
186 "int", "%d", "EBADSLT",
187 "int", "%d", "EDEADLOCK",
188 "int", "%d", "EBFONT",
189 "int", "%d", "ENOSTR",
190 "int", "%d", "ENODATA",
191 "int", "%d", "ETIME",
192 "int", "%d", "ENOSR",
193 "int", "%d", "ENONET",
194 "int", "%d", "ENOPKG",
195 "int", "%d", "EREMOTE",
196 "int", "%d", "ENOLINK",
198 "int", "%d", "ESRMNT",
199 "int", "%d", "ECOMM",
200 "int", "%d", "EPROTO",
201 "int", "%d", "EMULTIHOP",
202 "int", "%d", "EDOTDOT",
203 "int", "%d", "EBADMSG",
204 "int", "%d", "ENOTUNIQ",
205 "int", "%d", "EBADFD",
206 "int", "%d", "EREMCHG",
207 "int", "%d", "ELIBACC",
208 "int", "%d", "ELIBBAD",
209 "int", "%d", "ELIBSCN",
210 "int", "%d", "ELIBMAX",
211 "int", "%d", "ELIBEXEC",
212 "int", "%d", "EUSERS",
213 "int", "%d", "ENOTSOCK",
214 "int", "%d", "EDESTADDRREQ",
215 "int", "%d", "EMSGSIZE",
216 "int", "%d", "EPROTOTYPE",
217 "int", "%d", "ENOPROTOOPT",
218 "int", "%d", "EPROTONOSUPPORT",
219 "int", "%d", "ESOCKTNOSUPPORT",
220 "int", "%d", "EOPNOTSUPP",
221 "int", "%d", "EPFNOSUPPORT",
222 "int", "%d", "EAFNOSUPPORT",
223 "int", "%d", "EADDRINUSE",
224 "int", "%d", "EADDRNOTAVAIL",
225 "int", "%d", "ENETDOWN",
226 "int", "%d", "ENETUNREACH",
227 "int", "%d", "ENETRESET",
228 "int", "%d", "ECONNABORTED",
229 "int", "%d", "ECONNRESET",
230 "int", "%d", "ENOBUFS",
231 "int", "%d", "EISCONN",
232 "int", "%d", "ENOTCONN",
233 "int", "%d", "ESHUTDOWN",
234 "int", "%d", "ETOOMANYREFS",
235 "int", "%d", "ETIMEDOUT",
236 "int", "%d", "ECONNREFUSED",
237 "int", "%d", "EHOSTDOWN",
238 "int", "%d", "EHOSTUNREACH",
239 "int", "%d", "EALREADY",
240 "int", "%d", "EINPROGRESS",
241 "int", "%d", "ESTALE",
242 "int", "%d", "EDQUOT",
243 "int", "%d", "ENOMEDIUM",
244 "int", "%d", "ENOTDIR",
252 GetOptions ("c|csharp" => \$csmode,
253 "d|defmode" => \$defmode) or die "cant parse options";
262 %tmap = ("void" => "void",
263 "IntPtr" => "gpointer",
267 "ushort" => "guint16",
271 "ulong" => "guint64",
272 "string" => "const char *",
280 if ($name =~ m/(.*)\*\s*$/) {
282 $rname =~ s/\s+$//; # remove trailing spaces
283 $rval = $tmap{$rname} || die "unable to map type \"$name\"";
287 $rval = $tmap{$name} || die "unable to map type \"$name\"";
296 if ($func[1] eq "") {
297 $func[1] = "mono_wrapper_$func[2]";
301 $dlldef .= "\t$func[1]\n";
306 $res = "\t[DllImport(\"$func[0]\", EntryPoint=\"$func[1]\", CharSet=CharSet.Ansi)]\n";
307 $res .= "\tpublic unsafe static extern $func[3] $func[2] (";
309 while ($i <= $#func) {
313 $res .= "$func[$i] $func[$i+1]";
323 $res = t($func[3]) . "\n$func[1] (";
326 while ($i <= $#func) {
330 $res .= t($func[$i]) . " $func[$i+1]";
346 $res = "public struct $str[1] {\n";
348 while ($i <= $#str) {
349 $res .= "\tpublic $str[$i] $str[$i+1];\n";
354 $res = "typedef struct {\n";
356 while ($i <= $#str) {
357 $res .= "\t" . t($str[$i]) . " $str[$i+1];\n";
360 $res .= "} $str[0];\n\n";
363 $tmap{"$str[1]"} = "$str[0]";
378 my ($tfn) = "/tmp/etypes$$.c";
380 open (TFN, ">$tfn") || die (0);
382 for ($i = 0; $i <= $#includes; $i++) {
383 print TFN "#include \"$includes[$i]\"\n";
386 print TFN "\nint main () {\n";
387 for ($i = 0; $i <= $#co; $i+=3) {
389 $l = 20 - length($co[$i+2]);
392 for (my ($j) = 0; $j < $l; $j++) {
393 $space = $space . " ";
396 print TFN "printf (\"\\tpublic const %s %s $space= $co[$i+1];\\n\",".
397 " \"$co[$i]\", \"$co[$i+2]\", $co[$i+2]);\n";
400 print TFN "exit (-1);\n";
405 system ("$CC $cflags $tfn -o conftest.exe") == 0
406 or die "calling c compiler failed";
410 $res = `./conftest.exe`;
413 die "calling a.out failde";
416 $res_const = $res_const . $res;
418 system ("rm ./conftest.exe");
423 @ae = split (/\./, $__class);
427 print "public class $ae[$#ae] {\n\n";
430 print "$res_const\n\n";
435 printf "} // class $ae[$#ae]\n\n";
437 for ($i = $#ae - 1; $i >= 0; $i--) {
438 print "} // namescape $ae[$i]\n";
443 print "/*\n * Generated automatically: do not edit this file.\n */\n\n";
448 print "using System;\n";
449 print "using System.Runtime.InteropServices;\n\n";
451 print "namespace System.Private {\n\n";
455 print "public class Wrapper {\n\n";
458 print "$res_const\n\n";
469 print "LIBRARY libmonowrapper\n";
476 print "#ifndef _MONO_WRAPPER_H_\n#define _MONO_WRAPPER_H_ 1\n\n";
478 for ($i = 0; $i <= $#includes; $i++) {
479 print "#include <$includes[$i]>\n";