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