X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tools-for-build%2Fgrovel_headers.c;h=4e7afbef50d8c41fe0b4d78c983674d23738e6be;hb=bcbbce86c47a1c530d488c7876a453100fcd933e;hp=3b1a7fa41b20cdea3e209026bee9f7ed251a5aab;hpb=dfa55a883f94470267b626dae77ce7e7dfac3df6;p=sbcl.git diff --git a/tools-for-build/grovel_headers.c b/tools-for-build/grovel_headers.c index 3b1a7fa..4e7afbe 100644 --- a/tools-for-build/grovel_headers.c +++ b/tools-for-build/grovel_headers.c @@ -1,23 +1,39 @@ -/* get the sizes and signedness of basic system types. Doing this by - * hand is basically just too tedious. +/* + * Rummage through the system header files using the C compiler itself + * as a parser, extracting stuff like preprocessor constants and the + * sizes and signedness of basic system types, and write it out as + * Lisp code. + */ - * In the current system this doesn't get built or run automatically, - * because I (Dan) am lazy and do not want to think too hard about the - * interaction between generated source files, build trees, and CVS. - * You have to build it yourself when porting to a new architecture - - * which I'd guess doesn't happen too often anyway - - * The output from this is generally in code/$(architecture)-$(os)-types.h */ +/* + * This software is part of the SBCL system. See the README file for + * more information. + * + * While most of SBCL is derived from the CMU CL system, many + * utilities for the build process (like this one) were written from + * scratch after the fork from CMU CL. + * + * This software is in the public domain and is provided with + * absolutely no warranty. See the COPYING and CREDITS files for + * more information. + */ +#include #include #include #include #include +#include #define DEFTYPE(lispname,cname) { cname foo; \ - printf("(def-alien-type "##lispname##" (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); } + printf("(define-alien-type "##lispname##" (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); } -#define DEFCONSTANT(lispname,cname) { printf("(defconstant %s %d) ;; 0x%x\n",lispname,cname,cname);} +void +defconstant(char* lisp_name, long unix_number) +{ + printf("(defconstant %s %ld) ; #x%lx\n", + lisp_name, unix_number, unix_number); +} int main(int argc, char *argv[]) @@ -32,46 +48,53 @@ main(int argc, char *argv[]) printf( ";;;; This is an automatically generated file, please do not hand-edit it. ;;;; See the program \"grovel_headers.c\". + "); printf("(in-package \"SB!UNIX\")\n\n"); + printf(";;; types, types, types\n"); + DEFTYPE("clock-t", clock_t); DEFTYPE("dev-t", dev_t); + DEFTYPE("gid-t", gid_t); DEFTYPE("ino-t", ino_t); DEFTYPE("mode-t", mode_t); DEFTYPE("nlink-t", nlink_t); - DEFTYPE("uid-t", uid_t); - DEFTYPE("gid-t", gid_t); - DEFTYPE("clock-t", clock_t); DEFTYPE("off-t", off_t); + DEFTYPE("size-t", size_t); DEFTYPE("time-t", time_t); + DEFTYPE("uid-t", uid_t); + printf("\n"); - /* fcntl.h */ - DEFCONSTANT("r_ok", R_OK); - DEFCONSTANT("w_ok", W_OK); - DEFCONSTANT("x_ok", X_OK); - DEFCONSTANT("f_ok", F_OK); + printf(";;; fcntl.h (or unistd.h on OpenBSD)\n"); + defconstant("r_ok", R_OK); + defconstant("w_ok", W_OK); + defconstant("x_ok", X_OK); + defconstant("f_ok", F_OK); + printf("\n"); - /* fcntlbits.h */ - DEFCONSTANT("o_rdonly", O_RDONLY); - DEFCONSTANT("o_wronly", O_WRONLY); - DEFCONSTANT("o_rdwr", O_RDWR); - DEFCONSTANT("o_accmode", O_ACCMODE); - DEFCONSTANT("o_creat", O_CREAT); - DEFCONSTANT("o_excl", O_EXCL); - DEFCONSTANT("o_noctty", O_NOCTTY); - DEFCONSTANT("o_trunc", O_TRUNC); - DEFCONSTANT("o_append", O_APPEND); - /**/ - DEFCONSTANT( "s-ifmt", S_IFMT); - DEFCONSTANT( "s-ififo", S_IFIFO); - DEFCONSTANT( "s-ifchr", S_IFCHR); - DEFCONSTANT( "s-ifdir", S_IFDIR); - DEFCONSTANT( "s-ifblk", S_IFBLK); - DEFCONSTANT( "s-ifreg", S_IFREG); + printf(";;; fcntlbits.h\n"); + defconstant("o_rdonly", O_RDONLY); + defconstant("o_wronly", O_WRONLY); + defconstant("o_rdwr", O_RDWR); + defconstant("o_accmode", O_ACCMODE); + defconstant("o_creat", O_CREAT); + defconstant("o_excl", O_EXCL); + defconstant("o_noctty", O_NOCTTY); + defconstant("o_trunc", O_TRUNC); + defconstant("o_append", O_APPEND); + printf(";;;\n"); + defconstant("s-ifmt", S_IFMT); + defconstant("s-ififo", S_IFIFO); + defconstant("s-ifchr", S_IFCHR); + defconstant("s-ifdir", S_IFDIR); + defconstant("s-ifblk", S_IFBLK); + defconstant("s-ifreg", S_IFREG); + printf("\n"); - DEFCONSTANT( "s-iflnk", S_IFLNK); - DEFCONSTANT( "s-ifsock", S_IFSOCK); + defconstant("s-iflnk", S_IFLNK); + defconstant("s-ifsock", S_IFSOCK); + printf("\n"); return 0; }