gen-scmconfig.c 15 KB

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