* readline.scm: moved to ./ice-9/
[bpt/guile.git] / libguile / gen-scmconfig.c
CommitLineData
caeef9cb
RB
1
2/**********************************************************************
3
4 Description of Guile's public config header mechanics:
5 -----------------------------------------------------
6
7 Guile has four core headers:
8
9 config.h: Guile's private automatically generated configuration
10 header -- generated by configure.in and autoheader. *NOT*
11 installed during "make install" and so may not be referred to by
12 any public headers.
13
14 libguile/_scm.h: Guile's private core header. _scm.h is not
15 installed. It's only visible to the libguile sources
16 themselves, and it includes config.h, the private config header.
17 Among other things this file provides a place to make decisions
18 based on the information gathered in config.h.
19
20 libguile/scmconfig.h: Guile's public automatically generated
21 configuration header -- generated at build time by concatenating
22 the contents of libguile/scmconfig.h.top with the output from
23 libguile/gen-scmconfig. gen-scmconfig bases its output on the
24 information in the private config.h header, the contents of
25 gen-scmconfig.h (which is created by configure.in from
26 gen-scmconfig.h.in), and the information provided in this file,
27 gen-scmconfig.c.
28
29 libguile/__scm.h: Guile's public core header. This file is
30 installed and publically visible. It includes
31 libguile/scmconfig.h, the public config header and provides a
32 place to make decisions based on the information gathered in
33 scmconfig.h to define things that other headers can depend on.
34
35 Notes and guidelines:
36
005f04cd
RB
37 - use 1 and 0 for public #defines instead of "def and undef",
38 i.e. use #define SCM_HAVE_FOO rather than just not defining
39 SCM_HAVE_FOO whenever possible. See GNU Coding Guidelines for
40 rationale. The only notable non-deprecated exceptions to this
41 rule are GUILE_DEBUG and GUILE_DEBUG_FREELIST which do not follow
42 this convention in order to retain backward compatibility.
43
caeef9cb
RB
44 - in the code below, be *VERY* careful not to use or rely on any
45 runtime-dynamic information below. For example, you cannot use
46 sizeof (FOO), but must use static information like SIZEOF_BAR
47 (from config.h) or SCM_SIZEOF_BAZ (from scmconfig.h). This is
48 because the gcc that is compiling gen-scmconfig.c and/or the
49 machine that is running gen-scmconfig may not be the same
50 compiler and/or hardware that will eventually be running Guile.
51 (i.e. keep the cross-compilation case in mind).
52
53 - try to avoid adding names to the public namespace when possible.
54 Note in the code below, that in a number of cases, we detect a
55 feature and based on that, we decide whether or not to print
56 anything at all. This decreases the extraneous #defines and
57 #ifdefery that we require in scmconfig.h
58
59 - try to avoid adding any duplicate definitions to config.h and
60 scmconfig.h. i.e. have just SCM_ENABLE_ELISP in scmconfig.h
61 rather than ENABLE_ELISP in config.h and SCM_ENABLE_ELISP in
62 scmconfig.h.
63
64 - in cases where you need to communicate information from
65 configure.in to gen-scmconfig.c, don't add an AC_DEFINE unless
66 you need it for other purposes. Just add a suitable SCM_I_GSC_*
67 variable to configure.in, set the value, AC_SUBST the value, and
68 add an appropriate line to gen-scmconfig.h.in. All gen-scmconfig
69 related AC_SUBST vars should be prefixed with SCM_I_GSC_.
70
71 - make sure that anything that we explicitly typedef publically is
72 prefixed with scm_t_. i.e. we used to typedef long to ptrdiff_t
73 if we didn't detect ptrdiff_t, but this has been changed so that
74 we typedef scm_t_ptrdiff instead so that we won't conflict with
75 any non-guile header definitions of the same type. For types
76 like intptr_t and uintptr_t which we just try to detect and don't
77 actually define, it's fine not to have a corresponding scm_t_
78 type.
79
80 - we now use SCM_SIZEOF_FOO != 0 rather than SCM_HAVE_FOO for any
81 cases where the size might actually vary. For types where the
82 size is fixed, we use SCM_HAVE_FOO, i.e. you can see us define or
83 not define SCM_HAVE_T_INT64 below when appropriate.
84
85 Rationales (not finished):
86
87 Why do we use a C program here rather than AC_OUTPUT_COMMANDS?
88 --------------------------------------------------------------
89
90 The main reason is that there are some values we would need
91 access to at AC_OUTPUT_COMMANDs that are determined by configure
92 but are not available at AC_OUTPUT time. The values are *only*
93 available via config.h. We use gen-scmconfig so we can see those
94 values and make decisions based on their settings.
95
96 Why have gen-scmconfig.h.in?
97 ----------------------------
98
99 Without that header, we could end up needing multiple aliases for
100 public settings like SCM_ENABLE_ELISP. We can't define
101 SCM_ENABLE_ELISP in config.h since that header is private and any
102 definition in scmconfig.h would conflict (#ifndef might be
103 possible but runs the risk of conflicting directives), so a
104 likely solution would be to AC_DEFINE([SCM_I_ENABLE_ELISP]), and
105 then use SCM_I_ENABLE_ELISP in gen-scmconfig via config.h to
106 determine whether or not to #define SCM_ENABLE_ELISP, but this
107 leaves us with two #defined symbols for each public setting --
108 better to just have one value (public or private) that all code
109 uses.
110
111 Having this header means we can AC_SUBST a value like
112 SCM_I_GSC_ENABLE_ELISP and then set it in here via AC_OUTPUT
113 substitutions, and gen-scmconfig can use that definition to
114 determine whether or not to #define SCM_ENABLE_ELISP when
115 generating scmconfig.h, and we end up with nothing extraneous
116 added to config.h.
117
118 **********************************************************************/
119
120#if HAVE_CONFIG_H
121# include <config.h>
122#endif
123
124#include "gen-scmconfig.h"
125
126#include <stdio.h>
127#include <string.h>
128
129#define pf printf
130
131int
132main (int argc, char *argv[])
133{
134 pf ("/* This file is automatically generated --"
135 " see configure.in for details */\n"
136 "\n"
137 "#ifndef SCM_SCMCONFIG_H\n"
138 "#define SCM_SCMCONFIG_H\n");
139
140 /*** various important headers ***/
141 pf ("\n");
142 pf ("/* Important headers */\n");
143 if (SCM_I_GSC_NEEDS_STDINT_H)
144 pf ("#include <stdint.h>\n");
145 if (SCM_I_GSC_NEEDS_INTTYPES_H)
146 pf ("#include <inttypes.h>\n");
147
148#ifdef HAVE_LIMITS_H
149 pf ("#include <limits.h>\n");
150#else
151 pf ("/* limits.h not available */\n");
152#endif
153
154# ifdef TIME_WITH_SYS_TIME
155 pf ("#include <sys/time.h>\n");
156 pf ("#include <time.h>\n");
157# else
158# ifdef HAVE_SYS_TIME_H
159 pf ("#include <sys/time.h>\n");
160# else
161# ifdef HAVE_TIME_H
162 pf ("#include <time.h>\n");
163# endif
164# endif
165# endif
166
167 pf("\n");
168#ifdef STDC_HEADERS
005f04cd 169 pf ("#define SCM_HAVE_STDC_HEADERS 1 /* 0 or 1 */\n");
caeef9cb
RB
170 pf ("#include <stdlib.h>\n");
171# if HAVE_SYS_TYPES_H
172 pf ("#include <sys/types.h>\n");
173# endif
174# if HAVE_SYS_STDTYPES_H
175 pf ("#include <sys/stdtypes.h>\n");
176# endif
177 pf ("#include <stddef.h>\n");
178#else /* STDC_HEADERS */
005f04cd 179 pf ("#define SCM_HAVE_STDC_HEADERS 0 /* 0 or 1 */");
caeef9cb
RB
180#endif /* def STDC_HEADERS */
181
182 pf("\n");
183#ifdef HAVE_SYS_SELECT_H
005f04cd 184 pf ("#define SCM_HAVE_SYS_SELECT_H 1 /* 0 or 1 */\n");
caeef9cb 185#else
005f04cd 186 pf ("#define SCM_HAVE_SYS_SELECT_H 0 /* 0 or 1 */\n");
caeef9cb
RB
187#endif
188
189#ifdef HAVE_FLOATINGPOINT_H
005f04cd 190 pf ("#define SCM_HAVE_FLOATINGPOINT_H 1 /* 0 or 1 */\n");
caeef9cb 191#else
005f04cd 192 pf ("#define SCM_HAVE_FLOATINGPOINT_H 0 /* 0 or 1 */\n");
caeef9cb
RB
193#endif
194
195#ifdef HAVE_IEEEFP_H
005f04cd 196 pf ("#define SCM_HAVE_IEEEFP_H 1 /* 0 or 1 */\n");
caeef9cb 197#else
005f04cd 198 pf ("#define SCM_HAVE_IEEEFP_H 0 /* 0 or 1 */\n");
caeef9cb
RB
199#endif
200
201#ifdef HAVE_NAN_H
005f04cd 202 pf ("#define SCM_HAVE_NAN_H 1 /* 0 or 1 */\n");
caeef9cb 203#else
005f04cd 204 pf ("#define SCM_HAVE_NAN_H 0 /* 0 or 1 */\n");
caeef9cb
RB
205#endif
206
207#ifdef HAVE_WINSOCK2_H
005f04cd 208 pf ("#define SCM_HAVE_WINSOCK2_H 1 /* 0 or 1 */\n");
caeef9cb 209#else
005f04cd 210 pf ("#define SCM_HAVE_WINSOCK2_H 0 /* 0 or 1 */\n");
caeef9cb
RB
211#endif
212
213
214 /*** GUILE_DEBUG (defined or undefined) ***/
215 pf ("\n");
216 pf ("/* Define to include various undocumented debugging functions. */\n");
217 if (SCM_I_GSC_GUILE_DEBUG)
218 pf ("#define GUILE_DEBUG 1 /* defined or undefined */\n");
219 else
220 pf ("/* #undef GUILE_DEBUG */\n");
221
005f04cd 222 /*** GUILE_DEBUG_FREELIST (deined or undefined) ***/
caeef9cb
RB
223 pf ("\n");
224 pf ("/* Define this to debug the free list (helps w/ GC bugs). */\n");
225 if (SCM_I_GSC_GUILE_DEBUG_FREELIST)
226 pf ("#define GUILE_DEBUG_FREELIST 1 /* defined or undefined */\n");
227 else
228 pf ("/* #undef GUILE_DEBUG_FREELIST */\n");
229
230 /*** SCM_ENABLE_DEPRECATED (0 or 1) ***/
231 pf ("\n");
232 pf ("/* Set to 1 if you want to enable deprecated features. */\n");
233 pf ("/* (value will be 0 or 1). */\n");
234 pf ("#define SCM_ENABLE_DEPRECATED %d\n", SCM_I_GSC_ENABLE_DEPRECATED);
235
005f04cd 236 /*** SCM_ENABLE_ELISP (0 or 1) ***/
caeef9cb 237 pf ("\n");
005f04cd
RB
238 pf ("/* Set to 1 to add Elisp support (in addition to Scheme). */\n");
239 pf ("#define SCM_ENABLE_ELISP %d /* 0 or 1 */\n", SCM_I_GSC_ENABLE_ELISP);
caeef9cb 240
005f04cd 241 /*** SCM_HAVE_ARRAYS (0 or 1) ***/
caeef9cb 242 pf ("\n");
005f04cd
RB
243 pf ("/* Set to 1 to add support for arrays and uniform arrays. */\n");
244 pf ("#define SCM_HAVE_ARRAYS %d /* 0 or 1 */\n", SCM_I_GSC_HAVE_ARRAYS);
caeef9cb 245
005f04cd 246 /*** SCM_STACK_GROWS_UP (0 or 1) ***/
caeef9cb 247 pf ("\n");
005f04cd
RB
248 pf ("/* Set to 1 if the stack grows up, 0 otherwise. */\n");
249 pf ("#define SCM_STACK_GROWS_UP %d /* 0 or 1 */\n",
250 SCM_I_GSC_STACK_GROWS_UP);
caeef9cb
RB
251
252 /*** SCM_C_INLINE (defined to appropriate string or undefined) ***/
253 pf ("\n");
254 pf ("/* C compiler's syntax for inline functions if any,\n"
255 " otherwise undefined. */\n");
256 if (SCM_I_GSC_C_INLINE)
257 pf ("#define SCM_C_INLINE %s\n", SCM_I_GSC_C_INLINE);
258 else
259 pf ("/* #undef SCM_C_INLINE */\n");
260
261 pf ("\n");
262 pf ("/* Standard types. */\n");
263
264 pf ("/* These are always defined */\n");
265 pf ("#define SCM_SIZEOF_CHAR %d\n", SIZEOF_CHAR);
266 pf ("#define SCM_SIZEOF_UNSIGNED_CHAR %d\n", SIZEOF_UNSIGNED_CHAR);
267 pf ("#define SCM_SIZEOF_SHORT %d\n", SIZEOF_SHORT);
268 pf ("#define SCM_SIZEOF_UNSIGNED_SHORT %d\n", SIZEOF_UNSIGNED_SHORT);
269 pf ("#define SCM_SIZEOF_LONG %d\n", SIZEOF_LONG);
270 pf ("#define SCM_SIZEOF_UNSIGNED_LONG %d\n", SIZEOF_UNSIGNED_LONG);
271 pf ("#define SCM_SIZEOF_INT %d\n", SIZEOF_INT);
272 pf ("#define SCM_SIZEOF_UNSIGNED_INT %d\n", SIZEOF_UNSIGNED_INT);
273
274 pf ("\n");
275 pf ("/* Size of (unsigned) long long or 0 if not available (scm_t_*64 may\n"
276 " be more likely to be what you want */\n");
277 pf ("#define SCM_SIZEOF_LONG_LONG %d\n", SIZEOF_LONG_LONG);
278 pf ("#define SCM_SIZEOF_UNSIGNED_LONG_LONG %d\n", SIZEOF_UNSIGNED_LONG_LONG);
9ca20a9c
RB
279
280 pf("\n");
281 pf("/* handling for the deprecated long_long and ulong_long types */\n");
282 pf("/* If anything suitable is available, it'll be defined here. */\n");
283 pf("#if (SCM_ENABLE_DEPRECATED == 1)\n");
284 if (SIZEOF_LONG_LONG != 0)
285 pf ("typedef long long long_long;\n");
286 else if (SIZEOF___INT64 != 0)
287 pf ("typedef __int64 long_long;\n");
288
289 if (SIZEOF_UNSIGNED_LONG_LONG != 0)
290 pf ("typedef unsigned long long ulong_long;\n");
291 else if (SIZEOF_UNSIGNED___INT64 != 0)
292 pf ("typedef unsigned __int64 ulong_long;\n");
293 pf("#endif /* SCM_ENABLE_DEPRECATED == 1 */\n");
caeef9cb
RB
294
295 pf ("\n");
296 pf ("/* These are always defined. */\n");
297 pf ("typedef %s scm_t_int8;\n", SCM_I_GSC_T_INT8);
298 pf ("typedef %s scm_t_uint8;\n", SCM_I_GSC_T_UINT8);
299 pf ("typedef %s scm_t_int16;\n", SCM_I_GSC_T_INT16);
300 pf ("typedef %s scm_t_uint16;\n", SCM_I_GSC_T_UINT16);
301 pf ("typedef %s scm_t_int32;\n", SCM_I_GSC_T_INT32);
302 pf ("typedef %s scm_t_uint32;\n", SCM_I_GSC_T_UINT32);
fc54d937
MV
303 pf ("typedef %s scm_t_intmax;\n", SCM_I_GSC_T_INTMAX);
304 pf ("typedef %s scm_t_uintmax;\n", SCM_I_GSC_T_UINTMAX);
caeef9cb
RB
305
306 pf ("\n");
005f04cd
RB
307 pf ("/* 64-bit integer -- if available SCM_HAVE_T_INT64 will be 1 and\n"
308 " scm_t_int64 will be a suitable type, otherwise SCM_HAVE_T_INT64\n"
309 " will be 0. */\n");
caeef9cb
RB
310 if (SCM_I_GSC_T_INT64)
311 {
005f04cd 312 pf ("#define SCM_HAVE_T_INT64 1 /* 0 or 1 */\n");
caeef9cb
RB
313 pf ("typedef %s scm_t_int64;\n", SCM_I_GSC_T_INT64);
314 }
315 else
005f04cd 316 pf ("#define SCM_HAVE_T_INT64 0 /* 0 or 1 */\n");
caeef9cb
RB
317
318 pf ("\n");
005f04cd
RB
319 pf ("/* 64-bit unsigned integer -- if available SCM_HAVE_T_UINT64 will\n"
320 " be 1 and scm_t_uint64 will be a suitable type, otherwise\n"
321 " SCM_HAVE_T_UINT64 will be 0. */\n");
caeef9cb
RB
322 if (SCM_I_GSC_T_UINT64)
323 {
005f04cd 324 pf ("#define SCM_HAVE_T_UINT64 1 /* 0 or 1 */\n");
caeef9cb
RB
325 pf ("typedef %s scm_t_uint64;\n", SCM_I_GSC_T_UINT64);
326 }
327 else
005f04cd 328 pf ("#define SCM_HAVE_T_UINT64 0 /* 0 or 1 */\n");
caeef9cb
RB
329
330 pf ("\n");
331 pf ("/* scm_t_ptrdiff_t and size, always defined -- defined to long if\n"
332 " platform doesn't have ptrdiff_t. */\n");
333 pf ("typedef %s scm_t_ptrdiff;\n", SCM_I_GSC_T_PTRDIFF);
334 if (0 == strcmp ("long", SCM_I_GSC_T_PTRDIFF))
335 pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_LONG);
336 else
337 pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_PTRDIFF_T);
338
339 pf ("\n");
340 pf ("/* Size of intptr_t or 0 if not available */\n");
341 pf ("#define SCM_SIZEOF_INTPTR_T %d\n", SIZEOF_INTPTR_T);
342 pf ("/* Size of uintptr_t or 0 if not available */\n");
343 pf ("#define SCM_SIZEOF_UINTPTR_T %d\n", SIZEOF_UINTPTR_T);
344
345 pf ("\n");
346 pf ("/* same as POSIX \"struct timespec\" -- always defined */\n");
347#ifdef HAVE_STRUCT_TIMESPEC
348 pf ("typedef struct timespec scm_t_timespec;\n");
349#else
350 pf ("/* POSIX.4 structure for a time value. This is like a `struct timeval'"
351 " but has nanoseconds instead of microseconds. */\n");
352 pf ("typedef struct\n"
353 "{\n"
354 " long int tv_sec; /* Seconds. */\n"
355 " long int tv_nsec; /* Nanoseconds. */\n"
356 "} scm_t_timespec;\n");
357#endif
358
359 pf ("\n");
360 pf ("/*** Threading model (scmconfig.h support not finished) ***/\n");
361
005f04cd
RB
362 pf ("/* Define to 1 if using pthread multithreading. */\n");
363 pf ("#define SCM_USE_PTHREAD_THREADS %d /* 0 or 1 */\n",
364 SCM_I_GSC_USE_PTHREAD_THREADS);
caeef9cb 365
005f04cd
RB
366 pf ("/* Define to 1 if using one-thread 'multi'threading. */\n");
367 pf ("#define SCM_USE_NULL_THREADS %d /* 0 or 1 */\n",
368 SCM_I_GSC_USE_NULL_THREADS);
caeef9cb
RB
369
370 pf ("/* FIXME: what is this used for now? */\n");
005f04cd
RB
371 pf ("#define SCM_USE_COOP_THREADS %d /* 0 or 1 */\n",
372 SCM_I_GSC_USE_COOP_THREADS);
caeef9cb
RB
373
374#if USE_DLL_IMPORT
375 pf ("\n");
376 pf ("/* Define some additional CPP macros on Win32 platforms. */\n");
377 pf ("# define __REGEX_IMPORT__ 1\n");
378 pf ("# define __CRYPT_IMPORT__ 1\n");
379 pf ("# define __READLINE_IMPORT__ 1\n");
380 pf ("# define QT_IMPORT 1\n");
381#endif
382
383 pf ("\n");
384 pf ("#if SCM_ENABLE_DEPRECATED == 1\n"
385 "# define USE_THREADS 1 /* always true now */\n"
386 "# define GUILE_ISELECT 1 /* always true now */\n"
387 "# define READER_EXTENSIONS 1 /* always true now */\n"
388 "# define DEBUG_EXTENSIONS 1 /* always true now */\n"
389 "# define DYNAMIC_LINKING 1 /* always true now */\n"
390 "#endif\n");
391 printf ("\n");
392
393 printf ("#endif\n");
394
395 return 0;
396}