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 = `pkg-config --cflags glib-2.0`;
25 $res_struct .= "[CLSCompliant(false)]\n";
27 create_struct
("MonoWrapperStat", "stat",
39 create_func
($lib, "", "seek", "long",
44 create_func
($lib, "", "mkdir", "int",
48 create_func
($lib, "", "rmdir", "int",
51 create_func
($lib, "", "read", "int",
56 create_func
($lib, "", "write", "int",
61 create_func
($lib, "", "fstat", "int",
65 create_func
($lib, "", "ftruncate", "int",
69 create_func
($lib, "", "open", "IntPtr",
74 create_func
($lib, "", "close", "int",
77 create_func
($lib, "", "stat", "int",
81 create_func
($lib, "", "unlink", "int",
84 create_func
($lib, "", "opendir", "IntPtr",
87 create_func
($lib, "", "readdir", "string",
90 create_func
($lib, "", "closedir", "int",
93 create_func
($lib, "", "getenv", "IntPtr",
94 "string", "variable");
96 create_func
($lib, "", "environ", "IntPtr");
98 create_func
($lib, "", "rename", "int",
102 create_func
($lib, "", "utime", "int",
107 create_func
($lib, "mono_glob_compile", "mono_glob_compile", "IntPtr",
110 create_func
($lib, "mono_glob_match", "mono_glob_match", "int",
114 create_func
($lib, "mono_glob_dispose", "mono_glob_dispose", "void",
117 map_const
("int", "%d", "SEEK_SET",
118 "int", "%d", "SEEK_CUR",
119 "int", "%d", "SEEK_END",
121 "int", "0x%08x", "O_RDONLY",
122 "int", "0x%08x", "O_WRONLY",
123 "int", "0x%08x", "O_RDWR",
124 "int", "0x%08x", "O_CREAT",
125 "int", "0x%08x", "O_EXCL",
126 "int", "0x%08x", "O_NOCTTY",
127 "int", "0x%08x", "O_TRUNC",
128 "int", "0x%08x", "O_SYNC",
129 "int", "0x%08x", "O_APPEND",
131 "int", "0x%08x", "STDIN_FILENO",
132 "int", "0x%08x", "STDOUT_FILENO",
133 "int", "0x%08x", "STDERR_FILENO",
135 "int", "0x%08x", "S_IFMT",
136 "int", "0x%08x", "S_IFSOCK",
137 "int", "0x%08x", "S_IFLNK",
138 "int", "0x%08x", "S_IFREG",
139 "int", "0x%08x", "S_IFBLK",
140 "int", "0x%08x", "S_IFDIR",
141 "int", "0x%08x", "S_IFCHR",
142 "int", "0x%08x", "S_IFIFO",
143 "int", "0x%08x", "S_ISUID",
144 "int", "0x%08x", "S_ISGID",
145 "int", "0x%08x", "S_ISVTX",
146 "int", "0x%08x", "S_IRWXU",
147 "int", "0x%08x", "S_IRUSR",
148 "int", "0x%08x", "S_IWUSR",
149 "int", "0x%08x", "S_IXUSR",
150 "int", "0x%08x", "S_IRWXG",
151 "int", "0x%08x", "S_IRGRP",
152 "int", "0x%08x", "S_IWGRP",
153 "int", "0x%08x", "S_IXGRP",
154 "int", "0x%08x", "S_IRWXO",
155 "int", "0x%08x", "S_IROTH",
156 "int", "0x%08x", "S_IWOTH",
157 "int", "0x%08x", "S_IXOTH",
159 "int", "%d", "EPERM",
160 "int", "%d", "ENOENT",
161 "int", "%d", "ESRCH",
162 "int", "%d", "EINTR",
164 "int", "%d", "ENXIO",
165 "int", "%d", "E2BIG",
166 "int", "%d", "ENOEXEC",
167 "int", "%d", "EBADF",
168 "int", "%d", "ECHILD",
169 "int", "%d", "EAGAIN",
170 "int", "%d", "ENOMEM",
171 "int", "%d", "EACCES",
172 "int", "%d", "EFAULT",
173 "int", "%d", "ENOTBLK",
174 "int", "%d", "EBUSY",
175 "int", "%d", "EEXIST",
176 "int", "%d", "EXDEV",
177 "int", "%d", "ENODEV",
178 "int", "%d", "EISDIR",
179 "int", "%d", "EINVAL",
180 "int", "%d", "ENFILE",
181 "int", "%d", "EMFILE",
182 "int", "%d", "ENOTTY",
183 "int", "%d", "ETXTBSY",
184 "int", "%d", "EFBIG",
185 "int", "%d", "ENOSPC",
186 "int", "%d", "ESPIPE",
187 "int", "%d", "EROFS",
188 "int", "%d", "EMLINK",
189 "int", "%d", "EPIPE",
191 "int", "%d", "ERANGE",
192 "int", "%d", "EDEADLK",
193 "int", "%d", "ENAMETOOLONG",
194 "int", "%d", "ENOLCK",
195 "int", "%d", "ENOSYS",
196 "int", "%d", "ENOTEMPTY",
197 "int", "%d", "ELOOP",
198 "int", "%d", "EWOULDBLOCK",
199 "int", "%d", "ENOMSG",
200 "int", "%d", "EIDRM",
201 "int", "%d", "ECHRNG",
202 "int", "%d", "EL2NSYNC",
203 "int", "%d", "EL3HLT",
204 "int", "%d", "EL3RST",
205 "int", "%d", "ELNRNG",
206 "int", "%d", "EUNATCH",
207 "int", "%d", "ENOCSI",
208 "int", "%d", "EL2HLT",
209 "int", "%d", "EBADE",
210 "int", "%d", "EBADR",
211 "int", "%d", "EXFULL",
212 "int", "%d", "ENOANO",
213 "int", "%d", "EBADRQC",
214 "int", "%d", "EBADSLT",
215 "int", "%d", "EDEADLOCK",
216 "int", "%d", "EBFONT",
217 "int", "%d", "ENOSTR",
218 "int", "%d", "ENODATA",
219 "int", "%d", "ETIME",
220 "int", "%d", "ENOSR",
221 "int", "%d", "ENONET",
222 "int", "%d", "ENOPKG",
223 "int", "%d", "EREMOTE",
224 "int", "%d", "ENOLINK",
226 "int", "%d", "ESRMNT",
227 "int", "%d", "ECOMM",
228 "int", "%d", "EPROTO",
229 "int", "%d", "EMULTIHOP",
230 "int", "%d", "EDOTDOT",
231 "int", "%d", "EBADMSG",
232 "int", "%d", "ENOTUNIQ",
233 "int", "%d", "EBADFD",
234 "int", "%d", "EREMCHG",
235 "int", "%d", "ELIBACC",
236 "int", "%d", "ELIBBAD",
237 "int", "%d", "ELIBSCN",
238 "int", "%d", "ELIBMAX",
239 "int", "%d", "ELIBEXEC",
240 "int", "%d", "EUSERS",
241 "int", "%d", "ENOTSOCK",
242 "int", "%d", "EDESTADDRREQ",
243 "int", "%d", "EMSGSIZE",
244 "int", "%d", "EPROTOTYPE",
245 "int", "%d", "ENOPROTOOPT",
246 "int", "%d", "EPROTONOSUPPORT",
247 "int", "%d", "ESOCKTNOSUPPORT",
248 "int", "%d", "EOPNOTSUPP",
249 "int", "%d", "EPFNOSUPPORT",
250 "int", "%d", "EAFNOSUPPORT",
251 "int", "%d", "EADDRINUSE",
252 "int", "%d", "EADDRNOTAVAIL",
253 "int", "%d", "ENETDOWN",
254 "int", "%d", "ENETUNREACH",
255 "int", "%d", "ENETRESET",
256 "int", "%d", "ECONNABORTED",
257 "int", "%d", "ECONNRESET",
258 "int", "%d", "ENOBUFS",
259 "int", "%d", "EISCONN",
260 "int", "%d", "ENOTCONN",
261 "int", "%d", "ESHUTDOWN",
262 "int", "%d", "ETOOMANYREFS",
263 "int", "%d", "ETIMEDOUT",
264 "int", "%d", "ECONNREFUSED",
265 "int", "%d", "EHOSTDOWN",
266 "int", "%d", "EHOSTUNREACH",
267 "int", "%d", "EALREADY",
268 "int", "%d", "EINPROGRESS",
269 "int", "%d", "ESTALE",
270 "int", "%d", "EDQUOT",
271 "int", "%d", "ENOMEDIUM",
272 "int", "%d", "ENOTDIR",
280 GetOptions
("c|csharp" => \
$csmode,
281 "d|defmode" => \
$defmode) or die "cant parse options";
290 %tmap = ("void" => "void",
291 "IntPtr" => "gpointer",
295 "ushort" => "guint16",
299 "ulong" => "guint64",
300 "string" => "const char *",
308 if ($name =~ m/(.*)\*\s*$/) {
310 $rname =~ s/\s+$//; # remove trailing spaces
311 $rval = $tmap{$rname} || die "unable to map type \"$name\"";
315 $rval = $tmap{$name} || die "unable to map type \"$name\"";
325 while ($j <= $#func){
326 if ($func[$j] =~ /\*/){
332 if ($func[1] eq "") {
333 $func[1] = "mono_wrapper_$func[2]";
337 $dlldef .= "\t$func[1]\n";
342 $res = "\t[DllImport(\"$func[0]\", EntryPoint=\"$func[1]\", CharSet=CharSet.Ansi)]\n";
344 $res .= "\t[CLSCompliant(false)]\n";
346 $res .= "\tpublic unsafe static extern $func[3] $func[2] (";
348 while ($i <= $#func) {
352 $res .= "$func[$i] $func[$i+1]";
362 $res = t
($func[3]) . "\n$func[1] (";
365 while ($i <= $#func) {
369 $res .= t
($func[$i]) . " $func[$i+1]";
385 $res = "public struct $str[1] {\n";
387 while ($i <= $#str) {
388 $res .= "\tpublic $str[$i] $str[$i+1];\n";
393 $res = "typedef struct {\n";
395 while ($i <= $#str) {
396 $res .= "\t" . t
($str[$i]) . " $str[$i+1];\n";
399 $res .= "} $str[0];\n\n";
402 $tmap{"$str[1]"} = "$str[0]";
417 my ($tfn) = "/tmp/etypes$$.c";
419 open (TFN
, ">$tfn") || die (0);
421 for ($i = 0; $i <= $#includes; $i++) {
422 print TFN
"#include \"$includes[$i]\"\n";
425 print TFN
"\nint main () {\n";
426 for ($i = 0; $i <= $#co; $i+=3) {
428 $l = 20 - length($co[$i+2]);
431 for (my ($j) = 0; $j < $l; $j++) {
432 $space = $space . " ";
435 print TFN
"printf (\"\\tpublic const %s %s $space= $co[$i+1];\\n\",".
436 " \"$co[$i]\", \"$co[$i+2]\", $co[$i+2]);\n";
439 print TFN
"exit (-1);\n";
444 system ("$CC $cflags $tfn -o conftest.exe") == 0
445 or die "calling c compiler failed";
449 $res = `./conftest.exe`;
452 die "calling a.out failde";
455 $res_const = $res_const . $res;
457 system ("rm ./conftest.exe");
462 @ae = split (/\./, $__class);
466 print "public class $ae[$#ae] {\n\n";
469 print "$res_const\n\n";
474 printf "} // class $ae[$#ae]\n\n";
476 for ($i = $#ae - 1; $i >= 0; $i--) {
477 print "} // namescape $ae[$i]\n";
482 print "/*\n * Generated automatically: do not edit this file.\n */\n\n";
487 print "using System;\n";
488 print "using System.Runtime.InteropServices;\n\n";
490 print "namespace System.Private {\n\n";
494 print "public class Wrapper {\n\n";
497 print "$res_const\n\n";
508 print "LIBRARY libmonowrapper\n";
515 print "#ifndef _MONO_WRAPPER_H_\n#define _MONO_WRAPPER_H_ 1\n\n";
517 for ($i = 0; $i <= $#includes; $i++) {
518 print "#include <$includes[$i]>\n";