2 * Rummage through the system header files using the C compiler itself
3 * as a parser, extracting stuff like preprocessor constants and the
4 * sizes and signedness of basic system types, and write it out as
9 * This software is part of the SBCL system. See the README file for
12 * While most of SBCL is derived from the CMU CL system, many
13 * utilities for the build process (like this one) were written from
14 * scratch after the fork from CMU CL.
16 * This software is in the public domain and is provided with
17 * absolutely no warranty. See the COPYING and CREDITS files for
23 #include <sys/types.h>
25 #define WIN32_LEAN_AND_MEAN
29 #include <sys/times.h>
31 #include <sys/ioctl.h>
32 #include <sys/termios.h>
34 #include "../src/runtime/darwin-dlshim.h"
35 #include "../src/runtime/darwin-langinfo.h"
48 #include "genesis/config.h"
50 #ifdef LISP_FEATURE_HPUX
51 #include <sys/bsdtty.h> /* for TIOCGPGRP */
56 #define DEFTYPE(lispname,cname) { cname foo; \
57 printf("(define-alien-type " lispname " (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); }
60 defconstant(char* lisp_name, unsigned long unix_number)
62 printf("(defconstant %s %lu) ; #x%lx\n",
63 lisp_name, unix_number, unix_number);
66 void deferrno(char* lisp_name, unsigned long unix_number)
68 defconstant(lisp_name, unix_number);
71 void defsignal(char* lisp_name, unsigned long unix_number)
73 defconstant(lisp_name, unix_number);
77 main(int argc, char *argv[])
79 /* don't need no steenking command line arguments */
81 fprintf(stderr, "argh! command line argument(s)\n");
85 /* don't need no steenking hand-editing */
87 ";;;; This is an automatically generated file, please do not hand-edit it.\n\
88 ;;;; See the program \"grovel-headers.c\".\n\
92 printf("(in-package \"SB!WIN32\")\n\n");
94 defconstant ("input-record-size", sizeof (INPUT_RECORD));
96 defconstant ("MAX_PATH", MAX_PATH);
98 printf(";;; CSIDL\n");
100 defconstant ("CSIDL_DESKTOP", CSIDL_DESKTOP);
101 defconstant ("CSIDL_INTERNET", CSIDL_INTERNET);
102 defconstant ("CSIDL_PROGRAMS", CSIDL_PROGRAMS);
103 defconstant ("CSIDL_CONTROLS", CSIDL_CONTROLS);
104 defconstant ("CSIDL_PRINTERS", CSIDL_PRINTERS);
105 defconstant ("CSIDL_PERSONAL", CSIDL_PERSONAL);
106 defconstant ("CSIDL_FAVORITES", CSIDL_FAVORITES);
107 defconstant ("CSIDL_STARTUP", CSIDL_STARTUP);
108 defconstant ("CSIDL_RECENT", CSIDL_RECENT);
109 defconstant ("CSIDL_SENDTO", CSIDL_SENDTO);
110 defconstant ("CSIDL_BITBUCKET", CSIDL_BITBUCKET);
111 defconstant ("CSIDL_STARTMENU", CSIDL_STARTMENU);
112 defconstant ("CSIDL_DESKTOPDIRECTORY", CSIDL_DESKTOPDIRECTORY);
113 defconstant ("CSIDL_DRIVES", CSIDL_DRIVES);
114 defconstant ("CSIDL_NETWORK", CSIDL_NETWORK);
115 defconstant ("CSIDL_NETHOOD", CSIDL_NETHOOD);
116 defconstant ("CSIDL_FONTS", CSIDL_FONTS);
117 defconstant ("CSIDL_TEMPLATES", CSIDL_TEMPLATES);
118 defconstant ("CSIDL_COMMON_STARTMENU", CSIDL_COMMON_STARTMENU);
119 defconstant ("CSIDL_COMMON_PROGRAMS", CSIDL_COMMON_PROGRAMS);
120 defconstant ("CSIDL_COMMON_STARTUP", CSIDL_COMMON_STARTUP);
121 defconstant ("CSIDL_COMMON_DESKTOPDIRECTORY", CSIDL_COMMON_DESKTOPDIRECTORY);
122 defconstant ("CSIDL_APPDATA", CSIDL_APPDATA);
123 defconstant ("CSIDL_PRINTHOOD", CSIDL_PRINTHOOD);
124 defconstant ("CSIDL_LOCAL_APPDATA", CSIDL_LOCAL_APPDATA);
125 defconstant ("CSIDL_ALTSTARTUP", CSIDL_ALTSTARTUP);
126 defconstant ("CSIDL_COMMON_ALTSTARTUP", CSIDL_COMMON_ALTSTARTUP);
127 defconstant ("CSIDL_COMMON_FAVORITES", CSIDL_COMMON_FAVORITES);
128 defconstant ("CSIDL_INTERNET_CACHE", CSIDL_INTERNET_CACHE);
129 defconstant ("CSIDL_COOKIES", CSIDL_COOKIES);
130 defconstant ("CSIDL_HISTORY", CSIDL_HISTORY);
131 defconstant ("CSIDL_COMMON_APPDATA", CSIDL_COMMON_APPDATA);
132 defconstant ("CSIDL_WINDOWS", CSIDL_WINDOWS);
133 defconstant ("CSIDL_SYSTEM", CSIDL_SYSTEM);
134 defconstant ("CSIDL_PROGRAM_FILES", CSIDL_PROGRAM_FILES);
135 defconstant ("CSIDL_MYPICTURES", CSIDL_MYPICTURES);
136 defconstant ("CSIDL_PROFILE", CSIDL_PROFILE);
137 defconstant ("CSIDL_SYSTEMX86", CSIDL_SYSTEMX86);
138 defconstant ("CSIDL_PROGRAM_FILESX86", CSIDL_PROGRAM_FILESX86);
139 defconstant ("CSIDL_PROGRAM_FILES_COMMON", CSIDL_PROGRAM_FILES_COMMON);
140 defconstant ("CSIDL_PROGRAM_FILES_COMMONX86", CSIDL_PROGRAM_FILES_COMMONX86);
141 defconstant ("CSIDL_COMMON_TEMPLATES", CSIDL_COMMON_TEMPLATES);
142 defconstant ("CSIDL_COMMON_DOCUMENTS", CSIDL_COMMON_DOCUMENTS);
143 defconstant ("CSIDL_COMMON_ADMINTOOLS", CSIDL_COMMON_ADMINTOOLS);
144 defconstant ("CSIDL_ADMINTOOLS", CSIDL_ADMINTOOLS);
145 defconstant ("CSIDL_CONNECTIONS", CSIDL_CONNECTIONS);
146 defconstant ("CSIDL_COMMON_MUSIC", CSIDL_COMMON_MUSIC);
147 defconstant ("CSIDL_COMMON_PICTURES", CSIDL_COMMON_PICTURES);
148 defconstant ("CSIDL_COMMON_VIDEO", CSIDL_COMMON_VIDEO);
149 defconstant ("CSIDL_RESOURCES", CSIDL_RESOURCES);
150 defconstant ("CSIDL_RESOURCES_LOCALIZED", CSIDL_RESOURCES_LOCALIZED);
151 defconstant ("CSIDL_COMMON_OEM_LINKS", CSIDL_COMMON_OEM_LINKS);
152 defconstant ("CSIDL_CDBURN_AREA", CSIDL_CDBURN_AREA);
153 defconstant ("CSIDL_COMPUTERSNEARME", CSIDL_COMPUTERSNEARME);
154 defconstant ("CSIDL_FLAG_DONT_VERIFY", CSIDL_FLAG_DONT_VERIFY);
155 defconstant ("CSIDL_FLAG_CREATE", CSIDL_FLAG_CREATE);
156 defconstant ("CSIDL_FLAG_MASK", CSIDL_FLAG_MASK);
158 printf(";;; Exception codes\n");
159 defconstant("+exception-access-violation+", EXCEPTION_ACCESS_VIOLATION);
160 defconstant("+exception-array-bounds-exceeded+", EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
161 defconstant("+exception-breakpoint+", EXCEPTION_BREAKPOINT);
162 defconstant("+exception-datatype-misalignment+", EXCEPTION_DATATYPE_MISALIGNMENT);
163 defconstant("+exception-flt-denormal-operand+", EXCEPTION_FLT_DENORMAL_OPERAND);
164 defconstant("+exception-flt-divide-by-zero+", EXCEPTION_FLT_DIVIDE_BY_ZERO);
165 defconstant("+exception-flt-inexact-result+", EXCEPTION_FLT_INEXACT_RESULT);
166 defconstant("+exception-flt-invalid-operation+", EXCEPTION_FLT_INVALID_OPERATION);
167 defconstant("+exception-flt-overflow+", EXCEPTION_FLT_OVERFLOW);
168 defconstant("+exception-flt-stack-check+", EXCEPTION_FLT_STACK_CHECK);
169 defconstant("+exception-flt-underflow+", EXCEPTION_FLT_UNDERFLOW);
170 defconstant("+exception-illegal-instruction+", EXCEPTION_ILLEGAL_INSTRUCTION);
171 defconstant("+exception-in-page-error+", EXCEPTION_IN_PAGE_ERROR);
172 defconstant("+exception-int-divide-by-zero+", EXCEPTION_INT_DIVIDE_BY_ZERO);
173 defconstant("+exception-int-overflow+", EXCEPTION_INT_OVERFLOW);
174 defconstant("+exception-invalid-disposition+", EXCEPTION_INVALID_DISPOSITION);
175 defconstant("+exception-noncontinuable-exception+", EXCEPTION_NONCONTINUABLE_EXCEPTION);
176 defconstant("+exception-priv-instruction+", EXCEPTION_PRIV_INSTRUCTION);
177 defconstant("+exception-single-step+", EXCEPTION_SINGLE_STEP);
178 defconstant("+exception-stack-overflow+", EXCEPTION_STACK_OVERFLOW);
180 printf(";;; FormatMessage\n");
182 defconstant ("FORMAT_MESSAGE_ALLOCATE_BUFFER", FORMAT_MESSAGE_ALLOCATE_BUFFER);
183 defconstant ("FORMAT_MESSAGE_FROM_SYSTEM", FORMAT_MESSAGE_FROM_SYSTEM);
185 printf(";;; Errors\n");
187 defconstant ("ERROR_ENVVAR_NOT_FOUND", ERROR_ENVVAR_NOT_FOUND);
189 printf(";;; GetComputerName\n");
191 defconstant ("MAX_COMPUTERNAME_LENGTH", MAX_COMPUTERNAME_LENGTH);
192 defconstant ("ERROR_BUFFER_OVERFLOW", ERROR_BUFFER_OVERFLOW);
194 printf(";;; Windows Types\n");
195 DEFTYPE("int-ptr", INT_PTR);
196 DEFTYPE("dword", DWORD);
197 DEFTYPE("bool", BOOL);
198 DEFTYPE("uint", UINT);
199 DEFTYPE("ulong", ULONG);
201 /* FIXME: SB-UNIX and SB-WIN32 really need to be untangled. */
202 printf("(in-package \"SB!UNIX\")\n\n");
203 printf(";;; Unix-like constants and types on Windows\n");
204 defconstant("o_rdonly", _O_RDONLY);
205 defconstant("o_wronly", _O_WRONLY);
206 defconstant("o_rdwr", _O_RDWR);
207 defconstant("o_creat", _O_CREAT);
208 defconstant("o_trunc", _O_TRUNC);
209 defconstant("o_append", _O_APPEND);
210 defconstant("o_excl", _O_EXCL);
211 defconstant("o_binary", _O_BINARY);
213 defconstant("enoent", ENOENT);
214 defconstant("eexist", EEXIST);
215 defconstant("eintr", EINTR);
216 defconstant("eagain", EAGAIN);
218 defconstant("s-ifmt", S_IFMT);
219 defconstant("s-ifdir", S_IFDIR);
220 defconstant("s-ifreg", S_IFREG);
222 DEFTYPE("ino-t", ino_t);
223 DEFTYPE("time-t", time_t);
224 DEFTYPE("off-t", off_t);
225 DEFTYPE("size-t", size_t);
226 DEFTYPE("mode-t", mode_t);
228 DEFTYPE("wst-dev-t", wst_dev_t);
229 DEFTYPE("wst-off-t", wst_off_t);
230 DEFTYPE("wst-blksize-t", wst_blksize_t);
231 DEFTYPE("wst-blkcnt-t", wst_blkcnt_t);
232 DEFTYPE("wst-nlink-t", wst_nlink_t);
233 DEFTYPE("wst-uid-t", wst_uid_t);
234 DEFTYPE("wst-gid-t", wst_gid_t);
237 printf("(in-package \"SB!ALIEN\")\n\n");
239 printf (";;;flags for dlopen()\n");
241 defconstant ("rtld-lazy", RTLD_LAZY);
242 defconstant ("rtld-now", RTLD_NOW);
243 defconstant ("rtld-global", RTLD_GLOBAL);
245 printf("(in-package \"SB!UNIX\")\n\n");
247 printf(";;; langinfo\n");
248 defconstant("codeset", CODESET);
250 printf(";;; types, types, types\n");
251 DEFTYPE("clock-t", clock_t);
252 DEFTYPE("dev-t", dev_t);
253 DEFTYPE("gid-t", gid_t);
254 DEFTYPE("ino-t", ino_t);
255 DEFTYPE("mode-t", mode_t);
256 DEFTYPE("nlink-t", nlink_t);
257 DEFTYPE("off-t", off_t);
258 DEFTYPE("size-t", size_t);
259 DEFTYPE("time-t", time_t);
260 #if !defined(LISP_FEATURE_OS_PROVIDES_SUSECONDS_T)
261 /* Similar kludge in sb-posix. */
262 DEFTYPE("suseconds-t", long);
264 DEFTYPE("suseconds-t", suseconds_t);
266 DEFTYPE("uid-t", uid_t);
267 printf(";; Types in src/runtime/wrap.h. See that file for explantion.\n");
268 printf(";; Don't use these types for anything other than the stat wrapper.\n");
269 DEFTYPE("wst-dev-t", wst_dev_t);
270 DEFTYPE("wst-off-t", wst_off_t);
271 DEFTYPE("wst-blksize-t", wst_blksize_t);
272 DEFTYPE("wst-blkcnt-t", wst_blkcnt_t);
273 DEFTYPE("wst-nlink-t", wst_nlink_t);
274 DEFTYPE("wst-uid-t", wst_uid_t);
275 DEFTYPE("wst-gid-t", wst_gid_t);
278 printf(";;; fcntl.h (or unistd.h on OpenBSD and NetBSD)\n");
279 defconstant("r_ok", R_OK);
280 defconstant("w_ok", W_OK);
281 defconstant("x_ok", X_OK);
282 defconstant("f_ok", F_OK);
285 printf(";;; fcntlbits.h\n");
286 defconstant("o_rdonly", O_RDONLY);
287 defconstant("o_wronly", O_WRONLY);
288 defconstant("o_rdwr", O_RDWR);
289 defconstant("o_accmode", O_ACCMODE);
290 defconstant("o_creat", O_CREAT);
291 defconstant("o_excl", O_EXCL);
292 defconstant("o_noctty", O_NOCTTY);
293 defconstant("o_trunc", O_TRUNC);
294 defconstant("o_append", O_APPEND);
295 #ifdef LISP_FEATURE_LARGEFILE
296 defconstant("o_largefile", O_LARGEFILE);
300 defconstant("s-ifmt", S_IFMT);
301 defconstant("s-ififo", S_IFIFO);
302 defconstant("s-ifchr", S_IFCHR);
303 defconstant("s-ifdir", S_IFDIR);
304 defconstant("s-ifblk", S_IFBLK);
305 defconstant("s-ifreg", S_IFREG);
308 defconstant("s-iflnk", S_IFLNK);
309 defconstant("s-ifsock", S_IFSOCK);
312 printf(";;; error numbers\n");
313 deferrno("ebadf", EBADF);
314 deferrno("enoent", ENOENT);
315 deferrno("eintr", EINTR);
316 deferrno("eagain", EAGAIN);
317 deferrno("eio", EIO);
318 deferrno("eexist", EEXIST);
319 deferrno("eloop", ELOOP);
320 deferrno("espipe", ESPIPE);
321 deferrno("ewouldblock", EWOULDBLOCK);
324 printf(";;; for wait3(2) in run-program.lisp\n");
325 defconstant("wnohang", WNOHANG);
326 defconstant("wuntraced", WUNTRACED);
329 printf(";;; various ioctl(2) flags\n");
330 defconstant("tiocgpgrp", TIOCGPGRP);
331 defconstant("tiocspgrp", TIOCSPGRP);
332 defconstant("tiocgwinsz", TIOCGWINSZ);
333 defconstant("tiocswinsz", TIOCSWINSZ);
334 /* KLUDGE: These are referenced by old CMUCL-derived code, but
335 * Linux doesn't define them.
337 * I think these are the BSD names, but I don't know what the
338 * corresponding SysV/Linux names are. As a point of reference,
339 * CMUCL doesn't have these defined either (although the defining
340 * forms *do* exist in src/code/unix.lisp), so I don't feel nearly
341 * so bad about not hunting them down. Insight into renamed
342 * obscure ioctl(2) flags appreciated. --njf, 2002-08-26
344 * I note that the first one I grepped for, TIOCSIGSEND, is
345 * referenced in SBCL conditional on #+HPUX. Maybe the porters of
346 * Oxbridge know more about things like that? And even if they
347 * don't, one benefit of the Rhodes crusade to heal the worthy
348 * ports should be that afterwards, if we grep for something like
349 * this in CVS and it's not there, we can lightheartedly nuke it.
350 * -- WHN 2002-08-30 */
352 defconstant("tiocsigsend", TIOCSIGSEND);
353 defconstant("tiocflush", TIOCFLUSH);
354 defconstant("tiocgetp", TIOCGETP);
355 defconstant("tiocsetp", TIOCSETP);
356 defconstant("tiocgetc", TIOCGETC);
357 defconstant("tiocsetc", TIOCSETC);
358 defconstant("tiocgltc", TIOCGLTC);
359 defconstant("tiocsltc", TIOCSLTC);
363 printf(";;; signals\n");
364 defconstant("sig-dfl", (unsigned long)SIG_DFL);
365 defconstant("sig-ign", (unsigned long)SIG_IGN);
367 defsignal("sigalrm", SIGALRM);
368 defsignal("sigbus", SIGBUS);
369 defsignal("sigchld", SIGCHLD);
370 defsignal("sigcont", SIGCONT);
372 defsignal("sigemt", SIGEMT);
374 defsignal("sigfpe", SIGFPE);
375 defsignal("sighup", SIGHUP);
376 defsignal("sigill", SIGILL);
377 defsignal("sigint", SIGINT);
378 defsignal("sigio", SIGIO);
379 defsignal("sigiot", SIGIOT);
380 defsignal("sigkill", SIGKILL);
381 defsignal("sigpipe", SIGPIPE);
382 defsignal("sigprof", SIGPROF);
383 defsignal("sigquit", SIGQUIT);
384 defsignal("sigsegv", SIGSEGV);
386 defsignal("sigstkflt", SIGSTKFLT);
388 defsignal("sigstop", SIGSTOP);
390 defsignal("sigsys", SIGSYS);
392 defsignal("sigterm", SIGTERM);
393 defsignal("sigtrap", SIGTRAP);
394 defsignal("sigtstp", SIGTSTP);
395 defsignal("sigttin", SIGTTIN);
396 defsignal("sigttou", SIGTTOU);
397 defsignal("sigurg", SIGURG);
398 defsignal("sigusr1", SIGUSR1);
399 defsignal("sigusr2", SIGUSR2);
400 defsignal("sigvtalrm", SIGVTALRM);
402 defsignal("sigwaiting", SIGWAITING);
404 defsignal("sigwinch", SIGWINCH);
406 defsignal("sigxcpu", SIGXCPU);
409 defsignal("sigxfsz", SIGXFSZ);
412 /* Floating point exception codes. Some of these
413 * are missing on Darwin. */
415 defconstant("fpe-intovf", FPE_INTOVF);
417 defconstant("fpe-intovf", -1);
420 defconstant("fpe-intdiv", FPE_INTDIV);
422 defconstant("fpe-intdiv", -1);
424 defconstant("fpe-fltdiv", FPE_FLTDIV);
425 defconstant("fpe-fltovf", FPE_FLTOVF);
426 defconstant("fpe-fltund", FPE_FLTUND);
427 defconstant("fpe-fltres", FPE_FLTRES);
428 defconstant("fpe-fltinv", FPE_FLTINV);
430 defconstant("fpe-fltsub", FPE_FLTSUB);
432 defconstant("fpe-fltsub", -1);