gen-scmconfig.c 16 KB

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