3c8be4f8e7791867e043e088344ae0f86a5b8775
[bpt/guile.git] / libguile / gen-scmconfig.c
1 /* Copyright (C) 2003-2014 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 exceptions to this
58 rule are GUILE_DEBUG and GUILE_DEBUG_FREELIST which do not follow
59 this convention in order to 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 /* Don't include <config.h> when cross-compiling because it contains
136 information about the host, not about the build machine. */
137 #ifndef CROSS_COMPILING
138 # include <config.h>
139 #endif
140
141 #include <libguile/gen-scmconfig.h>
142
143 #include <stdio.h>
144 #include <string.h>
145
146 #define pf printf
147
148 int
149 main (int argc, char *argv[])
150 {
151 pf ("/* This file is automatically generated --"
152 " see configure.in for details */\n"
153 "\n"
154 "#ifndef SCM_SCMCONFIG_H\n"
155 "#define SCM_SCMCONFIG_H\n");
156
157 /*** various important headers ***/
158 pf ("\n");
159 pf ("/* Important headers */\n");
160 if (SCM_I_GSC_NEEDS_STDINT_H)
161 pf ("#include <stdint.h>\n");
162 if (SCM_I_GSC_NEEDS_INTTYPES_H)
163 pf ("#include <inttypes.h>\n");
164
165 #ifdef HAVE_LIMITS_H
166 pf ("#include <limits.h>\n");
167 #else
168 pf ("/* limits.h not available */\n");
169 #endif
170
171 #if HAVE_SYS_TIME_H
172 pf ("#include <sys/time.h>\n");
173 #else
174 pf ("/* sys/time.h not available */\n");
175 #endif
176
177 #if HAVE_TIME_H
178 pf ("#include <time.h>\n");
179 #else
180 pf ("/* time.h not available */\n");
181 #endif
182
183 pf("\n");
184 #ifdef STDC_HEADERS
185 pf ("#define SCM_HAVE_STDC_HEADERS 1 /* 0 or 1 */\n");
186 pf ("#include <stdlib.h>\n");
187 # ifdef HAVE_SYS_TYPES_H
188 pf ("#include <sys/types.h>\n");
189 # endif
190 # ifdef HAVE_SYS_STDTYPES_H
191 pf ("#include <sys/stdtypes.h>\n");
192 # endif
193 pf ("#include <stddef.h>\n");
194 #else /* STDC_HEADERS */
195 pf ("#define SCM_HAVE_STDC_HEADERS 0 /* 0 or 1 */");
196 #endif /* def STDC_HEADERS */
197
198 pf("\n");
199 #ifdef HAVE_SYS_SELECT_H
200 pf ("#define SCM_HAVE_SYS_SELECT_H 1 /* 0 or 1 */\n");
201 #else
202 pf ("#define SCM_HAVE_SYS_SELECT_H 0 /* 0 or 1 */\n");
203 #endif
204
205 #ifdef HAVE_WINSOCK2_H
206 pf ("#define SCM_HAVE_WINSOCK2_H 1 /* 0 or 1 */\n");
207 #else
208 pf ("#define SCM_HAVE_WINSOCK2_H 0 /* 0 or 1 */\n");
209 #endif
210
211
212 /*** GUILE_DEBUG (defined or undefined) ***/
213 pf ("\n");
214 pf ("/* Define to include various undocumented debugging functions. */\n");
215 if (SCM_I_GSC_GUILE_DEBUG)
216 pf ("#define GUILE_DEBUG 1 /* defined or undefined */\n");
217 else
218 pf ("/* #undef GUILE_DEBUG */\n");
219
220 /*** SCM_ENABLE_DEPRECATED (0 or 1) ***/
221 pf ("\n");
222 pf ("/* Set to 1 if you want to enable deprecated features. */\n");
223 pf ("/* (value will be 0 or 1). */\n");
224 pf ("#define SCM_ENABLE_DEPRECATED %d\n", SCM_I_GSC_ENABLE_DEPRECATED);
225
226 /*** SCM_STACK_GROWS_UP (0 or 1) ***/
227 pf ("\n");
228 pf ("/* Set to 1 if the stack grows up, 0 otherwise. */\n");
229 pf ("#define SCM_STACK_GROWS_UP %d /* 0 or 1 */\n",
230 SCM_I_GSC_STACK_GROWS_UP);
231
232 /*** SCM_C_INLINE (defined to appropriate string or undefined) ***/
233 pf ("\n");
234 pf ("/* C compiler's syntax for inline functions if any,\n"
235 " otherwise undefined. */\n");
236 if (SCM_I_GSC_C_INLINE)
237 pf ("#define SCM_C_INLINE %s\n", SCM_I_GSC_C_INLINE);
238 else
239 pf ("/* #undef SCM_C_INLINE */\n");
240
241 pf ("\n");
242 pf ("/* Standard types. */\n");
243
244 pf ("/* These are always defined */\n");
245 pf ("#define SCM_SIZEOF_CHAR %d\n", SIZEOF_CHAR);
246 pf ("#define SCM_SIZEOF_UNSIGNED_CHAR %d\n", SIZEOF_UNSIGNED_CHAR);
247 pf ("#define SCM_SIZEOF_SHORT %d\n", SIZEOF_SHORT);
248 pf ("#define SCM_SIZEOF_UNSIGNED_SHORT %d\n", SIZEOF_UNSIGNED_SHORT);
249 pf ("#define SCM_SIZEOF_LONG %d\n", SIZEOF_LONG);
250 pf ("#define SCM_SIZEOF_UNSIGNED_LONG %d\n", SIZEOF_UNSIGNED_LONG);
251 pf ("#define SCM_SIZEOF_INT %d\n", SIZEOF_INT);
252 pf ("#define SCM_SIZEOF_UNSIGNED_INT %d\n", SIZEOF_UNSIGNED_INT);
253 pf ("#define SCM_SIZEOF_SIZE_T %d\n", SIZEOF_SIZE_T);
254
255 pf ("\n");
256 pf ("/* Size of (unsigned) long long or 0 if not available (scm_t_*64 may\n"
257 " be more likely to be what you want */\n");
258 pf ("#define SCM_SIZEOF_LONG_LONG %d\n", SIZEOF_LONG_LONG);
259 pf ("#define SCM_SIZEOF_UNSIGNED_LONG_LONG %d\n", SIZEOF_UNSIGNED_LONG_LONG);
260
261 pf ("\n");
262 pf ("/* These are always defined. */\n");
263 pf ("typedef %s scm_t_int8;\n", SCM_I_GSC_T_INT8);
264 pf ("typedef %s scm_t_uint8;\n", SCM_I_GSC_T_UINT8);
265 pf ("typedef %s scm_t_int16;\n", SCM_I_GSC_T_INT16);
266 pf ("typedef %s scm_t_uint16;\n", SCM_I_GSC_T_UINT16);
267 pf ("typedef %s scm_t_int32;\n", SCM_I_GSC_T_INT32);
268 pf ("typedef %s scm_t_uint32;\n", SCM_I_GSC_T_UINT32);
269 pf ("typedef %s scm_t_intmax;\n", SCM_I_GSC_T_INTMAX);
270 pf ("typedef %s scm_t_uintmax;\n", SCM_I_GSC_T_UINTMAX);
271 pf ("typedef %s scm_t_intptr;\n", SCM_I_GSC_T_INTPTR);
272 pf ("typedef %s scm_t_uintptr;\n", SCM_I_GSC_T_UINTPTR);
273
274 if (0 == strcmp ("intmax_t", SCM_I_GSC_T_INTMAX))
275 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_INTMAX_T);
276 else if (0 == strcmp ("long long", SCM_I_GSC_T_INTMAX))
277 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_LONG_LONG);
278 else if (0 == strcmp ("__int64", SCM_I_GSC_T_INTMAX))
279 pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF___INT64);
280 else
281 return 1;
282
283 pf ("\n");
284 pf ("#define SCM_HAVE_T_INT64 1 /* 0 or 1 */\n");
285 pf ("typedef %s scm_t_int64;\n", SCM_I_GSC_T_INT64);
286 pf ("#define SCM_HAVE_T_UINT64 1 /* 0 or 1 */\n");
287 pf ("typedef %s scm_t_uint64;\n", SCM_I_GSC_T_UINT64);
288
289 pf ("\n");
290 pf ("/* scm_t_ptrdiff and size, always defined -- defined to long if\n"
291 " platform doesn't have ptrdiff_t. */\n");
292 pf ("typedef %s scm_t_ptrdiff;\n", SCM_I_GSC_T_PTRDIFF);
293 if (0 == strcmp ("long", SCM_I_GSC_T_PTRDIFF))
294 pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_LONG);
295 else
296 pf ("#define SCM_SIZEOF_SCM_T_PTRDIFF %d\n", SIZEOF_PTRDIFF_T);
297
298 pf ("\n");
299 pf ("/* Size of intptr_t or 0 if not available */\n");
300 pf ("#define SCM_SIZEOF_INTPTR_T %d\n", SIZEOF_INTPTR_T);
301 pf ("/* Size of uintptr_t or 0 if not available */\n");
302 pf ("#define SCM_SIZEOF_UINTPTR_T %d\n", SIZEOF_UINTPTR_T);
303
304 pf ("\n");
305 pf ("/* same as POSIX \"struct timespec\" -- always defined */\n");
306 #ifdef HAVE_SYSTEM_STRUCT_TIMESPEC
307 pf ("typedef struct timespec scm_t_timespec;\n");
308 #else
309 pf ("/* POSIX.4 structure for a time value. This is like a `struct timeval'"
310 " but has nanoseconds instead of microseconds. */\n");
311 pf ("typedef struct\n"
312 "{\n"
313 " long int tv_sec; /* Seconds. */\n"
314 " long int tv_nsec; /* Nanoseconds. */\n"
315 "} scm_t_timespec;\n");
316 #endif
317
318 pf ("\n");
319 pf ("/*** Threading model (scmconfig.h support not finished) ***/\n");
320
321 pf ("/* Define to 1 if using pthread multithreading. */\n");
322 pf ("#define SCM_USE_PTHREAD_THREADS %d /* 0 or 1 */\n",
323 SCM_I_GSC_USE_PTHREAD_THREADS);
324
325 pf ("/* Define to 1 if using one-thread 'multi'threading. */\n");
326 pf ("#define SCM_USE_NULL_THREADS %d /* 0 or 1 */\n",
327 SCM_I_GSC_USE_NULL_THREADS);
328
329 pf ("/* Define to 1 if need braces around PTHREAD_ONCE_INIT (for Solaris). */\n");
330 pf ("#define SCM_NEED_BRACES_ON_PTHREAD_ONCE_INIT %d /* 0 or 1 */\n",
331 SCM_I_GSC_NEED_BRACES_ON_PTHREAD_ONCE_INIT);
332
333 pf ("/* Define to 1 if need braces around PTHREAD_MUTEX_INITIALIZER\n"
334 " (for IRIX with GCC) */\n");
335 pf ("#define SCM_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER %d /* 0 or 1 */\n",
336 SCM_I_GSC_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER);
337
338 #ifdef HAVE_GC_PTHREAD_CANCEL
339 pf ("#define SCM_HAVE_GC_PTHREAD_CANCEL 1 /* 0 or 1 */\n");
340 #else
341 pf ("#define SCM_HAVE_GC_PTHREAD_CANCEL 0 /* 0 or 1 */\n");
342 #endif
343
344 #ifdef HAVE_GC_PTHREAD_EXIT
345 pf ("#define SCM_HAVE_GC_PTHREAD_EXIT 1 /* 0 or 1 */\n");
346 #else
347 pf ("#define SCM_HAVE_GC_PTHREAD_EXIT 0 /* 0 or 1 */\n");
348 #endif
349
350 #ifdef HAVE_GC_PTHREAD_SIGMASK
351 pf ("#define SCM_HAVE_GC_PTHREAD_SIGMASK 1 /* 0 or 1 */\n");
352 #else
353 pf ("#define SCM_HAVE_GC_PTHREAD_SIGMASK 0 /* 0 or 1 */\n");
354 #endif
355
356 pf ("\n\n/*** File system access ***/\n");
357
358 pf ("/* Define to 1 if `struct dirent64' is available. */\n");
359 pf ("#define SCM_HAVE_STRUCT_DIRENT64 %d /* 0 or 1 */\n",
360 SCM_I_GSC_HAVE_STRUCT_DIRENT64);
361
362 pf ("/* Define to 1 if `readdir64_r ()' is available. */\n");
363 #ifdef HAVE_READDIR64_R
364 pf ("#define SCM_HAVE_READDIR64_R 1 /* 0 or 1 */\n");
365 #else
366 pf ("#define SCM_HAVE_READDIR64_R 0 /* 0 or 1 */\n");
367 #endif
368
369 /* Arrange so that we have a file offset type that reflects the one
370 used when compiling Guile, regardless of what the application's
371 `_FILE_OFFSET_BITS' says. See
372 http://lists.gnu.org/archive/html/bug-guile/2009-06/msg00018.html
373 for the original bug report.
374
375 Note that we can't define `scm_t_off' in terms of `off_t' or
376 `off64_t' because they may or may not be available depending on
377 how the application that uses Guile is compiled. */
378
379 #if defined GUILE_USE_64_CALLS && defined HAVE_STAT64
380 pf ("typedef scm_t_int64 scm_t_off;\n");
381 #elif SIZEOF_OFF_T == SIZEOF_INT
382 pf ("typedef int scm_t_off;\n");
383 #else
384 pf ("typedef long int scm_t_off;\n");
385 #endif
386
387 pf ("/* Define to 1 if the compiler supports the "
388 "`__thread' storage class. */\n");
389 if (SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS)
390 pf ("#define SCM_HAVE_THREAD_STORAGE_CLASS\n");
391 else
392 pf ("/* #undef SCM_HAVE_THREAD_STORAGE_CLASS */\n");
393
394 #ifdef USE_DLL_IMPORT
395 pf ("\n");
396 pf ("/* Define some additional CPP macros on Win32 platforms. */\n");
397 pf ("# define __REGEX_IMPORT__ 1\n");
398 pf ("# define __CRYPT_IMPORT__ 1\n");
399 pf ("# define __READLINE_IMPORT__ 1\n");
400 pf ("# define QT_IMPORT 1\n");
401 #endif
402
403 pf ("\n");
404 pf ("#if SCM_ENABLE_DEPRECATED == 1\n"
405 "# define USE_THREADS 1 /* always true now */\n"
406 "# define GUILE_ISELECT 1 /* always true now */\n"
407 "# define READER_EXTENSIONS 1 /* always true now */\n"
408 "# define DEBUG_EXTENSIONS 1 /* always true now */\n"
409 "# define DYNAMIC_LINKING 1 /* always true now */\n"
410 "#endif\n");
411 printf ("\n");
412
413 pf ("#define SCM_HAVE_ARRAYS 1 /* always true now */\n");
414
415 pf ("\n");
416 pf ("/* Constants from uniconv.h. */\n");
417 pf ("#define SCM_ICONVEH_ERROR %d\n", SCM_I_GSC_ICONVEH_ERROR);
418 pf ("#define SCM_ICONVEH_QUESTION_MARK %d\n",
419 SCM_I_GSC_ICONVEH_QUESTION_MARK);
420 pf ("#define SCM_ICONVEH_ESCAPE_SEQUENCE %d\n",
421 SCM_I_GSC_ICONVEH_ESCAPE_SEQUENCE);
422
423 printf ("#endif\n");
424
425 return 0;
426 }