1.0.1.18:
[sbcl/simd.git] / tools-for-build / grovel-headers.c
blob628605e8511b3943043d19b127fb7189c868ebde
1 /*
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
5 * Lisp code.
6 */
8 /*
9 * This software is part of the SBCL system. See the README file for
10 * more information.
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
18 * more information.
21 #include <stdio.h>
22 #include <sys/types.h>
23 #ifdef _WIN32
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26 #include <stdlib.h>
27 #include <shlobj.h>
28 #else
29 #include <sys/times.h>
30 #include <sys/wait.h>
31 #include <sys/ioctl.h>
32 #include <sys/termios.h>
33 #ifdef __APPLE_CC__
34 #include "../src/runtime/darwin-dlshim.h"
35 #include "../src/runtime/darwin-langinfo.h"
36 #else
37 #include <dlfcn.h>
38 #include <langinfo.h>
39 #endif
40 #endif
42 #include <sys/stat.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45 #include <signal.h>
46 #include <errno.h>
48 #include "genesis/config.h"
50 #define DEFTYPE(lispname,cname) { cname foo; \
51 printf("(define-alien-type " lispname " (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); }
53 void
54 defconstant(char* lisp_name, unsigned long unix_number)
56 printf("(defconstant %s %lu) ; #x%lx\n",
57 lisp_name, unix_number, unix_number);
60 void deferrno(char* lisp_name, unsigned long unix_number)
62 defconstant(lisp_name, unix_number);
65 void defsignal(char* lisp_name, unsigned long unix_number)
67 defconstant(lisp_name, unix_number);
70 int
71 main(int argc, char *argv[])
73 /* don't need no steenking command line arguments */
74 if (1 != argc) {
75 fprintf(stderr, "argh! command line argument(s)\n");
76 exit(1);
79 /* don't need no steenking hand-editing */
80 printf(
81 ";;;; This is an automatically generated file, please do not hand-edit it.\n\
82 ;;;; See the program \"grovel-headers.c\".\n\
83 \n\
84 ");
85 #ifdef _WIN32
86 printf("(in-package \"SB!WIN32\")\n\n");
88 defconstant ("input-record-size", sizeof (INPUT_RECORD));
90 defconstant ("MAX_PATH", MAX_PATH);
92 printf(";;; CSIDL\n");
94 defconstant ("CSIDL_DESKTOP", CSIDL_DESKTOP);
95 defconstant ("CSIDL_INTERNET", CSIDL_INTERNET);
96 defconstant ("CSIDL_PROGRAMS", CSIDL_PROGRAMS);
97 defconstant ("CSIDL_CONTROLS", CSIDL_CONTROLS);
98 defconstant ("CSIDL_PRINTERS", CSIDL_PRINTERS);
99 defconstant ("CSIDL_PERSONAL", CSIDL_PERSONAL);
100 defconstant ("CSIDL_FAVORITES", CSIDL_FAVORITES);
101 defconstant ("CSIDL_STARTUP", CSIDL_STARTUP);
102 defconstant ("CSIDL_RECENT", CSIDL_RECENT);
103 defconstant ("CSIDL_SENDTO", CSIDL_SENDTO);
104 defconstant ("CSIDL_BITBUCKET", CSIDL_BITBUCKET);
105 defconstant ("CSIDL_STARTMENU", CSIDL_STARTMENU);
106 defconstant ("CSIDL_DESKTOPDIRECTORY", CSIDL_DESKTOPDIRECTORY);
107 defconstant ("CSIDL_DRIVES", CSIDL_DRIVES);
108 defconstant ("CSIDL_NETWORK", CSIDL_NETWORK);
109 defconstant ("CSIDL_NETHOOD", CSIDL_NETHOOD);
110 defconstant ("CSIDL_FONTS", CSIDL_FONTS);
111 defconstant ("CSIDL_TEMPLATES", CSIDL_TEMPLATES);
112 defconstant ("CSIDL_COMMON_STARTMENU", CSIDL_COMMON_STARTMENU);
113 defconstant ("CSIDL_COMMON_PROGRAMS", CSIDL_COMMON_PROGRAMS);
114 defconstant ("CSIDL_COMMON_STARTUP", CSIDL_COMMON_STARTUP);
115 defconstant ("CSIDL_COMMON_DESKTOPDIRECTORY", CSIDL_COMMON_DESKTOPDIRECTORY);
116 defconstant ("CSIDL_APPDATA", CSIDL_APPDATA);
117 defconstant ("CSIDL_PRINTHOOD", CSIDL_PRINTHOOD);
118 defconstant ("CSIDL_LOCAL_APPDATA", CSIDL_LOCAL_APPDATA);
119 defconstant ("CSIDL_ALTSTARTUP", CSIDL_ALTSTARTUP);
120 defconstant ("CSIDL_COMMON_ALTSTARTUP", CSIDL_COMMON_ALTSTARTUP);
121 defconstant ("CSIDL_COMMON_FAVORITES", CSIDL_COMMON_FAVORITES);
122 defconstant ("CSIDL_INTERNET_CACHE", CSIDL_INTERNET_CACHE);
123 defconstant ("CSIDL_COOKIES", CSIDL_COOKIES);
124 defconstant ("CSIDL_HISTORY", CSIDL_HISTORY);
125 defconstant ("CSIDL_COMMON_APPDATA", CSIDL_COMMON_APPDATA);
126 defconstant ("CSIDL_WINDOWS", CSIDL_WINDOWS);
127 defconstant ("CSIDL_SYSTEM", CSIDL_SYSTEM);
128 defconstant ("CSIDL_PROGRAM_FILES", CSIDL_PROGRAM_FILES);
129 defconstant ("CSIDL_MYPICTURES", CSIDL_MYPICTURES);
130 defconstant ("CSIDL_PROFILE", CSIDL_PROFILE);
131 defconstant ("CSIDL_SYSTEMX86", CSIDL_SYSTEMX86);
132 defconstant ("CSIDL_PROGRAM_FILESX86", CSIDL_PROGRAM_FILESX86);
133 defconstant ("CSIDL_PROGRAM_FILES_COMMON", CSIDL_PROGRAM_FILES_COMMON);
134 defconstant ("CSIDL_PROGRAM_FILES_COMMONX86", CSIDL_PROGRAM_FILES_COMMONX86);
135 defconstant ("CSIDL_COMMON_TEMPLATES", CSIDL_COMMON_TEMPLATES);
136 defconstant ("CSIDL_COMMON_DOCUMENTS", CSIDL_COMMON_DOCUMENTS);
137 defconstant ("CSIDL_COMMON_ADMINTOOLS", CSIDL_COMMON_ADMINTOOLS);
138 defconstant ("CSIDL_ADMINTOOLS", CSIDL_ADMINTOOLS);
139 defconstant ("CSIDL_CONNECTIONS", CSIDL_CONNECTIONS);
140 defconstant ("CSIDL_COMMON_MUSIC", CSIDL_COMMON_MUSIC);
141 defconstant ("CSIDL_COMMON_PICTURES", CSIDL_COMMON_PICTURES);
142 defconstant ("CSIDL_COMMON_VIDEO", CSIDL_COMMON_VIDEO);
143 defconstant ("CSIDL_RESOURCES", CSIDL_RESOURCES);
144 defconstant ("CSIDL_RESOURCES_LOCALIZED", CSIDL_RESOURCES_LOCALIZED);
145 defconstant ("CSIDL_COMMON_OEM_LINKS", CSIDL_COMMON_OEM_LINKS);
146 defconstant ("CSIDL_CDBURN_AREA", CSIDL_CDBURN_AREA);
147 defconstant ("CSIDL_COMPUTERSNEARME", CSIDL_COMPUTERSNEARME);
148 defconstant ("CSIDL_FLAG_DONT_VERIFY", CSIDL_FLAG_DONT_VERIFY);
149 defconstant ("CSIDL_FLAG_CREATE", CSIDL_FLAG_CREATE);
150 defconstant ("CSIDL_FLAG_MASK", CSIDL_FLAG_MASK);
152 printf(";;; Exception codes\n");
153 defconstant("+exception-access-violation+", EXCEPTION_ACCESS_VIOLATION);
154 defconstant("+exception-array-bounds-exceeded+", EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
155 defconstant("+exception-breakpoint+", EXCEPTION_BREAKPOINT);
156 defconstant("+exception-datatype-misalignment+", EXCEPTION_DATATYPE_MISALIGNMENT);
157 defconstant("+exception-flt-denormal-operand+", EXCEPTION_FLT_DENORMAL_OPERAND);
158 defconstant("+exception-flt-divide-by-zero+", EXCEPTION_FLT_DIVIDE_BY_ZERO);
159 defconstant("+exception-flt-inexact-result+", EXCEPTION_FLT_INEXACT_RESULT);
160 defconstant("+exception-flt-invalid-operation+", EXCEPTION_FLT_INVALID_OPERATION);
161 defconstant("+exception-flt-overflow+", EXCEPTION_FLT_OVERFLOW);
162 defconstant("+exception-flt-stack-check+", EXCEPTION_FLT_STACK_CHECK);
163 defconstant("+exception-flt-underflow+", EXCEPTION_FLT_UNDERFLOW);
164 defconstant("+exception-illegal-instruction+", EXCEPTION_ILLEGAL_INSTRUCTION);
165 defconstant("+exception-in-page-error+", EXCEPTION_IN_PAGE_ERROR);
166 defconstant("+exception-int-divide-by-zero+", EXCEPTION_INT_DIVIDE_BY_ZERO);
167 defconstant("+exception-int-overflow+", EXCEPTION_INT_OVERFLOW);
168 defconstant("+exception-invalid-disposition+", EXCEPTION_INVALID_DISPOSITION);
169 defconstant("+exception-noncontinuable-exception+", EXCEPTION_NONCONTINUABLE_EXCEPTION);
170 defconstant("+exception-priv-instruction+", EXCEPTION_PRIV_INSTRUCTION);
171 defconstant("+exception-single-step+", EXCEPTION_SINGLE_STEP);
172 defconstant("+exception-stack-overflow+", EXCEPTION_STACK_OVERFLOW);
174 printf(";;; FormatMessage\n");
176 defconstant ("FORMAT_MESSAGE_ALLOCATE_BUFFER", FORMAT_MESSAGE_ALLOCATE_BUFFER);
177 defconstant ("FORMAT_MESSAGE_FROM_SYSTEM", FORMAT_MESSAGE_FROM_SYSTEM);
179 printf(";;; Errors\n");
181 defconstant ("ERROR_ENVVAR_NOT_FOUND", ERROR_ENVVAR_NOT_FOUND);
183 printf(";;; GetComputerName\n");
185 defconstant ("MAX_COMPUTERNAME_LENGTH", MAX_COMPUTERNAME_LENGTH);
186 defconstant ("ERROR_BUFFER_OVERFLOW", ERROR_BUFFER_OVERFLOW);
188 printf(";;; Windows Types\n");
189 DEFTYPE("int-ptr", INT_PTR);
190 DEFTYPE("dword", DWORD);
191 DEFTYPE("bool", BOOL);
192 DEFTYPE("uint", UINT);
193 DEFTYPE("ulong", ULONG);
195 /* FIXME: SB-UNIX and SB-WIN32 really need to be untangled. */
196 printf("(in-package \"SB!UNIX\")\n\n");
197 printf(";;; Unix-like constants and types on Windows\n");
198 defconstant("o_rdonly", _O_RDONLY);
199 defconstant("o_wronly", _O_WRONLY);
200 defconstant("o_rdwr", _O_RDWR);
201 defconstant("o_creat", _O_CREAT);
202 defconstant("o_trunc", _O_TRUNC);
203 defconstant("o_append", _O_APPEND);
204 defconstant("o_excl", _O_EXCL);
205 defconstant("o_binary", _O_BINARY);
207 defconstant("enoent", ENOENT);
208 defconstant("eexist", EEXIST);
210 defconstant("s-ifmt", S_IFMT);
211 defconstant("s-ifdir", S_IFDIR);
212 defconstant("s-ifreg", S_IFREG);
214 DEFTYPE("ino-t", ino_t);
215 DEFTYPE("time-t", time_t);
216 DEFTYPE("off-t", off_t);
217 DEFTYPE("size-t", size_t);
218 DEFTYPE("mode-t", mode_t);
220 #else
221 printf("(in-package \"SB!ALIEN\")\n\n");
223 printf (";;;flags for dlopen()\n");
225 defconstant ("rtld-lazy", RTLD_LAZY);
226 defconstant ("rtld-now", RTLD_NOW);
227 defconstant ("rtld-global", RTLD_GLOBAL);
229 printf("(in-package \"SB!UNIX\")\n\n");
231 printf(";;; langinfo\n");
232 defconstant("codeset", CODESET);
234 printf(";;; types, types, types\n");
235 DEFTYPE("clock-t", clock_t);
236 DEFTYPE("dev-t", dev_t);
237 DEFTYPE("gid-t", gid_t);
238 DEFTYPE("ino-t", ino_t);
239 DEFTYPE("mode-t", mode_t);
240 DEFTYPE("nlink-t", nlink_t);
241 DEFTYPE("off-t", off_t);
242 DEFTYPE("size-t", size_t);
243 DEFTYPE("time-t", time_t);
244 DEFTYPE("uid-t", uid_t);
245 printf("\n");
247 printf(";;; fcntl.h (or unistd.h on OpenBSD and NetBSD)\n");
248 defconstant("r_ok", R_OK);
249 defconstant("w_ok", W_OK);
250 defconstant("x_ok", X_OK);
251 defconstant("f_ok", F_OK);
252 printf("\n");
254 printf(";;; fcntlbits.h\n");
255 defconstant("o_rdonly", O_RDONLY);
256 defconstant("o_wronly", O_WRONLY);
257 defconstant("o_rdwr", O_RDWR);
258 defconstant("o_accmode", O_ACCMODE);
259 defconstant("o_creat", O_CREAT);
260 defconstant("o_excl", O_EXCL);
261 defconstant("o_noctty", O_NOCTTY);
262 defconstant("o_trunc", O_TRUNC);
263 defconstant("o_append", O_APPEND);
264 #ifdef LISP_FEATURE_LARGEFILE
265 defconstant("o_largefile", O_LARGEFILE);
266 #endif
268 printf(";;;\n");
269 defconstant("s-ifmt", S_IFMT);
270 defconstant("s-ififo", S_IFIFO);
271 defconstant("s-ifchr", S_IFCHR);
272 defconstant("s-ifdir", S_IFDIR);
273 defconstant("s-ifblk", S_IFBLK);
274 defconstant("s-ifreg", S_IFREG);
275 printf("\n");
277 defconstant("s-iflnk", S_IFLNK);
278 defconstant("s-ifsock", S_IFSOCK);
279 printf("\n");
281 printf(";;; error numbers\n");
282 deferrno("enoent", ENOENT);
283 deferrno("eintr", EINTR);
284 deferrno("eio", EIO);
285 deferrno("eexist", EEXIST);
286 deferrno("espipe", ESPIPE);
287 deferrno("ewouldblock", EWOULDBLOCK);
288 printf("\n");
290 printf(";;; for wait3(2) in run-program.lisp\n");
291 defconstant("wnohang", WNOHANG);
292 defconstant("wuntraced", WUNTRACED);
293 printf("\n");
295 printf(";;; various ioctl(2) flags\n");
296 defconstant("tiocnotty", TIOCNOTTY);
297 defconstant("tiocgwinsz", TIOCGWINSZ);
298 defconstant("tiocswinsz", TIOCSWINSZ);
299 defconstant("tiocgpgrp", TIOCGPGRP);
300 defconstant("tiocspgrp", TIOCSPGRP);
301 /* KLUDGE: These are referenced by old CMUCL-derived code, but
302 * Linux doesn't define them.
304 * I think these are the BSD names, but I don't know what the
305 * corresponding SysV/Linux names are. As a point of reference,
306 * CMUCL doesn't have these defined either (although the defining
307 * forms *do* exist in src/code/unix.lisp), so I don't feel nearly
308 * so bad about not hunting them down. Insight into renamed
309 * obscure ioctl(2) flags appreciated. --njf, 2002-08-26
311 * I note that the first one I grepped for, TIOCSIGSEND, is
312 * referenced in SBCL conditional on #+HPUX. Maybe the porters of
313 * Oxbridge know more about things like that? And even if they
314 * don't, one benefit of the Rhodes crusade to heal the worthy
315 * ports should be that afterwards, if we grep for something like
316 * this in CVS and it's not there, we can lightheartedly nuke it.
317 * -- WHN 2002-08-30 */
319 defconstant("tiocsigsend", TIOCSIGSEND);
320 defconstant("tiocflush", TIOCFLUSH);
321 defconstant("tiocgetp", TIOCGETP);
322 defconstant("tiocsetp", TIOCSETP);
323 defconstant("tiocgetc", TIOCGETC);
324 defconstant("tiocsetc", TIOCSETC);
325 defconstant("tiocgltc", TIOCGLTC);
326 defconstant("tiocsltc", TIOCSLTC);
328 printf("\n");
330 printf(";;; signals\n");
331 defsignal("sigalrm", SIGALRM);
332 defsignal("sigbus", SIGBUS);
333 defsignal("sigchld", SIGCHLD);
334 defsignal("sigcont", SIGCONT);
335 #ifdef SIGEMT
336 defsignal("sigemt", SIGEMT);
337 #endif
338 defsignal("sigfpe", SIGFPE);
339 defsignal("sighup", SIGHUP);
340 defsignal("sigill", SIGILL);
341 defsignal("sigint", SIGINT);
342 defsignal("sigio", SIGIO);
343 defsignal("sigiot", SIGIOT);
344 defsignal("sigkill", SIGKILL);
345 defsignal("sigpipe", SIGPIPE);
346 defsignal("sigprof", SIGPROF);
347 defsignal("sigquit", SIGQUIT);
348 defsignal("sigsegv", SIGSEGV);
349 #if ((defined LISP_FEATURE_LINUX) && (defined LISP_FEATURE_X86))
350 defsignal("sigstkflt", SIGSTKFLT);
351 #endif
352 defsignal("sigstop", SIGSTOP);
353 #if (!((defined LISP_FEATURE_LINUX) && (defined LISP_FEATURE_X86)))
354 defsignal("sigsys", SIGSYS);
355 #endif
356 defsignal("sigterm", SIGTERM);
357 defsignal("sigtrap", SIGTRAP);
358 defsignal("sigtstp", SIGTSTP);
359 defsignal("sigttin", SIGTTIN);
360 defsignal("sigttou", SIGTTOU);
361 defsignal("sigurg", SIGURG);
362 defsignal("sigusr1", SIGUSR1);
363 defsignal("sigusr2", SIGUSR2);
364 defsignal("sigvtalrm", SIGVTALRM);
365 #ifdef LISP_FEATURE_SUNOS
366 defsignal("sigwaiting", SIGWAITING);
367 #endif
368 defsignal("sigwinch", SIGWINCH);
369 #ifndef LISP_FEATURE_HPUX
370 defsignal("sigxcpu", SIGXCPU);
371 defsignal("sigxfsz", SIGXFSZ);
372 #endif
374 /* Floating point exception codes. Some of these
375 * are missing on Darwin. */
376 #ifdef FPE_INTOVF
377 defconstant("fpe-intovf", FPE_INTOVF);
378 #else
379 defconstant("fpe-intovf", -1);
380 #endif
381 #ifdef FPE_INTDIV
382 defconstant("fpe-intdiv", FPE_INTDIV);
383 #else
384 defconstant("fpe-intdiv", -1);
385 #endif
386 defconstant("fpe-fltdiv", FPE_FLTDIV);
387 defconstant("fpe-fltovf", FPE_FLTOVF);
388 defconstant("fpe-fltund", FPE_FLTUND);
389 defconstant("fpe-fltres", FPE_FLTRES);
390 defconstant("fpe-fltinv", FPE_FLTINV);
391 #ifdef FPE_FLTSUB
392 defconstant("fpe-fltsub", FPE_FLTSUB);
393 #else
394 defconstant("fpe-fltsub", -1);
395 #endif
397 #endif // _WIN32
398 return 0;