2 /**********************************************************************
4 Description of Guile's public config header mechanics:
5 -----------------------------------------------------
7 Guile has four core headers:
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
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.
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,
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.
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.
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).
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
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
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_.
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_
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.
85 Rationales (not finished):
87 Why do we use a C program here rather than AC_OUTPUT_COMMANDS?
88 --------------------------------------------------------------
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.
96 Why have gen-scmconfig.h.in?
97 ----------------------------
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
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
118 **********************************************************************/
124 #include <libguile/gen-scmconfig.h>
133 main (int argc
, char *argv
[])
135 pf ("/* This file is automatically generated --"
136 " see configure.in for details */\n"
138 "#ifndef SCM_SCMCONFIG_H\n"
139 "#define SCM_SCMCONFIG_H\n");
141 /*** various important headers ***/
143 pf ("/* Important headers */\n");
144 if (SCM_I_GSC_NEEDS_STDINT_H
)
145 pf ("#include <stdint.h>\n");
146 if (SCM_I_GSC_NEEDS_INTTYPES_H
)
147 pf ("#include <inttypes.h>\n");
150 pf ("#include <limits.h>\n");
152 pf ("/* limits.h not available */\n");
155 # ifdef TIME_WITH_SYS_TIME
156 pf ("#include <sys/time.h>\n");
157 pf ("#include <time.h>\n");
159 # ifdef HAVE_SYS_TIME_H
160 pf ("#include <sys/time.h>\n");
163 pf ("#include <time.h>\n");
170 pf ("#define SCM_HAVE_STDC_HEADERS 1 /* 0 or 1 */\n");
171 pf ("#include <stdlib.h>\n");
172 # if HAVE_SYS_TYPES_H
173 pf ("#include <sys/types.h>\n");
175 # if HAVE_SYS_STDTYPES_H
176 pf ("#include <sys/stdtypes.h>\n");
178 pf ("#include <stddef.h>\n");
179 #else /* STDC_HEADERS */
180 pf ("#define SCM_HAVE_STDC_HEADERS 0 /* 0 or 1 */");
181 #endif /* def STDC_HEADERS */
184 #ifdef HAVE_SYS_SELECT_H
185 pf ("#define SCM_HAVE_SYS_SELECT_H 1 /* 0 or 1 */\n");
187 pf ("#define SCM_HAVE_SYS_SELECT_H 0 /* 0 or 1 */\n");
190 #ifdef HAVE_FLOATINGPOINT_H
191 pf ("#define SCM_HAVE_FLOATINGPOINT_H 1 /* 0 or 1 */\n");
193 pf ("#define SCM_HAVE_FLOATINGPOINT_H 0 /* 0 or 1 */\n");
197 pf ("#define SCM_HAVE_IEEEFP_H 1 /* 0 or 1 */\n");
199 pf ("#define SCM_HAVE_IEEEFP_H 0 /* 0 or 1 */\n");
203 pf ("#define SCM_HAVE_NAN_H 1 /* 0 or 1 */\n");
205 pf ("#define SCM_HAVE_NAN_H 0 /* 0 or 1 */\n");
208 #ifdef HAVE_WINSOCK2_H
209 pf ("#define SCM_HAVE_WINSOCK2_H 1 /* 0 or 1 */\n");
211 pf ("#define SCM_HAVE_WINSOCK2_H 0 /* 0 or 1 */\n");
215 /*** GUILE_DEBUG (defined or undefined) ***/
217 pf ("/* Define to include various undocumented debugging functions. */\n");
218 if (SCM_I_GSC_GUILE_DEBUG
)
219 pf ("#define GUILE_DEBUG 1 /* defined or undefined */\n");
221 pf ("/* #undef GUILE_DEBUG */\n");
223 /*** GUILE_DEBUG_FREELIST (deined or undefined) ***/
225 pf ("/* Define this to debug the free list (helps w/ GC bugs). */\n");
226 if (SCM_I_GSC_GUILE_DEBUG_FREELIST
)
227 pf ("#define GUILE_DEBUG_FREELIST 1 /* defined or undefined */\n");
229 pf ("/* #undef GUILE_DEBUG_FREELIST */\n");
231 /*** SCM_ENABLE_DISCOURAGED (0 or 1) ***/
233 pf ("/* Set to 1 if you want to enable discouraged features. */\n");
234 pf ("/* (value will be 0 or 1). */\n");
235 pf ("#define SCM_ENABLE_DISCOURAGED %d\n", SCM_I_GSC_ENABLE_DISCOURAGED
);
237 /*** SCM_ENABLE_DEPRECATED (0 or 1) ***/
239 pf ("/* Set to 1 if you want to enable deprecated features. */\n");
240 pf ("/* (value will be 0 or 1). */\n");
241 pf ("#define SCM_ENABLE_DEPRECATED %d\n", SCM_I_GSC_ENABLE_DEPRECATED
);
243 /*** SCM_ENABLE_ELISP (0 or 1) ***/
245 pf ("/* Set to 1 to add Elisp support (in addition to Scheme). */\n");
246 pf ("#define SCM_ENABLE_ELISP %d /* 0 or 1 */\n", SCM_I_GSC_ENABLE_ELISP
);
248 /*** SCM_STACK_GROWS_UP (0 or 1) ***/
250 pf ("/* Set to 1 if the stack grows up, 0 otherwise. */\n");
251 pf ("#define SCM_STACK_GROWS_UP %d /* 0 or 1 */\n",
252 SCM_I_GSC_STACK_GROWS_UP
);
254 /*** SCM_C_INLINE (defined to appropriate string or undefined) ***/
256 pf ("/* C compiler's syntax for inline functions if any,\n"
257 " otherwise undefined. */\n");
258 if (SCM_I_GSC_C_INLINE
)
259 pf ("#define SCM_C_INLINE %s\n", SCM_I_GSC_C_INLINE
);
261 pf ("/* #undef SCM_C_INLINE */\n");
264 pf ("/* Standard types. */\n");
266 pf ("/* These are always defined */\n");
267 pf ("#define SCM_SIZEOF_CHAR %d\n", SIZEOF_CHAR
);
268 pf ("#define SCM_SIZEOF_UNSIGNED_CHAR %d\n", SIZEOF_UNSIGNED_CHAR
);
269 pf ("#define SCM_SIZEOF_SHORT %d\n", SIZEOF_SHORT
);
270 pf ("#define SCM_SIZEOF_UNSIGNED_SHORT %d\n", SIZEOF_UNSIGNED_SHORT
);
271 pf ("#define SCM_SIZEOF_LONG %d\n", SIZEOF_LONG
);
272 pf ("#define SCM_SIZEOF_UNSIGNED_LONG %d\n", SIZEOF_UNSIGNED_LONG
);
273 pf ("#define SCM_SIZEOF_INT %d\n", SIZEOF_INT
);
274 pf ("#define SCM_SIZEOF_UNSIGNED_INT %d\n", SIZEOF_UNSIGNED_INT
);
275 pf ("#define SCM_SIZEOF_SIZE_T %d\n", SIZEOF_SIZE_T
);
278 pf ("/* Size of (unsigned) long long or 0 if not available (scm_t_*64 may\n"
279 " be more likely to be what you want */\n");
280 pf ("#define SCM_SIZEOF_LONG_LONG %d\n", SIZEOF_LONG_LONG
);
281 pf ("#define SCM_SIZEOF_UNSIGNED_LONG_LONG %d\n", SIZEOF_UNSIGNED_LONG_LONG
);
284 pf ("/* These are always defined. */\n");
285 pf ("typedef %s scm_t_int8;\n", SCM_I_GSC_T_INT8
);
286 pf ("typedef %s scm_t_uint8;\n", SCM_I_GSC_T_UINT8
);
287 pf ("typedef %s scm_t_int16;\n", SCM_I_GSC_T_INT16
);
288 pf ("typedef %s scm_t_uint16;\n", SCM_I_GSC_T_UINT16
);
289 pf ("typedef %s scm_t_int32;\n", SCM_I_GSC_T_INT32
);
290 pf ("typedef %s scm_t_uint32;\n", SCM_I_GSC_T_UINT32
);
291 pf ("typedef %s scm_t_intmax;\n", SCM_I_GSC_T_INTMAX
);
292 pf ("typedef %s scm_t_uintmax;\n", SCM_I_GSC_T_UINTMAX
);
294 if (0 == strcmp ("intmax_t", SCM_I_GSC_T_INTMAX
))
295 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_INTMAX_T
);
296 else if (0 == strcmp ("long long", SCM_I_GSC_T_INTMAX
))
297 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_LONG_LONG
);
298 else if (0 == strcmp ("__int64", SCM_I_GSC_T_INTMAX
))
299 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF___INT64
);
304 pf ("/* 64-bit integer -- if available SCM_HAVE_T_INT64 will be 1 and\n"
305 " scm_t_int64 will be a suitable type, otherwise SCM_HAVE_T_INT64\n"
307 if (SCM_I_GSC_T_INT64
)
309 pf ("#define SCM_HAVE_T_INT64 1 /* 0 or 1 */\n");
310 pf ("typedef %s scm_t_int64;\n", SCM_I_GSC_T_INT64
);
313 pf ("#define SCM_HAVE_T_INT64 0 /* 0 or 1 */\n");
316 pf ("/* 64-bit unsigned integer -- if available SCM_HAVE_T_UINT64 will\n"
317 " be 1 and scm_t_uint64 will be a suitable type, otherwise\n"
318 " SCM_HAVE_T_UINT64 will be 0. */\n");
319 if (SCM_I_GSC_T_UINT64
)
321 pf ("#define SCM_HAVE_T_UINT64 1 /* 0 or 1 */\n");
322 pf ("typedef %s scm_t_uint64;\n", SCM_I_GSC_T_UINT64
);
325 pf ("#define SCM_HAVE_T_UINT64 0 /* 0 or 1 */\n");
328 pf ("/* scm_t_ptrdiff_t and size, always defined -- defined to long if\n"
329 " platform doesn't have ptrdiff_t. */\n");
330 pf ("typedef %s scm_t_ptrdiff;\n", SCM_I_GSC_T_PTRDIFF
);
331 if (0 == strcmp ("long", SCM_I_GSC_T_PTRDIFF
))
332 pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_LONG
);
334 pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_PTRDIFF_T
);
337 pf ("/* Size of intptr_t or 0 if not available */\n");
338 pf ("#define SCM_SIZEOF_INTPTR_T %d\n", SIZEOF_INTPTR_T
);
339 pf ("/* Size of uintptr_t or 0 if not available */\n");
340 pf ("#define SCM_SIZEOF_UINTPTR_T %d\n", SIZEOF_UINTPTR_T
);
343 pf ("/* same as POSIX \"struct timespec\" -- always defined */\n");
344 #ifdef HAVE_STRUCT_TIMESPEC
345 pf ("typedef struct timespec scm_t_timespec;\n");
347 pf ("/* POSIX.4 structure for a time value. This is like a `struct timeval'"
348 " but has nanoseconds instead of microseconds. */\n");
349 pf ("typedef struct\n"
351 " long int tv_sec; /* Seconds. */\n"
352 " long int tv_nsec; /* Nanoseconds. */\n"
353 "} scm_t_timespec;\n");
357 pf ("/*** Threading model (scmconfig.h support not finished) ***/\n");
359 pf ("/* Define to 1 if using pthread multithreading. */\n");
360 pf ("#define SCM_USE_PTHREAD_THREADS %d /* 0 or 1 */\n",
361 SCM_I_GSC_USE_PTHREAD_THREADS
);
363 pf ("/* Define to 1 if using one-thread 'multi'threading. */\n");
364 pf ("#define SCM_USE_NULL_THREADS %d /* 0 or 1 */\n",
365 SCM_I_GSC_USE_NULL_THREADS
);
367 pf ("/* Define to 1 if need braces around PTHREAD_ONCE_INIT (for Solaris). */\n");
368 pf ("#define SCM_NEED_BRACES_ON_PTHREAD_ONCE_INIT %d /* 0 or 1 */\n",
369 SCM_I_GSC_NEED_BRACES_ON_PTHREAD_ONCE_INIT
);
371 pf ("/* Define to 1 if need braces around PTHREAD_MUTEX_INITIALIZER\n"
372 " (for IRIX with GCC) */\n");
373 pf ("#define SCM_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER %d /* 0 or 1 */\n",
374 SCM_I_GSC_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER
);
376 pf ("\n\n/*** File system access ***/\n");
378 pf ("/* Define to 1 if `struct dirent64' is available. */\n");
379 pf ("#define SCM_HAVE_STRUCT_DIRENT64 %d /* 0 or 1 */\n",
380 SCM_I_GSC_HAVE_STRUCT_DIRENT64
);
382 pf ("/* Define to 1 if `readdir64_r ()' is available. */\n");
383 #ifdef HAVE_READDIR64_R
384 pf ("#define SCM_HAVE_READDIR64_R 1 /* 0 or 1 */\n");
386 pf ("#define SCM_HAVE_READDIR64_R 0 /* 0 or 1 */\n");
389 /* Arrange so that we have a file offset type that reflects the one
390 used when compiling Guile, regardless of what the application's
391 `_FILE_OFFSET_BITS' says. See
392 http://lists.gnu.org/archive/html/bug-guile/2009-06/msg00018.html
393 for the original bug report.
395 Note that we can't define `scm_t_off' in terms of `off_t' or
396 `off64_t' because they may or may not be available depending on
397 how the application that uses Guile is compiled. */
399 #if defined GUILE_USE_64_CALLS && defined HAVE_STAT64
400 pf ("typedef scm_t_int64 scm_t_off;\n");
401 #elif SIZEOF_OFF_T == SIZEOF_INT
402 pf ("typedef int scm_t_off;\n");
404 pf ("typedef long int scm_t_off;\n");
407 pf ("/* Define to 1 if the compiler supports the "
408 "`__thread' storage class. */\n");
409 if (SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS
)
410 pf ("#define SCM_HAVE_THREAD_STORAGE_CLASS\n");
412 pf ("/* #undef SCM_HAVE_THREAD_STORAGE_CLASS */\n");
416 pf ("/* Define some additional CPP macros on Win32 platforms. */\n");
417 pf ("# define __REGEX_IMPORT__ 1\n");
418 pf ("# define __CRYPT_IMPORT__ 1\n");
419 pf ("# define __READLINE_IMPORT__ 1\n");
420 pf ("# define QT_IMPORT 1\n");
424 pf ("#if SCM_ENABLE_DEPRECATED == 1\n"
425 "# define USE_THREADS 1 /* always true now */\n"
426 "# define GUILE_ISELECT 1 /* always true now */\n"
427 "# define READER_EXTENSIONS 1 /* always true now */\n"
428 "# define DEBUG_EXTENSIONS 1 /* always true now */\n"
429 "# define DYNAMIC_LINKING 1 /* always true now */\n"
433 pf ("#define SCM_HAVE_ARRAYS 1 /* always true now */\n");
436 pf ("/* Constants from uniconv.h. */\n");
437 pf ("#define SCM_ICONVEH_ERROR %d\n", (int) iconveh_error
);
438 pf ("#define SCM_ICONVEH_QUESTION_MARK %d\n",
439 (int) iconveh_question_mark
);
440 pf ("#define SCM_ICONVEH_ESCAPE_SEQUENCE %d\n",
441 (int) iconveh_escape_sequence
);