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
21 #include "genesis/config.h"
25 #include <sys/types.h>
27 /* KLUDGE: From src/runtime/runtime.h, avoid double definition of
28 boolean. We really should clean up our act on this one. */
29 #define boolean rpcndr_boolean
30 #define WIN32_LEAN_AND_MEAN
35 #include <sys/times.h>
37 #include <sys/ioctl.h>
38 #include <sys/termios.h>
39 #ifdef LISP_FEATURE_DARWIN
40 #include "../src/runtime/darwin-langinfo.h"
44 #ifdef LISP_FEATURE_DLSHIM
45 #include "../src/runtime/darwin-dlshim.h"
57 #ifdef LISP_FEATURE_HPUX
58 #include <sys/bsdtty.h> /* for TIOCGPGRP */
61 #ifdef LISP_FEATURE_BSD
62 #include <sys/param.h>
63 #include <sys/sysctl.h>
69 #define DEFTYPE(lispname,cname) { cname foo; \
70 printf("(define-alien-type " lispname " (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); }
73 defconstant(char* lisp_name, unsigned long unix_number)
75 printf("(defconstant %s %lu) ; #x%lx\n",
76 lisp_name, unix_number, unix_number);
79 void deferrno(char* lisp_name, unsigned long unix_number)
81 defconstant(lisp_name, unix_number);
84 void defsignal(char* lisp_name, unsigned long unix_number)
86 defconstant(lisp_name, unix_number);
90 main(int argc, char *argv[])
92 /* don't need no steenking command line arguments */
94 fprintf(stderr, "argh! command line argument(s)\n");
98 /* don't need no steenking hand-editing */
100 ";;;; This is an automatically generated file, please do not hand-edit it.\n\
101 ;;;; See the program \"grovel-headers.c\".\n\
105 printf("(in-package \"SB!WIN32\")\n\n");
107 defconstant ("input-record-size", sizeof (INPUT_RECORD));
109 defconstant ("MAX_PATH", MAX_PATH);
111 printf(";;; CSIDL\n");
113 defconstant ("CSIDL_DESKTOP", CSIDL_DESKTOP);
114 defconstant ("CSIDL_INTERNET", CSIDL_INTERNET);
115 defconstant ("CSIDL_PROGRAMS", CSIDL_PROGRAMS);
116 defconstant ("CSIDL_CONTROLS", CSIDL_CONTROLS);
117 defconstant ("CSIDL_PRINTERS", CSIDL_PRINTERS);
118 defconstant ("CSIDL_PERSONAL", CSIDL_PERSONAL);
119 defconstant ("CSIDL_FAVORITES", CSIDL_FAVORITES);
120 defconstant ("CSIDL_STARTUP", CSIDL_STARTUP);
121 defconstant ("CSIDL_RECENT", CSIDL_RECENT);
122 defconstant ("CSIDL_SENDTO", CSIDL_SENDTO);
123 defconstant ("CSIDL_BITBUCKET", CSIDL_BITBUCKET);
124 defconstant ("CSIDL_STARTMENU", CSIDL_STARTMENU);
125 defconstant ("CSIDL_DESKTOPDIRECTORY", CSIDL_DESKTOPDIRECTORY);
126 defconstant ("CSIDL_DRIVES", CSIDL_DRIVES);
127 defconstant ("CSIDL_NETWORK", CSIDL_NETWORK);
128 defconstant ("CSIDL_NETHOOD", CSIDL_NETHOOD);
129 defconstant ("CSIDL_FONTS", CSIDL_FONTS);
130 defconstant ("CSIDL_TEMPLATES", CSIDL_TEMPLATES);
131 defconstant ("CSIDL_COMMON_STARTMENU", CSIDL_COMMON_STARTMENU);
132 defconstant ("CSIDL_COMMON_PROGRAMS", CSIDL_COMMON_PROGRAMS);
133 defconstant ("CSIDL_COMMON_STARTUP", CSIDL_COMMON_STARTUP);
134 defconstant ("CSIDL_COMMON_DESKTOPDIRECTORY", CSIDL_COMMON_DESKTOPDIRECTORY);
135 defconstant ("CSIDL_APPDATA", CSIDL_APPDATA);
136 defconstant ("CSIDL_PRINTHOOD", CSIDL_PRINTHOOD);
137 defconstant ("CSIDL_LOCAL_APPDATA", CSIDL_LOCAL_APPDATA);
138 defconstant ("CSIDL_ALTSTARTUP", CSIDL_ALTSTARTUP);
139 defconstant ("CSIDL_COMMON_ALTSTARTUP", CSIDL_COMMON_ALTSTARTUP);
140 defconstant ("CSIDL_COMMON_FAVORITES", CSIDL_COMMON_FAVORITES);
141 defconstant ("CSIDL_INTERNET_CACHE", CSIDL_INTERNET_CACHE);
142 defconstant ("CSIDL_COOKIES", CSIDL_COOKIES);
143 defconstant ("CSIDL_HISTORY", CSIDL_HISTORY);
144 defconstant ("CSIDL_COMMON_APPDATA", CSIDL_COMMON_APPDATA);
145 defconstant ("CSIDL_WINDOWS", CSIDL_WINDOWS);
146 defconstant ("CSIDL_SYSTEM", CSIDL_SYSTEM);
147 defconstant ("CSIDL_PROGRAM_FILES", CSIDL_PROGRAM_FILES);
148 defconstant ("CSIDL_MYPICTURES", CSIDL_MYPICTURES);
149 defconstant ("CSIDL_PROFILE", CSIDL_PROFILE);
150 defconstant ("CSIDL_SYSTEMX86", CSIDL_SYSTEMX86);
151 defconstant ("CSIDL_PROGRAM_FILESX86", CSIDL_PROGRAM_FILESX86);
152 defconstant ("CSIDL_PROGRAM_FILES_COMMON", CSIDL_PROGRAM_FILES_COMMON);
153 defconstant ("CSIDL_PROGRAM_FILES_COMMONX86", CSIDL_PROGRAM_FILES_COMMONX86);
154 defconstant ("CSIDL_COMMON_TEMPLATES", CSIDL_COMMON_TEMPLATES);
155 defconstant ("CSIDL_COMMON_DOCUMENTS", CSIDL_COMMON_DOCUMENTS);
156 defconstant ("CSIDL_COMMON_ADMINTOOLS", CSIDL_COMMON_ADMINTOOLS);
157 defconstant ("CSIDL_ADMINTOOLS", CSIDL_ADMINTOOLS);
158 defconstant ("CSIDL_CONNECTIONS", CSIDL_CONNECTIONS);
159 defconstant ("CSIDL_COMMON_MUSIC", CSIDL_COMMON_MUSIC);
160 defconstant ("CSIDL_COMMON_PICTURES", CSIDL_COMMON_PICTURES);
161 defconstant ("CSIDL_COMMON_VIDEO", CSIDL_COMMON_VIDEO);
162 defconstant ("CSIDL_RESOURCES", CSIDL_RESOURCES);
163 defconstant ("CSIDL_RESOURCES_LOCALIZED", CSIDL_RESOURCES_LOCALIZED);
164 defconstant ("CSIDL_COMMON_OEM_LINKS", CSIDL_COMMON_OEM_LINKS);
165 defconstant ("CSIDL_CDBURN_AREA", CSIDL_CDBURN_AREA);
166 defconstant ("CSIDL_COMPUTERSNEARME", CSIDL_COMPUTERSNEARME);
167 defconstant ("CSIDL_FLAG_DONT_VERIFY", CSIDL_FLAG_DONT_VERIFY);
168 defconstant ("CSIDL_FLAG_CREATE", CSIDL_FLAG_CREATE);
169 defconstant ("CSIDL_FLAG_MASK", CSIDL_FLAG_MASK);
171 printf(";;; Exception codes\n");
172 defconstant("+exception-access-violation+", EXCEPTION_ACCESS_VIOLATION);
173 defconstant("+exception-array-bounds-exceeded+", EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
174 defconstant("+exception-breakpoint+", EXCEPTION_BREAKPOINT);
175 defconstant("+exception-datatype-misalignment+", EXCEPTION_DATATYPE_MISALIGNMENT);
176 defconstant("+exception-flt-denormal-operand+", EXCEPTION_FLT_DENORMAL_OPERAND);
177 defconstant("+exception-flt-divide-by-zero+", EXCEPTION_FLT_DIVIDE_BY_ZERO);
178 defconstant("+exception-flt-inexact-result+", EXCEPTION_FLT_INEXACT_RESULT);
179 defconstant("+exception-flt-invalid-operation+", EXCEPTION_FLT_INVALID_OPERATION);
180 defconstant("+exception-flt-overflow+", EXCEPTION_FLT_OVERFLOW);
181 defconstant("+exception-flt-stack-check+", EXCEPTION_FLT_STACK_CHECK);
182 defconstant("+exception-flt-underflow+", EXCEPTION_FLT_UNDERFLOW);
183 defconstant("+exception-illegal-instruction+", EXCEPTION_ILLEGAL_INSTRUCTION);
184 defconstant("+exception-in-page-error+", EXCEPTION_IN_PAGE_ERROR);
185 defconstant("+exception-int-divide-by-zero+", EXCEPTION_INT_DIVIDE_BY_ZERO);
186 defconstant("+exception-int-overflow+", EXCEPTION_INT_OVERFLOW);
187 defconstant("+exception-invalid-disposition+", EXCEPTION_INVALID_DISPOSITION);
188 defconstant("+exception-noncontinuable-exception+", EXCEPTION_NONCONTINUABLE_EXCEPTION);
189 defconstant("+exception-priv-instruction+", EXCEPTION_PRIV_INSTRUCTION);
190 defconstant("+exception-single-step+", EXCEPTION_SINGLE_STEP);
191 defconstant("+exception-stack-overflow+", EXCEPTION_STACK_OVERFLOW);
193 printf(";;; FormatMessage\n");
195 defconstant ("FORMAT_MESSAGE_ALLOCATE_BUFFER", FORMAT_MESSAGE_ALLOCATE_BUFFER);
196 defconstant ("FORMAT_MESSAGE_FROM_SYSTEM", FORMAT_MESSAGE_FROM_SYSTEM);
198 printf(";;; Errors\n");
200 defconstant ("ERROR_ENVVAR_NOT_FOUND", ERROR_ENVVAR_NOT_FOUND);
202 printf(";;; GetComputerName\n");
204 defconstant ("MAX_COMPUTERNAME_LENGTH", MAX_COMPUTERNAME_LENGTH);
205 defconstant ("ERROR_BUFFER_OVERFLOW", ERROR_BUFFER_OVERFLOW);
207 printf(";;; Windows Types\n");
208 DEFTYPE("int-ptr", INT_PTR);
209 DEFTYPE("dword", DWORD);
210 DEFTYPE("bool", BOOL);
211 DEFTYPE("uint", UINT);
212 DEFTYPE("ulong", ULONG);
214 /* FIXME: SB-UNIX and SB-WIN32 really need to be untangled. */
215 printf("(in-package \"SB!UNIX\")\n\n");
216 printf(";;; Unix-like constants and types on Windows\n");
217 defconstant("o_rdonly", _O_RDONLY);
218 defconstant("o_wronly", _O_WRONLY);
219 defconstant("o_rdwr", _O_RDWR);
220 defconstant("o_creat", _O_CREAT);
221 defconstant("o_trunc", _O_TRUNC);
222 defconstant("o_append", _O_APPEND);
223 defconstant("o_excl", _O_EXCL);
224 defconstant("o_binary", _O_BINARY);
226 defconstant("enoent", ENOENT);
227 defconstant("eexist", EEXIST);
228 defconstant("eintr", EINTR);
229 defconstant("eagain", EAGAIN);
231 defconstant("s-ifmt", S_IFMT);
232 defconstant("s-ifdir", S_IFDIR);
233 defconstant("s-ifreg", S_IFREG);
235 DEFTYPE("ino-t", ino_t);
236 DEFTYPE("time-t", time_t);
237 DEFTYPE("off-t", off_t);
238 DEFTYPE("size-t", size_t);
239 DEFTYPE("mode-t", mode_t);
241 DEFTYPE("wst-dev-t", wst_dev_t);
242 DEFTYPE("wst-off-t", wst_off_t);
243 DEFTYPE("wst-blksize-t", wst_blksize_t);
244 DEFTYPE("wst-blkcnt-t", wst_blkcnt_t);
245 DEFTYPE("wst-nlink-t", wst_nlink_t);
246 DEFTYPE("wst-uid-t", wst_uid_t);
247 DEFTYPE("wst-gid-t", wst_gid_t);
250 printf("(in-package \"SB!ALIEN\")\n\n");
252 printf (";;;flags for dlopen()\n");
254 defconstant ("rtld-lazy", RTLD_LAZY);
255 defconstant ("rtld-now", RTLD_NOW);
256 defconstant ("rtld-global", RTLD_GLOBAL);
258 printf("(in-package \"SB!UNIX\")\n\n");
260 printf(";;; langinfo\n");
261 defconstant("codeset", CODESET);
263 printf(";;; types, types, types\n");
264 DEFTYPE("clock-t", clock_t);
265 DEFTYPE("dev-t", dev_t);
266 DEFTYPE("gid-t", gid_t);
267 DEFTYPE("ino-t", ino_t);
268 DEFTYPE("mode-t", mode_t);
269 DEFTYPE("nlink-t", nlink_t);
270 DEFTYPE("off-t", off_t);
271 DEFTYPE("size-t", size_t);
272 DEFTYPE("time-t", time_t);
273 #if !defined(LISP_FEATURE_OS_PROVIDES_SUSECONDS_T)
274 /* Similar kludge in sb-posix. */
275 DEFTYPE("suseconds-t", long);
277 DEFTYPE("suseconds-t", suseconds_t);
279 DEFTYPE("uid-t", uid_t);
280 printf(";; Types in src/runtime/wrap.h. See that file for explantion.\n");
281 printf(";; Don't use these types for anything other than the stat wrapper.\n");
282 DEFTYPE("wst-dev-t", wst_dev_t);
283 DEFTYPE("wst-off-t", wst_off_t);
284 DEFTYPE("wst-blksize-t", wst_blksize_t);
285 DEFTYPE("wst-blkcnt-t", wst_blkcnt_t);
286 DEFTYPE("wst-nlink-t", wst_nlink_t);
287 DEFTYPE("wst-uid-t", wst_uid_t);
288 DEFTYPE("wst-gid-t", wst_gid_t);
291 printf(";;; fcntl.h (or unistd.h on OpenBSD and NetBSD)\n");
292 defconstant("r_ok", R_OK);
293 defconstant("w_ok", W_OK);
294 defconstant("x_ok", X_OK);
295 defconstant("f_ok", F_OK);
298 printf(";;; fcntlbits.h\n");
299 defconstant("o_rdonly", O_RDONLY);
300 defconstant("o_wronly", O_WRONLY);
301 defconstant("o_rdwr", O_RDWR);
302 defconstant("o_accmode", O_ACCMODE);
303 defconstant("o_creat", O_CREAT);
304 defconstant("o_excl", O_EXCL);
305 defconstant("o_noctty", O_NOCTTY);
306 defconstant("o_trunc", O_TRUNC);
307 defconstant("o_append", O_APPEND);
308 #ifdef LISP_FEATURE_LARGEFILE
309 defconstant("o_largefile", O_LARGEFILE);
313 defconstant("s-ifmt", S_IFMT);
314 defconstant("s-ififo", S_IFIFO);
315 defconstant("s-ifchr", S_IFCHR);
316 defconstant("s-ifdir", S_IFDIR);
317 defconstant("s-ifblk", S_IFBLK);
318 defconstant("s-ifreg", S_IFREG);
321 defconstant("s-iflnk", S_IFLNK);
322 defconstant("s-ifsock", S_IFSOCK);
325 printf(";;; error numbers\n");
326 deferrno("ebadf", EBADF);
327 deferrno("enoent", ENOENT);
328 deferrno("eintr", EINTR);
329 deferrno("eagain", EAGAIN);
330 deferrno("eio", EIO);
331 deferrno("eexist", EEXIST);
332 deferrno("eloop", ELOOP);
333 deferrno("espipe", ESPIPE);
334 deferrno("ewouldblock", EWOULDBLOCK);
337 printf(";;; for wait3(2) in run-program.lisp\n");
338 defconstant("wnohang", WNOHANG);
339 defconstant("wuntraced", WUNTRACED);
342 printf(";;; various ioctl(2) flags\n");
343 defconstant("tiocgpgrp", TIOCGPGRP);
344 defconstant("tiocspgrp", TIOCSPGRP);
345 defconstant("tiocgwinsz", TIOCGWINSZ);
346 defconstant("tiocswinsz", TIOCSWINSZ);
347 /* KLUDGE: These are referenced by old CMUCL-derived code, but
348 * Linux doesn't define them.
350 * I think these are the BSD names, but I don't know what the
351 * corresponding SysV/Linux names are. As a point of reference,
352 * CMUCL doesn't have these defined either (although the defining
353 * forms *do* exist in src/code/unix.lisp), so I don't feel nearly
354 * so bad about not hunting them down. Insight into renamed
355 * obscure ioctl(2) flags appreciated. --njf, 2002-08-26
357 * I note that the first one I grepped for, TIOCSIGSEND, is
358 * referenced in SBCL conditional on #+HPUX. Maybe the porters of
359 * Oxbridge know more about things like that? And even if they
360 * don't, one benefit of the Rhodes crusade to heal the worthy
361 * ports should be that afterwards, if we grep for something like
362 * this in CVS and it's not there, we can lightheartedly nuke it.
363 * -- WHN 2002-08-30 */
365 defconstant("tiocsigsend", TIOCSIGSEND);
366 defconstant("tiocflush", TIOCFLUSH);
367 defconstant("tiocgetp", TIOCGETP);
368 defconstant("tiocsetp", TIOCSETP);
369 defconstant("tiocgetc", TIOCGETC);
370 defconstant("tiocsetc", TIOCSETC);
371 defconstant("tiocgltc", TIOCGLTC);
372 defconstant("tiocsltc", TIOCSLTC);
376 printf(";;; signals\n");
377 defconstant("sig-dfl", (unsigned long)SIG_DFL);
378 defconstant("sig-ign", (unsigned long)SIG_IGN);
380 defsignal("sigalrm", SIGALRM);
381 defsignal("sigbus", SIGBUS);
382 defsignal("sigchld", SIGCHLD);
383 defsignal("sigcont", SIGCONT);
385 defsignal("sigemt", SIGEMT);
387 defsignal("sigfpe", SIGFPE);
388 defsignal("sighup", SIGHUP);
389 defsignal("sigill", SIGILL);
390 defsignal("sigint", SIGINT);
391 defsignal("sigio", SIGIO);
392 defsignal("sigiot", SIGIOT);
393 defsignal("sigkill", SIGKILL);
394 defsignal("sigpipe", SIGPIPE);
395 defsignal("sigprof", SIGPROF);
396 defsignal("sigquit", SIGQUIT);
397 defsignal("sigsegv", SIGSEGV);
399 defsignal("sigstkflt", SIGSTKFLT);
401 defsignal("sigstop", SIGSTOP);
403 defsignal("sigsys", SIGSYS);
405 defsignal("sigterm", SIGTERM);
406 defsignal("sigtrap", SIGTRAP);
407 defsignal("sigtstp", SIGTSTP);
408 defsignal("sigttin", SIGTTIN);
409 defsignal("sigttou", SIGTTOU);
410 defsignal("sigurg", SIGURG);
411 defsignal("sigusr1", SIGUSR1);
412 defsignal("sigusr2", SIGUSR2);
413 defsignal("sigvtalrm", SIGVTALRM);
415 defsignal("sigwaiting", SIGWAITING);
417 defsignal("sigwinch", SIGWINCH);
419 defsignal("sigxcpu", SIGXCPU);
422 defsignal("sigxfsz", SIGXFSZ);
425 /* Floating point exception codes. Some of these
426 * are missing on Darwin. */
428 defconstant("fpe-intovf", FPE_INTOVF);
430 defconstant("fpe-intovf", -1);
433 defconstant("fpe-intdiv", FPE_INTDIV);
435 defconstant("fpe-intdiv", -1);
437 defconstant("fpe-fltdiv", FPE_FLTDIV);
438 defconstant("fpe-fltovf", FPE_FLTOVF);
439 defconstant("fpe-fltund", FPE_FLTUND);
440 defconstant("fpe-fltres", FPE_FLTRES);
441 defconstant("fpe-fltinv", FPE_FLTINV);
443 defconstant("fpe-fltsub", FPE_FLTSUB);
445 defconstant("fpe-fltsub", -1);
450 #ifdef LISP_FEATURE_BSD
451 printf(";;; sysctl(3) names\n");
452 printf("(in-package \"SB!IMPL\")\n");
453 defconstant("ctl-kern", CTL_KERN);
454 defconstant("ctl-hw", CTL_HW);
455 defconstant("ctl-maxname", CTL_MAXNAME);
456 defconstant("kern-ostype", KERN_OSTYPE);
457 defconstant("kern-osrelease", KERN_OSRELEASE);
458 defconstant("hw-model", HW_MODEL);
459 defconstant("hw-pagesize", HW_PAGESIZE);
463 #ifdef LISP_FEATURE_GENCGC
464 printf(";;; GENCGC related\n");
465 printf("(in-package \"SB!KERNEL\")\n");
466 DEFTYPE("page-index-t", page_index_t);
467 DEFTYPE("generation-index-t", generation_index_t);