0.6.12.3:
[sbcl.git] / tools-for-build / grovel_headers.c
1 /* get the sizes and signedness of basic system types. Doing this by
2  * hand is basically just too tedious.
3
4  * In the current system this doesn't get built or run automatically,
5  * because I (Dan) am lazy and do not want to think too hard about the
6  * interaction between generated source files, build trees, and CVS.
7  * You have to build it yourself when porting to a new architecture -
8  * which I'd guess doesn't happen too often anyway
9
10  * The output from this is generally in code/$(architecture)-$(os)-types.h */
11
12 #include <sys/types.h>
13 #include <sys/times.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16
17 #define DEFTYPE(lispname,cname) { cname foo; \
18     printf("(def-alien-type "##lispname##" (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); }
19
20 #define DEFCONSTANT(lispname,cname) { printf("(defconstant %s %d) ;; 0x%x\n",lispname,cname,cname);} 
21
22 int
23 main(int argc, char *argv[])
24 {
25     /* don't need no steenking command line arguments */
26     if (1 != argc) {
27         fprintf(stderr, "argh! command line argument(s)\n");
28         exit(1);
29     }
30
31     /* don't need no steenking hand-editing */
32     printf(
33 ";;;; This is an automatically generated file, please do not hand-edit it.
34 ;;;; See the program \"grovel_headers.c\".
35 ");
36
37     printf("(in-package \"SB!UNIX\")\n\n");
38
39     DEFTYPE("dev-t",   dev_t);
40     DEFTYPE("ino-t",   ino_t);
41     DEFTYPE("mode-t",  mode_t);
42     DEFTYPE("nlink-t", nlink_t);
43     DEFTYPE("uid-t",   uid_t);
44     DEFTYPE("gid-t",   gid_t);
45     DEFTYPE("clock-t", clock_t);
46     DEFTYPE("off-t",   off_t);
47     DEFTYPE("time-t",  time_t);
48
49     /* fcntl.h */
50     DEFCONSTANT("r_ok", R_OK);
51     DEFCONSTANT("w_ok", W_OK);
52     DEFCONSTANT("x_ok", X_OK);
53     DEFCONSTANT("f_ok", F_OK);
54
55     /* fcntlbits.h */
56     DEFCONSTANT("o_rdonly",  O_RDONLY);
57     DEFCONSTANT("o_wronly",  O_WRONLY);
58     DEFCONSTANT("o_rdwr",    O_RDWR);
59     DEFCONSTANT("o_accmode", O_ACCMODE);
60     DEFCONSTANT("o_creat",   O_CREAT);
61     DEFCONSTANT("o_excl",    O_EXCL);
62     DEFCONSTANT("o_noctty",  O_NOCTTY);
63     DEFCONSTANT("o_trunc",   O_TRUNC);
64     DEFCONSTANT("o_append",  O_APPEND);
65     /**/
66     DEFCONSTANT( "s-ifmt",  S_IFMT);
67     DEFCONSTANT( "s-ififo", S_IFIFO);
68     DEFCONSTANT( "s-ifchr", S_IFCHR);
69     DEFCONSTANT( "s-ifdir", S_IFDIR);
70     DEFCONSTANT( "s-ifblk", S_IFBLK);
71     DEFCONSTANT( "s-ifreg", S_IFREG);
72   
73     DEFCONSTANT( "s-iflnk",  S_IFLNK);
74     DEFCONSTANT( "s-ifsock", S_IFSOCK);
75
76     return 0;
77 }