Debian Codegraph @

m4/gnulib-common.m4

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