gen-scmconfig.c 16 KB

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