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