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