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