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