extensions.m4 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. # serial 22 -*- Autoconf -*-
  2. # Enable extensions on systems that normally disable them.
  3. # Copyright (C) 2003, 2006-2021 Free Software Foundation, Inc.
  4. # This file is free software; the Free Software Foundation
  5. # gives unlimited permission to copy and/or distribute it,
  6. # with or without modifications, as long as this notice is preserved.
  7. dnl Define to empty for the benefit of Autoconf 2.69 and earlier, so that
  8. dnl AC_USE_SYSTEM_EXTENSIONS (below) can be used unchanged from Autoconf 2.70+.
  9. m4_ifndef([AC_CHECK_INCLUDES_DEFAULT],
  10. [AC_DEFUN([AC_CHECK_INCLUDES_DEFAULT], [])])
  11. # This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from git
  12. # Autoconf. Perhaps we can remove this once we can assume Autoconf
  13. # is recent-enough everywhere, but since Autoconf mutates rapidly
  14. # enough in this area it's likely we'll need to redefine
  15. # AC_USE_SYSTEM_EXTENSIONS for quite some time.
  16. # If autoconf reports a warning
  17. # warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
  18. # or warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
  19. # the fix is
  20. # 1) to ensure that AC_USE_SYSTEM_EXTENSIONS is never directly invoked
  21. # but always AC_REQUIREd,
  22. # 2) to ensure that for each occurrence of
  23. # AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  24. # or
  25. # AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  26. # the corresponding gnulib module description has 'extensions' among
  27. # its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS
  28. # invocation occurs in gl_EARLY, not in gl_INIT.
  29. m4_version_prereq([2.70.1], [], [
  30. # AC_USE_SYSTEM_EXTENSIONS
  31. # ------------------------
  32. # Enable extensions on systems that normally disable them,
  33. # typically due to standards-conformance issues.
  34. # We unconditionally define as many of the known feature-enabling
  35. # as possible, reserving conditional behavior for macros that are
  36. # known to cause problems on some platforms (such as __EXTENSIONS__).
  37. AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS],
  38. [AC_BEFORE([$0], [AC_PREPROC_IFELSE])dnl
  39. AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
  40. AC_BEFORE([$0], [AC_LINK_IFELSE])dnl
  41. AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
  42. AC_BEFORE([$0], [AC_CHECK_INCLUDES_DEFAULT])dnl
  43. dnl #undef in AH_VERBATIM gets replaced with #define by AC_DEFINE.
  44. dnl Use a different key than __EXTENSIONS__, as that name broke existing
  45. dnl configure.ac when using autoheader 2.62.
  46. dnl The macros below are in alphabetical order ignoring leading _ or __
  47. dnl prefixes.
  48. AH_VERBATIM([USE_SYSTEM_EXTENSIONS],
  49. [/* Enable extensions on AIX 3, Interix. */
  50. #ifndef _ALL_SOURCE
  51. # undef _ALL_SOURCE
  52. #endif
  53. /* Enable general extensions on macOS. */
  54. #ifndef _DARWIN_C_SOURCE
  55. # undef _DARWIN_C_SOURCE
  56. #endif
  57. /* Enable general extensions on Solaris. */
  58. #ifndef __EXTENSIONS__
  59. # undef __EXTENSIONS__
  60. #endif
  61. /* Enable GNU extensions on systems that have them. */
  62. #ifndef _GNU_SOURCE
  63. # undef _GNU_SOURCE
  64. #endif
  65. /* Enable X/Open compliant socket functions that do not require linking
  66. with -lxnet on HP-UX 11.11. */
  67. #ifndef _HPUX_ALT_XOPEN_SOCKET_API
  68. # undef _HPUX_ALT_XOPEN_SOCKET_API
  69. #endif
  70. /* Identify the host operating system as Minix.
  71. This macro does not affect the system headers' behavior.
  72. A future release of Autoconf may stop defining this macro. */
  73. #ifndef _MINIX
  74. # undef _MINIX
  75. #endif
  76. /* Enable general extensions on NetBSD.
  77. Enable NetBSD compatibility extensions on Minix. */
  78. #ifndef _NETBSD_SOURCE
  79. # undef _NETBSD_SOURCE
  80. #endif
  81. /* Enable OpenBSD compatibility extensions on NetBSD.
  82. Oddly enough, this does nothing on OpenBSD. */
  83. #ifndef _OPENBSD_SOURCE
  84. # undef _OPENBSD_SOURCE
  85. #endif
  86. /* Define to 1 if needed for POSIX-compatible behavior. */
  87. #ifndef _POSIX_SOURCE
  88. # undef _POSIX_SOURCE
  89. #endif
  90. /* Define to 2 if needed for POSIX-compatible behavior. */
  91. #ifndef _POSIX_1_SOURCE
  92. # undef _POSIX_1_SOURCE
  93. #endif
  94. /* Enable POSIX-compatible threading on Solaris. */
  95. #ifndef _POSIX_PTHREAD_SEMANTICS
  96. # undef _POSIX_PTHREAD_SEMANTICS
  97. #endif
  98. /* Enable extensions specified by ISO/IEC TS 18661-5:2014. */
  99. #ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
  100. # undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
  101. #endif
  102. /* Enable extensions specified by ISO/IEC TS 18661-1:2014. */
  103. #ifndef __STDC_WANT_IEC_60559_BFP_EXT__
  104. # undef __STDC_WANT_IEC_60559_BFP_EXT__
  105. #endif
  106. /* Enable extensions specified by ISO/IEC TS 18661-2:2015. */
  107. #ifndef __STDC_WANT_IEC_60559_DFP_EXT__
  108. # undef __STDC_WANT_IEC_60559_DFP_EXT__
  109. #endif
  110. /* Enable extensions specified by ISO/IEC TS 18661-4:2015. */
  111. #ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
  112. # undef __STDC_WANT_IEC_60559_FUNCS_EXT__
  113. #endif
  114. /* Enable extensions specified by ISO/IEC TS 18661-3:2015. */
  115. #ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
  116. # undef __STDC_WANT_IEC_60559_TYPES_EXT__
  117. #endif
  118. /* Enable extensions specified by ISO/IEC TR 24731-2:2010. */
  119. #ifndef __STDC_WANT_LIB_EXT2__
  120. # undef __STDC_WANT_LIB_EXT2__
  121. #endif
  122. /* Enable extensions specified by ISO/IEC 24747:2009. */
  123. #ifndef __STDC_WANT_MATH_SPEC_FUNCS__
  124. # undef __STDC_WANT_MATH_SPEC_FUNCS__
  125. #endif
  126. /* Enable extensions on HP NonStop. */
  127. #ifndef _TANDEM_SOURCE
  128. # undef _TANDEM_SOURCE
  129. #endif
  130. /* Enable X/Open extensions. Define to 500 only if necessary
  131. to make mbstate_t available. */
  132. #ifndef _XOPEN_SOURCE
  133. # undef _XOPEN_SOURCE
  134. #endif
  135. ])dnl
  136. AC_REQUIRE([AC_CHECK_INCLUDES_DEFAULT])dnl
  137. _AC_CHECK_HEADER_ONCE([wchar.h])
  138. _AC_CHECK_HEADER_ONCE([minix/config.h])
  139. dnl Defining __EXTENSIONS__ may break the system headers on some systems.
  140. dnl (FIXME: Which ones?)
  141. AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
  142. [ac_cv_safe_to_define___extensions__],
  143. [AC_COMPILE_IFELSE(
  144. [AC_LANG_PROGRAM([[
  145. # define __EXTENSIONS__ 1
  146. ]AC_INCLUDES_DEFAULT])],
  147. [ac_cv_safe_to_define___extensions__=yes],
  148. [ac_cv_safe_to_define___extensions__=no])])
  149. dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to
  150. dnl 500, regardless of whether compiling with -Ae or -D_HPUX_SOURCE=1.
  151. dnl But defining _XOPEN_SOURCE may turn *off* extensions on platforms
  152. dnl not covered by turn-on-extensions macros (notably Dragonfly, Free,
  153. dnl and OpenBSD, which don't have any equivalent of _NETBSD_SOURCE) so
  154. dnl it should only be defined when necessary.
  155. AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined],
  156. [ac_cv_should_define__xopen_source],
  157. [ac_cv_should_define__xopen_source=no
  158. AS_IF([test $ac_cv_header_wchar_h = yes],
  159. [AC_COMPILE_IFELSE(
  160. [AC_LANG_PROGRAM([[
  161. #include <wchar.h>
  162. mbstate_t x;]])],
  163. [],
  164. [AC_COMPILE_IFELSE(
  165. [AC_LANG_PROGRAM([[
  166. #define _XOPEN_SOURCE 500
  167. #include <wchar.h>
  168. mbstate_t x;]])],
  169. [ac_cv_should_define__xopen_source=yes])])])])
  170. AC_DEFINE([_ALL_SOURCE])
  171. AC_DEFINE([_DARWIN_C_SOURCE])
  172. AC_DEFINE([_GNU_SOURCE])
  173. AC_DEFINE([_HPUX_ALT_XOPEN_SOCKET_API])
  174. AC_DEFINE([_NETBSD_SOURCE])
  175. AC_DEFINE([_OPENBSD_SOURCE])
  176. AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
  177. AC_DEFINE([__STDC_WANT_IEC_60559_ATTRIBS_EXT__])
  178. AC_DEFINE([__STDC_WANT_IEC_60559_BFP_EXT__])
  179. AC_DEFINE([__STDC_WANT_IEC_60559_DFP_EXT__])
  180. AC_DEFINE([__STDC_WANT_IEC_60559_FUNCS_EXT__])
  181. AC_DEFINE([__STDC_WANT_IEC_60559_TYPES_EXT__])
  182. AC_DEFINE([__STDC_WANT_LIB_EXT2__])
  183. AC_DEFINE([__STDC_WANT_MATH_SPEC_FUNCS__])
  184. AC_DEFINE([_TANDEM_SOURCE])
  185. AS_IF([test $ac_cv_header_minix_config_h = yes],
  186. [MINIX=yes
  187. AC_DEFINE([_MINIX])
  188. AC_DEFINE([_POSIX_SOURCE])
  189. AC_DEFINE([_POSIX_1_SOURCE], [2])],
  190. [MINIX=])
  191. AS_IF([test $ac_cv_safe_to_define___extensions__ = yes],
  192. [AC_DEFINE([__EXTENSIONS__])])
  193. AS_IF([test $ac_cv_should_define__xopen_source = yes],
  194. [AC_DEFINE([_XOPEN_SOURCE], [500])])
  195. ])# AC_USE_SYSTEM_EXTENSIONS
  196. ])
  197. # gl_USE_SYSTEM_EXTENSIONS
  198. # ------------------------
  199. # Enable extensions on systems that normally disable them,
  200. # typically due to standards-conformance issues.
  201. AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS],
  202. [
  203. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  204. dnl On OpenBSD 6.8 with GCC, the include files contain a couple of
  205. dnl definitions that are only activated with an explicit -D_ISOC11_SOURCE.
  206. dnl That's because this version of GCC (4.2.1) supports the option
  207. dnl '-std=gnu99' but not the option '-std=gnu11'.
  208. AC_REQUIRE([AC_CANONICAL_HOST])
  209. case "$host_os" in
  210. openbsd*)
  211. AC_DEFINE([_ISOC11_SOURCE], [1],
  212. [Define to enable the declarations of ISO C 11 types and functions.])
  213. ;;
  214. esac
  215. ])