gen-scmconfig.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. #define pf printf
  104. int
  105. main (int argc, char *argv[])
  106. {
  107. pf ("/* This file is automatically generated --"
  108. " see configure.in for details */\n"
  109. "\n"
  110. "#ifndef SCM_SCMCONFIG_H\n"
  111. "#define SCM_SCMCONFIG_H\n");
  112. /*** various important headers ***/
  113. pf ("\n");
  114. pf ("/* Important headers */\n");
  115. if (SCM_I_GSC_NEEDS_STDINT_H)
  116. pf ("#include <stdint.h>\n");
  117. if (SCM_I_GSC_NEEDS_INTTYPES_H)
  118. pf ("#include <inttypes.h>\n");
  119. #ifdef HAVE_LIMITS_H
  120. pf ("#include <limits.h>\n");
  121. #else
  122. pf ("/* limits.h not available */\n");
  123. #endif
  124. # ifdef TIME_WITH_SYS_TIME
  125. pf ("#include <sys/time.h>\n");
  126. pf ("#include <time.h>\n");
  127. # else
  128. # ifdef HAVE_SYS_TIME_H
  129. pf ("#include <sys/time.h>\n");
  130. # else
  131. # ifdef HAVE_TIME_H
  132. pf ("#include <time.h>\n");
  133. # endif
  134. # endif
  135. # endif
  136. pf("\n");
  137. #ifdef STDC_HEADERS
  138. pf ("#define SCM_HAVE_STDC_HEADERS 1 /* 0 or 1 */\n");
  139. pf ("#include <stdlib.h>\n");
  140. # if HAVE_SYS_TYPES_H
  141. pf ("#include <sys/types.h>\n");
  142. # endif
  143. # if HAVE_SYS_STDTYPES_H
  144. pf ("#include <sys/stdtypes.h>\n");
  145. # endif
  146. pf ("#include <stddef.h>\n");
  147. #else /* STDC_HEADERS */
  148. pf ("#define SCM_HAVE_STDC_HEADERS 0 /* 0 or 1 */");
  149. #endif /* def STDC_HEADERS */
  150. pf("\n");
  151. #ifdef HAVE_SYS_SELECT_H
  152. pf ("#define SCM_HAVE_SYS_SELECT_H 1 /* 0 or 1 */\n");
  153. #else
  154. pf ("#define SCM_HAVE_SYS_SELECT_H 0 /* 0 or 1 */\n");
  155. #endif
  156. #ifdef HAVE_FLOATINGPOINT_H
  157. pf ("#define SCM_HAVE_FLOATINGPOINT_H 1 /* 0 or 1 */\n");
  158. #else
  159. pf ("#define SCM_HAVE_FLOATINGPOINT_H 0 /* 0 or 1 */\n");
  160. #endif
  161. #ifdef HAVE_IEEEFP_H
  162. pf ("#define SCM_HAVE_IEEEFP_H 1 /* 0 or 1 */\n");
  163. #else
  164. pf ("#define SCM_HAVE_IEEEFP_H 0 /* 0 or 1 */\n");
  165. #endif
  166. #ifdef HAVE_NAN_H
  167. pf ("#define SCM_HAVE_NAN_H 1 /* 0 or 1 */\n");
  168. #else
  169. pf ("#define SCM_HAVE_NAN_H 0 /* 0 or 1 */\n");
  170. #endif
  171. #ifdef HAVE_WINSOCK2_H
  172. pf ("#define SCM_HAVE_WINSOCK2_H 1 /* 0 or 1 */\n");
  173. #else
  174. pf ("#define SCM_HAVE_WINSOCK2_H 0 /* 0 or 1 */\n");
  175. #endif
  176. /*** GUILE_DEBUG (defined or undefined) ***/
  177. pf ("\n");
  178. pf ("/* Define to include various undocumented debugging functions. */\n");
  179. if (SCM_I_GSC_GUILE_DEBUG)
  180. pf ("#define GUILE_DEBUG 1 /* defined or undefined */\n");
  181. else
  182. pf ("/* #undef GUILE_DEBUG */\n");
  183. /*** GUILE_DEBUG_FREELIST (deined or undefined) ***/
  184. pf ("\n");
  185. pf ("/* Define this to debug the free list (helps w/ GC bugs). */\n");
  186. if (SCM_I_GSC_GUILE_DEBUG_FREELIST)
  187. pf ("#define GUILE_DEBUG_FREELIST 1 /* defined or undefined */\n");
  188. else
  189. pf ("/* #undef GUILE_DEBUG_FREELIST */\n");
  190. /*** SCM_ENABLE_DISCOURAGED (0 or 1) ***/
  191. pf ("\n");
  192. pf ("/* Set to 1 if you want to enable discouraged features. */\n");
  193. pf ("/* (value will be 0 or 1). */\n");
  194. pf ("#define SCM_ENABLE_DISCOURAGED %d\n", SCM_I_GSC_ENABLE_DISCOURAGED);
  195. /*** SCM_ENABLE_DEPRECATED (0 or 1) ***/
  196. pf ("\n");
  197. pf ("/* Set to 1 if you want to enable deprecated features. */\n");
  198. pf ("/* (value will be 0 or 1). */\n");
  199. pf ("#define SCM_ENABLE_DEPRECATED %d\n", SCM_I_GSC_ENABLE_DEPRECATED);
  200. /*** SCM_ENABLE_ELISP (0 or 1) ***/
  201. pf ("\n");
  202. pf ("/* Set to 1 to add Elisp support (in addition to Scheme). */\n");
  203. pf ("#define SCM_ENABLE_ELISP %d /* 0 or 1 */\n", SCM_I_GSC_ENABLE_ELISP);
  204. /*** SCM_STACK_GROWS_UP (0 or 1) ***/
  205. pf ("\n");
  206. pf ("/* Set to 1 if the stack grows up, 0 otherwise. */\n");
  207. pf ("#define SCM_STACK_GROWS_UP %d /* 0 or 1 */\n",
  208. SCM_I_GSC_STACK_GROWS_UP);
  209. /*** SCM_C_INLINE (defined to appropriate string or undefined) ***/
  210. pf ("\n");
  211. pf ("/* C compiler's syntax for inline functions if any,\n"
  212. " otherwise undefined. */\n");
  213. if (SCM_I_GSC_C_INLINE)
  214. pf ("#define SCM_C_INLINE %s\n", SCM_I_GSC_C_INLINE);
  215. else
  216. pf ("/* #undef SCM_C_INLINE */\n");
  217. pf ("\n");
  218. pf ("/* Standard types. */\n");
  219. pf ("/* These are always defined */\n");
  220. pf ("#define SCM_SIZEOF_CHAR %d\n", SIZEOF_CHAR);
  221. pf ("#define SCM_SIZEOF_UNSIGNED_CHAR %d\n", SIZEOF_UNSIGNED_CHAR);
  222. pf ("#define SCM_SIZEOF_SHORT %d\n", SIZEOF_SHORT);
  223. pf ("#define SCM_SIZEOF_UNSIGNED_SHORT %d\n", SIZEOF_UNSIGNED_SHORT);
  224. pf ("#define SCM_SIZEOF_LONG %d\n", SIZEOF_LONG);
  225. pf ("#define SCM_SIZEOF_UNSIGNED_LONG %d\n", SIZEOF_UNSIGNED_LONG);
  226. pf ("#define SCM_SIZEOF_INT %d\n", SIZEOF_INT);
  227. pf ("#define SCM_SIZEOF_UNSIGNED_INT %d\n", SIZEOF_UNSIGNED_INT);
  228. pf ("#define SCM_SIZEOF_SIZE_T %d\n", SIZEOF_SIZE_T);
  229. pf ("\n");
  230. pf ("/* Size of (unsigned) long long or 0 if not available (scm_t_*64 may\n"
  231. " be more likely to be what you want */\n");
  232. pf ("#define SCM_SIZEOF_LONG_LONG %d\n", SIZEOF_LONG_LONG);
  233. pf ("#define SCM_SIZEOF_UNSIGNED_LONG_LONG %d\n", SIZEOF_UNSIGNED_LONG_LONG);
  234. pf("\n");
  235. pf("/* handling for the deprecated long_long and ulong_long types */\n");
  236. pf("/* If anything suitable is available, it'll be defined here. */\n");
  237. pf("#if (SCM_ENABLE_DEPRECATED == 1)\n");
  238. if (SIZEOF_LONG_LONG != 0)
  239. pf ("typedef long long long_long;\n");
  240. else if (SIZEOF___INT64 != 0)
  241. pf ("typedef __int64 long_long;\n");
  242. if (SIZEOF_UNSIGNED_LONG_LONG != 0)
  243. pf ("typedef unsigned long long ulong_long;\n");
  244. else if (SIZEOF_UNSIGNED___INT64 != 0)
  245. pf ("typedef unsigned __int64 ulong_long;\n");
  246. pf("#endif /* SCM_ENABLE_DEPRECATED == 1 */\n");
  247. pf ("\n");
  248. pf ("/* These are always defined. */\n");
  249. pf ("typedef %s scm_t_int8;\n", SCM_I_GSC_T_INT8);
  250. pf ("typedef %s scm_t_uint8;\n", SCM_I_GSC_T_UINT8);
  251. pf ("typedef %s scm_t_int16;\n", SCM_I_GSC_T_INT16);
  252. pf ("typedef %s scm_t_uint16;\n", SCM_I_GSC_T_UINT16);
  253. pf ("typedef %s scm_t_int32;\n", SCM_I_GSC_T_INT32);
  254. pf ("typedef %s scm_t_uint32;\n", SCM_I_GSC_T_UINT32);
  255. pf ("typedef %s scm_t_intmax;\n", SCM_I_GSC_T_INTMAX);
  256. pf ("typedef %s scm_t_uintmax;\n", SCM_I_GSC_T_UINTMAX);
  257. if (0 == strcmp ("intmax_t", SCM_I_GSC_T_INTMAX))
  258. pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_INTMAX_T);
  259. else if (0 == strcmp ("long long", SCM_I_GSC_T_INTMAX))
  260. pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_LONG_LONG);
  261. else if (0 == strcmp ("__int64", SCM_I_GSC_T_INTMAX))
  262. pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF___INT64);
  263. else
  264. return 1;
  265. pf ("\n");
  266. pf ("/* 64-bit integer -- if available SCM_HAVE_T_INT64 will be 1 and\n"
  267. " scm_t_int64 will be a suitable type, otherwise SCM_HAVE_T_INT64\n"
  268. " will be 0. */\n");
  269. if (SCM_I_GSC_T_INT64)
  270. {
  271. pf ("#define SCM_HAVE_T_INT64 1 /* 0 or 1 */\n");
  272. pf ("typedef %s scm_t_int64;\n", SCM_I_GSC_T_INT64);
  273. }
  274. else
  275. pf ("#define SCM_HAVE_T_INT64 0 /* 0 or 1 */\n");
  276. pf ("\n");
  277. pf ("/* 64-bit unsigned integer -- if available SCM_HAVE_T_UINT64 will\n"
  278. " be 1 and scm_t_uint64 will be a suitable type, otherwise\n"
  279. " SCM_HAVE_T_UINT64 will be 0. */\n");
  280. if (SCM_I_GSC_T_UINT64)
  281. {
  282. pf ("#define SCM_HAVE_T_UINT64 1 /* 0 or 1 */\n");
  283. pf ("typedef %s scm_t_uint64;\n", SCM_I_GSC_T_UINT64);
  284. }
  285. else
  286. pf ("#define SCM_HAVE_T_UINT64 0 /* 0 or 1 */\n");
  287. pf ("\n");
  288. pf ("/* scm_t_ptrdiff_t 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. pf ("\n");
  296. pf ("/* Size of intptr_t or 0 if not available */\n");
  297. pf ("#define SCM_SIZEOF_INTPTR_T %d\n", SIZEOF_INTPTR_T);
  298. pf ("/* Size of uintptr_t or 0 if not available */\n");
  299. pf ("#define SCM_SIZEOF_UINTPTR_T %d\n", SIZEOF_UINTPTR_T);
  300. pf ("\n");
  301. pf ("/* same as POSIX \"struct timespec\" -- always defined */\n");
  302. #ifdef HAVE_STRUCT_TIMESPEC
  303. pf ("typedef struct timespec scm_t_timespec;\n");
  304. #else
  305. pf ("/* POSIX.4 structure for a time value. This is like a `struct timeval'"
  306. " but has nanoseconds instead of microseconds. */\n");
  307. pf ("typedef struct\n"
  308. "{\n"
  309. " long int tv_sec; /* Seconds. */\n"
  310. " long int tv_nsec; /* Nanoseconds. */\n"
  311. "} scm_t_timespec;\n");
  312. #endif
  313. pf ("\n");
  314. pf ("/*** Threading model (scmconfig.h support not finished) ***/\n");
  315. pf ("/* Define to 1 if using pthread multithreading. */\n");
  316. pf ("#define SCM_USE_PTHREAD_THREADS %d /* 0 or 1 */\n",
  317. SCM_I_GSC_USE_PTHREAD_THREADS);
  318. pf ("/* Define to 1 if using one-thread 'multi'threading. */\n");
  319. pf ("#define SCM_USE_NULL_THREADS %d /* 0 or 1 */\n",
  320. SCM_I_GSC_USE_NULL_THREADS);
  321. pf ("/* Define to 1 if need braces around PTHREAD_ONCE_INIT (for Solaris). */\n");
  322. pf ("#define SCM_NEED_BRACES_ON_PTHREAD_ONCE_INIT %d /* 0 or 1 */\n",
  323. SCM_I_GSC_NEED_BRACES_ON_PTHREAD_ONCE_INIT);
  324. pf ("/* Define to 1 if need braces around PTHREAD_MUTEX_INITIALIZER\n"
  325. " (for IRIX with GCC) */\n");
  326. pf ("#define SCM_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER %d /* 0 or 1 */\n",
  327. SCM_I_GSC_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER);
  328. pf ("\n\n/*** File system access ***/\n");
  329. pf ("/* Define to 1 if `struct dirent64' is available. */\n");
  330. pf ("#define SCM_HAVE_STRUCT_DIRENT64 %d /* 0 or 1 */\n",
  331. SCM_I_GSC_HAVE_STRUCT_DIRENT64);
  332. pf ("/* Define to 1 if `readdir64_r ()' is available. */\n");
  333. #ifdef HAVE_READDIR64_R
  334. pf ("#define SCM_HAVE_READDIR64_R 1 /* 0 or 1 */\n");
  335. #else
  336. pf ("#define SCM_HAVE_READDIR64_R 0 /* 0 or 1 */\n");
  337. #endif
  338. #if USE_DLL_IMPORT
  339. pf ("\n");
  340. pf ("/* Define some additional CPP macros on Win32 platforms. */\n");
  341. pf ("# define __REGEX_IMPORT__ 1\n");
  342. pf ("# define __CRYPT_IMPORT__ 1\n");
  343. pf ("# define __READLINE_IMPORT__ 1\n");
  344. pf ("# define QT_IMPORT 1\n");
  345. #endif
  346. pf ("\n");
  347. pf ("#if SCM_ENABLE_DEPRECATED == 1\n"
  348. "# define USE_THREADS 1 /* always true now */\n"
  349. "# define GUILE_ISELECT 1 /* always true now */\n"
  350. "# define READER_EXTENSIONS 1 /* always true now */\n"
  351. "# define DEBUG_EXTENSIONS 1 /* always true now */\n"
  352. "# define DYNAMIC_LINKING 1 /* always true now */\n"
  353. "#endif\n");
  354. printf ("\n");
  355. pf ("#define SCM_HAVE_ARRAYS 1 /* always true now */\n");
  356. printf ("#endif\n");
  357. return 0;
  358. }