Avoid use of private typedefs
[sbcl.git] / tools-for-build / grovel-headers.c
blobf5eab412e62d396afb884b9dc6914af2bcc478fe
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 "genesis/config.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <sys/types.h>
26 #ifdef _WIN32
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
31 #include <windows.h>
32 #include <shlobj.h>
33 #include <wincrypt.h>
34 #include <winsock2.h>
35 #undef boolean
36 #else
37 #include <poll.h>
38 #include <sys/select.h>
39 #include <sys/times.h>
40 #include <sys/wait.h>
41 #include <sys/ioctl.h>
42 #ifdef LISP_FEATURE_ANDROID
43 #include <termios.h>
44 #else
45 #include <sys/termios.h>
46 #include <langinfo.h>
47 #endif
48 #include <sys/time.h>
49 #include <dlfcn.h>
50 #endif
52 #include <sys/stat.h>
53 #include <fcntl.h>
54 #include <unistd.h>
55 #include <signal.h>
56 #include <errno.h>
57 #include <time.h>
59 #ifdef LISP_FEATURE_HPUX
60 #include <sys/bsdtty.h> /* for TIOCGPGRP */
61 #endif
63 #ifdef LISP_FEATURE_BSD
64 #include <sys/param.h>
65 #include <sys/sysctl.h>
66 #endif
68 #if defined(LISP_FEATURE_WIN32) && defined(LISP_FEATURE_SB_THREAD)
69 #include "pthreads_win32.h"
70 #endif
72 #include "wrap.h"
73 #include "gc.h"
75 #define DEFTYPE(lispname,cname) { cname foo; \
76 printf("(define-alien-type " lispname " (%s %d))\n", (((foo=-1)<0) ? "signed" : "unsigned"), (8 * (sizeof foo))); }
78 #define DEFSTRUCT(lispname,cname,body) { cname bar; \
79 printf("(define-alien-type nil\n (struct %s", #lispname); \
80 body; \
81 printf("))\n"); }
82 #define DEFSLOT(lispname,cname) \
83 printf("\n (%s (%s %d))", \
84 #lispname, \
85 (((bar.cname=-1)<0) ? "signed" : "unsigned"), \
86 (8 * (sizeof bar.cname)))
88 void
89 defconstant(char* lisp_name, unsigned long unix_number)
91 printf("(defconstant %s %lu) ; #x%lx\n",
92 lisp_name, unix_number, unix_number);
95 void deferrno(char* lisp_name, unsigned long unix_number)
97 defconstant(lisp_name, unix_number);
100 void defsignal(char* lisp_name, unsigned long unix_number)
102 defconstant(lisp_name, unix_number);
106 main(int argc, char *argv[])
108 /* don't need no steenking command line arguments */
109 if (1 != argc) {
110 fprintf(stderr, "argh! command line argument(s)\n");
111 exit(1);
114 /* don't need no steenking hand-editing */
115 printf(
116 ";;;; This is an automatically generated file, please do not hand-edit it.\n\
117 ;;;; See the program \"grovel-headers.c\".\n\
120 #ifdef _WIN32
121 #include "grovel-headers-win32.h"
122 #else
123 printf("(in-package \"SB!ALIEN\")\n\n");
125 printf (";;;flags for dlopen()\n");
127 defconstant ("rtld-lazy", RTLD_LAZY);
128 defconstant ("rtld-now", RTLD_NOW);
129 defconstant ("rtld-global", RTLD_GLOBAL);
131 printf("(in-package \"SB!UNIX\")\n\n");
133 printf(";;; select()\n");
134 defconstant("fd-setsize", FD_SETSIZE);
136 printf(";;; poll()\n");
137 defconstant("pollin", POLLIN);
138 defconstant("pollout", POLLOUT);
139 defconstant("pollpri", POLLPRI);
140 defconstant("pollhup", POLLHUP);
141 defconstant("pollnval", POLLNVAL);
142 defconstant("pollerr", POLLERR);
143 DEFTYPE("nfds-t", nfds_t);
144 #ifndef LISP_FEATURE_ANDROID
145 printf(";;; langinfo\n");
146 defconstant("codeset", CODESET);
147 #endif
148 printf(";;; types, types, types\n");
149 DEFTYPE("clock-t", clock_t);
150 DEFTYPE("dev-t", dev_t);
151 DEFTYPE("gid-t", gid_t);
152 DEFTYPE("ino-t", ino_t);
153 DEFTYPE("mode-t", mode_t);
154 DEFTYPE("nlink-t", nlink_t);
155 DEFTYPE("off-t", off_t);
156 DEFTYPE("size-t", size_t);
157 DEFTYPE("ssize-t", ssize_t);
158 DEFTYPE("time-t", time_t);
159 #if !defined(LISP_FEATURE_OS_PROVIDES_SUSECONDS_T)
160 /* Similar kludge in sb-posix. */
161 DEFTYPE("suseconds-t", long);
162 #else
163 DEFTYPE("suseconds-t", suseconds_t);
164 #endif
165 DEFTYPE("uid-t", uid_t);
166 printf(";; Types in src/runtime/wrap.h. See that file for explantion.\n");
167 printf(";; Don't use these types for anything other than the stat wrapper.\n");
168 DEFTYPE("wst-ino-t", wst_ino_t);
169 DEFTYPE("wst-dev-t", wst_dev_t);
170 DEFTYPE("wst-off-t", wst_off_t);
171 DEFTYPE("wst-blksize-t", wst_blksize_t);
172 DEFTYPE("wst-blkcnt-t", wst_blkcnt_t);
173 DEFTYPE("wst-nlink-t", wst_nlink_t);
174 DEFTYPE("wst-uid-t", wst_uid_t);
175 DEFTYPE("wst-gid-t", wst_gid_t);
176 printf("\n");
178 printf(";;; fcntl.h (or unistd.h on OpenBSD and NetBSD)\n");
179 defconstant("r_ok", R_OK);
180 defconstant("w_ok", W_OK);
181 defconstant("x_ok", X_OK);
182 defconstant("f_ok", F_OK);
183 printf("\n");
185 printf(";;; fcntlbits.h\n");
186 defconstant("o_rdonly", O_RDONLY);
187 defconstant("o_wronly", O_WRONLY);
188 defconstant("o_rdwr", O_RDWR);
189 defconstant("o_accmode", O_ACCMODE);
190 defconstant("o_creat", O_CREAT);
191 defconstant("o_excl", O_EXCL);
192 defconstant("o_noctty", O_NOCTTY);
193 defconstant("o_trunc", O_TRUNC);
194 defconstant("o_append", O_APPEND);
195 #ifdef LISP_FEATURE_LARGEFILE
196 defconstant("o_largefile", O_LARGEFILE);
197 #endif
199 printf(";;;\n");
200 defconstant("s-ifmt", S_IFMT);
201 defconstant("s-ififo", S_IFIFO);
202 defconstant("s-ifchr", S_IFCHR);
203 defconstant("s-ifdir", S_IFDIR);
204 defconstant("s-ifblk", S_IFBLK);
205 defconstant("s-ifreg", S_IFREG);
206 printf("\n");
208 defconstant("s-iflnk", S_IFLNK);
209 defconstant("s-ifsock", S_IFSOCK);
210 printf("\n");
212 printf(";;; error numbers\n");
213 deferrno("ebadf", EBADF);
214 deferrno("enoent", ENOENT);
215 deferrno("eintr", EINTR);
216 deferrno("eagain", EAGAIN);
217 deferrno("eio", EIO);
218 deferrno("eexist", EEXIST);
219 deferrno("eloop", ELOOP);
220 deferrno("espipe", ESPIPE);
221 deferrno("ewouldblock", EWOULDBLOCK);
222 printf("\n");
224 printf(";;; for wait3(2) in run-program.lisp\n");
225 defconstant("wnohang", WNOHANG);
226 defconstant("wuntraced", WUNTRACED);
227 printf("\n");
229 printf(";;; various ioctl(2) flags\n");
230 defconstant("tiocgpgrp", TIOCGPGRP);
231 defconstant("tiocspgrp", TIOCSPGRP);
232 defconstant("tiocgwinsz", TIOCGWINSZ);
233 defconstant("tiocswinsz", TIOCSWINSZ);
234 /* KLUDGE: These are referenced by old CMUCL-derived code, but
235 * Linux doesn't define them.
237 * I think these are the BSD names, but I don't know what the
238 * corresponding SysV/Linux names are. As a point of reference,
239 * CMUCL doesn't have these defined either (although the defining
240 * forms *do* exist in src/code/unix.lisp), so I don't feel nearly
241 * so bad about not hunting them down. Insight into renamed
242 * obscure ioctl(2) flags appreciated. --njf, 2002-08-26
244 * I note that the first one I grepped for, TIOCSIGSEND, is
245 * referenced in SBCL conditional on #+HPUX. Maybe the porters of
246 * Oxbridge know more about things like that? And even if they
247 * don't, one benefit of the Rhodes crusade to heal the worthy
248 * ports should be that afterwards, if we grep for something like
249 * this in CVS and it's not there, we can lightheartedly nuke it.
250 * -- WHN 2002-08-30 */
252 defconstant("tiocsigsend", TIOCSIGSEND);
253 defconstant("tiocflush", TIOCFLUSH);
254 defconstant("tiocgetp", TIOCGETP);
255 defconstant("tiocsetp", TIOCSETP);
256 defconstant("tiocgetc", TIOCGETC);
257 defconstant("tiocsetc", TIOCSETC);
258 defconstant("tiocgltc", TIOCGLTC);
259 defconstant("tiocsltc", TIOCSLTC);
261 printf("\n");
263 printf(";;; signals\n");
264 defconstant("sig-dfl", (unsigned long)SIG_DFL);
265 defconstant("sig-ign", (unsigned long)SIG_IGN);
267 defsignal("sigalrm", SIGALRM);
268 defsignal("sigbus", SIGBUS);
269 defsignal("sigchld", SIGCHLD);
270 defsignal("sigcont", SIGCONT);
271 #ifdef SIGEMT
272 defsignal("sigemt", SIGEMT);
273 #endif
274 defsignal("sigfpe", SIGFPE);
275 defsignal("sighup", SIGHUP);
276 defsignal("sigill", SIGILL);
277 defsignal("sigint", SIGINT);
278 defsignal("sigio", SIGIO);
279 defsignal("sigiot", SIGIOT);
280 defsignal("sigkill", SIGKILL);
281 defsignal("sigpipe", SIGPIPE);
282 defsignal("sigprof", SIGPROF);
283 defsignal("sigquit", SIGQUIT);
284 defsignal("sigsegv", SIGSEGV);
285 #ifdef SIGSTKFLT
286 defsignal("sigstkflt", SIGSTKFLT);
287 #endif
288 defsignal("sigstop", SIGSTOP);
289 #ifdef SIGSYS
290 defsignal("sigsys", SIGSYS);
291 #endif
292 defsignal("sigterm", SIGTERM);
293 defsignal("sigtrap", SIGTRAP);
294 defsignal("sigtstp", SIGTSTP);
295 defsignal("sigttin", SIGTTIN);
296 defsignal("sigttou", SIGTTOU);
297 defsignal("sigurg", SIGURG);
298 defsignal("sigusr1", SIGUSR1);
299 defsignal("sigusr2", SIGUSR2);
300 defsignal("sigvtalrm", SIGVTALRM);
301 #ifdef SIGWAITING
302 defsignal("sigwaiting", SIGWAITING);
303 #endif
304 defsignal("sigwinch", SIGWINCH);
305 #ifdef SIGXCPU
306 defsignal("sigxcpu", SIGXCPU);
307 #endif
308 #ifdef SIGXFSZ
309 defsignal("sigxfsz", SIGXFSZ);
310 #endif
312 /* Floating point exception codes. Some of these
313 * are missing on Darwin. */
314 #ifdef FPE_INTOVF
315 defconstant("fpe-intovf", FPE_INTOVF);
316 #else
317 defconstant("fpe-intovf", -1);
318 #endif
319 #ifdef FPE_INTDIV
320 defconstant("fpe-intdiv", FPE_INTDIV);
321 #else
322 defconstant("fpe-intdiv", -1);
323 #endif
324 defconstant("fpe-fltdiv", FPE_FLTDIV);
325 defconstant("fpe-fltovf", FPE_FLTOVF);
326 defconstant("fpe-fltund", FPE_FLTUND);
327 defconstant("fpe-fltres", FPE_FLTRES);
328 defconstant("fpe-fltinv", FPE_FLTINV);
329 #ifdef FPE_FLTSUB
330 defconstant("fpe-fltsub", FPE_FLTSUB);
331 #else
332 defconstant("fpe-fltsub", -1);
333 #endif
334 #endif // !WIN32
335 printf("\n");
337 printf(";;; structures\n");
338 DEFSTRUCT(timeval, struct timeval,
339 DEFSLOT(tv-sec, tv_sec);
340 DEFSLOT(tv-usec, tv_usec));
341 DEFSTRUCT(timespec, struct timespec,
342 DEFSLOT(tv-sec, tv_sec);
343 DEFSLOT(tv-nsec, tv_nsec));
344 printf("\n");
346 #ifdef LISP_FEATURE_ANDROID
347 defconstant("path-max", PATH_MAX);
348 printf("\n");
349 #endif
351 #ifdef LISP_FEATURE_BSD
352 printf(";;; sysctl(3) names\n");
353 printf("(in-package \"SB!IMPL\")\n");
354 defconstant("ctl-kern", CTL_KERN);
355 defconstant("ctl-hw", CTL_HW);
356 defconstant("ctl-maxname", CTL_MAXNAME);
357 defconstant("kern-ostype", KERN_OSTYPE);
358 defconstant("kern-osrelease", KERN_OSRELEASE);
359 defconstant("hw-model", HW_MODEL);
360 defconstant("hw-pagesize", HW_PAGESIZE);
362 defconstant("path-max", PATH_MAX);
363 printf("\n");
364 #endif
366 printf("(in-package \"SB!KERNEL\")\n\n");
367 #ifdef LISP_FEATURE_GENCGC
368 printf(";;; GENCGC related\n");
369 DEFTYPE("page-index-t", page_index_t);
370 DEFTYPE("generation-index-t", generation_index_t);
371 printf("\n");
372 #endif
374 printf(";;; Our runtime types\n");
375 DEFTYPE("os-vm-size-t", os_vm_size_t);
377 return 0;