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.
11 # is expanded unconditionally through gnulib-tool magic.
12 AC_DEFUN([gl_COMMON], [
13 dnl Use AC_REQUIRE here, so that the code is expanded once only.
14 AC_REQUIRE([gl_00GNULIB])
15 AC_REQUIRE([gl_COMMON_BODY])
16 AC_REQUIRE([gl_ZZGNULIB])
18 AC_DEFUN([gl_COMMON_BODY], [
19 AH_VERBATIM([0witness],
20 [/* Witness that <config.h> has been included. */
21 #define _GL_CONFIG_H_INCLUDED 1
23 AH_VERBATIM([_GL_GNUC_PREREQ],
24 [/* True if the compiler says it groks GNU C version MAJOR.MINOR. */
25 #if defined __GNUC__ && defined __GNUC_MINOR__
26 # define _GL_GNUC_PREREQ(major, minor) \
27 ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__))
29 # define _GL_GNUC_PREREQ(major, minor) 0
32 AH_VERBATIM([_Noreturn],
33 [/* The _Noreturn keyword of C11. */
35 # if (defined __cplusplus \
36 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
37 || (defined _MSC_VER && 1900 <= _MSC_VER)) \
39 /* [[noreturn]] is not practically usable, because with it the syntax
40 extern _Noreturn void func (...);
41 would not be valid; such a declaration would only be valid with 'extern'
42 and '_Noreturn' swapped, or without the 'extern' keyword. However, some
43 AIX system header files and several gnulib header files use precisely
44 this syntax with 'extern'. */
45 # define _Noreturn [[noreturn]]
46 # elif (defined __clang__ && __clang_major__ < 16 \
47 && defined _GL_WORK_AROUND_LLVM_BUG_59792)
48 /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around
49 that rare LLVM bug, though you may get many false-alarm warnings. */
51 # elif ((!defined __cplusplus || defined __clang__) \
52 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
53 || (!defined __STRICT_ANSI__ \
54 && (_GL_GNUC_PREREQ (4, 7) \
55 || (defined __apple_build_version__ \
56 ? 6000000 <= __apple_build_version__ \
57 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
58 /* _Noreturn works as-is. */
59 # elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
60 # define _Noreturn __attribute__ ((__noreturn__))
61 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
62 # define _Noreturn __declspec (noreturn)
68 AH_VERBATIM([isoc99_inline],
69 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
70 the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
71 earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
72 __APPLE__ && __MACH__ test for Mac OS X.
73 __APPLE_CC__ tests for the Apple compiler and its version.
74 __STDC_VERSION__ tests for the C99 mode. */
75 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
76 # define __GNUC_STDC_INLINE__ 1
78 AH_VERBATIM([attribute],
80 /* Define _GL_HAS_ATTRIBUTE only once, because on FreeBSD, with gcc < 5, if
81 <config.h> gets included once again after <sys/cdefs.h>, __has_attribute(x)
82 expands to 0 always, and redefining _GL_HAS_ATTRIBUTE would turn off all
84 #ifndef _GL_HAS_ATTRIBUTE
85 # if (defined __has_attribute \
86 && (!defined __clang_minor__ \
87 || (defined __apple_build_version__ \
88 ? 7000000 <= __apple_build_version__ \
89 : 5 <= __clang_major__)))
90 # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
92 # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
93 # define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
94 # define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
95 # define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
96 # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
97 # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
98 # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
99 # define _GL_ATTR_diagnose_if 0
100 # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
101 # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
102 # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
103 # define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
104 # define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
105 # define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
107 # define _GL_ATTR_may_alias 0
109 # define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
111 # define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
112 # define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
113 # define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
114 # define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
115 # define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
116 # define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
117 # define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
118 # define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
119 # define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
120 # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
124 /* Use __has_c_attribute if available. However, do not use with
125 pre-C23 GCC, which can issue false positives if -Wpedantic. */
126 #if (defined __has_c_attribute \
127 && ! (_GL_GNUC_PREREQ (4, 6) \
128 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710))
129 # define _GL_HAVE___HAS_C_ATTRIBUTE 1
131 # define _GL_HAVE___HAS_C_ATTRIBUTE 0
134 /* Define if, in a function declaration, the attributes in bracket syntax
135 [[...]] must come before the attributes in __attribute__((...)) syntax.
136 If this is defined, it is best to avoid the bracket syntax, so that the
137 various _GL_ATTRIBUTE_* can be cumulated on the same declaration in any
140 # if defined __clang__
141 # define _GL_BRACKET_BEFORE_ATTRIBUTE 1
144 # if defined __GNUC__ && !defined __clang__
145 # define _GL_BRACKET_BEFORE_ATTRIBUTE 1
148 ]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead.
150 /* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
151 is the size of the returned memory block.
152 _GL_ATTRIBUTE_ALLOC_SIZE ((M, N)) declares that the Mth argument multiplied
153 by the Nth argument of the function is the size of the returned memory block.
155 /* Applies to: function, pointer to function, function types. */
156 #ifndef _GL_ATTRIBUTE_ALLOC_SIZE
157 # if _GL_HAS_ATTRIBUTE (alloc_size)
158 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
160 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
164 /* _GL_ATTRIBUTE_ALWAYS_INLINE tells that the compiler should always inline the
165 function and report an error if it cannot do so. */
166 /* Applies to: function. */
167 #ifndef _GL_ATTRIBUTE_ALWAYS_INLINE
168 # if _GL_HAS_ATTRIBUTE (always_inline)
169 # define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
171 # define _GL_ATTRIBUTE_ALWAYS_INLINE
175 /* _GL_ATTRIBUTE_ARTIFICIAL declares that the function is not important to show
176 in stack traces when debugging. The compiler should omit the function from
178 /* Applies to: function. */
179 #ifndef _GL_ATTRIBUTE_ARTIFICIAL
180 # if _GL_HAS_ATTRIBUTE (artificial)
181 # define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
183 # define _GL_ATTRIBUTE_ARTIFICIAL
187 /* _GL_ATTRIBUTE_COLD declares that the function is rarely executed. */
188 /* Applies to: functions. */
189 /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
190 <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
191 Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
192 #ifndef _GL_ATTRIBUTE_COLD
193 # if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
195 # define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
197 # define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
200 # define _GL_ATTRIBUTE_COLD
204 /* _GL_ATTRIBUTE_CONST declares that it is OK for a compiler to omit duplicate
205 calls to the function with the same arguments.
206 This attribute is safe for a function that neither depends on nor affects
207 observable state, and always returns exactly once - e.g., does not loop
208 forever, and does not call longjmp.
209 (This attribute is stricter than _GL_ATTRIBUTE_PURE.) */
210 /* Applies to: functions. */
211 #ifndef _GL_ATTRIBUTE_CONST
212 # if _GL_HAS_ATTRIBUTE (const)
213 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
215 # define _GL_ATTRIBUTE_CONST
219 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
220 that can be freed by passing them as the Ith argument to the
222 _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
223 can be freed via 'free'; it can be used only after declaring 'free'. */
224 /* Applies to: functions. Cannot be used on inline functions. */
225 #ifndef _GL_ATTRIBUTE_DEALLOC
226 # if _GL_GNUC_PREREQ (11, 0)
227 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
229 # define _GL_ATTRIBUTE_DEALLOC(f, i)
232 /* If gnulib's <string.h> or <wchar.h> has already defined this macro, continue
233 to use this earlier definition, since <stdlib.h> may not have been included
235 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
236 # if defined __cplusplus && defined __GNUC__ && !defined __clang__
237 /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
238 # define _GL_ATTRIBUTE_DEALLOC_FREE \
239 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
241 # define _GL_ATTRIBUTE_DEALLOC_FREE \
242 _GL_ATTRIBUTE_DEALLOC (free, 1)
246 /* _GL_ATTRIBUTE_DEPRECATED: Declares that an entity is deprecated.
247 The compiler may warn if the entity is used. */
249 - function, variable,
250 - struct, union, struct/union member,
251 - enumeration, enumeration item,
253 in C++ also: namespace, class, template specialization. */
254 #ifndef _GL_ATTRIBUTE_DEPRECATED
255 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
256 # if _GL_HAVE___HAS_C_ATTRIBUTE
257 # if __has_c_attribute (__deprecated__)
258 # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
262 # if !defined _GL_ATTRIBUTE_DEPRECATED && _GL_HAS_ATTRIBUTE (deprecated)
263 # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
265 # ifndef _GL_ATTRIBUTE_DEPRECATED
266 # define _GL_ATTRIBUTE_DEPRECATED
270 /* _GL_ATTRIBUTE_ERROR(msg) requests an error if a function is called and
271 the function call is not optimized away.
272 _GL_ATTRIBUTE_WARNING(msg) requests a warning if a function is called and
273 the function call is not optimized away. */
274 /* Applies to: functions. */
275 #if !(defined _GL_ATTRIBUTE_ERROR && defined _GL_ATTRIBUTE_WARNING)
276 # if _GL_HAS_ATTRIBUTE (error)
277 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
278 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
279 # elif _GL_HAS_ATTRIBUTE (diagnose_if)
280 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
281 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
283 # define _GL_ATTRIBUTE_ERROR(msg)
284 # define _GL_ATTRIBUTE_WARNING(msg)
288 /* _GL_ATTRIBUTE_EXTERNALLY_VISIBLE declares that the entity should remain
289 visible to debuggers etc., even with '-fwhole-program'. */
290 /* Applies to: functions, variables. */
291 #ifndef _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
292 # if _GL_HAS_ATTRIBUTE (externally_visible)
293 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
295 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
299 /* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if
300 the control flow falls through to the immediately following 'case' or
301 'default' label. The compiler should not warn in this case. */
302 /* Applies to: Empty statement (;), inside a 'switch' statement. */
303 /* Always expands to something. */
304 #ifndef _GL_ATTRIBUTE_FALLTHROUGH
305 # if _GL_HAVE___HAS_C_ATTRIBUTE
306 # if __has_c_attribute (__fallthrough__)
307 # define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
310 # if !defined _GL_ATTRIBUTE_FALLTHROUGH && _GL_HAS_ATTRIBUTE (fallthrough)
311 # define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
313 # ifndef _GL_ATTRIBUTE_FALLTHROUGH
314 # define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
318 /* _GL_ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK))
319 declares that the STRING-INDEXth function argument is a format string of
320 style ARCHETYPE, which is one of:
323 strftime, gnu_strftime,
325 or the same thing prefixed and suffixed with '__'.
326 If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
327 are suitable for the format string. */
328 /* Applies to: functions. */
329 #ifndef _GL_ATTRIBUTE_FORMAT
330 # if _GL_HAS_ATTRIBUTE (format)
331 # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
333 # define _GL_ATTRIBUTE_FORMAT(spec)
337 /* _GL_ATTRIBUTE_LEAF declares that if the function is called from some other
338 compilation unit, it executes code from that unit only by return or by
339 exception handling. This declaration lets the compiler optimize that unit
340 more aggressively. */
341 /* Applies to: functions. */
342 #ifndef _GL_ATTRIBUTE_LEAF
343 # if _GL_HAS_ATTRIBUTE (leaf)
344 # define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
346 # define _GL_ATTRIBUTE_LEAF
350 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
352 /* Applies to: functions. */
353 #ifndef _GL_ATTRIBUTE_MALLOC
354 # if _GL_HAS_ATTRIBUTE (malloc)
355 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
357 # define _GL_ATTRIBUTE_MALLOC
361 /* _GL_ATTRIBUTE_MAY_ALIAS declares that pointers to the type may point to the
362 same storage as pointers to other types. Thus this declaration disables
363 strict aliasing optimization. */
364 /* Applies to: types. */
365 /* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
366 #ifndef _GL_ATTRIBUTE_MAY_ALIAS
367 # if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
368 # define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
370 # define _GL_ATTRIBUTE_MAY_ALIAS
374 /* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if
375 the entity is not used. The compiler should not warn if the entity is not
378 - function, variable,
379 - struct, union, struct/union member,
380 - enumeration, enumeration item,
382 in C++ also: class. */
383 /* In C++ and C23, this is spelled [[__maybe_unused__]].
384 GCC's syntax is __attribute__ ((__unused__)).
385 clang supports both syntaxes. Except that with clang ≥ 6, < 10, in C++ mode,
386 __has_c_attribute (__maybe_unused__) yields true but the use of
387 [[__maybe_unused__]] nevertheless produces a warning. */
388 #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
389 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
390 # if defined __clang__ && defined __cplusplus
391 # if !defined __apple_build_version__ && __clang_major__ >= 10
392 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
394 # elif _GL_HAVE___HAS_C_ATTRIBUTE
395 # if __has_c_attribute (__maybe_unused__)
396 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
400 # ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
401 # define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
404 /* Alternative spelling of this macro, for convenience and for
405 compatibility with glibc/include/libc-symbols.h. */
406 #define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
407 /* Earlier spellings of this macro. */
408 #define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
410 /* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not
411 discard the return value. The compiler may warn if the caller does not use
412 the return value, unless the caller uses something like ignore_value. */
413 /* Applies to: function, enumeration, class. */
414 #ifndef _GL_ATTRIBUTE_NODISCARD
415 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
416 # if defined __clang__ && defined __cplusplus
417 /* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]] produces
419 The 1000 below means a yet unknown threshold. When clang++ version X
420 starts supporting [[__nodiscard__]] without warning about it, you can
421 replace the 1000 with X. */
422 # if __clang_major__ >= 1000
423 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
425 # elif _GL_HAVE___HAS_C_ATTRIBUTE
426 # if __has_c_attribute (__nodiscard__)
427 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
431 # if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE (warn_unused_result)
432 # define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
434 # ifndef _GL_ATTRIBUTE_NODISCARD
435 # define _GL_ATTRIBUTE_NODISCARD
439 /* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the
441 /* Applies to: functions. */
442 #ifndef _GL_ATTRIBUTE_NOINLINE
443 # if _GL_HAS_ATTRIBUTE (noinline)
444 # define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
446 # define _GL_ATTRIBUTE_NOINLINE
450 /* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,...
452 _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be
454 /* Applies to: functions. */
455 #ifndef _GL_ATTRIBUTE_NONNULL
456 # if _GL_HAS_ATTRIBUTE (nonnull)
457 # define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
459 # define _GL_ATTRIBUTE_NONNULL(args)
463 /* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
464 not meant to be NUL-terminated. */
465 /* Applies to: struct/union members and variables that are arrays of element
466 type '[[un]signed] char'. */
467 #ifndef _GL_ATTRIBUTE_NONSTRING
468 # if _GL_HAS_ATTRIBUTE (nonstring)
469 # define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
471 # define _GL_ATTRIBUTE_NONSTRING
475 /* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
477 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
479 /* Applies to: functions. */
480 /* After a function's parameter list, this attribute must come first, before
482 #ifndef _GL_ATTRIBUTE_NOTHROW
483 # if defined __cplusplus
484 # if _GL_GNUC_PREREQ (2, 8) || __clang_major >= 4
485 # if __cplusplus >= 201103L
486 # define _GL_ATTRIBUTE_NOTHROW noexcept (true)
488 # define _GL_ATTRIBUTE_NOTHROW throw ()
491 # define _GL_ATTRIBUTE_NOTHROW
494 # if _GL_HAS_ATTRIBUTE (nothrow)
495 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
497 # define _GL_ATTRIBUTE_NOTHROW
502 /* _GL_ATTRIBUTE_PACKED declares:
503 For struct members: The member has the smallest possible alignment.
504 For struct, union, class: All members have the smallest possible alignment,
505 minimizing the memory required. */
506 /* Applies to: struct members, struct, union,
507 in C++ also: class. */
508 /* Oracle Studio 12.6 miscompiles code with __attribute__ ((__packed__)) despite
509 __has_attribute OK. */
510 #ifndef _GL_ATTRIBUTE_PACKED
511 # if _GL_HAS_ATTRIBUTE (packed) && !defined __SUNPRO_C
512 # define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
514 # define _GL_ATTRIBUTE_PACKED
518 /* _GL_ATTRIBUTE_PURE declares that It is OK for a compiler to omit duplicate
519 calls to the function with the same arguments if observable state is not
520 changed between calls.
521 This attribute is safe for a function that does not affect
522 observable state, and always returns exactly once.
523 (This attribute is looser than _GL_ATTRIBUTE_CONST.) */
524 /* Applies to: functions. */
525 #ifndef _GL_ATTRIBUTE_PURE
526 # if _GL_HAS_ATTRIBUTE (pure)
527 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
529 # define _GL_ATTRIBUTE_PURE
533 /* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is
534 a non-NULL pointer. */
535 /* Applies to: functions. */
536 #ifndef _GL_ATTRIBUTE_RETURNS_NONNULL
537 # if _GL_HAS_ATTRIBUTE (returns_nonnull)
538 # define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
540 # define _GL_ATTRIBUTE_RETURNS_NONNULL
544 /* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a
545 trailing NULL argument.
546 _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
547 _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
548 /* Applies to: functions. */
549 #ifndef _GL_ATTRIBUTE_SENTINEL
550 # if _GL_HAS_ATTRIBUTE (sentinel)
551 # define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
553 # define _GL_ATTRIBUTE_SENTINEL(pos)
557 /* A helper macro. Don't use it directly. */
558 #ifndef _GL_ATTRIBUTE_UNUSED
559 # if _GL_HAS_ATTRIBUTE (unused)
560 # define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
562 # define _GL_ATTRIBUTE_UNUSED
566 ]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
568 /* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the
569 immediately preceding label is not used. The compiler should not warn
570 if the label is not used. */
571 /* Applies to: label (both in C and C++). */
572 /* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;'
573 syntax. But clang does. */
574 #ifndef _GL_UNUSED_LABEL
575 # if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__
576 # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
578 # define _GL_UNUSED_LABEL
582 AH_VERBATIM([c_linkage],
583 [/* In C++, there is the concept of "language linkage", that encompasses
584 name mangling and function calling conventions.
585 The following macros start and end a block of "C" linkage. */
587 # define _GL_BEGIN_C_LINKAGE extern "C" {
588 # define _GL_END_C_LINKAGE }
590 # define _GL_BEGIN_C_LINKAGE
591 # define _GL_END_C_LINKAGE
594 AH_VERBATIM([async_safe],
595 [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
596 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
597 invoked from such signal handlers. Such functions have some restrictions:
598 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
599 or should be listed as async-signal-safe in POSIX
600 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
601 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
602 particular, are NOT async-signal-safe.
603 * All memory locations (variables and struct fields) that these functions
604 access must be marked 'volatile'. This holds for both read and write
605 accesses. Otherwise the compiler might optimize away stores to and
606 reads from such locations that occur in the program, depending on its
607 data flow analysis. For example, when the program contains a loop
608 that is intended to inspect a variable set from within a signal handler
609 while (!signal_occurred)
611 the compiler is allowed to transform this into an endless loop if the
612 variable 'signal_occurred' is not declared 'volatile'.
613 Additionally, recall that:
614 * A signal handler should not modify errno (except if it is a handler
615 for a fatal signal and ends by raising the same signal again, thus
616 provoking the termination of the process). If it invokes a function
617 that may clobber errno, it needs to save and restore the value of
619 #define _GL_ASYNC_SAFE
621 AH_VERBATIM([micro_optimizations],
622 [/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
623 n1 and n2 are expressions without side effects, that evaluate to real
624 numbers (excluding NaN).
629 The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
630 jump with nearly all GCC versions up to GCC 10.
631 This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
632 GCC versions up to GCC 9.
633 The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
634 avoids conditional jumps in all GCC versions >= 3.4. */
635 #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
637 dnl Hint which direction to take regarding cross-compilation guesses:
638 dnl When a user installs a program on a platform they are not intimately
639 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
640 dnl choice. It implements the "If we don't know, assume the worst" principle.
641 dnl However, when an operating system developer (on a platform which is not
642 dnl yet known to gnulib) builds packages for their platform, they want to
643 dnl expose, not hide, possible platform bugs; in this case,
644 dnl --enable-cross-guesses=risky is the appropriate choice.
645 dnl Sets the variables
646 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
647 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
648 AC_ARG_ENABLE([cross-guesses],
649 [AS_HELP_STRING([[--enable-cross-guesses={conservative|risky}]],
650 [specify policy for cross-compilation guesses])],
651 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
652 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
653 enableval=conservative
655 gl_cross_guesses="$enableval"],
656 [gl_cross_guesses=conservative])
657 if test $gl_cross_guesses = risky; then
658 gl_cross_guess_normal="guessing yes"
659 gl_cross_guess_inverted="guessing no"
661 gl_cross_guess_normal="guessing no"
662 gl_cross_guess_inverted="guessing yes"
664 dnl Preparation for running test programs:
665 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
666 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
667 dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
669 export LIBC_FATAL_STDERR_
672 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
673 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
674 # initializes the shell variable that indicates the presence of the given module
675 # as a C preprocessor expression.
676 AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
678 GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
679 AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
682 # gl_MODULE_INDICATOR_CONDITION
683 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
684 # whether a gnulib module that has been requested shall be considered present
686 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
688 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
689 # sets the shell variable that indicates the presence of the given module to
690 # a C preprocessor expression that will evaluate to 1.
691 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
693 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
694 [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
695 [abcdefghijklmnopqrstuvwxyz./-],
696 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
697 [gl_MODULE_INDICATOR_CONDITION])
700 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
701 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
702 # The shell variable's value is a C preprocessor expression that evaluates
704 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
706 m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
708 dnl Simplify the expression VALUE || 1 to 1.
711 [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
712 [gl_MODULE_INDICATOR_CONDITION])])
715 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
716 # modifies the shell variable to include the given condition. The shell
717 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
718 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
720 dnl Simplify the expression 1 || CONDITION to 1.
721 if test "$[]$1" != 1; then
722 dnl Simplify the expression 0 || CONDITION to CONDITION.
723 if test "$[]$1" = 0; then
731 # gl_MODULE_INDICATOR([modulename])
732 # defines a C macro indicating the presence of the given module
733 # in a location where it can be used.
735 # | in lib/ | in tests/ |
736 # --------------------------------------------+---------+-----------+
737 # Module present among main modules: | 1 | 1 |
738 # --------------------------------------------+---------+-----------+
739 # Module present among tests-related modules: | 0 | 1 |
740 # --------------------------------------------+---------+-----------+
741 # Module not present at all: | 0 | 0 |
742 # --------------------------------------------+---------+-----------+
743 AC_DEFUN([gl_MODULE_INDICATOR],
745 AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
746 [abcdefghijklmnopqrstuvwxyz./-],
747 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
748 [gl_MODULE_INDICATOR_CONDITION],
749 [Define to a C preprocessor expression that evaluates to 1 or 0,
750 depending whether the gnulib module $1 shall be considered present.])
753 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
754 # defines a C macro indicating the presence of the given module
755 # in lib or tests. This is useful to determine whether the module
758 # | in lib/ | in tests/ |
759 # --------------------------------------------+---------+-----------+
760 # Module present among main modules: | 1 | 1 |
761 # --------------------------------------------+---------+-----------+
762 # Module present among tests-related modules: | 1 | 1 |
763 # --------------------------------------------+---------+-----------+
764 # Module not present at all: | 0 | 0 |
765 # --------------------------------------------+---------+-----------+
766 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
768 AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
769 [abcdefghijklmnopqrstuvwxyz./-],
770 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
771 [Define to 1 when the gnulib module $1 should be tested.])
774 # gl_ASSERT_NO_GNULIB_POSIXCHECK
775 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
776 # and thereby enables an optimization of configure and config.h.
778 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
780 dnl Override gl_WARN_ON_USE_PREPARE.
781 dnl But hide this definition from 'aclocal'.
782 AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
785 # gl_ASSERT_NO_GNULIB_TESTS
786 # asserts that there will be no gnulib tests in the scope of the configure.ac
787 # and thereby enables an optimization of config.h.
789 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
791 dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
792 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
795 # Test whether <features.h> exists.
796 # Set HAVE_FEATURES_H.
797 AC_DEFUN([gl_FEATURES_H],
799 AC_CHECK_HEADERS_ONCE([features.h])
800 if test $ac_cv_header_features_h = yes; then
805 AC_SUBST([HAVE_FEATURES_H])
809 # Modifies the value of the shell variable CC in an attempt to make $CC
810 # understand ISO C99 source code.
811 AC_DEFUN([gl_PROG_CC_C99],
813 dnl Just use AC_PROG_CC_C99.
814 dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
815 dnl value of CC will contain the C99 enabling options twice. But this is only
816 dnl a cosmetic problem.
817 dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
818 dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
819 m4_version_prereq([2.70],
820 [AC_REQUIRE([AC_PROG_CC])],
821 [AC_REQUIRE([AC_PROG_CC_C99])])
825 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
826 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
828 AC_DEFUN([gl_PROG_AR_RANLIB],
830 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
831 dnl as "cc", and GCC as "gcc". They have different object file formats and
832 dnl library formats. In particular, the GNU binutils programs ar and ranlib
833 dnl produce libraries that work only with gcc, not with cc.
834 AC_REQUIRE([AC_PROG_CC])
835 dnl The '][' hides this use from 'aclocal'.
836 AC_BEFORE([$0], [A][M_PROG_AR])
837 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
839 AC_EGREP_CPP([Amsterdam],
845 [gl_cv_c_amsterdam_compiler=yes],
846 [gl_cv_c_amsterdam_compiler=no])
849 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
850 dnl building with __ACK__.
851 if test $gl_cv_c_amsterdam_compiler = yes; then
852 if test -z "$AR"; then
855 if test -z "$ARFLAGS"; then
859 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
860 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
861 dnl script on-demand, if not specified by ./configure of course).
862 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
863 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
864 dnl because AM_PROG_AR is written so it could re-set AR variable even for
865 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
866 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
867 dnl default value and automake should usually know them).
869 dnl The '][' hides this use from 'aclocal'.
870 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
873 dnl In case the code above has not helped with setting AR/ARFLAGS, use
874 dnl Automake-documented default values for AR and ARFLAGS, but prefer
875 dnl ${host}-ar over ar (useful for cross-compiling).
876 AC_CHECK_TOOL([AR], [ar], [ar])
877 if test -z "$ARFLAGS"; then
883 if test -z "$RANLIB"; then
884 if test $gl_cv_c_amsterdam_compiler = yes; then
887 dnl Use the ranlib program if it is available.
895 # This definition is copied from post-2.70 Autoconf and overrides the
896 # AC_C_RESTRICT macro from autoconf 2.60..2.70.
897 m4_version_prereq([2.70.1], [], [
898 AC_DEFUN([AC_C_RESTRICT],
899 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
901 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
902 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
903 # Put 'restrict' last, because C++ lacks it.
904 for ac_kw in __restrict__ __restrict _Restrict restrict; do
907 [[typedef int *int_ptr;
908 int foo (int_ptr $ac_kw ip) { return ip[0]; }
909 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
910 int bar (int ip[$ac_kw]) { return ip[0]; }
915 return foo (t) + bar (t);
917 [ac_cv_c_restrict=$ac_kw])
918 test "$ac_cv_c_restrict" != no && break
921 AH_VERBATIM([restrict],
922 [/* Define to the equivalent of the C99 'restrict' keyword, or to
923 nothing if this is not supported. Do not define if restrict is
924 supported only directly. */
926 /* Work around a bug in older versions of Sun C++, which did not
927 #define __restrict__ or support _Restrict or __restrict__
928 even though the corresponding Sun C compiler ended up with
929 "#define restrict _Restrict" or "#define restrict __restrict__"
930 in the previous line. This workaround can be removed once
931 we assume Oracle Developer Studio 12.5 (2016) or later. */
932 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
934 # define __restrict__
936 case $ac_cv_c_restrict in
938 no) AC_DEFINE([restrict], []) ;;
939 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
945 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
946 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
947 # macros invoke AC_C_BIGENDIAN with arguments.
948 AC_DEFUN([gl_BIGENDIAN],
953 # A temporary file descriptor.
954 # Must be less than 10, because dash 0.5.8 does not support redirections
955 # with multi-digit file descriptors.
956 m4_define([GL_TMP_FD], 9)
959 # executes command, but without the normal configure output.
960 # This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
961 # inside another AC_CACHE_CHECK.
962 AC_DEFUN([gl_SILENT],
964 exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
966 exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
969 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
970 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
971 # output a spurious "(cached)" mark in the midst of other configure output.
972 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
973 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
974 AC_DEFUN([gl_CACHE_VAL_SILENT],
977 AC_CACHE_VAL([$1], [$2])
981 # gl_CONDITIONAL(conditional, condition)
982 # is like AM_CONDITIONAL(conditional, condition), except that it does not
984 # configure: error: conditional "..." was never defined.
985 # Usually this means the macro was only invoked conditionally.
986 # when only invoked conditionally. Instead, in that case, both the _TRUE
987 # and the _FALSE case are disabled.
988 AC_DEFUN([gl_CONDITIONAL],
990 pushdef([AC_CONFIG_COMMANDS_PRE], [:])dnl
991 AM_CONDITIONAL([$1], [$2])
992 popdef([AC_CONFIG_COMMANDS_PRE])dnl
993 if test -z "${[$1]_TRUE}" && test -z "${[$1]_FALSE}"; then
999 # gl_CC_ALLOW_WARNINGS
1000 # sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
1001 # that reverts a preceding '-Werror' option, if available.
1002 # This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
1003 # and empty otherwise.
1004 AC_DEFUN([gl_CC_ALLOW_WARNINGS],
1006 AC_REQUIRE([AC_PROG_CC])
1007 AC_CACHE_CHECK([for C compiler option to allow warnings],
1010 echo 'int dummy;' > conftest.c
1011 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
1012 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
1013 dnl Test the number of error output lines, because AIX xlc accepts the
1014 dnl option '-Wno-error', just to produce a warning
1015 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
1017 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
1018 gl_cv_cc_wallow='-Wno-error'
1020 gl_cv_cc_wallow=none
1024 case "$gl_cv_cc_wallow" in
1025 none) GL_CFLAG_ALLOW_WARNINGS='' ;;
1026 *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
1028 AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
1031 # gl_CXX_ALLOW_WARNINGS
1032 # sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
1033 # that reverts a preceding '-Werror' option, if available.
1034 AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
1036 dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
1037 if test -n "$CXX" && test "$CXX" != no; then
1038 AC_CACHE_CHECK([for C++ compiler option to allow warnings],
1041 echo 'int dummy;' > conftest.cc
1042 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
1043 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
1044 dnl Test the number of error output lines, because AIX xlC accepts the
1045 dnl option '-Wno-error', just to produce a warning
1046 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
1048 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
1049 gl_cv_cxx_wallow='-Wno-error'
1051 gl_cv_cxx_wallow=none
1055 case "$gl_cv_cxx_wallow" in
1056 none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
1057 *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
1060 GL_CXXFLAG_ALLOW_WARNINGS=''
1062 AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
1065 # gl_CC_GNULIB_WARNINGS
1066 # sets and substitutes a variable GL_CFLAG_GNULIB_WARNINGS, to a $(CC) option
1067 # set that enables or disables warnings as suitable for the Gnulib coding style.
1068 AC_DEFUN([gl_CC_GNULIB_WARNINGS],
1070 AC_REQUIRE([gl_CC_ALLOW_WARNINGS])
1071 dnl Assume that the compiler supports -Wno-* options only if it also supports
1073 GL_CFLAG_GNULIB_WARNINGS=''
1074 if test -n "$GL_CFLAG_ALLOW_WARNINGS"; then
1075 dnl Enable these warning options:
1078 dnl -Wno-cast-qual >= 3 >= 3.9
1079 dnl -Wno-conversion >= 3 >= 3.9
1080 dnl -Wno-float-conversion >= 4.9 >= 3.9
1081 dnl -Wno-float-equal >= 3 >= 3.9
1082 dnl -Wimplicit-fallthrough >= 7 >= 3.9
1083 dnl -Wno-pedantic >= 4.8 >= 3.9
1084 dnl -Wno-sign-compare >= 3 >= 3.9
1085 dnl -Wno-sign-conversion >= 4.3 >= 3.9
1086 dnl -Wno-tautological-out-of-range-compare - >= 3.9
1087 dnl -Wno-type-limits >= 4.3 >= 3.9
1088 dnl -Wno-undef >= 3 >= 3.9
1089 dnl -Wno-unsuffixed-float-constants >= 4.5
1090 dnl -Wno-unused-function >= 3 >= 3.9
1091 dnl -Wno-unused-parameter >= 3 >= 3.9
1093 cat > conftest.c <<\EOF
1094 #if __GNUC__ >= 3 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1100 -Wno-unused-function
1101 -Wno-unused-parameter
1103 #if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1104 -Wno-float-conversion
1106 #if __GNUC__ >= 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1107 -Wimplicit-fallthrough
1109 #if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1112 #if 3 < __clang_major__ + (9 <= __clang_minor__)
1113 -Wno-tautological-constant-out-of-range-compare
1115 #if __GNUC__ + (__GNUC_MINOR__ >= 3) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1116 -Wno-sign-conversion
1119 #if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
1120 -Wno-unsuffixed-float-constants
1123 gl_command="$CC $CFLAGS $CPPFLAGS -E conftest.c > conftest.out"
1124 if AC_TRY_EVAL([gl_command]); then
1125 gl_options=`grep -v '#' conftest.out`
1126 for word in $gl_options; do
1127 GL_CFLAG_GNULIB_WARNINGS="$GL_CFLAG_GNULIB_WARNINGS $word"
1130 rm -f conftest.c conftest.out
1132 AC_SUBST([GL_CFLAG_GNULIB_WARNINGS])
1135 dnl gl_CONDITIONAL_HEADER([foo.h])
1136 dnl takes a shell variable GL_GENERATE_FOO_H (with value true or false) as input
1138 dnl - an AC_SUBSTed variable FOO_H that is either a file name or empty, based
1139 dnl on whether GL_GENERATE_FOO_H is true or false,
1140 dnl - an Automake conditional GL_GENERATE_FOO_H that evaluates to the value of
1141 dnl the shell variable GL_GENERATE_FOO_H.
1142 AC_DEFUN([gl_CONDITIONAL_HEADER],
1144 m4_pushdef([gl_header_name], AS_TR_SH(m4_toupper($1)))
1145 m4_pushdef([gl_generate_var], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1146 m4_pushdef([gl_generate_cond], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1147 case "$gl_generate_var" in
1148 false) gl_header_name='' ;;
1150 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
1152 if test -z "$gl_header_name"; then
1153 gl_header_name="${gl_source_base_prefix}$1"
1156 *) echo "*** gl_generate_var is not set correctly" 1>&2; exit 1 ;;
1158 AC_SUBST(gl_header_name)
1159 gl_CONDITIONAL(gl_generate_cond, [$gl_generate_var])
1160 m4_popdef([gl_generate_cond])
1161 m4_popdef([gl_generate_var])
1162 m4_popdef([gl_header_name])
1165 dnl Preparations for gl_CHECK_FUNCS_MACOS.
1166 AC_DEFUN([gl_PREPARE_CHECK_FUNCS_MACOS],
1168 AC_REQUIRE([AC_CANONICAL_HOST])
1169 AC_REQUIRE([gl_COMPILER_CLANG])
1170 AC_CACHE_CHECK([for compiler option needed when checking for future declarations],
1171 [gl_cv_compiler_check_future_option],
1173 dnl This is only needed on macOS.
1175 if test $gl_cv_compiler_clang = yes; then
1176 dnl Test whether the compiler supports the option
1177 dnl '-Werror=unguarded-availability-new'.
1178 saved_ac_compile="$ac_compile"
1179 ac_compile="$ac_compile -Werror=unguarded-availability-new"
1180 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
1181 [gl_cv_compiler_check_future_option='-Werror=unguarded-availability-new'],
1182 [gl_cv_compiler_check_future_option=none])
1183 ac_compile="$saved_ac_compile"
1185 gl_cv_compiler_check_future_option=none
1188 *) gl_cv_compiler_check_future_option=none ;;
1193 dnl Pieces of the expansion of
1194 dnl gl_CHECK_FUNCS_ANDROID
1195 dnl gl_CHECK_FUNCS_MACOS
1196 dnl gl_CHECK_FUNCS_ANDROID_MACOS
1198 AC_DEFUN([gl_CHECK_FUNCS_DEFAULT_CASE],
1202 [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
1206 AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_ANDROID],
1209 AC_CHECK_DECL([$1], , , [$2])
1210 if test $[ac_cv_have_decl_][$1] = yes; then
1211 AC_CHECK_FUNC([[$1]])
1212 if test $[ac_cv_func_][$1] = yes; then
1213 [gl_cv_onwards_func_][$1]=yes
1215 dnl The function is declared but does not exist. This should not
1216 dnl happen normally. But anyway, we know that a future version
1217 dnl of Android will have the function.
1218 [gl_cv_onwards_func_][$1]='future OS version'
1221 [gl_cv_onwards_func_][$1]='future OS version'
1226 AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_MACOS],
1229 if test "x$gl_cv_compiler_check_future_option" != "xnone"; then
1230 dnl Use a compile test, not a link test.
1231 saved_ac_compile="$ac_compile"
1232 ac_compile="$ac_compile $gl_cv_compiler_check_future_option"
1233 saved_ac_compile_for_check_decl="$ac_compile_for_check_decl"
1234 ac_compile_for_check_decl="$ac_compile_for_check_decl $gl_cv_compiler_check_future_option"
1235 unset [ac_cv_have_decl_][$1]
1236 AC_CHECK_DECL([$1], , , [$2])
1237 ac_compile="$saved_ac_compile"
1238 ac_compile_for_check_decl="$saved_ac_compile_for_check_decl"
1239 [ac_cv_func_][$1]="$[ac_cv_have_decl_][$1]"
1240 if test $[ac_cv_func_][$1] = yes; then
1241 [gl_cv_onwards_func_][$1]=yes
1243 unset [ac_cv_have_decl_][$1]
1244 AC_CHECK_DECL([$1], , , [$2])
1245 if test $[ac_cv_have_decl_][$1] = yes; then
1246 [gl_cv_onwards_func_][$1]='future OS version'
1248 [gl_cv_onwards_func_][$1]=no
1253 [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
1258 AC_DEFUN([gl_CHECK_FUNCS_SET_RESULTS],
1260 case "$[gl_cv_onwards_func_][$1]" in
1261 future*) [ac_cv_func_][$1]=no ;;
1262 *) [ac_cv_func_][$1]=$[gl_cv_onwards_func_][$1] ;;
1264 if test $[ac_cv_func_][$1] = yes; then
1265 AC_DEFINE([HAVE_]m4_translit([[$1]],
1266 [abcdefghijklmnopqrstuvwxyz],
1267 [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
1268 [1], [Define to 1 if you have the `$1' function.])
1272 dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
1273 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1276 dnl When code is compiled on Android, it is in the context of a certain
1277 dnl "Android API level", which indicates the minimum version of Android on
1278 dnl which the app can be installed. In other words, you don't compile for a
1279 dnl specific version of Android. You compile for all versions of Android,
1280 dnl onwards from the given API level.
1281 dnl Thus, the question "does the OS have the function func" has three possible
1283 dnl - yes, in all versions starting from the given API level,
1284 dnl - no, in no version,
1285 dnl - not in the given API level, but in a later version of Android.
1287 dnl In detail, this works as follows:
1288 dnl If func was added to Android API level, say, 28, then the libc.so has the
1289 dnl symbol func always, whereas the header file <foo.h> declares func
1291 dnl #if __ANDROID_API__ >= 28
1292 dnl ... func (...) __INTRODUCED_IN(28);
1294 dnl Thus, when compiling with "clang -target armv7a-unknown-linux-android28",
1295 dnl the function func is declared and exists in libc.
1296 dnl Whereas when compiling with "clang -target armv7a-unknown-linux-android27",
1297 dnl the function func is not declared but exists in libc.
1299 dnl This macro sets two variables:
1300 dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
1301 dnl - ac_cv_func_<func> to yes / no / no
1302 dnl The first variable allows to distinguish all three cases.
1303 dnl The second variable is set, so that an invocation
1304 dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
1305 dnl can be used as a drop-in replacement for
1306 dnl AC_CHECK_FUNCS([func]).
1307 AC_DEFUN([gl_CHECK_FUNCS_ANDROID],
1309 AC_REQUIRE([AC_CANONICAL_HOST])
1310 AC_CACHE_CHECK([for [$1]],
1311 [[gl_cv_onwards_func_][$1]],
1314 gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
1315 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1319 gl_CHECK_FUNCS_SET_RESULTS([$1])
1322 dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
1323 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1326 dnl When code is compiled on macOS, it is in the context of a certain minimum
1327 dnl macOS version, that can be set through the option '-mmacosx-version-min='.
1328 dnl In other words, you don't compile for a specific version of macOS. You
1329 dnl compile for all versions of macOS, onwards from the given version.
1330 dnl Thus, the question "does the OS have the function func" has three possible
1332 dnl - yes, in all versions starting from the given version,
1333 dnl - no, in no version,
1334 dnl - not in the given version, but in a later version of macOS.
1336 dnl In detail, this works as follows:
1337 dnl If func was added to, say, macOS version 13, then the libc has the
1338 dnl symbol func always, whereas the header file <foo.h> declares func
1339 dnl conditionally with a special availability attribute:
1340 dnl ... func (...) __attribute__((availability(macos,introduced=13.0)));
1341 dnl Thus, when compiling with "clang mmacosx-version-min=13", there is no
1342 dnl warning about the use of func, and the resulting binary
1343 dnl - runs fine on macOS 13,
1344 dnl - aborts with a dyld "Symbol not found" message on macOS 12.
1345 dnl Whereas, when compiling with "clang mmacosx-version-min=12", there is a
1346 dnl warning: 'func' is only available on macOS 13.0 or newer
1347 dnl [-Wunguarded-availability-new],
1348 dnl and the resulting binary
1349 dnl - runs fine on macOS 13,
1350 dnl - crashes with a SIGSEGV (signal 11) on macOS 12.
1352 dnl This macro sets two variables:
1353 dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
1354 dnl - ac_cv_func_<func> to yes / no / no
1355 dnl The first variable allows to distinguish all three cases.
1356 dnl The second variable is set, so that an invocation
1357 dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
1358 dnl can be used as a drop-in replacement for
1359 dnl AC_CHECK_FUNCS([func]).
1360 AC_DEFUN([gl_CHECK_FUNCS_MACOS],
1362 AC_REQUIRE([AC_CANONICAL_HOST])
1363 AC_REQUIRE([gl_PREPARE_CHECK_FUNCS_MACOS])
1364 AC_CACHE_CHECK([for [$1]],
1365 [[gl_cv_onwards_func_][$1]],
1368 gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
1369 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1373 gl_CHECK_FUNCS_SET_RESULTS([$1])
1376 dnl gl_CHECK_FUNCS_ANDROID_MACOS([func], [[#include <foo.h>]])
1377 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1378 dnl on Android and on macOS.
1379 dnl It is the combination of gl_CHECK_FUNCS_ANDROID and gl_CHECK_FUNCS_MACOS.
1380 AC_DEFUN([gl_CHECK_FUNCS_ANDROID_MACOS],
1382 AC_REQUIRE([AC_CANONICAL_HOST])
1383 AC_REQUIRE([gl_PREPARE_CHECK_FUNCS_MACOS])
1384 AC_CACHE_CHECK([for [$1]],
1385 [[gl_cv_onwards_func_][$1]],
1388 gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
1389 gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
1390 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1394 gl_CHECK_FUNCS_SET_RESULTS([$1])
1397 dnl Expands to some code for use in .c programs that, on native Windows, defines
1398 dnl the Microsoft deprecated alias function names to the underscore-prefixed
1399 dnl actual function names. With this macro, these function names are available
1400 dnl without linking with '-loldnames' and without generating warnings.
1401 dnl Usage: Use it after all system header files are included.
1404 dnl ]GL_MDA_DEFINES[
1406 AC_DEFUN([GL_MDA_DEFINES],[
1407 AC_REQUIRE([_GL_MDA_DEFINES])
1410 AC_DEFUN([_GL_MDA_DEFINES],
1412 #if defined _WIN32 && !defined __CYGWIN__
1413 #define access _access
1414 #define chdir _chdir
1415 #define chmod _chmod
1416 #define close _close
1417 #define creat _creat
1421 #define execl _execl
1422 #define execle _execle
1423 #define execlp _execlp
1424 #define execv _execv
1425 #define execve _execve
1426 #define execvp _execvp
1427 #define execvpe _execvpe
1428 #define fcloseall _fcloseall
1430 #define fdopen _fdopen
1431 #define fileno _fileno
1433 #define getcwd _getcwd
1434 #define getpid _getpid
1436 #define isatty _isatty
1440 #define lfind _lfind
1441 #define lsearch _lsearch
1442 #define lseek _lseek
1443 #define memccpy _memccpy
1444 #define mkdir _mkdir
1445 #define mktemp _mktemp
1447 #define putenv _putenv
1450 #define rmdir _rmdir
1451 #define strdup _strdup
1453 #define tempnam _tempnam
1454 #define tzset _tzset
1455 #define umask _umask
1456 #define unlink _unlink
1457 #define utime _utime
1458 #define wcsdup _wcsdup
1459 #define write _write