3 dnl Copyright (C) 2007-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.
12 # is expanded unconditionally through gnulib-tool magic.
13 AC_DEFUN([gl_COMMON], [
14 dnl Use AC_REQUIRE here, so that the code is expanded once only.
15 AC_REQUIRE([gl_00GNULIB])
16 AC_REQUIRE([gl_COMMON_BODY])
17 AC_REQUIRE([gl_ZZGNULIB])
19 AC_DEFUN([gl_COMMON_BODY], [
20 AH_VERBATIM([0witness],
21 [/* Witness that <config.h> has been included. */
22 #define _GL_CONFIG_H_INCLUDED 1
24 AH_VERBATIM([_GL_GNUC_PREREQ],
25 [/* True if the compiler says it groks GNU C version MAJOR.MINOR.
27 - clang groks GNU C 4.2, even on Windows, where it does not define
29 - The OpenMandriva-modified clang compiler pretends that it groks
30 GNU C version 13.1, but it doesn't: It does not support
31 __attribute__ ((__malloc__ (f, i))), nor does it support
32 __attribute__ ((__warning__ (message))) on a function redeclaration.
33 - Users can make clang lie as well, through the -fgnuc-version option. */
34 #if defined __GNUC__ && defined __GNUC_MINOR__ && !defined __clang__
35 # define _GL_GNUC_PREREQ(major, minor) \
36 ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__))
37 #elif defined __clang__
38 /* clang really only groks GNU C 4.2. */
39 # define _GL_GNUC_PREREQ(major, minor) \
40 ((major) < 4 + ((minor) <= 2))
42 # define _GL_GNUC_PREREQ(major, minor) 0
45 AH_VERBATIM([_Noreturn],
46 [/* The _Noreturn keyword of C11. */
48 # if (defined __cplusplus \
49 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
50 || (defined _MSC_VER && 1900 <= _MSC_VER)) \
52 /* [[noreturn]] is not practically usable, because with it the syntax
53 extern _Noreturn void func (...);
54 would not be valid; such a declaration would only be valid with 'extern'
55 and '_Noreturn' swapped, or without the 'extern' keyword. However, some
56 AIX system header files and several gnulib header files use precisely
57 this syntax with 'extern'. */
58 # define _Noreturn [[noreturn]]
59 # elif (defined __clang__ && __clang_major__ < 16 \
60 && defined _GL_WORK_AROUND_LLVM_BUG_59792)
61 /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around
62 that rare LLVM bug, though you may get many false-alarm warnings. */
64 # elif ((!defined __cplusplus || defined __clang__) \
65 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
66 || (!defined __STRICT_ANSI__ \
67 && (_GL_GNUC_PREREQ (4, 7) \
68 || (defined __apple_build_version__ \
69 ? 6000000 <= __apple_build_version__ \
70 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
71 /* _Noreturn works as-is. */
72 # elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
73 # define _Noreturn __attribute__ ((__noreturn__))
74 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
75 # define _Noreturn __declspec (noreturn)
81 AH_VERBATIM([isoc99_inline],
82 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
83 the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
84 earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
85 __APPLE__ && __MACH__ test for Mac OS X.
86 __APPLE_CC__ tests for the Apple compiler and its version.
87 __STDC_VERSION__ tests for the C99 mode. */
88 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
89 # define __GNUC_STDC_INLINE__ 1
91 AH_VERBATIM([attribute],
93 /* Define _GL_HAS_ATTRIBUTE only once, because on FreeBSD, with gcc < 5, if
94 <config.h> gets included once again after <sys/cdefs.h>, __has_attribute(x)
95 expands to 0 always, and redefining _GL_HAS_ATTRIBUTE would turn off all
97 #ifndef _GL_HAS_ATTRIBUTE
98 # if (defined __has_attribute \
99 && (!defined __clang_minor__ \
100 || (defined __apple_build_version__ \
101 ? 7000000 <= __apple_build_version__ \
102 : 5 <= __clang_major__)))
103 # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
105 # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
106 # define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
107 # define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
108 # define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
109 # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
110 # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
111 # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
112 # define _GL_ATTR_diagnose_if 0
113 # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
114 # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
115 # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
116 # define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
117 # define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
118 # define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
120 # define _GL_ATTR_may_alias 0
122 # define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
124 # define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
125 # define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
126 # define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
127 # define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
128 # define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
129 # define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
130 # define _GL_ATTR_reproducible 0 /* not yet supported, as of GCC 14 */
131 # define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
132 # define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
133 # define _GL_ATTR_unsequenced 0 /* not yet supported, as of GCC 14 */
134 # define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
135 # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
139 /* Use __has_c_attribute if available. However, do not use with
140 pre-C23 GCC, which can issue false positives if -Wpedantic. */
141 #if (defined __has_c_attribute \
142 && ! (_GL_GNUC_PREREQ (4, 6) \
143 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710))
144 # define _GL_HAVE___HAS_C_ATTRIBUTE 1
146 # define _GL_HAVE___HAS_C_ATTRIBUTE 0
149 /* Attributes in bracket syntax [[...]] vs. attributes in __attribute__((...))
150 syntax, in function declarations. There are two problems here.
151 (Last tested with gcc/g++ 14 and clang/clang++ 18.)
153 1) We want that the _GL_ATTRIBUTE_* can be cumulated on the same declaration
155 =========================== foo.c = foo.cc ===========================
156 __attribute__ ((__deprecated__)) [[__nodiscard__]] int bar1 (int);
157 [[__nodiscard__]] __attribute__ ((__deprecated__)) int bar2 (int);
158 ======================================================================
159 This gives a syntax error
161 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108796>, and
162 - in C++ mode with clang++ version < 16, and
163 - in C++ mode, inside extern "C" {}, still in newer clang++ versions
164 <https://github.com/llvm/llvm-project/issues/101990>.
166 /* Define if, in a function declaration, the attributes in bracket syntax
167 [[...]] must come before the attributes in __attribute__((...)) syntax.
168 If this is defined, it is best to avoid the bracket syntax, so that the
169 various _GL_ATTRIBUTE_* can be cumulated on the same declaration in any
172 # if defined __clang__
173 # define _GL_BRACKET_BEFORE_ATTRIBUTE 1
176 # if defined __GNUC__ && !defined __clang__
177 # define _GL_BRACKET_BEFORE_ATTRIBUTE 1
181 2) We want that the _GL_ATTRIBUTE_* can be placed in a declaration
182 - without 'extern', in C as well as in C++,
183 - with 'extern', in C,
184 - with 'extern "C"', in C++
185 in the same position. That is, we don't want to be forced to use a
186 macro which arranges for the attribute to come before 'extern' in
187 one case and after 'extern' in the other case, because such a macro
188 would make the source code of .h files pretty ugly.
189 =========================== foo.c = foo.cc ===========================
196 #define ND [[__nodiscard__]]
197 #define WUR __attribute__((__warn_unused_result__))
202 // gcc clang g++ clang++
205 int ND foo (int); // warn error warn error
207 int foo (int) ND; // warn error warn error
211 int fo1 WUR (int); // error error error error
218 // gcc clang g++ clang++
220 ND extern CC int foo (int); // error error
221 extern CC ND int foo (int); // error error
222 extern CC int ND foo (int); // warn error warn error
223 extern CC int foo ND (int);
224 extern CC int foo (int) ND; // warn error warn error
226 WUR extern CC int foo (int); // warn
227 extern CC WUR int foo (int);
228 extern CC int WUR foo (int);
229 extern CC int foo WUR (int); // error error error error
230 extern CC int foo (int) WUR;
232 ND EXTERN_C_FUNC int foo (int); // error error
233 EXTERN_C_FUNC ND int foo (int);
234 EXTERN_C_FUNC int ND foo (int); // warn error warn error
235 EXTERN_C_FUNC int foo ND (int);
236 EXTERN_C_FUNC int foo (int) ND; // warn error warn error
238 WUR EXTERN_C_FUNC int foo (int); // warn
239 EXTERN_C_FUNC WUR int foo (int);
240 EXTERN_C_FUNC int WUR foo (int);
241 EXTERN_C_FUNC int fo2 WUR (int); // error error error error
242 EXTERN_C_FUNC int foo (int) WUR;
243 ======================================================================
244 So, if we insist on using the 'extern' keyword ('extern CC' idiom):
245 * If _GL_ATTRIBUTE_* expands to bracket syntax [[...]]
246 in both C and C++, there is one available position:
247 - between the function name and the parameter list.
248 * If _GL_ATTRIBUTE_* expands to __attribute__((...)) syntax
249 in both C and C++, there are several available positions:
250 - before the return type,
251 - between return type and function name,
252 - at the end of the declaration.
253 * If _GL_ATTRIBUTE_* expands to bracket syntax [[...]] in C and to
254 __attribute__((...)) syntax in C++, there is no available position:
255 it would need to come before 'extern' in C but after 'extern "C"'
257 * If _GL_ATTRIBUTE_* expands to __attribute__((...)) syntax in C and
258 to bracket syntax [[...]] in C++, there is one available position:
259 - before the return type.
260 Whereas, if we use the 'EXTERN_C_FUNC' idiom, which conditionally
261 omits the 'extern' keyword:
262 * If _GL_ATTRIBUTE_* expands to bracket syntax [[...]]
263 in both C and C++, there are two available positions:
264 - before the return type,
265 - between the function name and the parameter list.
266 * If _GL_ATTRIBUTE_* expands to __attribute__((...)) syntax
267 in both C and C++, there are several available positions:
268 - before the return type,
269 - between return type and function name,
270 - at the end of the declaration.
271 * If _GL_ATTRIBUTE_* expands to bracket syntax [[...]] in C and to
272 __attribute__((...)) syntax in C++, there is one available position:
273 - before the return type.
274 * If _GL_ATTRIBUTE_* expands to __attribute__((...)) syntax in C and
275 to bracket syntax [[...]] in C++, there is one available position:
276 - before the return type.
277 The best choice is therefore to use the 'EXTERN_C_FUNC' idiom and
278 put the attributes before the return type. This works regardless
279 to what the _GL_ATTRIBUTE_* macros expand.
282 /* Attributes in bracket syntax [[...]] vs. attributes in __attribute__((...))
283 syntax, in static/inline function definitions.
285 There are similar constraints as for function declarations. However, here,
286 we cannot omit the storage-class specifier. Therefore, the following rule
290 _GL_ATTRIBUTE_DEPRECATED
291 _GL_ATTRIBUTE_MAYBE_UNUSED
292 _GL_ATTRIBUTE_NODISCARD
294 _GL_ATTRIBUTE_REPRODUCIBLE
295 _GL_ATTRIBUTE_UNSEQUENCED
296 which may expand to bracket syntax [[...]], must come first, before the
297 storage-class specifier.
298 * Other _GL_ATTRIBUTE_* macros, that expand to __attribute__((...)) syntax,
299 are better placed between the storage-class specifier and the return
303 /* Attributes in bracket syntax [[...]] vs. attributes in __attribute__((...))
304 syntax, in variable declarations.
306 At which position can they be placed?
307 (Last tested with gcc/g++ 14 and clang/clang++ 18.)
309 =========================== foo.c = foo.cc ===========================
316 #define BD [[__deprecated__]]
317 #define AD __attribute__ ((__deprecated__))
319 // gcc clang g++ clang++
321 BD extern CC int var; // error error
322 extern CC BD int var; // error error
323 extern CC int BD var; // warn error warn error
324 extern CC int var BD;
326 AD extern CC int var; // warn
327 extern CC AD int var;
328 extern CC int AD var;
329 extern CC int var AD;
331 BD extern CC int z[]; // error error
332 extern CC BD int z[]; // error error
333 extern CC int BD z[]; // warn error warn error
334 extern CC int z1 BD [];
335 extern CC int z[] BD; // warn error error
337 AD extern CC int z[]; // warn
338 extern CC AD int z[];
339 extern CC int AD z[];
340 extern CC int z2 AD []; // error error error error
341 extern CC int z[] AD;
342 ======================================================================
344 * For non-array variables, the only good position is after the variable name,
345 that is, at the end of the declaration.
346 * For array variables, you will need to distinguish C and C++:
347 - In C, before the 'extern' keyword.
348 - In C++, between the 'extern "C"' and the variable's type.
350 ]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead.
352 /* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
353 is the size of the returned memory block.
354 _GL_ATTRIBUTE_ALLOC_SIZE ((M, N)) declares that the Mth argument multiplied
355 by the Nth argument of the function is the size of the returned memory block.
357 /* Applies to: functions, pointer to functions, function types. */
358 #ifndef _GL_ATTRIBUTE_ALLOC_SIZE
359 # if _GL_HAS_ATTRIBUTE (alloc_size)
360 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
362 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
366 /* _GL_ATTRIBUTE_ALWAYS_INLINE tells that the compiler should always inline the
367 function and report an error if it cannot do so. */
368 /* Applies to: functions. */
369 #ifndef _GL_ATTRIBUTE_ALWAYS_INLINE
370 # if _GL_HAS_ATTRIBUTE (always_inline)
371 # define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
373 # define _GL_ATTRIBUTE_ALWAYS_INLINE
377 /* _GL_ATTRIBUTE_ARTIFICIAL declares that the function is not important to show
378 in stack traces when debugging. The compiler should omit the function from
380 /* Applies to: functions. */
381 #ifndef _GL_ATTRIBUTE_ARTIFICIAL
382 # if _GL_HAS_ATTRIBUTE (artificial)
383 # define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
385 # define _GL_ATTRIBUTE_ARTIFICIAL
389 /* _GL_ATTRIBUTE_COLD declares that the function is rarely executed. */
390 /* Applies to: functions. */
391 /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
392 <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
393 Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
394 #ifndef _GL_ATTRIBUTE_COLD
395 # if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
397 # define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
399 # define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
402 # define _GL_ATTRIBUTE_COLD
406 /* _GL_ATTRIBUTE_CONST declares:
407 It is OK for a compiler to move calls to the function and to omit
408 calls to the function if another call has the same arguments or the
410 This attribute is safe for a function that neither depends on
411 nor affects state, and always returns exactly once -
412 e.g., does not raise an exception, call longjmp, or loop forever.
413 (This attribute is stricter than _GL_ATTRIBUTE_PURE because the
414 function cannot observe state. It is stricter than
415 _GL_ATTRIBUTE_UNSEQUENCED because the function must return exactly
416 once and cannot depend on state addressed by its arguments.) */
417 /* Applies to: functions. */
418 #ifndef _GL_ATTRIBUTE_CONST
419 # if _GL_HAS_ATTRIBUTE (const)
420 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
422 # define _GL_ATTRIBUTE_CONST _GL_ATTRIBUTE_UNSEQUENCED
426 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
427 that can be freed by passing them as the Ith argument to the
429 _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
430 can be freed via 'free'; it can be used only after declaring 'free'. */
431 /* Applies to: functions. Cannot be used on inline functions. */
432 #ifndef _GL_ATTRIBUTE_DEALLOC
433 # if _GL_GNUC_PREREQ (11, 0)
434 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
436 # define _GL_ATTRIBUTE_DEALLOC(f, i)
439 /* If gnulib's <string.h> or <wchar.h> has already defined this macro, continue
440 to use this earlier definition, since <stdlib.h> may not have been included
442 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
443 # if defined __cplusplus && defined __GNUC__ && !defined __clang__
444 /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
445 # define _GL_ATTRIBUTE_DEALLOC_FREE \
446 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
448 # define _GL_ATTRIBUTE_DEALLOC_FREE \
449 _GL_ATTRIBUTE_DEALLOC (free, 1)
453 /* _GL_ATTRIBUTE_DEPRECATED: Declares that an entity is deprecated.
454 The compiler may warn if the entity is used. */
456 - function, variable,
457 - struct, union, struct/union member,
458 - enumeration, enumeration item,
460 in C++ also: namespace, class, template specialization. */
461 #ifndef _GL_ATTRIBUTE_DEPRECATED
462 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
463 # if _GL_HAVE___HAS_C_ATTRIBUTE
464 # if __has_c_attribute (__deprecated__)
465 # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
469 # if !defined _GL_ATTRIBUTE_DEPRECATED && _GL_HAS_ATTRIBUTE (deprecated)
470 # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
472 # ifndef _GL_ATTRIBUTE_DEPRECATED
473 # define _GL_ATTRIBUTE_DEPRECATED
477 /* _GL_ATTRIBUTE_ERROR(msg) requests an error if a function is called and
478 the function call is not optimized away.
479 _GL_ATTRIBUTE_WARNING(msg) requests a warning if a function is called and
480 the function call is not optimized away. */
481 /* Applies to: functions. */
482 #if !(defined _GL_ATTRIBUTE_ERROR && defined _GL_ATTRIBUTE_WARNING)
483 # if _GL_HAS_ATTRIBUTE (error)
484 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
485 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
486 # elif _GL_HAS_ATTRIBUTE (diagnose_if)
487 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
488 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
490 # define _GL_ATTRIBUTE_ERROR(msg)
491 # define _GL_ATTRIBUTE_WARNING(msg)
495 /* _GL_ATTRIBUTE_EXTERNALLY_VISIBLE declares that the entity should remain
496 visible to debuggers etc., even with '-fwhole-program'. */
497 /* Applies to: functions, variables. */
498 #ifndef _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
499 # if _GL_HAS_ATTRIBUTE (externally_visible)
500 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
502 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
506 /* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if
507 the control flow falls through to the immediately following 'case' or
508 'default' label. The compiler should not warn in this case. */
509 /* Applies to: Empty statement (;), inside a 'switch' statement. */
510 /* Always expands to something. */
511 #ifndef _GL_ATTRIBUTE_FALLTHROUGH
512 # if _GL_HAVE___HAS_C_ATTRIBUTE
513 # if __has_c_attribute (__fallthrough__)
514 # define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
517 # if !defined _GL_ATTRIBUTE_FALLTHROUGH && _GL_HAS_ATTRIBUTE (fallthrough)
518 # define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
520 # ifndef _GL_ATTRIBUTE_FALLTHROUGH
521 # define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
525 /* _GL_ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK))
526 declares that the STRING-INDEXth function argument is a format string of
527 style ARCHETYPE, which is one of:
530 strftime, gnu_strftime,
532 or the same thing prefixed and suffixed with '__'.
533 If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
534 are suitable for the format string. */
535 /* Applies to: functions. */
536 #ifndef _GL_ATTRIBUTE_FORMAT
537 # if _GL_HAS_ATTRIBUTE (format)
538 # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
540 # define _GL_ATTRIBUTE_FORMAT(spec)
544 /* _GL_ATTRIBUTE_LEAF declares that if the function is called from some other
545 compilation unit, it executes code from that unit only by return or by
546 exception handling. This declaration lets the compiler optimize that unit
547 more aggressively. */
548 /* Applies to: functions. */
549 #ifndef _GL_ATTRIBUTE_LEAF
550 # if _GL_HAS_ATTRIBUTE (leaf)
551 # define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
553 # define _GL_ATTRIBUTE_LEAF
557 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
559 /* Applies to: functions. */
560 #ifndef _GL_ATTRIBUTE_MALLOC
561 # if _GL_HAS_ATTRIBUTE (malloc)
562 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
564 # define _GL_ATTRIBUTE_MALLOC
568 /* _GL_ATTRIBUTE_MAY_ALIAS declares that pointers to the type may point to the
569 same storage as pointers to other types. Thus this declaration disables
570 strict aliasing optimization. */
571 /* Applies to: types. */
572 /* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
573 #ifndef _GL_ATTRIBUTE_MAY_ALIAS
574 # if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
575 # define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
577 # define _GL_ATTRIBUTE_MAY_ALIAS
581 /* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if
582 the entity is not used. The compiler should not warn if the entity is not
585 - function, variable,
586 - struct, union, struct/union member,
587 - enumeration, enumeration item,
589 in C++ also: class. */
590 /* In C++ and C23, this is spelled [[__maybe_unused__]].
591 GCC's syntax is __attribute__ ((__unused__)).
592 clang supports both syntaxes. Except that with clang ≥ 6, < 10, in C++ mode,
593 __has_c_attribute (__maybe_unused__) yields true but the use of
594 [[__maybe_unused__]] nevertheless produces a warning. */
595 #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
596 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
597 # if defined __clang__ && defined __cplusplus
598 # if !defined __apple_build_version__ && __clang_major__ >= 10
599 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
601 # elif _GL_HAVE___HAS_C_ATTRIBUTE
602 # if __has_c_attribute (__maybe_unused__)
603 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
607 # ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
608 # define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
611 /* Alternative spelling of this macro, for convenience and for
612 compatibility with glibc/include/libc-symbols.h. */
613 #define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
614 /* Earlier spellings of this macro. */
615 #define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
617 /* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not
618 discard the return value. The compiler may warn if the caller does not use
619 the return value, unless the caller uses something like ignore_value. */
620 /* Applies to: function, enumeration, class. */
621 #ifndef _GL_ATTRIBUTE_NODISCARD
622 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
623 # if defined __clang__ && defined __cplusplus
624 /* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]] produces
626 The 1000 below means a yet unknown threshold. When clang++ version X
627 starts supporting [[__nodiscard__]] without warning about it, you can
628 replace the 1000 with X. */
629 # if __clang_major__ >= 1000
630 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
632 # elif _GL_HAVE___HAS_C_ATTRIBUTE
633 # if __has_c_attribute (__nodiscard__)
634 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
638 # if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE (warn_unused_result)
639 # define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
641 # ifndef _GL_ATTRIBUTE_NODISCARD
642 # define _GL_ATTRIBUTE_NODISCARD
646 /* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the
648 /* Applies to: functions. */
649 #ifndef _GL_ATTRIBUTE_NOINLINE
650 # if _GL_HAS_ATTRIBUTE (noinline)
651 # define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
653 # define _GL_ATTRIBUTE_NOINLINE
657 /* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,...
659 _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be
661 /* Applies to: functions. */
662 #ifndef _GL_ATTRIBUTE_NONNULL
663 # if _GL_HAS_ATTRIBUTE (nonnull)
664 # define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
666 # define _GL_ATTRIBUTE_NONNULL(args)
670 /* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
671 not meant to be NUL-terminated. */
672 /* Applies to: struct/union members and variables that are arrays of element
673 type '[[un]signed] char'. */
674 #ifndef _GL_ATTRIBUTE_NONSTRING
675 # if _GL_HAS_ATTRIBUTE (nonstring)
676 # define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
678 # define _GL_ATTRIBUTE_NONSTRING
682 /* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
684 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
686 /* Applies to: functions. */
687 /* After a function's parameter list, this attribute must come first, before
689 #ifndef _GL_ATTRIBUTE_NOTHROW
690 # if defined __cplusplus
691 # if _GL_GNUC_PREREQ (2, 8) || __clang_major__ >= 4
692 # if __cplusplus >= 201103L
693 # define _GL_ATTRIBUTE_NOTHROW noexcept (true)
695 # define _GL_ATTRIBUTE_NOTHROW throw ()
698 # define _GL_ATTRIBUTE_NOTHROW
701 # if _GL_HAS_ATTRIBUTE (nothrow)
702 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
704 # define _GL_ATTRIBUTE_NOTHROW
709 /* _GL_ATTRIBUTE_PACKED declares:
710 For struct members: The member has the smallest possible alignment.
711 For struct, union, class: All members have the smallest possible alignment,
712 minimizing the memory required. */
713 /* Applies to: struct members, struct, union,
714 in C++ also: class. */
715 #ifndef _GL_ATTRIBUTE_PACKED
716 /* Oracle Studio 12.6 miscompiles code with __attribute__ ((__packed__)) despite
717 __has_attribute OK. */
718 # if _GL_HAS_ATTRIBUTE (packed) && !defined __SUNPRO_C
719 # define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
721 # define _GL_ATTRIBUTE_PACKED
725 /* _GL_ATTRIBUTE_PURE declares:
726 It is OK for a compiler to move calls to the function and to omit
727 calls to the function if another call has the same arguments or the
728 result is not used, and if observable state is the same.
729 This attribute is safe for a function that does not affect observable state
730 and always returns exactly once.
731 (This attribute is looser than _GL_ATTRIBUTE_CONST because the function
732 can depend on observable state. It is stricter than
733 _GL_ATTRIBUTE_REPRODUCIBLE because the function must return exactly
734 once and cannot affect state addressed by its arguments.) */
735 /* Applies to: functions. */
736 #ifndef _GL_ATTRIBUTE_PURE
737 # if _GL_HAS_ATTRIBUTE (pure)
738 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
740 # define _GL_ATTRIBUTE_PURE _GL_ATTRIBUTE_REPRODUCIBLE
744 /* _GL_ATTRIBUTE_REPRODUCIBLE declares:
745 It is OK for a compiler to move calls to the function and to omit duplicate
746 calls to the function with the same arguments, so long as the state
747 addressed by its arguments is the same and is updated in time for
748 the rest of the program.
749 This attribute is safe for a function that is effectless and idempotent; see
750 ISO C 23 § 6.7.12.7 for a definition of these terms.
751 (This attribute is looser than _GL_ATTRIBUTE_UNSEQUENCED because
752 the function need not be stateless and idempotent. It is looser
753 than _GL_ATTRIBUTE_PURE because the function need not return
754 exactly once and can affect state addressed by its arguments.)
755 See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
756 <https://stackoverflow.com/questions/76847905/>. */
757 /* Applies to: functions, pointer to functions, function types. */
758 #ifndef _GL_ATTRIBUTE_REPRODUCIBLE
759 /* This may be revisited when gcc and clang support [[reproducible]] or possibly
760 __attribute__ ((__reproducible__)). */
761 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
762 # if _GL_HAS_ATTRIBUTE (reproducible)
763 # define _GL_ATTRIBUTE_REPRODUCIBLE [[reproducible]]
766 # ifndef _GL_ATTRIBUTE_REPRODUCIBLE
767 # define _GL_ATTRIBUTE_REPRODUCIBLE
771 /* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is
772 a non-NULL pointer. */
773 /* Applies to: functions. */
774 #ifndef _GL_ATTRIBUTE_RETURNS_NONNULL
775 # if _GL_HAS_ATTRIBUTE (returns_nonnull)
776 # define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
778 # define _GL_ATTRIBUTE_RETURNS_NONNULL
782 /* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a
783 trailing NULL argument.
784 _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
785 _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
786 /* Applies to: functions. */
787 #ifndef _GL_ATTRIBUTE_SENTINEL
788 # if _GL_HAS_ATTRIBUTE (sentinel)
789 # define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
791 # define _GL_ATTRIBUTE_SENTINEL(pos)
795 /* _GL_ATTRIBUTE_UNSEQUENCED declares:
796 It is OK for a compiler to move calls to the function and to omit duplicate
797 calls to the function with the same arguments, so long as the state
798 addressed by its arguments is the same.
799 This attribute is safe for a function that is effectless, idempotent,
800 stateless, and independent; see ISO C 23 § 6.7.12.7 for a definition of
802 (This attribute is stricter than _GL_ATTRIBUTE_REPRODUCIBLE because
803 the function must be stateless and independent. It is looser than
804 _GL_ATTRIBUTE_CONST because the function need not return exactly
805 once and can depend on state addressed by its arguments.)
806 See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
807 <https://stackoverflow.com/questions/76847905/>. */
808 /* Applies to: functions, pointer to functions, function types. */
809 #ifndef _GL_ATTRIBUTE_UNSEQUENCED
810 /* This may be revisited when gcc and clang support [[unsequenced]] or possibly
811 __attribute__ ((__unsequenced__)). */
812 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
813 # if _GL_HAS_ATTRIBUTE (unsequenced)
814 # define _GL_ATTRIBUTE_UNSEQUENCED [[unsequenced]]
817 # ifndef _GL_ATTRIBUTE_UNSEQUENCED
818 # define _GL_ATTRIBUTE_UNSEQUENCED
822 /* A helper macro. Don't use it directly. */
823 #ifndef _GL_ATTRIBUTE_UNUSED
824 # if _GL_HAS_ATTRIBUTE (unused)
825 # define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
827 # define _GL_ATTRIBUTE_UNUSED
831 ]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
833 /* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the
834 immediately preceding label is not used. The compiler should not warn
835 if the label is not used. */
836 /* Applies to: label (both in C and C++). */
837 /* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;'
838 syntax. But clang does. */
839 #ifndef _GL_UNUSED_LABEL
840 # if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__
841 # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
843 # define _GL_UNUSED_LABEL
847 /* The following attributes enable detection of multithread-safety problems
848 and resource leaks at compile-time, by clang ≥ 15, when the warning option
849 -Wthread-safety is enabled. For usage, see
850 <https://clang.llvm.org/docs/ThreadSafetyAnalysis.html>. */
851 #ifndef _GL_ATTRIBUTE_CAPABILITY_TYPE
852 # if __clang_major__ >= 15
853 # define _GL_ATTRIBUTE_CAPABILITY_TYPE(concept) \
854 __attribute__ ((__capability__ (concept)))
856 # define _GL_ATTRIBUTE_CAPABILITY_TYPE(concept)
859 #ifndef _GL_ATTRIBUTE_ACQUIRE_CAPABILITY
860 # if __clang_major__ >= 15
861 # define _GL_ATTRIBUTE_ACQUIRE_CAPABILITY(resource) \
862 __attribute__ ((__acquire_capability__ (resource)))
864 # define _GL_ATTRIBUTE_ACQUIRE_CAPABILITY(resource)
867 #ifndef _GL_ATTRIBUTE_RELEASE_CAPABILITY
868 # if __clang_major__ >= 15
869 # define _GL_ATTRIBUTE_RELEASE_CAPABILITY(resource) \
870 __attribute__ ((__release_capability__ (resource)))
872 # define _GL_ATTRIBUTE_RELEASE_CAPABILITY(resource)
876 AH_VERBATIM([c_linkage],
877 [/* In C++, there is the concept of "language linkage", that encompasses
878 name mangling and function calling conventions.
879 The following macros start and end a block of "C" linkage. */
881 # define _GL_BEGIN_C_LINKAGE extern "C" {
882 # define _GL_END_C_LINKAGE }
884 # define _GL_BEGIN_C_LINKAGE
885 # define _GL_END_C_LINKAGE
888 AH_VERBATIM([async_safe],
889 [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
890 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
891 invoked from such signal handlers. Such functions have some restrictions:
892 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
893 or should be listed as async-signal-safe in POSIX
894 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
895 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
896 particular, are NOT async-signal-safe.
897 * All memory locations (variables and struct fields) that these functions
898 access must be marked 'volatile'. This holds for both read and write
899 accesses. Otherwise the compiler might optimize away stores to and
900 reads from such locations that occur in the program, depending on its
901 data flow analysis. For example, when the program contains a loop
902 that is intended to inspect a variable set from within a signal handler
903 while (!signal_occurred)
905 the compiler is allowed to transform this into an endless loop if the
906 variable 'signal_occurred' is not declared 'volatile'.
907 Additionally, recall that:
908 * A signal handler should not modify errno (except if it is a handler
909 for a fatal signal and ends by raising the same signal again, thus
910 provoking the termination of the process). If it invokes a function
911 that may clobber errno, it needs to save and restore the value of
913 #define _GL_ASYNC_SAFE
915 AH_VERBATIM([micro_optimizations],
916 [/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
917 n1 and n2 are expressions without side effects, that evaluate to real
918 numbers (excluding NaN).
923 The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
924 jump with nearly all GCC versions up to GCC 10.
925 This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
926 GCC versions up to GCC 9.
927 The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
928 avoids conditional jumps in all GCC versions >= 3.4. */
929 #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
931 dnl Hint which direction to take regarding cross-compilation guesses:
932 dnl When a user installs a program on a platform they are not intimately
933 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
934 dnl choice. It implements the "If we don't know, assume the worst" principle.
935 dnl However, when an operating system developer (on a platform which is not
936 dnl yet known to gnulib) builds packages for their platform, they want to
937 dnl expose, not hide, possible platform bugs; in this case,
938 dnl --enable-cross-guesses=risky is the appropriate choice.
939 dnl Sets the variables
940 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
941 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
942 AC_ARG_ENABLE([cross-guesses],
943 [AS_HELP_STRING([[--enable-cross-guesses={conservative|risky}]],
944 [specify policy for cross-compilation guesses])],
945 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
946 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
947 enableval=conservative
949 gl_cross_guesses="$enableval"],
950 [gl_cross_guesses=conservative])
951 if test $gl_cross_guesses = risky; then
952 gl_cross_guess_normal="guessing yes"
953 gl_cross_guess_inverted="guessing no"
955 gl_cross_guess_normal="guessing no"
956 gl_cross_guess_inverted="guessing yes"
958 dnl Preparation for running test programs:
959 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
960 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
961 dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
963 export LIBC_FATAL_STDERR_
966 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
967 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
968 # initializes the shell variable that indicates the presence of the given module
969 # as a C preprocessor expression.
970 AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
972 GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
973 AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
976 # gl_MODULE_INDICATOR_CONDITION
977 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
978 # whether a gnulib module that has been requested shall be considered present
980 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
982 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
983 # sets the shell variable that indicates the presence of the given module to
984 # a C preprocessor expression that will evaluate to 1.
985 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
987 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
988 [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
989 [abcdefghijklmnopqrstuvwxyz./-],
990 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
991 [gl_MODULE_INDICATOR_CONDITION])
994 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
995 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
996 # The shell variable's value is a C preprocessor expression that evaluates
998 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
1000 m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
1002 dnl Simplify the expression VALUE || 1 to 1.
1005 [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
1006 [gl_MODULE_INDICATOR_CONDITION])])
1009 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
1010 # modifies the shell variable to include the given condition. The shell
1011 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
1012 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
1014 dnl Simplify the expression 1 || CONDITION to 1.
1015 if test "$[]$1" != 1; then
1016 dnl Simplify the expression 0 || CONDITION to CONDITION.
1017 if test "$[]$1" = 0; then
1025 # gl_MODULE_INDICATOR([modulename])
1026 # defines a C macro indicating the presence of the given module
1027 # in a location where it can be used.
1029 # | in lib/ | in tests/ |
1030 # --------------------------------------------+---------+-----------+
1031 # Module present among main modules: | 1 | 1 |
1032 # --------------------------------------------+---------+-----------+
1033 # Module present among tests-related modules: | 0 | 1 |
1034 # --------------------------------------------+---------+-----------+
1035 # Module not present at all: | 0 | 0 |
1036 # --------------------------------------------+---------+-----------+
1037 AC_DEFUN([gl_MODULE_INDICATOR],
1039 AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
1040 [abcdefghijklmnopqrstuvwxyz./-],
1041 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
1042 [gl_MODULE_INDICATOR_CONDITION],
1043 [Define to a C preprocessor expression that evaluates to 1 or 0,
1044 depending whether the gnulib module $1 shall be considered present.])
1047 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
1048 # defines a C macro indicating the presence of the given module
1049 # in lib or tests. This is useful to determine whether the module
1052 # | in lib/ | in tests/ |
1053 # --------------------------------------------+---------+-----------+
1054 # Module present among main modules: | 1 | 1 |
1055 # --------------------------------------------+---------+-----------+
1056 # Module present among tests-related modules: | 1 | 1 |
1057 # --------------------------------------------+---------+-----------+
1058 # Module not present at all: | 0 | 0 |
1059 # --------------------------------------------+---------+-----------+
1060 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
1062 AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
1063 [abcdefghijklmnopqrstuvwxyz./-],
1064 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
1065 [Define to 1 when the gnulib module $1 should be tested.])
1068 # gl_ASSERT_NO_GNULIB_POSIXCHECK
1069 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
1070 # and thereby enables an optimization of configure and config.h.
1072 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
1074 dnl Override gl_WARN_ON_USE_PREPARE.
1075 dnl But hide this definition from 'aclocal'.
1076 AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
1079 # gl_ASSERT_NO_GNULIB_TESTS
1080 # asserts that there will be no gnulib tests in the scope of the configure.ac
1081 # and thereby enables an optimization of config.h.
1083 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
1085 dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
1086 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
1089 # Test whether <features.h> exists.
1090 # Set HAVE_FEATURES_H.
1091 AC_DEFUN([gl_FEATURES_H],
1093 AC_CHECK_HEADERS_ONCE([features.h])
1094 if test $ac_cv_header_features_h = yes; then
1099 AC_SUBST([HAVE_FEATURES_H])
1103 # Modifies the value of the shell variable CC in an attempt to make $CC
1104 # understand ISO C99 source code.
1105 AC_DEFUN([gl_PROG_CC_C99],
1107 dnl Just use AC_PROG_CC_C99.
1108 dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
1109 dnl value of CC will contain the C99 enabling options twice. But this is only
1110 dnl a cosmetic problem.
1111 dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
1112 dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
1113 m4_version_prereq([2.70],
1114 [AC_REQUIRE([AC_PROG_CC])],
1115 [AC_REQUIRE([AC_PROG_CC_C99])])
1119 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
1120 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
1122 AC_DEFUN([gl_PROG_AR_RANLIB],
1124 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
1125 dnl as "cc", and GCC as "gcc". They have different object file formats and
1126 dnl library formats. In particular, the GNU binutils programs ar and ranlib
1127 dnl produce libraries that work only with gcc, not with cc.
1128 AC_REQUIRE([AC_PROG_CC])
1129 dnl The '][' hides this use from 'aclocal'.
1130 AC_BEFORE([$0], [A][M_PROG_AR])
1131 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
1133 AC_EGREP_CPP([Amsterdam],
1139 [gl_cv_c_amsterdam_compiler=yes],
1140 [gl_cv_c_amsterdam_compiler=no])
1143 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
1144 dnl building with __ACK__.
1145 if test $gl_cv_c_amsterdam_compiler = yes; then
1146 if test -z "$AR"; then
1149 if test -z "$ARFLAGS"; then
1153 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
1154 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
1155 dnl script on-demand, if not specified by ./configure of course).
1156 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
1157 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
1158 dnl because AM_PROG_AR is written so it could re-set AR variable even for
1159 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
1160 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
1161 dnl default value and automake should usually know them).
1163 dnl The '][' hides this use from 'aclocal'.
1164 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
1167 dnl In case the code above has not helped with setting AR/ARFLAGS, use
1168 dnl Automake-documented default values for AR and ARFLAGS, but prefer
1169 dnl ${host}-ar over ar (useful for cross-compiling).
1170 AC_CHECK_TOOL([AR], [ar], [ar])
1171 if test -z "$ARFLAGS"; then
1177 if test -z "$RANLIB"; then
1178 if test $gl_cv_c_amsterdam_compiler = yes; then
1181 dnl Use the ranlib program if it is available.
1189 # This definition is copied from post-2.70 Autoconf and overrides the
1190 # AC_C_RESTRICT macro from autoconf 2.60..2.70.
1191 m4_version_prereq([2.70.1], [], [
1192 AC_DEFUN([AC_C_RESTRICT],
1193 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
1194 [ac_cv_c_restrict=no
1195 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
1196 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
1197 # Put 'restrict' last, because C++ lacks it.
1198 for ac_kw in __restrict__ __restrict _Restrict restrict; do
1201 [[typedef int *int_ptr;
1202 int foo (int_ptr $ac_kw ip) { return ip[0]; }
1203 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
1204 int bar (int ip[$ac_kw]) { return ip[0]; }
1209 return foo (t) + bar (t);
1211 [ac_cv_c_restrict=$ac_kw])
1212 test "$ac_cv_c_restrict" != no && break
1215 AH_VERBATIM([restrict],
1216 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1217 nothing if this is not supported. Do not define if restrict is
1218 supported only directly. */
1220 /* Work around a bug in older versions of Sun C++, which did not
1221 #define __restrict__ or support _Restrict or __restrict__
1222 even though the corresponding Sun C compiler ended up with
1223 "#define restrict _Restrict" or "#define restrict __restrict__"
1224 in the previous line. This workaround can be removed once
1225 we assume Oracle Developer Studio 12.5 (2016) or later. */
1226 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
1228 # define __restrict__
1230 case $ac_cv_c_restrict in
1232 no) AC_DEFINE([restrict], []) ;;
1233 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1239 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
1240 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
1241 # macros invoke AC_C_BIGENDIAN with arguments.
1242 AC_DEFUN([gl_BIGENDIAN],
1247 # A temporary file descriptor.
1248 # Must be less than 10, because dash 0.5.8 does not support redirections
1249 # with multi-digit file descriptors.
1250 m4_define([GL_TMP_FD], 9)
1252 # gl_SILENT(command)
1253 # executes command, but without the normal configure output.
1254 # This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
1255 # inside another AC_CACHE_CHECK.
1256 AC_DEFUN([gl_SILENT],
1258 exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
1260 exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
1263 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
1264 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
1265 # output a spurious "(cached)" mark in the midst of other configure output.
1266 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
1267 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
1268 AC_DEFUN([gl_CACHE_VAL_SILENT],
1271 AC_CACHE_VAL([$1], [$2])
1275 # gl_CONDITIONAL(conditional, condition)
1276 # is like AM_CONDITIONAL(conditional, condition), except that it does not
1278 # configure: error: conditional "..." was never defined.
1279 # Usually this means the macro was only invoked conditionally.
1280 # when only invoked conditionally. Instead, in that case, both the _TRUE
1281 # and the _FALSE case are disabled.
1282 AC_DEFUN([gl_CONDITIONAL],
1284 pushdef([AC_CONFIG_COMMANDS_PRE], [:])dnl
1285 AM_CONDITIONAL([$1], [$2])
1286 popdef([AC_CONFIG_COMMANDS_PRE])dnl
1287 if test -z "${[$1]_TRUE}" && test -z "${[$1]_FALSE}"; then
1293 # gl_CC_ALLOW_WARNINGS
1294 # sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
1295 # that reverts a preceding '-Werror' option, if available.
1296 # This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
1297 # and empty otherwise.
1298 AC_DEFUN([gl_CC_ALLOW_WARNINGS],
1300 AC_REQUIRE([AC_PROG_CC])
1301 AC_CACHE_CHECK([for C compiler option to allow warnings],
1304 echo 'int dummy;' > conftest.c
1305 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
1306 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
1307 dnl Test the number of error output lines, because AIX xlc accepts the
1308 dnl option '-Wno-error', just to produce a warning
1309 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
1311 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
1312 gl_cv_cc_wallow='-Wno-error'
1314 gl_cv_cc_wallow=none
1318 case "$gl_cv_cc_wallow" in
1319 none) GL_CFLAG_ALLOW_WARNINGS='' ;;
1320 *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
1322 AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
1325 # gl_CXX_ALLOW_WARNINGS
1326 # sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
1327 # that reverts a preceding '-Werror' option, if available.
1328 AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
1330 dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
1331 if test -n "$CXX" && test "$CXX" != no; then
1332 AC_CACHE_CHECK([for C++ compiler option to allow warnings],
1335 echo 'int dummy;' > conftest.cc
1336 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
1337 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
1338 dnl Test the number of error output lines, because AIX xlC accepts the
1339 dnl option '-Wno-error', just to produce a warning
1340 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
1342 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
1343 gl_cv_cxx_wallow='-Wno-error'
1345 gl_cv_cxx_wallow=none
1349 case "$gl_cv_cxx_wallow" in
1350 none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
1351 *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
1354 GL_CXXFLAG_ALLOW_WARNINGS=''
1356 AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
1359 # gl_CC_GNULIB_WARNINGS
1360 # sets and substitutes a variable GL_CFLAG_GNULIB_WARNINGS, to a $(CC) option
1361 # set that enables or disables warnings as suitable for the Gnulib coding style.
1362 AC_DEFUN([gl_CC_GNULIB_WARNINGS],
1364 AC_REQUIRE([gl_CC_ALLOW_WARNINGS])
1365 dnl Assume that the compiler supports -Wno-* options only if it also supports
1367 GL_CFLAG_GNULIB_WARNINGS=''
1368 if test -n "$GL_CFLAG_ALLOW_WARNINGS"; then
1369 dnl Enable these warning options:
1372 dnl -Wno-cast-qual >= 3 >= 3.9
1373 dnl -Wno-conversion >= 3 >= 3.9
1374 dnl -Wno-float-conversion >= 4.9 >= 3.9
1375 dnl -Wno-float-equal >= 3 >= 3.9
1376 dnl -Wimplicit-fallthrough >= 7 >= 3.9
1377 dnl -Wno-pedantic >= 4.8 >= 3.9
1378 dnl -Wno-sign-compare >= 3 >= 3.9
1379 dnl -Wno-sign-conversion >= 4.3 >= 3.9
1380 dnl -Wno-tautological-out-of-range-compare - >= 3.9
1381 dnl -Wno-type-limits >= 4.3 >= 3.9
1382 dnl -Wno-undef >= 3 >= 3.9
1383 dnl -Wno-unsuffixed-float-constants >= 4.5
1384 dnl -Wno-unused-const-variable >= 4.4 >= 3.9
1385 dnl -Wno-unused-function >= 3 >= 3.9
1386 dnl -Wno-unused-parameter >= 3 >= 3.9
1388 cat > conftest.c <<\EOF
1389 #if (__GNUC__ >= 3 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1395 -Wno-unused-function
1396 -Wno-unused-parameter
1398 #if (__GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1399 -Wno-float-conversion
1401 #if (__GNUC__ >= 7 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1402 -Wimplicit-fallthrough
1404 #if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1407 #if 3 < __clang_major__ + (9 <= __clang_minor__)
1408 -Wno-tautological-constant-out-of-range-compare
1410 #if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1411 -Wno-sign-conversion
1414 #if (__GNUC__ + (__GNUC_MINOR__ >= 4) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1415 -Wno-unused-const-variable
1417 #if (__GNUC__ + (__GNUC_MINOR__ >= 5) > 4 && !defined __clang__)
1418 -Wno-unsuffixed-float-constants
1421 gl_command="$CC $CFLAGS $CPPFLAGS -E conftest.c > conftest.out"
1422 if AC_TRY_EVAL([gl_command]); then
1423 gl_options=`grep -v '#' conftest.out`
1424 for word in $gl_options; do
1425 GL_CFLAG_GNULIB_WARNINGS="$GL_CFLAG_GNULIB_WARNINGS $word"
1428 rm -f conftest.c conftest.out
1430 AC_SUBST([GL_CFLAG_GNULIB_WARNINGS])
1433 dnl gl_CONDITIONAL_HEADER([foo.h])
1434 dnl takes a shell variable GL_GENERATE_FOO_H (with value true or false) as input
1436 dnl - an AC_SUBSTed variable FOO_H that is either a file name or empty, based
1437 dnl on whether GL_GENERATE_FOO_H is true or false,
1438 dnl - an Automake conditional GL_GENERATE_FOO_H that evaluates to the value of
1439 dnl the shell variable GL_GENERATE_FOO_H.
1440 AC_DEFUN([gl_CONDITIONAL_HEADER],
1442 m4_pushdef([gl_header_name], AS_TR_SH(m4_toupper($1)))
1443 m4_pushdef([gl_generate_var], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1444 m4_pushdef([gl_generate_cond], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1445 case "$gl_generate_var" in
1446 false) gl_header_name='' ;;
1448 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
1450 if test -z "$gl_header_name"; then
1451 gl_header_name="${gl_source_base_prefix}$1"
1454 *) echo "*** gl_generate_var is not set correctly" 1>&2; exit 1 ;;
1456 AC_SUBST(gl_header_name)
1457 gl_CONDITIONAL(gl_generate_cond, [$gl_generate_var])
1458 m4_popdef([gl_generate_cond])
1459 m4_popdef([gl_generate_var])
1460 m4_popdef([gl_header_name])
1463 dnl Preparations for gl_CHECK_FUNCS_MACOS.
1464 AC_DEFUN([gl_PREPARE_CHECK_FUNCS_MACOS],
1466 AC_REQUIRE([AC_CANONICAL_HOST])
1467 AC_REQUIRE([gl_COMPILER_CLANG])
1468 AC_CACHE_CHECK([for compiler option needed when checking for future declarations],
1469 [gl_cv_compiler_check_future_option],
1471 dnl This is only needed on macOS.
1473 if test $gl_cv_compiler_clang = yes; then
1474 dnl Test whether the compiler supports the option
1475 dnl '-Werror=unguarded-availability-new'.
1476 saved_ac_compile="$ac_compile"
1477 ac_compile="$ac_compile -Werror=unguarded-availability-new"
1478 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
1479 [gl_cv_compiler_check_future_option='-Werror=unguarded-availability-new'],
1480 [gl_cv_compiler_check_future_option=none])
1481 ac_compile="$saved_ac_compile"
1483 gl_cv_compiler_check_future_option=none
1486 *) gl_cv_compiler_check_future_option=none ;;
1491 dnl Pieces of the expansion of
1492 dnl gl_CHECK_FUNCS_ANDROID
1493 dnl gl_CHECK_FUNCS_MACOS
1494 dnl gl_CHECK_FUNCS_ANDROID_MACOS
1496 AC_DEFUN([gl_CHECK_FUNCS_DEFAULT_CASE],
1500 [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
1504 AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_ANDROID],
1507 AC_CHECK_DECL([$1], , , [$2])
1508 if test $[ac_cv_have_decl_][$1] = yes; then
1509 AC_CHECK_FUNC([[$1]])
1510 if test $[ac_cv_func_][$1] = yes; then
1511 [gl_cv_onwards_func_][$1]=yes
1513 dnl The function is declared but does not exist. This should not
1514 dnl happen normally. But anyway, we know that a future version
1515 dnl of Android will have the function.
1516 [gl_cv_onwards_func_][$1]='future OS version'
1519 [gl_cv_onwards_func_][$1]='future OS version'
1524 AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_MACOS],
1527 if test "x$gl_cv_compiler_check_future_option" != "xnone"; then
1528 dnl Use a compile test, not a link test.
1529 saved_ac_compile="$ac_compile"
1530 ac_compile="$ac_compile $gl_cv_compiler_check_future_option"
1531 saved_ac_compile_for_check_decl="$ac_compile_for_check_decl"
1532 ac_compile_for_check_decl="$ac_compile_for_check_decl $gl_cv_compiler_check_future_option"
1533 unset [ac_cv_have_decl_][$1]
1534 AC_CHECK_DECL([$1], , , [$2])
1535 ac_compile="$saved_ac_compile"
1536 ac_compile_for_check_decl="$saved_ac_compile_for_check_decl"
1537 [ac_cv_func_][$1]="$[ac_cv_have_decl_][$1]"
1538 if test $[ac_cv_func_][$1] = yes; then
1539 [gl_cv_onwards_func_][$1]=yes
1541 unset [ac_cv_have_decl_][$1]
1542 AC_CHECK_DECL([$1], , , [$2])
1543 if test $[ac_cv_have_decl_][$1] = yes; then
1544 [gl_cv_onwards_func_][$1]='future OS version'
1546 [gl_cv_onwards_func_][$1]=no
1551 [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
1556 AC_DEFUN([gl_CHECK_FUNCS_SET_RESULTS],
1558 case "$[gl_cv_onwards_func_][$1]" in
1559 future*) [ac_cv_func_][$1]=no ;;
1560 *) [ac_cv_func_][$1]=$[gl_cv_onwards_func_][$1] ;;
1562 if test $[ac_cv_func_][$1] = yes; then
1563 AC_DEFINE([HAVE_]m4_translit([[$1]],
1564 [abcdefghijklmnopqrstuvwxyz],
1565 [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
1566 [1], [Define to 1 if you have the `$1' function.])
1570 dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
1571 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1574 dnl When code is compiled on Android, it is in the context of a certain
1575 dnl "Android API level", which indicates the minimum version of Android on
1576 dnl which the app can be installed. In other words, you don't compile for a
1577 dnl specific version of Android. You compile for all versions of Android,
1578 dnl onwards from the given API level.
1579 dnl Thus, the question "does the OS have the function func" has three possible
1581 dnl - yes, in all versions starting from the given API level,
1582 dnl - no, in no version,
1583 dnl - not in the given API level, but in a later version of Android.
1585 dnl In detail, this works as follows:
1586 dnl If func was added to Android API level, say, 28, then the libc.so has the
1587 dnl symbol func always, whereas the header file <foo.h> declares func
1589 dnl #if __ANDROID_API__ >= 28
1590 dnl ... func (...) __INTRODUCED_IN(28);
1592 dnl Thus, when compiling with "clang -target armv7a-unknown-linux-android28",
1593 dnl the function func is declared and exists in libc.
1594 dnl Whereas when compiling with "clang -target armv7a-unknown-linux-android27",
1595 dnl the function func is not declared but exists in libc.
1597 dnl This macro sets two variables:
1598 dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
1599 dnl - ac_cv_func_<func> to yes / no / no
1600 dnl The first variable allows to distinguish all three cases.
1601 dnl The second variable is set, so that an invocation
1602 dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
1603 dnl can be used as a drop-in replacement for
1604 dnl AC_CHECK_FUNCS([func]).
1605 AC_DEFUN([gl_CHECK_FUNCS_ANDROID],
1607 AC_REQUIRE([AC_CANONICAL_HOST])
1608 AC_CACHE_CHECK([for [$1]],
1609 [[gl_cv_onwards_func_][$1]],
1612 gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
1613 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1617 gl_CHECK_FUNCS_SET_RESULTS([$1])
1620 dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
1621 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1624 dnl When code is compiled on macOS, it is in the context of a certain minimum
1625 dnl macOS version, that can be set through the option '-mmacosx-version-min='.
1626 dnl In other words, you don't compile for a specific version of macOS. You
1627 dnl compile for all versions of macOS, onwards from the given version.
1628 dnl Thus, the question "does the OS have the function func" has three possible
1630 dnl - yes, in all versions starting from the given version,
1631 dnl - no, in no version,
1632 dnl - not in the given version, but in a later version of macOS.
1634 dnl In detail, this works as follows:
1635 dnl If func was added to, say, macOS version 13, then the libc has the
1636 dnl symbol func always, whereas the header file <foo.h> declares func
1637 dnl conditionally with a special availability attribute:
1638 dnl ... func (...) __attribute__((availability(macos,introduced=13.0)));
1639 dnl Thus, when compiling with "clang mmacosx-version-min=13", there is no
1640 dnl warning about the use of func, and the resulting binary
1641 dnl - runs fine on macOS 13,
1642 dnl - aborts with a dyld "Symbol not found" message on macOS 12.
1643 dnl Whereas, when compiling with "clang mmacosx-version-min=12", there is a
1644 dnl warning: 'func' is only available on macOS 13.0 or newer
1645 dnl [-Wunguarded-availability-new],
1646 dnl and the resulting binary
1647 dnl - runs fine on macOS 13,
1648 dnl - crashes with a SIGSEGV (signal 11) on macOS 12.
1650 dnl This macro sets two variables:
1651 dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
1652 dnl - ac_cv_func_<func> to yes / no / no
1653 dnl The first variable allows to distinguish all three cases.
1654 dnl The second variable is set, so that an invocation
1655 dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
1656 dnl can be used as a drop-in replacement for
1657 dnl AC_CHECK_FUNCS([func]).
1658 AC_DEFUN([gl_CHECK_FUNCS_MACOS],
1660 AC_REQUIRE([AC_CANONICAL_HOST])
1661 AC_REQUIRE([gl_PREPARE_CHECK_FUNCS_MACOS])
1662 AC_CACHE_CHECK([for [$1]],
1663 [[gl_cv_onwards_func_][$1]],
1666 gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
1667 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1671 gl_CHECK_FUNCS_SET_RESULTS([$1])
1674 dnl gl_CHECK_FUNCS_ANDROID_MACOS([func], [[#include <foo.h>]])
1675 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1676 dnl on Android and on macOS.
1677 dnl It is the combination of gl_CHECK_FUNCS_ANDROID and gl_CHECK_FUNCS_MACOS.
1678 AC_DEFUN([gl_CHECK_FUNCS_ANDROID_MACOS],
1680 AC_REQUIRE([AC_CANONICAL_HOST])
1681 AC_REQUIRE([gl_PREPARE_CHECK_FUNCS_MACOS])
1682 AC_CACHE_CHECK([for [$1]],
1683 [[gl_cv_onwards_func_][$1]],
1686 gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
1687 gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
1688 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1692 gl_CHECK_FUNCS_SET_RESULTS([$1])
1695 dnl Expands to some code for use in .c programs that, on native Windows, defines
1696 dnl the Microsoft deprecated alias function names to the underscore-prefixed
1697 dnl actual function names. With this macro, these function names are available
1698 dnl without linking with '-loldnames' and without generating warnings.
1699 dnl Usage: Use it after all system header files are included.
1702 dnl ]GL_MDA_DEFINES[
1704 AC_DEFUN([GL_MDA_DEFINES],[
1705 AC_REQUIRE([_GL_MDA_DEFINES])
1708 AC_DEFUN([_GL_MDA_DEFINES],
1710 #if defined _WIN32 && !defined __CYGWIN__
1711 #define access _access
1712 #define chdir _chdir
1713 #define chmod _chmod
1714 #define close _close
1715 #define creat _creat
1719 #define execl _execl
1720 #define execle _execle
1721 #define execlp _execlp
1722 #define execv _execv
1723 #define execve _execve
1724 #define execvp _execvp
1725 #define execvpe _execvpe
1726 #define fcloseall _fcloseall
1728 #define fdopen _fdopen
1729 #define fileno _fileno
1731 #define getcwd _getcwd
1732 #define getpid _getpid
1734 #define isatty _isatty
1738 #define lfind _lfind
1739 #define lsearch _lsearch
1740 #define lseek _lseek
1741 #define memccpy _memccpy
1742 #define mkdir _mkdir
1743 #define mktemp _mktemp
1745 #define putenv _putenv
1748 #define rmdir _rmdir
1749 #define strdup _strdup
1751 #define tempnam _tempnam
1752 #define tzset _tzset
1753 #define umask _umask
1754 #define unlink _unlink
1755 #define utime _utime
1756 #define wcsdup _wcsdup
1757 #define write _write