Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / libguile / gen-scmconfig.c
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 - 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 exception to this rule
41 is GUILE_DEBUG which does not follow this convention in order to
42 retain backward compatibility.
43
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.
82
83 Rationales (not finished):
84
85 Why do we use a C program here rather than AC_OUTPUT_COMMANDS?
86 --------------------------------------------------------------
87
88 The main reason is that there are some values we would need
89 access to at AC_OUTPUT_COMMANDs that are determined by configure
90 but are not available at AC_OUTPUT time. The values are *only*
91 available via config.h. We use gen-scmconfig so we can see those
92 values and make decisions based on their settings.
93
94 Why have gen-scmconfig.h.in?
95 ----------------------------
96
97 Without that header, we could end up needing multiple aliases for
98 public settings like SCM_ENABLE_ELISP. We can't define
99 SCM_ENABLE_ELISP in config.h since that header is private and any
100 definition in scmconfig.h would conflict (#ifndef might be
101 possible but runs the risk of conflicting directives), so a
102 likely solution would be to AC_DEFINE([SCM_I_ENABLE_ELISP]), and
103 then use SCM_I_ENABLE_ELISP in gen-scmconfig via config.h to
104 determine whether or not to #define SCM_ENABLE_ELISP, but this
105 leaves us with two #defined symbols for each public setting --
106 better to just have one value (public or private) that all code
107 uses.
108
109 Having this header means we can AC_SUBST a value like
110 SCM_I_GSC_ENABLE_ELISP and then set it in here via AC_OUTPUT
111 substitutions, and gen-scmconfig can use that definition to
112 determine whether or not to #define SCM_ENABLE_ELISP when
113 generating scmconfig.h, and we end up with nothing extraneous
114 added to config.h.
115
116 **********************************************************************/
117
118 #ifdef HAVE_CONFIG_H
119 # include <config.h>
120 #endif
121
122 #include <libguile/gen-scmconfig.h>
123
124 #include <stdio.h>
125 #include <string.h>
126
127 #define pf printf
128
129 int
130 main (int argc, char *argv[])
131 {
132 pf ("/* This file is automatically generated --"
133 " see configure.in for details */\n"
134 "\n"
135 "#ifndef SCM_SCMCONFIG_H\n"
136 "#define SCM_SCMCONFIG_H\n");
137
138 /*** various important headers ***/
139 pf ("\n");
140 pf ("/* Important headers */\n");
141 if (SCM_I_GSC_NEEDS_STDINT_H)
142 pf ("#include <stdint.h>\n");
143 if (SCM_I_GSC_NEEDS_INTTYPES_H)
144 pf ("#include <inttypes.h>\n");
145
146 #ifdef HAVE_LIMITS_H
147 pf ("#include <limits.h>\n");
148 #else
149 pf ("/* limits.h not available */\n");
150 #endif
151
152 #if HAVE_SYS_TIME_H
153 pf ("#include <sys/time.h>\n");
154 #else
155 pf ("/* sys/time.h not available */\n");
156 #endif
157
158 #if HAVE_TIME_H
159 pf ("#include <time.h>\n");
160 #else
161 pf ("/* time.h not available */\n");
162 #endif
163
164 pf("\n");
165 #ifdef STDC_HEADERS
166 pf ("#define SCM_HAVE_STDC_HEADERS 1 /* 0 or 1 */\n");
167 pf ("#include <stdlib.h>\n");
168 # ifdef HAVE_SYS_TYPES_H
169 pf ("#include <sys/types.h>\n");
170 # endif
171 # ifdef HAVE_SYS_STDTYPES_H
172 pf ("#include <sys/stdtypes.h>\n");
173 # endif
174 pf ("#include <stddef.h>\n");
175 #else /* STDC_HEADERS */
176 pf ("#define SCM_HAVE_STDC_HEADERS 0 /* 0 or 1 */");
177 #endif /* def STDC_HEADERS */
178
179 pf("\n");
180 #ifdef HAVE_SYS_SELECT_H
181 pf ("#define SCM_HAVE_SYS_SELECT_H 1 /* 0 or 1 */\n");
182 #else
183 pf ("#define SCM_HAVE_SYS_SELECT_H 0 /* 0 or 1 */\n");
184 #endif
185
186 #ifdef HAVE_WINSOCK2_H
187 pf ("#define SCM_HAVE_WINSOCK2_H 1 /* 0 or 1 */\n");
188 #else
189 pf ("#define SCM_HAVE_WINSOCK2_H 0 /* 0 or 1 */\n");
190 #endif
191
192
193 /*** GUILE_DEBUG (defined or undefined) ***/
194 pf ("\n");
195 pf ("/* Define to include various undocumented debugging functions. */\n");
196 if (SCM_I_GSC_GUILE_DEBUG)
197 pf ("#define GUILE_DEBUG 1 /* defined or undefined */\n");
198 else
199 pf ("/* #undef GUILE_DEBUG */\n");
200
201 /*** SCM_ENABLE_DEPRECATED (0 or 1) ***/
202 pf ("\n");
203 pf ("/* Set to 1 if you want to enable deprecated features. */\n");
204 pf ("/* (value will be 0 or 1). */\n");
205 pf ("#define SCM_ENABLE_DEPRECATED %d\n", SCM_I_GSC_ENABLE_DEPRECATED);
206
207 /*** SCM_STACK_GROWS_UP (0 or 1) ***/
208 pf ("\n");
209 pf ("/* Set to 1 if the stack grows up, 0 otherwise. */\n");
210 pf ("#define SCM_STACK_GROWS_UP %d /* 0 or 1 */\n",
211 SCM_I_GSC_STACK_GROWS_UP);
212
213 /*** SCM_C_INLINE (defined to appropriate string or undefined) ***/
214 pf ("\n");
215 pf ("/* C compiler's syntax for inline functions if any,\n"
216 " otherwise undefined. */\n");
217 if (SCM_I_GSC_C_INLINE)
218 pf ("#define SCM_C_INLINE %s\n", SCM_I_GSC_C_INLINE);
219 else
220 pf ("/* #undef SCM_C_INLINE */\n");
221
222 pf ("\n");
223 pf ("/* Standard types. */\n");
224
225 pf ("/* These are always defined */\n");
226 pf ("#define SCM_SIZEOF_CHAR %d\n", SIZEOF_CHAR);
227 pf ("#define SCM_SIZEOF_UNSIGNED_CHAR %d\n", SIZEOF_UNSIGNED_CHAR);
228 pf ("#define SCM_SIZEOF_SHORT %d\n", SIZEOF_SHORT);
229 pf ("#define SCM_SIZEOF_UNSIGNED_SHORT %d\n", SIZEOF_UNSIGNED_SHORT);
230 pf ("#define SCM_SIZEOF_LONG %d\n", SIZEOF_LONG);
231 pf ("#define SCM_SIZEOF_UNSIGNED_LONG %d\n", SIZEOF_UNSIGNED_LONG);
232 pf ("#define SCM_SIZEOF_INT %d\n", SIZEOF_INT);
233 pf ("#define SCM_SIZEOF_UNSIGNED_INT %d\n", SIZEOF_UNSIGNED_INT);
234 pf ("#define SCM_SIZEOF_SIZE_T %d\n", SIZEOF_SIZE_T);
235
236 pf ("\n");
237 pf ("/* Size of (unsigned) long long or 0 if not available (scm_t_*64 may\n"
238 " be more likely to be what you want */\n");
239 pf ("#define SCM_SIZEOF_LONG_LONG %d\n", SIZEOF_LONG_LONG);
240 pf ("#define SCM_SIZEOF_UNSIGNED_LONG_LONG %d\n", SIZEOF_UNSIGNED_LONG_LONG);
241
242 pf ("\n");
243 pf ("/* These are always defined. */\n");
244 pf ("typedef %s scm_t_int8;\n", SCM_I_GSC_T_INT8);
245 pf ("typedef %s scm_t_uint8;\n", SCM_I_GSC_T_UINT8);
246 pf ("typedef %s scm_t_int16;\n", SCM_I_GSC_T_INT16);
247 pf ("typedef %s scm_t_uint16;\n", SCM_I_GSC_T_UINT16);
248 pf ("typedef %s scm_t_int32;\n", SCM_I_GSC_T_INT32);
249 pf ("typedef %s scm_t_uint32;\n", SCM_I_GSC_T_UINT32);
250 pf ("typedef %s scm_t_intmax;\n", SCM_I_GSC_T_INTMAX);
251 pf ("typedef %s scm_t_uintmax;\n", SCM_I_GSC_T_UINTMAX);
252 pf ("typedef %s scm_t_intptr;\n", SCM_I_GSC_T_INTPTR);
253 pf ("typedef %s scm_t_uintptr;\n", SCM_I_GSC_T_UINTPTR);
254
255 if (0 == strcmp ("intmax_t", SCM_I_GSC_T_INTMAX))
256 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_INTMAX_T);
257 else if (0 == strcmp ("long long", SCM_I_GSC_T_INTMAX))
258 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_LONG_LONG);
259 else if (0 == strcmp ("__int64", SCM_I_GSC_T_INTMAX))
260 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF___INT64);
261 else
262 return 1;
263
264 pf ("\n");
265 pf ("#define SCM_HAVE_T_INT64 1 /* 0 or 1 */\n");
266 pf ("typedef %s scm_t_int64;\n", SCM_I_GSC_T_INT64);
267 pf ("#define SCM_HAVE_T_UINT64 1 /* 0 or 1 */\n");
268 pf ("typedef %s scm_t_uint64;\n", SCM_I_GSC_T_UINT64);
269
270 pf ("\n");
271 pf ("/* scm_t_ptrdiff_t and size, always defined -- defined to long if\n"
272 " platform doesn't have ptrdiff_t. */\n");
273 pf ("typedef %s scm_t_ptrdiff;\n", SCM_I_GSC_T_PTRDIFF);
274 if (0 == strcmp ("long", SCM_I_GSC_T_PTRDIFF))
275 pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_LONG);
276 else
277 pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_PTRDIFF_T);
278
279 pf ("\n");
280 pf ("/* Size of intptr_t or 0 if not available */\n");
281 pf ("#define SCM_SIZEOF_INTPTR_T %d\n", SIZEOF_INTPTR_T);
282 pf ("/* Size of uintptr_t or 0 if not available */\n");
283 pf ("#define SCM_SIZEOF_UINTPTR_T %d\n", SIZEOF_UINTPTR_T);
284
285 pf ("\n");
286 pf ("/* same as POSIX \"struct timespec\" -- always defined */\n");
287 #ifdef HAVE_STRUCT_TIMESPEC
288 pf ("typedef struct timespec scm_t_timespec;\n");
289 #else
290 pf ("/* POSIX.4 structure for a time value. This is like a `struct timeval'"
291 " but has nanoseconds instead of microseconds. */\n");
292 pf ("typedef struct\n"
293 "{\n"
294 " long int tv_sec; /* Seconds. */\n"
295 " long int tv_nsec; /* Nanoseconds. */\n"
296 "} scm_t_timespec;\n");
297 #endif
298
299 pf ("\n");
300 pf ("/*** Threading model (scmconfig.h support not finished) ***/\n");
301
302 pf ("/* Define to 1 if using pthread multithreading. */\n");
303 pf ("#define SCM_USE_PTHREAD_THREADS %d /* 0 or 1 */\n",
304 SCM_I_GSC_USE_PTHREAD_THREADS);
305
306 pf ("/* Define to 1 if using one-thread 'multi'threading. */\n");
307 pf ("#define SCM_USE_NULL_THREADS %d /* 0 or 1 */\n",
308 SCM_I_GSC_USE_NULL_THREADS);
309
310 pf ("/* Define to 1 if need braces around PTHREAD_ONCE_INIT (for Solaris). */\n");
311 pf ("#define SCM_NEED_BRACES_ON_PTHREAD_ONCE_INIT %d /* 0 or 1 */\n",
312 SCM_I_GSC_NEED_BRACES_ON_PTHREAD_ONCE_INIT);
313
314 pf ("/* Define to 1 if need braces around PTHREAD_MUTEX_INITIALIZER\n"
315 " (for IRIX with GCC) */\n");
316 pf ("#define SCM_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER %d /* 0 or 1 */\n",
317 SCM_I_GSC_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER);
318
319 #ifdef HAVE_GC_PTHREAD_CANCEL
320 pf ("#define SCM_HAVE_GC_PTHREAD_CANCEL 1 /* 0 or 1 */\n");
321 #else
322 pf ("#define SCM_HAVE_GC_PTHREAD_CANCEL 0 /* 0 or 1 */\n");
323 #endif
324
325 #ifdef HAVE_GC_PTHREAD_EXIT
326 pf ("#define SCM_HAVE_GC_PTHREAD_EXIT 1 /* 0 or 1 */\n");
327 #else
328 pf ("#define SCM_HAVE_GC_PTHREAD_EXIT 0 /* 0 or 1 */\n");
329 #endif
330
331 #ifdef HAVE_GC_PTHREAD_SIGMASK
332 pf ("#define SCM_HAVE_GC_PTHREAD_SIGMASK 1 /* 0 or 1 */\n");
333 #else
334 pf ("#define SCM_HAVE_GC_PTHREAD_SIGMASK 0 /* 0 or 1 */\n");
335 #endif
336
337 pf ("\n\n/*** File system access ***/\n");
338
339 pf ("/* Define to 1 if `struct dirent64' is available. */\n");
340 pf ("#define SCM_HAVE_STRUCT_DIRENT64 %d /* 0 or 1 */\n",
341 SCM_I_GSC_HAVE_STRUCT_DIRENT64);
342
343 pf ("/* Define to 1 if `readdir64_r ()' is available. */\n");
344 #ifdef HAVE_READDIR64_R
345 pf ("#define SCM_HAVE_READDIR64_R 1 /* 0 or 1 */\n");
346 #else
347 pf ("#define SCM_HAVE_READDIR64_R 0 /* 0 or 1 */\n");
348 #endif
349
350 /* Arrange so that we have a file offset type that reflects the one
351 used when compiling Guile, regardless of what the application's
352 `_FILE_OFFSET_BITS' says. See
353 http://lists.gnu.org/archive/html/bug-guile/2009-06/msg00018.html
354 for the original bug report.
355
356 Note that we can't define `scm_t_off' in terms of `off_t' or
357 `off64_t' because they may or may not be available depending on
358 how the application that uses Guile is compiled. */
359
360 #if defined GUILE_USE_64_CALLS && defined HAVE_STAT64
361 pf ("typedef scm_t_int64 scm_t_off;\n");
362 #elif SIZEOF_OFF_T == SIZEOF_INT
363 pf ("typedef int scm_t_off;\n");
364 #else
365 pf ("typedef long int scm_t_off;\n");
366 #endif
367
368 pf ("/* Define to 1 if the compiler supports the "
369 "`__thread' storage class. */\n");
370 if (SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS)
371 pf ("#define SCM_HAVE_THREAD_STORAGE_CLASS\n");
372 else
373 pf ("/* #undef SCM_HAVE_THREAD_STORAGE_CLASS */\n");
374
375 #ifdef USE_DLL_IMPORT
376 pf ("\n");
377 pf ("/* Define some additional CPP macros on Win32 platforms. */\n");
378 pf ("# define __REGEX_IMPORT__ 1\n");
379 pf ("# define __CRYPT_IMPORT__ 1\n");
380 pf ("# define __READLINE_IMPORT__ 1\n");
381 pf ("# define QT_IMPORT 1\n");
382 #endif
383
384 pf ("\n");
385 pf ("#define SCM_HAVE_ARRAYS 1 /* always true now */\n");
386
387 pf ("\n");
388 pf ("/* Constants from uniconv.h. */\n");
389 pf ("#define SCM_ICONVEH_ERROR %d\n", SCM_I_GSC_ICONVEH_ERROR);
390 pf ("#define SCM_ICONVEH_QUESTION_MARK %d\n",
391 SCM_I_GSC_ICONVEH_QUESTION_MARK);
392 pf ("#define SCM_ICONVEH_ESCAPE_SEQUENCE %d\n",
393 SCM_I_GSC_ICONVEH_ESCAPE_SEQUENCE);
394
395 printf ("#endif\n");
396
397 return 0;
398 }