0.8.3.76
[sbcl/lichteblau.git] / tools-for-build / grovel_headers.c
blobaf38bdcffd1c415654c98ae69f9a836cfc4c95e8
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 #include <sys/times.h>
24 #include <sys/stat.h>
25 #include <sys/wait.h>
26 #include <sys/ioctl.h>
27 #include <sys/termios.h>
28 #include <fcntl.h>
29 #include <unistd.h>
30 #include <signal.h>
32 #include "genesis/config.h"
34 #define DEFTYPE(lispname,cname) { cname foo; \
35 printf("(define-alien-type " lispname " (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); }
37 void
38 defconstant(char* lisp_name, long unix_number)
40 printf("(defconstant %s %ld) ; #x%lx\n",
41 lisp_name, unix_number, unix_number);
44 #define DEFSIGNAL(name) defconstant(#name, name)
46 int
47 main(int argc, char *argv[])
49 /* don't need no steenking command line arguments */
50 if (1 != argc) {
51 fprintf(stderr, "argh! command line argument(s)\n");
52 exit(1);
55 /* don't need no steenking hand-editing */
56 printf(
57 ";;;; This is an automatically generated file, please do not hand-edit it.\n\
58 ;;;; See the program \"grovel_headers.c\".\n\
59 \n\
60 ");
62 printf("(in-package \"SB!UNIX\")\n\n");
64 printf(";;; types, types, types\n");
65 DEFTYPE("clock-t", clock_t);
66 DEFTYPE("dev-t", dev_t);
67 DEFTYPE("gid-t", gid_t);
68 DEFTYPE("ino-t", ino_t);
69 DEFTYPE("mode-t", mode_t);
70 DEFTYPE("nlink-t", nlink_t);
71 DEFTYPE("off-t", off_t);
72 DEFTYPE("size-t", size_t);
73 DEFTYPE("time-t", time_t);
74 DEFTYPE("uid-t", uid_t);
75 printf("\n");
77 printf(";;; fcntl.h (or unistd.h on OpenBSD)\n");
78 defconstant("r_ok", R_OK);
79 defconstant("w_ok", W_OK);
80 defconstant("x_ok", X_OK);
81 defconstant("f_ok", F_OK);
82 printf("\n");
84 printf(";;; fcntlbits.h\n");
85 defconstant("o_rdonly", O_RDONLY);
86 defconstant("o_wronly", O_WRONLY);
87 defconstant("o_rdwr", O_RDWR);
88 defconstant("o_accmode", O_ACCMODE);
89 defconstant("o_creat", O_CREAT);
90 defconstant("o_excl", O_EXCL);
91 defconstant("o_noctty", O_NOCTTY);
92 defconstant("o_trunc", O_TRUNC);
93 defconstant("o_append", O_APPEND);
94 printf(";;;\n");
95 defconstant("s-ifmt", S_IFMT);
96 defconstant("s-ififo", S_IFIFO);
97 defconstant("s-ifchr", S_IFCHR);
98 defconstant("s-ifdir", S_IFDIR);
99 defconstant("s-ifblk", S_IFBLK);
100 defconstant("s-ifreg", S_IFREG);
101 printf("\n");
103 defconstant("s-iflnk", S_IFLNK);
104 defconstant("s-ifsock", S_IFSOCK);
105 printf("\n");
107 printf(";;; for wait3(2) in run-program.lisp\n");
108 defconstant("wnohang", WNOHANG);
109 defconstant("wuntraced", WUNTRACED);
110 printf("\n");
112 printf(";;; various ioctl(2) flags\n");
113 defconstant("tiocnotty", TIOCNOTTY);
114 defconstant("tiocgwinsz", TIOCGWINSZ);
115 defconstant("tiocswinsz", TIOCSWINSZ);
116 defconstant("tiocgpgrp", TIOCGPGRP);
117 defconstant("tiocspgrp", TIOCSPGRP);
118 /* KLUDGE: These are referenced by old CMUCL-derived code, but
119 * Linux doesn't define them.
121 * I think these are the BSD names, but I don't know what the
122 * corresponding SysV/Linux names are. As a point of reference,
123 * CMUCL doesn't have these defined either (although the defining
124 * forms *do* exist in src/code/unix.lisp), so I don't feel nearly
125 * so bad about not hunting them down. Insight into renamed
126 * obscure ioctl(2) flags appreciated. --njf, 2002-08-26
128 * I note that the first one I grepped for, TIOCSIGSEND, is
129 * referenced in SBCL conditional on #+HPUX. Maybe the porters of
130 * Oxbridge know more about things like that? And even if they
131 * don't, one benefit of the Rhodes crusade to heal the worthy
132 * ports should be that afterwards, if we grep for something like
133 * this in CVS and it's not there, we can lightheartedly nuke it.
134 * -- WHN 2002-08-30 */
136 defconstant("tiocsigsend", TIOCSIGSEND);
137 defconstant("tiocflush", TIOCFLUSH);
138 defconstant("tiocgetp", TIOCGETP);
139 defconstant("tiocsetp", TIOCSETP);
140 defconstant("tiocgetc", TIOCGETC);
141 defconstant("tiocsetc", TIOCSETC);
142 defconstant("tiocgltc", TIOCGLTC);
143 defconstant("tiocsltc", TIOCSLTC);
145 printf("\n");
147 printf(";;; signals\n");
148 DEFSIGNAL(SIGALRM);
149 DEFSIGNAL(SIGBUS);
150 DEFSIGNAL(SIGCHLD);
151 DEFSIGNAL(SIGCONT);
152 /* FIXME: Maybe #ifdef SIGEMT would be a smarter conditional? */
153 #if (!(defined LISP_FEATURE_LINUX) || !((defined LISP_FEATURE_PPC) || (defined LISP_FEATURE_X86)))
154 DEFSIGNAL(SIGEMT);
155 #endif
156 DEFSIGNAL(SIGFPE);
157 DEFSIGNAL(SIGHUP);
158 DEFSIGNAL(SIGILL);
159 DEFSIGNAL(SIGINT);
160 DEFSIGNAL(SIGIO);
161 DEFSIGNAL(SIGIOT);
162 DEFSIGNAL(SIGKILL);
163 DEFSIGNAL(SIGPIPE);
164 DEFSIGNAL(SIGPROF);
165 DEFSIGNAL(SIGQUIT);
166 DEFSIGNAL(SIGSEGV);
167 #if ((defined LISP_FEATURE_LINUX) && (defined LISP_FEATURE_X86))
168 DEFSIGNAL(SIGSTKFLT);
169 #endif
170 DEFSIGNAL(SIGSTOP);
171 #if (!((defined LISP_FEATURE_LINUX) && (defined LISP_FEATURE_X86)))
172 DEFSIGNAL(SIGSYS);
173 #endif
174 DEFSIGNAL(SIGTERM);
175 DEFSIGNAL(SIGTRAP);
176 DEFSIGNAL(SIGTSTP);
177 DEFSIGNAL(SIGTTIN);
178 DEFSIGNAL(SIGTTOU);
179 DEFSIGNAL(SIGURG);
180 DEFSIGNAL(SIGUSR1);
181 DEFSIGNAL(SIGUSR2);
182 DEFSIGNAL(SIGVTALRM);
183 #ifdef LISP_FEATURE_SUNOS
184 DEFSIGNAL(SIGWAITING);
185 #endif
186 DEFSIGNAL(SIGWINCH);
187 #ifndef LISP_FEATURE_HPUX
188 DEFSIGNAL(SIGXCPU);
189 DEFSIGNAL(SIGXFSZ);
190 #endif
192 return 0;