Debian Codegraph @

m4/gnulib-common.m4

raw
1 # gnulib-common.m4 serial 87
2 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_PREREQ([2.62])
8
9 # gl_COMMON
10 # is expanded unconditionally through gnulib-tool magic.
11 AC_DEFUN([gl_COMMON], [
12 dnl Use AC_REQUIRE here, so that the code is expanded once only.
13 AC_REQUIRE([gl_00GNULIB])
14 AC_REQUIRE([gl_COMMON_BODY])
15 AC_REQUIRE([gl_ZZGNULIB])
16 ])
17 AC_DEFUN([gl_COMMON_BODY], [
18 AH_VERBATIM([0witness],
19 [/* Witness that <config.h> has been included. */
20 #define _GL_CONFIG_H_INCLUDED 1
21 ])
22 AH_VERBATIM([_GL_GNUC_PREREQ],
23 [/* True if the compiler says it groks GNU C version MAJOR.MINOR. */
24 #if defined __GNUC__ && defined __GNUC_MINOR__
25 # define _GL_GNUC_PREREQ(major, minor) \
26 ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__))
27 #else
28 # define _GL_GNUC_PREREQ(major, minor) 0
29 #endif
30 ])
31 AH_VERBATIM([_Noreturn],
32 [/* The _Noreturn keyword of C11. */
33 #ifndef _Noreturn
34 # if (defined __cplusplus \
35 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
36 || (defined _MSC_VER && 1900 <= _MSC_VER)) \
37 && 0)
38 /* [[noreturn]] is not practically usable, because with it the syntax
39 extern _Noreturn void func (...);
40 would not be valid; such a declaration would only be valid with 'extern'
41 and '_Noreturn' swapped, or without the 'extern' keyword. However, some
42 AIX system header files and several gnulib header files use precisely
43 this syntax with 'extern'. */
44 # define _Noreturn [[noreturn]]
45 # elif (defined __clang__ && __clang_major__ < 16 \
46 && defined _GL_WORK_AROUND_LLVM_BUG_59792)
47 /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around
48 that rare LLVM bug, though you may get many false-alarm warnings. */
49 # define _Noreturn
50 # elif ((!defined __cplusplus || defined __clang__) \
51 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
52 || (!defined __STRICT_ANSI__ \
53 && (_GL_GNUC_PREREQ (4, 7) \
54 || (defined __apple_build_version__ \
55 ? 6000000 <= __apple_build_version__ \
56 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
57 /* _Noreturn works as-is. */
58 # elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
59 # define _Noreturn __attribute__ ((__noreturn__))
60 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
61 # define _Noreturn __declspec (noreturn)
62 # else
63 # define _Noreturn
64 # endif
65 #endif
66 ])
67 AH_VERBATIM([isoc99_inline],
68 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
69 the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
70 earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
71 __APPLE__ && __MACH__ test for Mac OS X.
72 __APPLE_CC__ tests for the Apple compiler and its version.
73 __STDC_VERSION__ tests for the C99 mode. */
74 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
75 # define __GNUC_STDC_INLINE__ 1
76 #endif])
77 AH_VERBATIM([attribute],
78 [/* Attributes. */
79 #if (defined __has_attribute \
80 && (!defined __clang_minor__ \
81 || (defined __apple_build_version__ \
82 ? 6000000 <= __apple_build_version__ \
83 : 5 <= __clang_major__)))
84 # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
85 #else
86 # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
87 # define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
88 # define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
89 # define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
90 # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
91 # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
92 # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
93 # define _GL_ATTR_diagnose_if 0
94 # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
95 # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
96 # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
97 # define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
98 # define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
99 # define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
100 # ifdef _ICC
101 # define _GL_ATTR_may_alias 0
102 # else
103 # define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
104 # endif
105 # define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
106 # define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
107 # define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
108 # define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
109 # define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
110 # define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
111 # define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
112 # define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
113 # define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
114 # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
115 #endif
116
117 /* Disable GCC -Wpedantic if using __has_c_attribute and this is not C23+. */
118 #if (defined __has_c_attribute && _GL_GNUC_PREREQ (4, 6) \
119 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710)
120 # pragma GCC diagnostic ignored "-Wpedantic"
121 #endif
122
123 /* Define if, in a function declaration, the attributes in bracket syntax
124 [[...]] must come before the attributes in __attribute__((...)) syntax.
125 If this is defined, it is best to avoid the bracket syntax, so that the
126 various _GL_ATTRIBUTE_* can be cumulated on the same declaration in any
127 order. */
128 #ifdef __cplusplus
129 # if defined __clang__
130 # define _GL_BRACKET_BEFORE_ATTRIBUTE 1
131 # endif
132 #else
133 # if defined __GNUC__ && !defined __clang__
134 # define _GL_BRACKET_BEFORE_ATTRIBUTE 1
135 # endif
136 #endif
137 ]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead.
138 [
139 /* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
140 is the size of the returned memory block.
141 _GL_ATTRIBUTE_ALLOC_SIZE ((M, N)) declares that the Mth argument multiplied
142 by the Nth argument of the function is the size of the returned memory block.
143 */
144 /* Applies to: function, pointer to function, function types. */
145 #ifndef _GL_ATTRIBUTE_ALLOC_SIZE
146 # if _GL_HAS_ATTRIBUTE (alloc_size)
147 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
148 # else
149 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
150 # endif
151 #endif
152
153 /* _GL_ATTRIBUTE_ALWAYS_INLINE tells that the compiler should always inline the
154 function and report an error if it cannot do so. */
155 /* Applies to: function. */
156 #ifndef _GL_ATTRIBUTE_ALWAYS_INLINE
157 # if _GL_HAS_ATTRIBUTE (always_inline)
158 # define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
159 # else
160 # define _GL_ATTRIBUTE_ALWAYS_INLINE
161 # endif
162 #endif
163
164 /* _GL_ATTRIBUTE_ARTIFICIAL declares that the function is not important to show
165 in stack traces when debugging. The compiler should omit the function from
166 stack traces. */
167 /* Applies to: function. */
168 #ifndef _GL_ATTRIBUTE_ARTIFICIAL
169 # if _GL_HAS_ATTRIBUTE (artificial)
170 # define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
171 # else
172 # define _GL_ATTRIBUTE_ARTIFICIAL
173 # endif
174 #endif
175
176 /* _GL_ATTRIBUTE_COLD declares that the function is rarely executed. */
177 /* Applies to: functions. */
178 /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
179 <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
180 Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
181 #ifndef _GL_ATTRIBUTE_COLD
182 # if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
183 # ifndef __SUNPRO_C
184 # define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
185 # else
186 # define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
187 # endif
188 # else
189 # define _GL_ATTRIBUTE_COLD
190 # endif
191 #endif
192
193 /* _GL_ATTRIBUTE_CONST declares that it is OK for a compiler to omit duplicate
194 calls to the function with the same arguments.
195 This attribute is safe for a function that neither depends on nor affects
196 observable state, and always returns exactly once - e.g., does not loop
197 forever, and does not call longjmp.
198 (This attribute is stricter than _GL_ATTRIBUTE_PURE.) */
199 /* Applies to: functions. */
200 #ifndef _GL_ATTRIBUTE_CONST
201 # if _GL_HAS_ATTRIBUTE (const)
202 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
203 # else
204 # define _GL_ATTRIBUTE_CONST
205 # endif
206 #endif
207
208 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
209 that can be freed by passing them as the Ith argument to the
210 function F.
211 _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
212 can be freed via 'free'; it can be used only after declaring 'free'. */
213 /* Applies to: functions. Cannot be used on inline functions. */
214 #ifndef _GL_ATTRIBUTE_DEALLOC
215 # if _GL_GNUC_PREREQ (11, 0)
216 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
217 # else
218 # define _GL_ATTRIBUTE_DEALLOC(f, i)
219 # endif
220 #endif
221 /* If gnulib's <string.h> or <wchar.h> has already defined this macro, continue
222 to use this earlier definition, since <stdlib.h> may not have been included
223 yet. */
224 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
225 # if defined __cplusplus && defined __GNUC__ && !defined __clang__
226 /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
227 # define _GL_ATTRIBUTE_DEALLOC_FREE \
228 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
229 # else
230 # define _GL_ATTRIBUTE_DEALLOC_FREE \
231 _GL_ATTRIBUTE_DEALLOC (free, 1)
232 # endif
233 #endif
234
235 /* _GL_ATTRIBUTE_DEPRECATED: Declares that an entity is deprecated.
236 The compiler may warn if the entity is used. */
237 /* Applies to:
238 - function, variable,
239 - struct, union, struct/union member,
240 - enumeration, enumeration item,
241 - typedef,
242 in C++ also: namespace, class, template specialization. */
243 #ifndef _GL_ATTRIBUTE_DEPRECATED
244 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
245 # ifdef __has_c_attribute
246 # if __has_c_attribute (__deprecated__)
247 # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
248 # endif
249 # endif
250 # endif
251 # if !defined _GL_ATTRIBUTE_DEPRECATED && _GL_HAS_ATTRIBUTE (deprecated)
252 # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
253 # endif
254 # ifndef _GL_ATTRIBUTE_DEPRECATED
255 # define _GL_ATTRIBUTE_DEPRECATED
256 # endif
257 #endif
258
259 /* _GL_ATTRIBUTE_ERROR(msg) requests an error if a function is called and
260 the function call is not optimized away.
261 _GL_ATTRIBUTE_WARNING(msg) requests a warning if a function is called and
262 the function call is not optimized away. */
263 /* Applies to: functions. */
264 #if !(defined _GL_ATTRIBUTE_ERROR && defined _GL_ATTRIBUTE_WARNING)
265 # if _GL_HAS_ATTRIBUTE (error)
266 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
267 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
268 # elif _GL_HAS_ATTRIBUTE (diagnose_if)
269 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
270 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
271 # else
272 # define _GL_ATTRIBUTE_ERROR(msg)
273 # define _GL_ATTRIBUTE_WARNING(msg)
274 # endif
275 #endif
276
277 /* _GL_ATTRIBUTE_EXTERNALLY_VISIBLE declares that the entity should remain
278 visible to debuggers etc., even with '-fwhole-program'. */
279 /* Applies to: functions, variables. */
280 #ifndef _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
281 # if _GL_HAS_ATTRIBUTE (externally_visible)
282 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
283 # else
284 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
285 # endif
286 #endif
287
288 /* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if
289 the control flow falls through to the immediately following 'case' or
290 'default' label. The compiler should not warn in this case. */
291 /* Applies to: Empty statement (;), inside a 'switch' statement. */
292 /* Always expands to something. */
293 #ifndef _GL_ATTRIBUTE_FALLTHROUGH
294 # ifdef __has_c_attribute
295 # if __has_c_attribute (__fallthrough__)
296 # define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
297 # endif
298 # endif
299 # if !defined _GL_ATTRIBUTE_FALLTHROUGH && _GL_HAS_ATTRIBUTE (fallthrough)
300 # define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
301 # endif
302 # ifndef _GL_ATTRIBUTE_FALLTHROUGH
303 # define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
304 # endif
305 #endif
306
307 /* _GL_ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK))
308 declares that the STRING-INDEXth function argument is a format string of
309 style ARCHETYPE, which is one of:
310 printf, gnu_printf
311 scanf, gnu_scanf,
312 strftime, gnu_strftime,
313 strfmon,
314 or the same thing prefixed and suffixed with '__'.
315 If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
316 are suitable for the format string. */
317 /* Applies to: functions. */
318 #ifndef _GL_ATTRIBUTE_FORMAT
319 # if _GL_HAS_ATTRIBUTE (format)
320 # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
321 # else
322 # define _GL_ATTRIBUTE_FORMAT(spec)
323 # endif
324 #endif
325
326 /* _GL_ATTRIBUTE_LEAF declares that if the function is called from some other
327 compilation unit, it executes code from that unit only by return or by
328 exception handling. This declaration lets the compiler optimize that unit
329 more aggressively. */
330 /* Applies to: functions. */
331 #ifndef _GL_ATTRIBUTE_LEAF
332 # if _GL_HAS_ATTRIBUTE (leaf)
333 # define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
334 # else
335 # define _GL_ATTRIBUTE_LEAF
336 # endif
337 #endif
338
339 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
340 allocated memory. */
341 /* Applies to: functions. */
342 #ifndef _GL_ATTRIBUTE_MALLOC
343 # if _GL_HAS_ATTRIBUTE (malloc)
344 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
345 # else
346 # define _GL_ATTRIBUTE_MALLOC
347 # endif
348 #endif
349
350 /* _GL_ATTRIBUTE_MAY_ALIAS declares that pointers to the type may point to the
351 same storage as pointers to other types. Thus this declaration disables
352 strict aliasing optimization. */
353 /* Applies to: types. */
354 /* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
355 #ifndef _GL_ATTRIBUTE_MAY_ALIAS
356 # if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
357 # define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
358 # else
359 # define _GL_ATTRIBUTE_MAY_ALIAS
360 # endif
361 #endif
362
363 /* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if
364 the entity is not used. The compiler should not warn if the entity is not
365 used. */
366 /* Applies to:
367 - function, variable,
368 - struct, union, struct/union member,
369 - enumeration, enumeration item,
370 - typedef,
371 in C++ also: class. */
372 /* In C++ and C23, this is spelled [[__maybe_unused__]].
373 GCC's syntax is __attribute__ ((__unused__)).
374 clang supports both syntaxes. Except that with clang ≥ 6, < 10, in C++ mode,
375 __has_c_attribute (__maybe_unused__) yields true but the use of
376 [[__maybe_unused__]] nevertheless produces a warning. */
377 #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
378 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
379 # if defined __clang__ && defined __cplusplus
380 # if !defined __apple_build_version__ && __clang_major__ >= 10
381 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
382 # endif
383 # elif defined __has_c_attribute
384 # if __has_c_attribute (__maybe_unused__)
385 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
386 # endif
387 # endif
388 # endif
389 # ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
390 # define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
391 # endif
392 #endif
393 /* Alternative spelling of this macro, for convenience and for
394 compatibility with glibc/include/libc-symbols.h. */
395 #define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
396 /* Earlier spellings of this macro. */
397 #define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
398
399 /* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not
400 discard the return value. The compiler may warn if the caller does not use
401 the return value, unless the caller uses something like ignore_value. */
402 /* Applies to: function, enumeration, class. */
403 #ifndef _GL_ATTRIBUTE_NODISCARD
404 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
405 # if defined __clang__ && defined __cplusplus
406 /* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]] produces
407 a warning.
408 The 1000 below means a yet unknown threshold. When clang++ version X
409 starts supporting [[__nodiscard__]] without warning about it, you can
410 replace the 1000 with X. */
411 # if __clang_major__ >= 1000
412 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
413 # endif
414 # elif defined __has_c_attribute
415 # if __has_c_attribute (__nodiscard__)
416 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
417 # endif
418 # endif
419 # endif
420 # if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE (warn_unused_result)
421 # define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
422 # endif
423 # ifndef _GL_ATTRIBUTE_NODISCARD
424 # define _GL_ATTRIBUTE_NODISCARD
425 # endif
426 #endif
427
428 /* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the
429 function. */
430 /* Applies to: functions. */
431 #ifndef _GL_ATTRIBUTE_NOINLINE
432 # if _GL_HAS_ATTRIBUTE (noinline)
433 # define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
434 # else
435 # define _GL_ATTRIBUTE_NOINLINE
436 # endif
437 #endif
438
439 /* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,...
440 must not be NULL.
441 _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be
442 null. */
443 /* Applies to: functions. */
444 #ifndef _GL_ATTRIBUTE_NONNULL
445 # if _GL_HAS_ATTRIBUTE (nonnull)
446 # define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
447 # else
448 # define _GL_ATTRIBUTE_NONNULL(args)
449 # endif
450 #endif
451
452 /* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
453 not meant to be NUL-terminated. */
454 /* Applies to: struct/union members and variables that are arrays of element
455 type '[[un]signed] char'. */
456 #ifndef _GL_ATTRIBUTE_NONSTRING
457 # if _GL_HAS_ATTRIBUTE (nonstring)
458 # define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
459 # else
460 # define _GL_ATTRIBUTE_NONSTRING
461 # endif
462 #endif
463
464 /* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
465
466 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
467 */
468 /* Applies to: functions. */
469 #ifndef _GL_ATTRIBUTE_NOTHROW
470 # if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
471 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
472 # else
473 # define _GL_ATTRIBUTE_NOTHROW
474 # endif
475 #endif
476
477 /* _GL_ATTRIBUTE_PACKED declares:
478 For struct members: The member has the smallest possible alignment.
479 For struct, union, class: All members have the smallest possible alignment,
480 minimizing the memory required. */
481 /* Applies to: struct members, struct, union,
482 in C++ also: class. */
483 #ifndef _GL_ATTRIBUTE_PACKED
484 # if _GL_HAS_ATTRIBUTE (packed)
485 # define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
486 # else
487 # define _GL_ATTRIBUTE_PACKED
488 # endif
489 #endif
490
491 /* _GL_ATTRIBUTE_PURE declares that It is OK for a compiler to omit duplicate
492 calls to the function with the same arguments if observable state is not
493 changed between calls.
494 This attribute is safe for a function that does not affect
495 observable state, and always returns exactly once.
496 (This attribute is looser than _GL_ATTRIBUTE_CONST.) */
497 /* Applies to: functions. */
498 #ifndef _GL_ATTRIBUTE_PURE
499 # if _GL_HAS_ATTRIBUTE (pure)
500 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
501 # else
502 # define _GL_ATTRIBUTE_PURE
503 # endif
504 #endif
505
506 /* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is
507 a non-NULL pointer. */
508 /* Applies to: functions. */
509 #ifndef _GL_ATTRIBUTE_RETURNS_NONNULL
510 # if _GL_HAS_ATTRIBUTE (returns_nonnull)
511 # define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
512 # else
513 # define _GL_ATTRIBUTE_RETURNS_NONNULL
514 # endif
515 #endif
516
517 /* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a
518 trailing NULL argument.
519 _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
520 _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
521 /* Applies to: functions. */
522 #ifndef _GL_ATTRIBUTE_SENTINEL
523 # if _GL_HAS_ATTRIBUTE (sentinel)
524 # define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
525 # else
526 # define _GL_ATTRIBUTE_SENTINEL(pos)
527 # endif
528 #endif
529
530 /* A helper macro. Don't use it directly. */
531 #ifndef _GL_ATTRIBUTE_UNUSED
532 # if _GL_HAS_ATTRIBUTE (unused)
533 # define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
534 # else
535 # define _GL_ATTRIBUTE_UNUSED
536 # endif
537 #endif
538
539 ]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
540 [
541 /* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the
542 immediately preceding label is not used. The compiler should not warn
543 if the label is not used. */
544 /* Applies to: label (both in C and C++). */
545 /* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;'
546 syntax. But clang does. */
547 #ifndef _GL_UNUSED_LABEL
548 # if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__
549 # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
550 # else
551 # define _GL_UNUSED_LABEL
552 # endif
553 #endif
554 ])
555 AH_VERBATIM([c_linkage],
556 [/* In C++, there is the concept of "language linkage", that encompasses
557 name mangling and function calling conventions.
558 The following macros start and end a block of "C" linkage. */
559 #ifdef __cplusplus
560 # define _GL_BEGIN_C_LINKAGE extern "C" {
561 # define _GL_END_C_LINKAGE }
562 #else
563 # define _GL_BEGIN_C_LINKAGE
564 # define _GL_END_C_LINKAGE
565 #endif
566 ])
567 AH_VERBATIM([async_safe],
568 [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
569 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
570 invoked from such signal handlers. Such functions have some restrictions:
571 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
572 or should be listed as async-signal-safe in POSIX
573 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
574 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
575 particular, are NOT async-signal-safe.
576 * All memory locations (variables and struct fields) that these functions
577 access must be marked 'volatile'. This holds for both read and write
578 accesses. Otherwise the compiler might optimize away stores to and
579 reads from such locations that occur in the program, depending on its
580 data flow analysis. For example, when the program contains a loop
581 that is intended to inspect a variable set from within a signal handler
582 while (!signal_occurred)
583 ;
584 the compiler is allowed to transform this into an endless loop if the
585 variable 'signal_occurred' is not declared 'volatile'.
586 Additionally, recall that:
587 * A signal handler should not modify errno (except if it is a handler
588 for a fatal signal and ends by raising the same signal again, thus
589 provoking the termination of the process). If it invokes a function
590 that may clobber errno, it needs to save and restore the value of
591 errno. */
592 #define _GL_ASYNC_SAFE
593 ])
594 AH_VERBATIM([micro_optimizations],
595 [/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
596 n1 and n2 are expressions without side effects, that evaluate to real
597 numbers (excluding NaN).
598 It returns
599 1 if n1 > n2
600 0 if n1 == n2
601 -1 if n1 < n2
602 The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
603 jump with nearly all GCC versions up to GCC 10.
604 This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
605 GCC versions up to GCC 9.
606 The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
607 avoids conditional jumps in all GCC versions >= 3.4. */
608 #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
609 ])
610 dnl Hint which direction to take regarding cross-compilation guesses:
611 dnl When a user installs a program on a platform they are not intimately
612 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
613 dnl choice. It implements the "If we don't know, assume the worst" principle.
614 dnl However, when an operating system developer (on a platform which is not
615 dnl yet known to gnulib) builds packages for their platform, they want to
616 dnl expose, not hide, possible platform bugs; in this case,
617 dnl --enable-cross-guesses=risky is the appropriate choice.
618 dnl Sets the variables
619 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
620 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
621 AC_ARG_ENABLE([cross-guesses],
622 [AS_HELP_STRING([[--enable-cross-guesses={conservative|risky}]],
623 [specify policy for cross-compilation guesses])],
624 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
625 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
626 enableval=conservative
627 fi
628 gl_cross_guesses="$enableval"],
629 [gl_cross_guesses=conservative])
630 if test $gl_cross_guesses = risky; then
631 gl_cross_guess_normal="guessing yes"
632 gl_cross_guess_inverted="guessing no"
633 else
634 gl_cross_guess_normal="guessing no"
635 gl_cross_guess_inverted="guessing yes"
636 fi
637 dnl Preparation for running test programs:
638 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
639 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
640 dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
641 LIBC_FATAL_STDERR_=1
642 export LIBC_FATAL_STDERR_
643 ])
644
645 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
646 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
647 # initializes the shell variable that indicates the presence of the given module
648 # as a C preprocessor expression.
649 AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
650 [
651 GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
652 AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
653 ])
654
655 # gl_MODULE_INDICATOR_CONDITION
656 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
657 # whether a gnulib module that has been requested shall be considered present
658 # or not.
659 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
660
661 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
662 # sets the shell variable that indicates the presence of the given module to
663 # a C preprocessor expression that will evaluate to 1.
664 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
665 [
666 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
667 [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
668 [abcdefghijklmnopqrstuvwxyz./-],
669 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
670 [gl_MODULE_INDICATOR_CONDITION])
671 ])
672
673 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
674 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
675 # The shell variable's value is a C preprocessor expression that evaluates
676 # to 0 or 1.
677 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
678 [
679 m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
680 [
681 dnl Simplify the expression VALUE || 1 to 1.
682 $1=1
683 ],
684 [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
685 [gl_MODULE_INDICATOR_CONDITION])])
686 ])
687
688 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
689 # modifies the shell variable to include the given condition. The shell
690 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
691 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
692 [
693 dnl Simplify the expression 1 || CONDITION to 1.
694 if test "$[]$1" != 1; then
695 dnl Simplify the expression 0 || CONDITION to CONDITION.
696 if test "$[]$1" = 0; then
697 $1=$2
698 else
699 $1="($[]$1 || $2)"
700 fi
701 fi
702 ])
703
704 # gl_MODULE_INDICATOR([modulename])
705 # defines a C macro indicating the presence of the given module
706 # in a location where it can be used.
707 # | Value | Value |
708 # | in lib/ | in tests/ |
709 # --------------------------------------------+---------+-----------+
710 # Module present among main modules: | 1 | 1 |
711 # --------------------------------------------+---------+-----------+
712 # Module present among tests-related modules: | 0 | 1 |
713 # --------------------------------------------+---------+-----------+
714 # Module not present at all: | 0 | 0 |
715 # --------------------------------------------+---------+-----------+
716 AC_DEFUN([gl_MODULE_INDICATOR],
717 [
718 AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
719 [abcdefghijklmnopqrstuvwxyz./-],
720 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
721 [gl_MODULE_INDICATOR_CONDITION],
722 [Define to a C preprocessor expression that evaluates to 1 or 0,
723 depending whether the gnulib module $1 shall be considered present.])
724 ])
725
726 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
727 # defines a C macro indicating the presence of the given module
728 # in lib or tests. This is useful to determine whether the module
729 # should be tested.
730 # | Value | Value |
731 # | in lib/ | in tests/ |
732 # --------------------------------------------+---------+-----------+
733 # Module present among main modules: | 1 | 1 |
734 # --------------------------------------------+---------+-----------+
735 # Module present among tests-related modules: | 1 | 1 |
736 # --------------------------------------------+---------+-----------+
737 # Module not present at all: | 0 | 0 |
738 # --------------------------------------------+---------+-----------+
739 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
740 [
741 AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
742 [abcdefghijklmnopqrstuvwxyz./-],
743 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
744 [Define to 1 when the gnulib module $1 should be tested.])
745 ])
746
747 # gl_ASSERT_NO_GNULIB_POSIXCHECK
748 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
749 # and thereby enables an optimization of configure and config.h.
750 # Used by Emacs.
751 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
752 [
753 dnl Override gl_WARN_ON_USE_PREPARE.
754 dnl But hide this definition from 'aclocal'.
755 AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
756 ])
757
758 # gl_ASSERT_NO_GNULIB_TESTS
759 # asserts that there will be no gnulib tests in the scope of the configure.ac
760 # and thereby enables an optimization of config.h.
761 # Used by Emacs.
762 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
763 [
764 dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
765 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
766 ])
767
768 # Test whether <features.h> exists.
769 # Set HAVE_FEATURES_H.
770 AC_DEFUN([gl_FEATURES_H],
771 [
772 AC_CHECK_HEADERS_ONCE([features.h])
773 if test $ac_cv_header_features_h = yes; then
774 HAVE_FEATURES_H=1
775 else
776 HAVE_FEATURES_H=0
777 fi
778 AC_SUBST([HAVE_FEATURES_H])
779 ])
780
781 # gl_PROG_CC_C99
782 # Modifies the value of the shell variable CC in an attempt to make $CC
783 # understand ISO C99 source code.
784 AC_DEFUN([gl_PROG_CC_C99],
785 [
786 dnl Just use AC_PROG_CC_C99.
787 dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
788 dnl value of CC will contain the C99 enabling options twice. But this is only
789 dnl a cosmetic problem.
790 dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
791 dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
792 m4_version_prereq([2.70],
793 [AC_REQUIRE([AC_PROG_CC])],
794 [AC_REQUIRE([AC_PROG_CC_C99])])
795 ])
796
797 # gl_PROG_AR_RANLIB
798 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
799 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
800 # the values.
801 AC_DEFUN([gl_PROG_AR_RANLIB],
802 [
803 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
804 dnl as "cc", and GCC as "gcc". They have different object file formats and
805 dnl library formats. In particular, the GNU binutils programs ar and ranlib
806 dnl produce libraries that work only with gcc, not with cc.
807 AC_REQUIRE([AC_PROG_CC])
808 dnl The '][' hides this use from 'aclocal'.
809 AC_BEFORE([$0], [A][M_PROG_AR])
810 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
811 [
812 AC_EGREP_CPP([Amsterdam],
813 [
814 #ifdef __ACK__
815 Amsterdam
816 #endif
817 ],
818 [gl_cv_c_amsterdam_compiler=yes],
819 [gl_cv_c_amsterdam_compiler=no])
820 ])
821
822 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
823 dnl building with __ACK__.
824 if test $gl_cv_c_amsterdam_compiler = yes; then
825 if test -z "$AR"; then
826 AR='cc -c.a'
827 fi
828 if test -z "$ARFLAGS"; then
829 ARFLAGS='-o'
830 fi
831 else
832 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
833 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
834 dnl script on-demand, if not specified by ./configure of course).
835 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
836 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
837 dnl because AM_PROG_AR is written so it could re-set AR variable even for
838 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
839 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
840 dnl default value and automake should usually know them).
841 dnl
842 dnl The '][' hides this use from 'aclocal'.
843 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
844 fi
845
846 dnl In case the code above has not helped with setting AR/ARFLAGS, use
847 dnl Automake-documented default values for AR and ARFLAGS, but prefer
848 dnl ${host}-ar over ar (useful for cross-compiling).
849 AC_CHECK_TOOL([AR], [ar], [ar])
850 if test -z "$ARFLAGS"; then
851 ARFLAGS='cr'
852 fi
853
854 AC_SUBST([AR])
855 AC_SUBST([ARFLAGS])
856 if test -z "$RANLIB"; then
857 if test $gl_cv_c_amsterdam_compiler = yes; then
858 RANLIB=':'
859 else
860 dnl Use the ranlib program if it is available.
861 AC_PROG_RANLIB
862 fi
863 fi
864 AC_SUBST([RANLIB])
865 ])
866
867 # AC_C_RESTRICT
868 # This definition is copied from post-2.70 Autoconf and overrides the
869 # AC_C_RESTRICT macro from autoconf 2.60..2.70.
870 m4_version_prereq([2.70.1], [], [
871 AC_DEFUN([AC_C_RESTRICT],
872 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
873 [ac_cv_c_restrict=no
874 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
875 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
876 # Put 'restrict' last, because C++ lacks it.
877 for ac_kw in __restrict__ __restrict _Restrict restrict; do
878 AC_COMPILE_IFELSE(
879 [AC_LANG_PROGRAM(
880 [[typedef int *int_ptr;
881 int foo (int_ptr $ac_kw ip) { return ip[0]; }
882 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
883 int bar (int ip[$ac_kw]) { return ip[0]; }
884 ]],
885 [[int s[1];
886 int *$ac_kw t = s;
887 t[0] = 0;
888 return foo (t) + bar (t);
889 ]])],
890 [ac_cv_c_restrict=$ac_kw])
891 test "$ac_cv_c_restrict" != no && break
892 done
893 ])
894 AH_VERBATIM([restrict],
895 [/* Define to the equivalent of the C99 'restrict' keyword, or to
896 nothing if this is not supported. Do not define if restrict is
897 supported only directly. */
898 #undef restrict
899 /* Work around a bug in older versions of Sun C++, which did not
900 #define __restrict__ or support _Restrict or __restrict__
901 even though the corresponding Sun C compiler ended up with
902 "#define restrict _Restrict" or "#define restrict __restrict__"
903 in the previous line. This workaround can be removed once
904 we assume Oracle Developer Studio 12.5 (2016) or later. */
905 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
906 # define _Restrict
907 # define __restrict__
908 #endif])
909 case $ac_cv_c_restrict in
910 restrict) ;;
911 no) AC_DEFINE([restrict], []) ;;
912 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
913 esac
914 ])# AC_C_RESTRICT
915 ])
916
917 # gl_BIGENDIAN
918 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
919 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
920 # macros invoke AC_C_BIGENDIAN with arguments.
921 AC_DEFUN([gl_BIGENDIAN],
922 [
923 AC_C_BIGENDIAN
924 ])
925
926 # A temporary file descriptor.
927 # Must be less than 10, because dash 0.5.8 does not support redirections
928 # with multi-digit file descriptors.
929 m4_define([GL_TMP_FD], 9)
930
931 # gl_SILENT(command)
932 # executes command, but without the normal configure output.
933 # This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
934 # inside another AC_CACHE_CHECK.
935 AC_DEFUN([gl_SILENT],
936 [
937 exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
938 $1
939 exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
940 ])
941
942 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
943 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
944 # output a spurious "(cached)" mark in the midst of other configure output.
945 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
946 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
947 AC_DEFUN([gl_CACHE_VAL_SILENT],
948 [
949 gl_SILENT([
950 AC_CACHE_VAL([$1], [$2])
951 ])
952 ])
953
954 # gl_CONDITIONAL(conditional, condition)
955 # is like AM_CONDITIONAL(conditional, condition), except that it does not
956 # produce an error
957 # configure: error: conditional "..." was never defined.
958 # Usually this means the macro was only invoked conditionally.
959 # when only invoked conditionally. Instead, in that case, both the _TRUE
960 # and the _FALSE case are disabled.
961 AC_DEFUN([gl_CONDITIONAL],
962 [
963 pushdef([AC_CONFIG_COMMANDS_PRE], [:])dnl
964 AM_CONDITIONAL([$1], [$2])
965 popdef([AC_CONFIG_COMMANDS_PRE])dnl
966 if test -z "${[$1]_TRUE}" && test -z "${[$1]_FALSE}"; then
967 [$1]_TRUE='#'
968 [$1]_FALSE='#'
969 fi
970 ])
971
972 # gl_CC_ALLOW_WARNINGS
973 # sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
974 # that reverts a preceding '-Werror' option, if available.
975 # This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
976 # and empty otherwise.
977 AC_DEFUN([gl_CC_ALLOW_WARNINGS],
978 [
979 AC_REQUIRE([AC_PROG_CC])
980 AC_CACHE_CHECK([for C compiler option to allow warnings],
981 [gl_cv_cc_wallow],
982 [rm -f conftest*
983 echo 'int dummy;' > conftest.c
984 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
985 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
986 dnl Test the number of error output lines, because AIX xlc accepts the
987 dnl option '-Wno-error', just to produce a warning
988 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
989 dnl afterwards.
990 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
991 gl_cv_cc_wallow='-Wno-error'
992 else
993 gl_cv_cc_wallow=none
994 fi
995 rm -f conftest*
996 ])
997 case "$gl_cv_cc_wallow" in
998 none) GL_CFLAG_ALLOW_WARNINGS='' ;;
999 *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
1000 esac
1001 AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
1002 ])
1003
1004 # gl_CXX_ALLOW_WARNINGS
1005 # sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
1006 # that reverts a preceding '-Werror' option, if available.
1007 AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
1008 [
1009 dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
1010 if test -n "$CXX" && test "$CXX" != no; then
1011 AC_CACHE_CHECK([for C++ compiler option to allow warnings],
1012 [gl_cv_cxx_wallow],
1013 [rm -f conftest*
1014 echo 'int dummy;' > conftest.cc
1015 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
1016 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
1017 dnl Test the number of error output lines, because AIX xlC accepts the
1018 dnl option '-Wno-error', just to produce a warning
1019 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
1020 dnl afterwards.
1021 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
1022 gl_cv_cxx_wallow='-Wno-error'
1023 else
1024 gl_cv_cxx_wallow=none
1025 fi
1026 rm -f conftest*
1027 ])
1028 case "$gl_cv_cxx_wallow" in
1029 none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
1030 *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
1031 esac
1032 else
1033 GL_CXXFLAG_ALLOW_WARNINGS=''
1034 fi
1035 AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
1036 ])
1037
1038 # gl_CC_GNULIB_WARNINGS
1039 # sets and substitutes a variable GL_CFLAG_GNULIB_WARNINGS, to a $(CC) option
1040 # set that enables or disables warnings as suitable for the Gnulib coding style.
1041 AC_DEFUN([gl_CC_GNULIB_WARNINGS],
1042 [
1043 AC_REQUIRE([gl_CC_ALLOW_WARNINGS])
1044 dnl Assume that the compiler supports -Wno-* options only if it also supports
1045 dnl -Wno-error.
1046 GL_CFLAG_GNULIB_WARNINGS=''
1047 if test -n "$GL_CFLAG_ALLOW_WARNINGS"; then
1048 dnl Enable these warning options:
1049 dnl
1050 dnl GCC clang
1051 dnl -Wno-cast-qual >= 3 >= 3.9
1052 dnl -Wno-conversion >= 3 >= 3.9
1053 dnl -Wno-float-conversion >= 4.9 >= 3.9
1054 dnl -Wno-float-equal >= 3 >= 3.9
1055 dnl -Wimplicit-fallthrough >= 7 >= 3.9
1056 dnl -Wno-pedantic >= 4.8 >= 3.9
1057 dnl -Wno-sign-compare >= 3 >= 3.9
1058 dnl -Wno-sign-conversion >= 4.3 >= 3.9
1059 dnl -Wno-type-limits >= 4.3 >= 3.9
1060 dnl -Wno-undef >= 3 >= 3.9
1061 dnl -Wno-unsuffixed-float-constants >= 4.5
1062 dnl -Wno-unused-function >= 3 >= 3.9
1063 dnl -Wno-unused-parameter >= 3 >= 3.9
1064 dnl
1065 cat > conftest.c <<\EOF
1066 #if __GNUC__ >= 3 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1067 -Wno-cast-qual
1068 -Wno-conversion
1069 -Wno-float-equal
1070 -Wno-sign-compare
1071 -Wno-undef
1072 -Wno-unused-function
1073 -Wno-unused-parameter
1074 #endif
1075 #if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1076 -Wno-float-conversion
1077 #endif
1078 #if __GNUC__ >= 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1079 -Wimplicit-fallthrough
1080 #endif
1081 #if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1082 -Wno-pedantic
1083 #endif
1084 #if __GNUC__ + (__GNUC_MINOR__ >= 3) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1085 -Wno-sign-conversion
1086 -Wno-type-limits
1087 #endif
1088 #if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
1089 -Wno-unsuffixed-float-constants
1090 #endif
1091 EOF
1092 gl_command="$CC $CFLAGS $CPPFLAGS -E conftest.c > conftest.out"
1093 if AC_TRY_EVAL([gl_command]); then
1094 gl_options=`grep -v '#' conftest.out`
1095 for word in $gl_options; do
1096 GL_CFLAG_GNULIB_WARNINGS="$GL_CFLAG_GNULIB_WARNINGS $word"
1097 done
1098 fi
1099 rm -f conftest.c conftest.out
1100 fi
1101 AC_SUBST([GL_CFLAG_GNULIB_WARNINGS])
1102 ])
1103
1104 dnl gl_CONDITIONAL_HEADER([foo.h])
1105 dnl takes a shell variable GL_GENERATE_FOO_H (with value true or false) as input
1106 dnl and produces
1107 dnl - an AC_SUBSTed variable FOO_H that is either a file name or empty, based
1108 dnl on whether GL_GENERATE_FOO_H is true or false,
1109 dnl - an Automake conditional GL_GENERATE_FOO_H that evaluates to the value of
1110 dnl the shell variable GL_GENERATE_FOO_H.
1111 AC_DEFUN([gl_CONDITIONAL_HEADER],
1112 [
1113 m4_pushdef([gl_header_name], AS_TR_SH(m4_toupper($1)))
1114 m4_pushdef([gl_generate_var], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1115 m4_pushdef([gl_generate_cond], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1116 case "$gl_generate_var" in
1117 false) gl_header_name='' ;;
1118 true)
1119 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
1120 dnl versa.
1121 if test -z "$gl_header_name"; then
1122 gl_header_name="${gl_source_base_prefix}$1"
1123 fi
1124 ;;
1125 *) echo "*** gl_generate_var is not set correctly" 1>&2; exit 1 ;;
1126 esac
1127 AC_SUBST(gl_header_name)
1128 gl_CONDITIONAL(gl_generate_cond, [$gl_generate_var])
1129 m4_popdef([gl_generate_cond])
1130 m4_popdef([gl_generate_var])
1131 m4_popdef([gl_header_name])
1132 ])
1133
1134 dnl Preparations for gl_CHECK_FUNCS_MACOS.
1135 AC_DEFUN([gl_PREPARE_CHECK_FUNCS_MACOS],
1136 [
1137 AC_REQUIRE([AC_CANONICAL_HOST])
1138 AC_REQUIRE([gl_COMPILER_CLANG])
1139 AC_CACHE_CHECK([for compiler option needed when checking for future declarations],
1140 [gl_cv_compiler_check_future_option],
1141 [case "$host_os" in
1142 dnl This is only needed on macOS.
1143 darwin*)
1144 if test $gl_cv_compiler_clang = yes; then
1145 dnl Test whether the compiler supports the option
1146 dnl '-Werror=unguarded-availability-new'.
1147 save_ac_compile="$ac_compile"
1148 ac_compile="$ac_compile -Werror=unguarded-availability-new"
1149 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
1150 [gl_cv_compiler_check_future_option='-Werror=unguarded-availability-new'],
1151 [gl_cv_compiler_check_future_option=none])
1152 ac_compile="$save_ac_compile"
1153 else
1154 gl_cv_compiler_check_future_option=none
1155 fi
1156 ;;
1157 *) gl_cv_compiler_check_future_option=none ;;
1158 esac
1159 ])
1160 ])
1161
1162 dnl Pieces of the expansion of
1163 dnl gl_CHECK_FUNCS_ANDROID
1164 dnl gl_CHECK_FUNCS_MACOS
1165 dnl gl_CHECK_FUNCS_ANDROID_MACOS
1166
1167 AC_DEFUN([gl_CHECK_FUNCS_DEFAULT_CASE],
1168 [
1169 *)
1170 AC_CHECK_FUNC([$1])
1171 [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
1172 ;;
1173 ])
1174
1175 AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_ANDROID],
1176 [
1177 linux*-android*)
1178 AC_CHECK_DECL([$1], , , [$2])
1179 if test $[ac_cv_have_decl_][$1] = yes; then
1180 AC_CHECK_FUNC([[$1]])
1181 if test $[ac_cv_func_][$1] = yes; then
1182 [gl_cv_onwards_func_][$1]=yes
1183 else
1184 dnl The function is declared but does not exist. This should not
1185 dnl happen normally. But anyway, we know that a future version
1186 dnl of Android will have the function.
1187 [gl_cv_onwards_func_][$1]='future OS version'
1188 fi
1189 else
1190 [gl_cv_onwards_func_][$1]='future OS version'
1191 fi
1192 ;;
1193 ])
1194
1195 AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_MACOS],
1196 [
1197 darwin*)
1198 if test "x$gl_cv_compiler_check_future_option" != "xnone"; then
1199 dnl Use a compile test, not a link test.
1200 save_ac_compile="$ac_compile"
1201 ac_compile="$ac_compile $gl_cv_compiler_check_future_option"
1202 save_ac_compile_for_check_decl="$ac_compile_for_check_decl"
1203 ac_compile_for_check_decl="$ac_compile_for_check_decl $gl_cv_compiler_check_future_option"
1204 unset [ac_cv_have_decl_][$1]
1205 AC_CHECK_DECL([$1], , , [$2])
1206 ac_compile="$save_ac_compile"
1207 ac_compile_for_check_decl="$save_ac_compile_for_check_decl"
1208 [ac_cv_func_][$1]="$[ac_cv_have_decl_][$1]"
1209 if test $[ac_cv_func_][$1] = yes; then
1210 [gl_cv_onwards_func_][$1]=yes
1211 else
1212 unset [ac_cv_have_decl_][$1]
1213 AC_CHECK_DECL([$1], , , [$2])
1214 if test $[ac_cv_have_decl_][$1] = yes; then
1215 [gl_cv_onwards_func_][$1]='future OS version'
1216 else
1217 [gl_cv_onwards_func_][$1]=no
1218 fi
1219 fi
1220 else
1221 AC_CHECK_FUNC([$1])
1222 [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
1223 fi
1224 ;;
1225 ])
1226
1227 AC_DEFUN([gl_CHECK_FUNCS_SET_RESULTS],
1228 [
1229 case "$[gl_cv_onwards_func_][$1]" in
1230 future*) [ac_cv_func_][$1]=no ;;
1231 *) [ac_cv_func_][$1]=$[gl_cv_onwards_func_][$1] ;;
1232 esac
1233 if test $[ac_cv_func_][$1] = yes; then
1234 AC_DEFINE([HAVE_]m4_translit([[$1]],
1235 [abcdefghijklmnopqrstuvwxyz],
1236 [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
1237 [1], [Define to 1 if you have the `$1' function.])
1238 fi
1239 ])
1240
1241 dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
1242 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1243 dnl on Android.
1244 dnl
1245 dnl When code is compiled on Android, it is in the context of a certain
1246 dnl "Android API level", which indicates the minimum version of Android on
1247 dnl which the app can be installed. In other words, you don't compile for a
1248 dnl specific version of Android. You compile for all versions of Android,
1249 dnl onwards from the given API level.
1250 dnl Thus, the question "does the OS have the function func" has three possible
1251 dnl answers:
1252 dnl - yes, in all versions starting from the given API level,
1253 dnl - no, in no version,
1254 dnl - not in the given API level, but in a later version of Android.
1255 dnl
1256 dnl In detail, this works as follows:
1257 dnl If func was added to Android API level, say, 28, then the libc.so has the
1258 dnl symbol func always, whereas the header file <foo.h> declares func
1259 dnl conditionally:
1260 dnl #if __ANDROID_API__ >= 28
1261 dnl ... func (...) __INTRODUCED_IN(28);
1262 dnl #endif
1263 dnl Thus, when compiling with "clang -target armv7a-unknown-linux-android28",
1264 dnl the function func is declared and exists in libc.
1265 dnl Whereas when compiling with "clang -target armv7a-unknown-linux-android27",
1266 dnl the function func is not declared but exists in libc.
1267 dnl
1268 dnl This macro sets two variables:
1269 dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
1270 dnl - ac_cv_func_<func> to yes / no / no
1271 dnl The first variable allows to distinguish all three cases.
1272 dnl The second variable is set, so that an invocation
1273 dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
1274 dnl can be used as a drop-in replacement for
1275 dnl AC_CHECK_FUNCS([func]).
1276 AC_DEFUN([gl_CHECK_FUNCS_ANDROID],
1277 [
1278 AC_REQUIRE([AC_CANONICAL_HOST])
1279 AC_CACHE_CHECK([for [$1]],
1280 [[gl_cv_onwards_func_][$1]],
1281 [gl_SILENT([
1282 case "$host_os" in
1283 gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
1284 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1285 esac
1286 ])
1287 ])
1288 gl_CHECK_FUNCS_SET_RESULTS([$1])
1289 ])
1290
1291 dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
1292 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1293 dnl on macOS.
1294 dnl
1295 dnl When code is compiled on macOS, it is in the context of a certain minimum
1296 dnl macOS version, that can be set through the option '-mmacosx-version-min='.
1297 dnl In other words, you don't compile for a specific version of macOS. You
1298 dnl compile for all versions of macOS, onwards from the given version.
1299 dnl Thus, the question "does the OS have the function func" has three possible
1300 dnl answers:
1301 dnl - yes, in all versions starting from the given version,
1302 dnl - no, in no version,
1303 dnl - not in the given version, but in a later version of macOS.
1304 dnl
1305 dnl In detail, this works as follows:
1306 dnl If func was added to, say, macOS version 13, then the libc has the
1307 dnl symbol func always, whereas the header file <foo.h> declares func
1308 dnl conditionally with a special availability attribute:
1309 dnl ... func (...) __attribute__((availability(macos,introduced=13.0)));
1310 dnl Thus, when compiling with "clang mmacosx-version-min=13", there is no
1311 dnl warning about the use of func, and the resulting binary
1312 dnl - runs fine on macOS 13,
1313 dnl - aborts with a dyld "Symbol not found" message on macOS 12.
1314 dnl Whereas, when compiling with "clang mmacosx-version-min=12", there is a
1315 dnl warning: 'func' is only available on macOS 13.0 or newer
1316 dnl [-Wunguarded-availability-new],
1317 dnl and the resulting binary
1318 dnl - runs fine on macOS 13,
1319 dnl - crashes with a SIGSEGV (signal 11) on macOS 12.
1320 dnl
1321 dnl This macro sets two variables:
1322 dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
1323 dnl - ac_cv_func_<func> to yes / no / no
1324 dnl The first variable allows to distinguish all three cases.
1325 dnl The second variable is set, so that an invocation
1326 dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
1327 dnl can be used as a drop-in replacement for
1328 dnl AC_CHECK_FUNCS([func]).
1329 AC_DEFUN([gl_CHECK_FUNCS_MACOS],
1330 [
1331 AC_REQUIRE([AC_CANONICAL_HOST])
1332 AC_REQUIRE([gl_PREPARE_CHECK_FUNCS_MACOS])
1333 AC_CACHE_CHECK([for [$1]],
1334 [[gl_cv_onwards_func_][$1]],
1335 [gl_SILENT([
1336 case "$host_os" in
1337 gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
1338 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1339 esac
1340 ])
1341 ])
1342 gl_CHECK_FUNCS_SET_RESULTS([$1])
1343 ])
1344
1345 dnl gl_CHECK_FUNCS_ANDROID_MACOS([func], [[#include <foo.h>]])
1346 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1347 dnl on Android and on macOS.
1348 dnl It is the combination of gl_CHECK_FUNCS_ANDROID and gl_CHECK_FUNCS_MACOS.
1349 AC_DEFUN([gl_CHECK_FUNCS_ANDROID_MACOS],
1350 [
1351 AC_REQUIRE([AC_CANONICAL_HOST])
1352 AC_REQUIRE([gl_PREPARE_CHECK_FUNCS_MACOS])
1353 AC_CACHE_CHECK([for [$1]],
1354 [[gl_cv_onwards_func_][$1]],
1355 [gl_SILENT([
1356 case "$host_os" in
1357 gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
1358 gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
1359 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1360 esac
1361 ])
1362 ])
1363 gl_CHECK_FUNCS_SET_RESULTS([$1])
1364 ])
1365
1366 dnl Expands to some code for use in .c programs that, on native Windows, defines
1367 dnl the Microsoft deprecated alias function names to the underscore-prefixed
1368 dnl actual function names. With this macro, these function names are available
1369 dnl without linking with '-loldnames' and without generating warnings.
1370 dnl Usage: Use it after all system header files are included.
1371 dnl #include <...>
1372 dnl #include <...>
1373 dnl ]GL_MDA_DEFINES[
1374 dnl ...
1375 AC_DEFUN([GL_MDA_DEFINES],[
1376 AC_REQUIRE([_GL_MDA_DEFINES])
1377 [$gl_mda_defines]
1378 ])
1379 AC_DEFUN([_GL_MDA_DEFINES],
1380 [gl_mda_defines='
1381 #if defined _WIN32 && !defined __CYGWIN__
1382 #define access _access
1383 #define chdir _chdir
1384 #define chmod _chmod
1385 #define close _close
1386 #define creat _creat
1387 #define dup _dup
1388 #define dup2 _dup2
1389 #define ecvt _ecvt
1390 #define execl _execl
1391 #define execle _execle
1392 #define execlp _execlp
1393 #define execv _execv
1394 #define execve _execve
1395 #define execvp _execvp
1396 #define execvpe _execvpe
1397 #define fcloseall _fcloseall
1398 #define fcvt _fcvt
1399 #define fdopen _fdopen
1400 #define fileno _fileno
1401 #define gcvt _gcvt
1402 #define getcwd _getcwd
1403 #define getpid _getpid
1404 #define getw _getw
1405 #define isatty _isatty
1406 #define j0 _j0
1407 #define j1 _j1
1408 #define jn _jn
1409 #define lfind _lfind
1410 #define lsearch _lsearch
1411 #define lseek _lseek
1412 #define memccpy _memccpy
1413 #define mkdir _mkdir
1414 #define mktemp _mktemp
1415 #define open _open
1416 #define putenv _putenv
1417 #define putw _putw
1418 #define read _read
1419 #define rmdir _rmdir
1420 #define strdup _strdup
1421 #define swab _swab
1422 #define tempnam _tempnam
1423 #define tzset _tzset
1424 #define umask _umask
1425 #define unlink _unlink
1426 #define utime _utime
1427 #define wcsdup _wcsdup
1428 #define write _write
1429 #define y0 _y0
1430 #define y1 _y1
1431 #define yn _yn
1432 #endif
1433 '
1434 ])