Debian Codegraph @

m4/extensions.m4

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