Debian Codegraph @

m4/gnulib-common.m4

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