gen-scmconfig.c 15 KB

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