summaryrefslogtreecommitdiffstats
path: root/gl/m4/gnulib-common.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/gnulib-common.m4')
-rw-r--r--gl/m4/gnulib-common.m41022
1 files changed, 898 insertions, 124 deletions
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4
index 0ae5a9e..facc340 100644
--- a/gl/m4/gnulib-common.m4
+++ b/gl/m4/gnulib-common.m4
@@ -1,25 +1,59 @@
1# gnulib-common.m4 serial 33 1# gnulib-common.m4 serial 75a
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2023 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 __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
21# define _Noreturn __attribute__ ((__noreturn__)) 55# define _Noreturn __attribute__ ((__noreturn__))
22# elif defined _MSC_VER && 1200 <= _MSC_VER 56# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
23# define _Noreturn __declspec (noreturn) 57# define _Noreturn __declspec (noreturn)
24# else 58# else
25# define _Noreturn 59# define _Noreturn
@@ -36,33 +70,519 @@ AC_DEFUN([gl_COMMON_BODY], [
36#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__ 70#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
37# define __GNUC_STDC_INLINE__ 1 71# define __GNUC_STDC_INLINE__ 1
38#endif]) 72#endif])
39 AH_VERBATIM([unused_parameter], 73 AH_VERBATIM([attribute],
40[/* Define as a marker that can be attached to declarations that might not 74[/* Attributes. */
41 be used. This helps to reduce warnings, such as from 75#if (defined __has_attribute \
42 GCC -Wunused-parameter. */ 76 && (!defined __clang_minor__ \
43#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 77 || (defined __apple_build_version__ \
44# define _GL_UNUSED __attribute__ ((__unused__)) 78 ? 6000000 <= __apple_build_version__ \
79 : 3 < __clang_major__ + (5 <= __clang_minor__))))
80# define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
45#else 81#else
46# define _GL_UNUSED 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)
47#endif 111#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 112
52/* The __pure__ attribute was added in gcc 2.96. */ 113/* Disable GCC -Wpedantic if using __has_c_attribute and this is not C23+. */
53#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 114#if (defined __has_c_attribute && _GL_GNUC_PREREQ (4, 6) \
54# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) 115 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710)
55#else 116# pragma GCC diagnostic ignored "-Wpedantic"
56# define _GL_ATTRIBUTE_PURE /* empty */
57#endif 117#endif
58 118
59/* The __const__ attribute was added in gcc 2.95. */ 119]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead.
60#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 120[
61# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__)) 121/* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
62#else 122 is the size of the returned memory block.
63# define _GL_ATTRIBUTE_CONST /* empty */ 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. */
355#ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
356# ifdef __has_c_attribute
357# if __has_c_attribute (__maybe_unused__)
358# define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
359# endif
360# endif
361# ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
362# define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
363# endif
364#endif
365/* Alternative spelling of this macro, for convenience and for
366 compatibility with glibc/include/libc-symbols.h. */
367#define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
368/* Earlier spellings of this macro. */
369#define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
370
371/* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not
372 discard the return value. The compiler may warn if the caller does not use
373 the return value, unless the caller uses something like ignore_value. */
374/* Applies to: function, enumeration, class. */
375#ifndef _GL_ATTRIBUTE_NODISCARD
376# ifdef __has_c_attribute
377# if __has_c_attribute (__nodiscard__)
378# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
379# endif
380# endif
381# if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE (warn_unused_result)
382# define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
383# endif
384# ifndef _GL_ATTRIBUTE_NODISCARD
385# define _GL_ATTRIBUTE_NODISCARD
386# endif
387#endif
388
389/* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the
390 function. */
391/* Applies to: functions. */
392#ifndef _GL_ATTRIBUTE_NOINLINE
393# if _GL_HAS_ATTRIBUTE (noinline)
394# define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
395# else
396# define _GL_ATTRIBUTE_NOINLINE
397# endif
398#endif
399
400/* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,...
401 must not be NULL.
402 _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be
403 null. */
404/* Applies to: functions. */
405#ifndef _GL_ATTRIBUTE_NONNULL
406# if _GL_HAS_ATTRIBUTE (nonnull)
407# define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
408# else
409# define _GL_ATTRIBUTE_NONNULL(args)
410# endif
411#endif
412
413/* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
414 not meant to be NUL-terminated. */
415/* Applies to: struct/union members and variables that are arrays of element
416 type '[[un]signed] char'. */
417#ifndef _GL_ATTRIBUTE_NONSTRING
418# if _GL_HAS_ATTRIBUTE (nonstring)
419# define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
420# else
421# define _GL_ATTRIBUTE_NONSTRING
422# endif
423#endif
424
425/* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
426
427/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
428 */
429/* Applies to: functions. */
430#ifndef _GL_ATTRIBUTE_NOTHROW
431# if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
432# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
433# else
434# define _GL_ATTRIBUTE_NOTHROW
435# endif
436#endif
437
438/* _GL_ATTRIBUTE_PACKED declares:
439 For struct members: The member has the smallest possible alignment.
440 For struct, union, class: All members have the smallest possible alignment,
441 minimizing the memory required. */
442/* Applies to: struct members, struct, union,
443 in C++ also: class. */
444#ifndef _GL_ATTRIBUTE_PACKED
445# if _GL_HAS_ATTRIBUTE (packed)
446# define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
447# else
448# define _GL_ATTRIBUTE_PACKED
449# endif
450#endif
451
452/* _GL_ATTRIBUTE_PURE declares that It is OK for a compiler to omit duplicate
453 calls to the function with the same arguments if observable state is not
454 changed between calls.
455 This attribute is safe for a function that does not affect
456 observable state, and always returns exactly once.
457 (This attribute is looser than _GL_ATTRIBUTE_CONST.) */
458/* Applies to: functions. */
459#ifndef _GL_ATTRIBUTE_PURE
460# if _GL_HAS_ATTRIBUTE (pure)
461# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
462# else
463# define _GL_ATTRIBUTE_PURE
464# endif
465#endif
466
467/* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is
468 a non-NULL pointer. */
469/* Applies to: functions. */
470#ifndef _GL_ATTRIBUTE_RETURNS_NONNULL
471# if _GL_HAS_ATTRIBUTE (returns_nonnull)
472# define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
473# else
474# define _GL_ATTRIBUTE_RETURNS_NONNULL
475# endif
476#endif
477
478/* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a
479 trailing NULL argument.
480 _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
481 _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
482/* Applies to: functions. */
483#ifndef _GL_ATTRIBUTE_SENTINEL
484# if _GL_HAS_ATTRIBUTE (sentinel)
485# define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
486# else
487# define _GL_ATTRIBUTE_SENTINEL(pos)
488# endif
489#endif
490
491/* A helper macro. Don't use it directly. */
492#ifndef _GL_ATTRIBUTE_UNUSED
493# if _GL_HAS_ATTRIBUTE (unused)
494# define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
495# else
496# define _GL_ATTRIBUTE_UNUSED
497# endif
498#endif
499
500]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
501[
502/* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the
503 immediately preceding label is not used. The compiler should not warn
504 if the label is not used. */
505/* Applies to: label (both in C and C++). */
506/* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;'
507 syntax. But clang does. */
508#ifndef _GL_UNUSED_LABEL
509# if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__
510# define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
511# else
512# define _GL_UNUSED_LABEL
513# endif
64#endif 514#endif
65]) 515])
516 AH_VERBATIM([async_safe],
517[/* The _GL_ASYNC_SAFE marker should be attached to functions that are
518 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
519 invoked from such signal handlers. Such functions have some restrictions:
520 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
521 or should be listed as async-signal-safe in POSIX
522 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
523 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
524 particular, are NOT async-signal-safe.
525 * All memory locations (variables and struct fields) that these functions
526 access must be marked 'volatile'. This holds for both read and write
527 accesses. Otherwise the compiler might optimize away stores to and
528 reads from such locations that occur in the program, depending on its
529 data flow analysis. For example, when the program contains a loop
530 that is intended to inspect a variable set from within a signal handler
531 while (!signal_occurred)
532 ;
533 the compiler is allowed to transform this into an endless loop if the
534 variable 'signal_occurred' is not declared 'volatile'.
535 Additionally, recall that:
536 * A signal handler should not modify errno (except if it is a handler
537 for a fatal signal and ends by raising the same signal again, thus
538 provoking the termination of the process). If it invokes a function
539 that may clobber errno, it needs to save and restore the value of
540 errno. */
541#define _GL_ASYNC_SAFE
542])
543 AH_VERBATIM([micro_optimizations],
544[/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
545 n1 and n2 are expressions without side effects, that evaluate to real
546 numbers (excluding NaN).
547 It returns
548 1 if n1 > n2
549 0 if n1 == n2
550 -1 if n1 < n2
551 The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
552 jump with nearly all GCC versions up to GCC 10.
553 This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
554 GCC versions up to GCC 9.
555 The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
556 avoids conditional jumps in all GCC versions >= 3.4. */
557#define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
558])
559 dnl Hint which direction to take regarding cross-compilation guesses:
560 dnl When a user installs a program on a platform they are not intimately
561 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
562 dnl choice. It implements the "If we don't know, assume the worst" principle.
563 dnl However, when an operating system developer (on a platform which is not
564 dnl yet known to gnulib) builds packages for their platform, they want to
565 dnl expose, not hide, possible platform bugs; in this case,
566 dnl --enable-cross-guesses=risky is the appropriate choice.
567 dnl Sets the variables
568 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
569 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
570 AC_ARG_ENABLE([cross-guesses],
571 [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
572 [specify policy for cross-compilation guesses])],
573 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
574 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
575 enableval=conservative
576 fi
577 gl_cross_guesses="$enableval"],
578 [gl_cross_guesses=conservative])
579 if test $gl_cross_guesses = risky; then
580 gl_cross_guess_normal="guessing yes"
581 gl_cross_guess_inverted="guessing no"
582 else
583 gl_cross_guess_normal="guessing no"
584 gl_cross_guess_inverted="guessing yes"
585 fi
66 dnl Preparation for running test programs: 586 dnl Preparation for running test programs:
67 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not 587 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 588 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
@@ -71,6 +591,16 @@ AC_DEFUN([gl_COMMON_BODY], [
71 export LIBC_FATAL_STDERR_ 591 export LIBC_FATAL_STDERR_
72]) 592])
73 593
594# gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
595# gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
596# initializes the shell variable that indicates the presence of the given module
597# as a C preprocessor expression.
598AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
599[
600 GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
601 AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
602])
603
74# gl_MODULE_INDICATOR_CONDITION 604# gl_MODULE_INDICATOR_CONDITION
75# expands to a C preprocessor expression that evaluates to 1 or 0, depending 605# 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 606# whether a gnulib module that has been requested shall be considered present
@@ -83,9 +613,9 @@ m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
83AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE], 613AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
84[ 614[
85 gl_MODULE_INDICATOR_SET_VARIABLE_AUX( 615 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
86 [GNULIB_[]m4_translit([[$1]], 616 [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
87 [abcdefghijklmnopqrstuvwxyz./-], 617 [abcdefghijklmnopqrstuvwxyz./-],
88 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])], 618 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
89 [gl_MODULE_INDICATOR_CONDITION]) 619 [gl_MODULE_INDICATOR_CONDITION])
90]) 620])
91 621
@@ -197,42 +727,20 @@ AC_DEFUN([gl_FEATURES_H],
197 AC_SUBST([HAVE_FEATURES_H]) 727 AC_SUBST([HAVE_FEATURES_H])
198]) 728])
199 729
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 730# gl_PROG_CC_C99
216# Modifies the value of the shell variable CC in an attempt to make $CC 731# Modifies the value of the shell variable CC in an attempt to make $CC
217# understand ISO C99 source code. 732# 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], 733AC_DEFUN([gl_PROG_CC_C99],
230[ 734[
231 dnl Change that version number to the minimum Autoconf version that supports 735 dnl Just use AC_PROG_CC_C99.
232 dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls. 736 dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
233 m4_version_prereq([9.0], 737 dnl value of CC will contain the C99 enabling options twice. But this is only
234 [AC_REQUIRE([AC_PROG_CC_C99])], 738 dnl a cosmetic problem.
235 [AC_REQUIRE([AC_PROG_CC_STDC])]) 739 dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
740 dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
741 m4_version_prereq([2.70],
742 [AC_REQUIRE([AC_PROG_CC])],
743 [AC_REQUIRE([AC_PROG_CC_C99])])
236]) 744])
237 745
238# gl_PROG_AR_RANLIB 746# gl_PROG_AR_RANLIB
@@ -243,9 +751,11 @@ AC_DEFUN([gl_PROG_AR_RANLIB],
243[ 751[
244 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler 752 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 753 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 754 dnl library formats. In particular, the GNU binutils programs ar and ranlib
247 dnl produce libraries that work only with gcc, not with cc. 755 dnl produce libraries that work only with gcc, not with cc.
248 AC_REQUIRE([AC_PROG_CC]) 756 AC_REQUIRE([AC_PROG_CC])
757 dnl The '][' hides this use from 'aclocal'.
758 AC_BEFORE([$0], [A][M_PROG_AR])
249 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler], 759 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
250 [ 760 [
251 AC_EGREP_CPP([Amsterdam], 761 AC_EGREP_CPP([Amsterdam],
@@ -257,25 +767,39 @@ Amsterdam
257 [gl_cv_c_amsterdam_compiler=yes], 767 [gl_cv_c_amsterdam_compiler=yes],
258 [gl_cv_c_amsterdam_compiler=no]) 768 [gl_cv_c_amsterdam_compiler=no])
259 ]) 769 ])
260 if test -z "$AR"; then 770
261 if test $gl_cv_c_amsterdam_compiler = yes; then 771 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
772 dnl building with __ACK__.
773 if test $gl_cv_c_amsterdam_compiler = yes; then
774 if test -z "$AR"; then
262 AR='cc -c.a' 775 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 776 fi
274 else
275 if test -z "$ARFLAGS"; then 777 if test -z "$ARFLAGS"; then
276 ARFLAGS='cru' 778 ARFLAGS='-o'
277 fi 779 fi
780 else
781 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
782 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
783 dnl script on-demand, if not specified by ./configure of course).
784 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
785 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
786 dnl because AM_PROG_AR is written so it could re-set AR variable even for
787 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
788 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
789 dnl default value and automake should usually know them).
790 dnl
791 dnl The '][' hides this use from 'aclocal'.
792 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
278 fi 793 fi
794
795 dnl In case the code above has not helped with setting AR/ARFLAGS, use
796 dnl Automake-documented default values for AR and ARFLAGS, but prefer
797 dnl ${host}-ar over ar (useful for cross-compiling).
798 AC_CHECK_TOOL([AR], [ar], [ar])
799 if test -z "$ARFLAGS"; then
800 ARFLAGS='cr'
801 fi
802
279 AC_SUBST([AR]) 803 AC_SUBST([AR])
280 AC_SUBST([ARFLAGS]) 804 AC_SUBST([ARFLAGS])
281 if test -z "$RANLIB"; then 805 if test -z "$RANLIB"; then
@@ -289,46 +813,29 @@ Amsterdam
289 AC_SUBST([RANLIB]) 813 AC_SUBST([RANLIB])
290]) 814])
291 815
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 816# AC_C_RESTRICT
312# This definition overrides the AC_C_RESTRICT macro from autoconf 2.60..2.61, 817# 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++ 818# AC_C_RESTRICT macro from autoconf 2.60..2.70.
314# works. 819m4_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], 820AC_DEFUN([AC_C_RESTRICT],
319[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict], 821[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
320 [ac_cv_c_restrict=no 822 [ac_cv_c_restrict=no
321 # The order here caters to the fact that C++ does not require restrict. 823 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
322 for ac_kw in __restrict __restrict__ _Restrict restrict; do 824 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
323 AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 825 # Put 'restrict' last, because C++ lacks it.
324 [[typedef int * int_ptr; 826 for ac_kw in __restrict__ __restrict _Restrict restrict; do
325 int foo (int_ptr $ac_kw ip) { 827 AC_COMPILE_IFELSE(
326 return ip[0]; 828 [AC_LANG_PROGRAM(
327 }]], 829 [[typedef int *int_ptr;
328 [[int s[1]; 830 int foo (int_ptr $ac_kw ip) { return ip[0]; }
329 int * $ac_kw t = s; 831 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
330 t[0] = 0; 832 int bar (int ip[$ac_kw]) { return ip[0]; }
331 return foo(t)]])], 833 ]],
834 [[int s[1];
835 int *$ac_kw t = s;
836 t[0] = 0;
837 return foo (t) + bar (t);
838 ]])],
332 [ac_cv_c_restrict=$ac_kw]) 839 [ac_cv_c_restrict=$ac_kw])
333 test "$ac_cv_c_restrict" != no && break 840 test "$ac_cv_c_restrict" != no && break
334 done 841 done
@@ -336,22 +843,24 @@ AC_DEFUN([AC_C_RESTRICT],
336 AH_VERBATIM([restrict], 843 AH_VERBATIM([restrict],
337[/* Define to the equivalent of the C99 'restrict' keyword, or to 844[/* Define to the equivalent of the C99 'restrict' keyword, or to
338 nothing if this is not supported. Do not define if restrict is 845 nothing if this is not supported. Do not define if restrict is
339 supported directly. */ 846 supported only directly. */
340#undef restrict 847#undef restrict
341/* Work around a bug in Sun C++: it does not support _Restrict, even 848/* Work around a bug in older versions of Sun C++, which did not
342 though the corresponding Sun C compiler does, which causes 849 #define __restrict__ or support _Restrict or __restrict__
343 "#define restrict _Restrict" in the previous line. Perhaps some future 850 even though the corresponding Sun C compiler ended up with
344 version of Sun C++ will work with _Restrict; if so, it'll probably 851 "#define restrict _Restrict" or "#define restrict __restrict__"
345 define __RESTRICT, just as Sun C does. */ 852 in the previous line. This workaround can be removed once
346#if defined __SUNPRO_CC && !defined __RESTRICT 853 we assume Oracle Developer Studio 12.5 (2016) or later. */
854#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
347# define _Restrict 855# define _Restrict
856# define __restrict__
348#endif]) 857#endif])
349 case $ac_cv_c_restrict in 858 case $ac_cv_c_restrict in
350 restrict) ;; 859 restrict) ;;
351 no) AC_DEFINE([restrict], []) ;; 860 no) AC_DEFINE([restrict], []) ;;
352 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;; 861 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
353 esac 862 esac
354]) 863])# AC_C_RESTRICT
355]) 864])
356 865
357# gl_BIGENDIAN 866# gl_BIGENDIAN
@@ -363,6 +872,22 @@ AC_DEFUN([gl_BIGENDIAN],
363 AC_C_BIGENDIAN 872 AC_C_BIGENDIAN
364]) 873])
365 874
875# A temporary file descriptor.
876# Must be less than 10, because dash 0.5.8 does not support redirections
877# with multi-digit file descriptors.
878m4_define([GL_TMP_FD], 9)
879
880# gl_SILENT(command)
881# executes command, but without the normal configure output.
882# This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
883# inside another AC_CACHE_CHECK.
884AC_DEFUN([gl_SILENT],
885[
886 exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
887 $1
888 exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
889])
890
366# gl_CACHE_VAL_SILENT(cache-id, command-to-set-it) 891# 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 892# 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. 893# output a spurious "(cached)" mark in the midst of other configure output.
@@ -370,8 +895,257 @@ AC_DEFUN([gl_BIGENDIAN],
370# by an AC_MSG_CHECKING/AC_MSG_RESULT pair. 895# by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
371AC_DEFUN([gl_CACHE_VAL_SILENT], 896AC_DEFUN([gl_CACHE_VAL_SILENT],
372[ 897[
373 saved_as_echo_n="$as_echo_n" 898 gl_SILENT([
374 as_echo_n=':' 899 AC_CACHE_VAL([$1], [$2])
375 AC_CACHE_VAL([$1], [$2]) 900 ])
376 as_echo_n="$saved_as_echo_n" 901])
902
903# gl_CONDITIONAL(conditional, condition)
904# is like AM_CONDITIONAL(conditional, condition), except that it does not
905# produce an error
906# configure: error: conditional "..." was never defined.
907# Usually this means the macro was only invoked conditionally.
908# when only invoked conditionally. Instead, in that case, both the _TRUE
909# and the _FALSE case are disabled.
910AC_DEFUN([gl_CONDITIONAL],
911[
912 pushdef([AC_CONFIG_COMMANDS_PRE], [:])dnl
913 AM_CONDITIONAL([$1], [$2])
914 popdef([AC_CONFIG_COMMANDS_PRE])dnl
915 if test -z "${[$1]_TRUE}" && test -z "${[$1]_FALSE}"; then
916 [$1]_TRUE='#'
917 [$1]_FALSE='#'
918 fi
919])
920
921# gl_CC_ALLOW_WARNINGS
922# sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
923# that reverts a preceding '-Werror' option, if available.
924# This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
925# and empty otherwise.
926AC_DEFUN([gl_CC_ALLOW_WARNINGS],
927[
928 AC_REQUIRE([AC_PROG_CC])
929 AC_CACHE_CHECK([for C compiler option to allow warnings],
930 [gl_cv_cc_wallow],
931 [rm -f conftest*
932 echo 'int dummy;' > conftest.c
933 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
934 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
935 dnl Test the number of error output lines, because AIX xlc accepts the
936 dnl option '-Wno-error', just to produce a warning
937 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
938 dnl afterwards.
939 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
940 gl_cv_cc_wallow='-Wno-error'
941 else
942 gl_cv_cc_wallow=none
943 fi
944 rm -f conftest*
945 ])
946 case "$gl_cv_cc_wallow" in
947 none) GL_CFLAG_ALLOW_WARNINGS='' ;;
948 *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
949 esac
950 AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
951])
952
953# gl_CXX_ALLOW_WARNINGS
954# sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
955# that reverts a preceding '-Werror' option, if available.
956AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
957[
958 dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
959 if test -n "$CXX" && test "$CXX" != no; then
960 AC_CACHE_CHECK([for C++ compiler option to allow warnings],
961 [gl_cv_cxx_wallow],
962 [rm -f conftest*
963 echo 'int dummy;' > conftest.cc
964 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
965 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
966 dnl Test the number of error output lines, because AIX xlC accepts the
967 dnl option '-Wno-error', just to produce a warning
968 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
969 dnl afterwards.
970 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
971 gl_cv_cxx_wallow='-Wno-error'
972 else
973 gl_cv_cxx_wallow=none
974 fi
975 rm -f conftest*
976 ])
977 case "$gl_cv_cxx_wallow" in
978 none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
979 *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
980 esac
981 else
982 GL_CXXFLAG_ALLOW_WARNINGS=''
983 fi
984 AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
985])
986
987# gl_CC_GNULIB_WARNINGS
988# sets and substitutes a variable GL_CFLAG_GNULIB_WARNINGS, to a $(CC) option
989# set that enables or disables warnings as suitable for the Gnulib coding style.
990AC_DEFUN([gl_CC_GNULIB_WARNINGS],
991[
992 AC_REQUIRE([gl_CC_ALLOW_WARNINGS])
993 dnl Assume that the compiler supports -Wno-* options only if it also supports
994 dnl -Wno-error.
995 GL_CFLAG_GNULIB_WARNINGS=''
996 if test -n "$GL_CFLAG_ALLOW_WARNINGS"; then
997 dnl Enable these warning options:
998 dnl
999 dnl GCC clang
1000 dnl -Wno-cast-qual >= 3 >= 3.9
1001 dnl -Wno-conversion >= 3 >= 3.9
1002 dnl -Wno-float-conversion >= 4.9 >= 3.9
1003 dnl -Wno-float-equal >= 3 >= 3.9
1004 dnl -Wimplicit-fallthrough >= 7 >= 3.9
1005 dnl -Wno-pedantic >= 4.8 >= 3.9
1006 dnl -Wno-sign-compare >= 3 >= 3.9
1007 dnl -Wno-sign-conversion >= 4.3 >= 3.9
1008 dnl -Wno-type-limits >= 4.3 >= 3.9
1009 dnl -Wno-undef >= 3 >= 3.9
1010 dnl -Wno-unsuffixed-float-constants >= 4.5
1011 dnl -Wno-unused-function >= 3 >= 3.9
1012 dnl -Wno-unused-parameter >= 3 >= 3.9
1013 dnl
1014 cat > conftest.c <<\EOF
1015 #if __GNUC__ >= 3 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1016 -Wno-cast-qual
1017 -Wno-conversion
1018 -Wno-float-equal
1019 -Wno-sign-compare
1020 -Wno-undef
1021 -Wno-unused-function
1022 -Wno-unused-parameter
1023 #endif
1024 #if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1025 -Wno-float-conversion
1026 #endif
1027 #if __GNUC__ >= 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1028 -Wimplicit-fallthrough
1029 #endif
1030 #if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1031 -Wno-pedantic
1032 #endif
1033 #if __GNUC__ + (__GNUC_MINOR__ >= 3) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1034 -Wno-sign-conversion
1035 -Wno-type-limits
1036 #endif
1037 #if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
1038 -Wno-unsuffixed-float-constants
1039 #endif
1040EOF
1041 gl_command="$CC $CFLAGS $CPPFLAGS -E conftest.c > conftest.out"
1042 if AC_TRY_EVAL([gl_command]); then
1043 gl_options=`grep -v '#' conftest.out`
1044 for word in $gl_options; do
1045 GL_CFLAG_GNULIB_WARNINGS="$GL_CFLAG_GNULIB_WARNINGS $word"
1046 done
1047 fi
1048 rm -f conftest.c conftest.out
1049 fi
1050 AC_SUBST([GL_CFLAG_GNULIB_WARNINGS])
1051])
1052
1053dnl gl_CONDITIONAL_HEADER([foo.h])
1054dnl takes a shell variable GL_GENERATE_FOO_H (with value true or false) as input
1055dnl and produces
1056dnl - an AC_SUBSTed variable FOO_H that is either a file name or empty, based
1057dnl on whether GL_GENERATE_FOO_H is true or false,
1058dnl - an Automake conditional GL_GENERATE_FOO_H that evaluates to the value of
1059dnl the shell variable GL_GENERATE_FOO_H.
1060AC_DEFUN([gl_CONDITIONAL_HEADER],
1061[
1062 m4_pushdef([gl_header_name], AS_TR_SH(m4_toupper($1)))
1063 m4_pushdef([gl_generate_var], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1064 m4_pushdef([gl_generate_cond], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1065 case "$gl_generate_var" in
1066 false) gl_header_name='' ;;
1067 true)
1068 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
1069 dnl versa.
1070 if test -z "$gl_header_name"; then
1071 gl_header_name="${gl_source_base_prefix}$1"
1072 fi
1073 ;;
1074 *) echo "*** gl_generate_var is not set correctly" 1>&2; exit 1 ;;
1075 esac
1076 AC_SUBST(gl_header_name)
1077 gl_CONDITIONAL(gl_generate_cond, [$gl_generate_var])
1078 m4_popdef([gl_generate_cond])
1079 m4_popdef([gl_generate_var])
1080 m4_popdef([gl_header_name])
1081])
1082
1083dnl Expands to some code for use in .c programs that, on native Windows, defines
1084dnl the Microsoft deprecated alias function names to the underscore-prefixed
1085dnl actual function names. With this macro, these function names are available
1086dnl without linking with '-loldnames' and without generating warnings.
1087dnl Usage: Use it after all system header files are included.
1088dnl #include <...>
1089dnl #include <...>
1090dnl ]GL_MDA_DEFINES[
1091dnl ...
1092AC_DEFUN([GL_MDA_DEFINES],[
1093AC_REQUIRE([_GL_MDA_DEFINES])
1094[$gl_mda_defines]
1095])
1096AC_DEFUN([_GL_MDA_DEFINES],
1097[gl_mda_defines='
1098#if defined _WIN32 && !defined __CYGWIN__
1099#define access _access
1100#define chdir _chdir
1101#define chmod _chmod
1102#define close _close
1103#define creat _creat
1104#define dup _dup
1105#define dup2 _dup2
1106#define ecvt _ecvt
1107#define execl _execl
1108#define execle _execle
1109#define execlp _execlp
1110#define execv _execv
1111#define execve _execve
1112#define execvp _execvp
1113#define execvpe _execvpe
1114#define fcloseall _fcloseall
1115#define fcvt _fcvt
1116#define fdopen _fdopen
1117#define fileno _fileno
1118#define gcvt _gcvt
1119#define getcwd _getcwd
1120#define getpid _getpid
1121#define getw _getw
1122#define isatty _isatty
1123#define j0 _j0
1124#define j1 _j1
1125#define jn _jn
1126#define lfind _lfind
1127#define lsearch _lsearch
1128#define lseek _lseek
1129#define memccpy _memccpy
1130#define mkdir _mkdir
1131#define mktemp _mktemp
1132#define open _open
1133#define putenv _putenv
1134#define putw _putw
1135#define read _read
1136#define rmdir _rmdir
1137#define strdup _strdup
1138#define swab _swab
1139#define tempnam _tempnam
1140#define tzset _tzset
1141#define umask _umask
1142#define unlink _unlink
1143#define utime _utime
1144#define wcsdup _wcsdup
1145#define write _write
1146#define y0 _y0
1147#define y1 _y1
1148#define yn _yn
1149#endif
1150'
377]) 1151])