Imported Upstream version 3.8
[platform/upstream/diffutils.git] / m4 / gnulib-common.m4
1 # gnulib-common.m4 serial 66
2 dnl Copyright (C) 2007-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_PREREQ([2.62])
8
9 # gl_COMMON
10 # is expanded unconditionally through gnulib-tool magic.
11 AC_DEFUN([gl_COMMON], [
12   dnl Use AC_REQUIRE here, so that the code is expanded once only.
13   AC_REQUIRE([gl_00GNULIB])
14   AC_REQUIRE([gl_COMMON_BODY])
15   AC_REQUIRE([gl_ZZGNULIB])
16 ])
17 AC_DEFUN([gl_COMMON_BODY], [
18   AH_VERBATIM([_GL_GNUC_PREREQ],
19 [/* True if the compiler says it groks GNU C version MAJOR.MINOR.  */
20 #if defined __GNUC__ && defined __GNUC_MINOR__
21 # define _GL_GNUC_PREREQ(major, minor) \
22     ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__))
23 #else
24 # define _GL_GNUC_PREREQ(major, minor) 0
25 #endif
26 ])
27   AH_VERBATIM([_Noreturn],
28 [/* The _Noreturn keyword of C11.  */
29 #ifndef _Noreturn
30 # if (defined __cplusplus \
31       && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
32           || (defined _MSC_VER && 1900 <= _MSC_VER)) \
33       && 0)
34     /* [[noreturn]] is not practically usable, because with it the syntax
35          extern _Noreturn void func (...);
36        would not be valid; such a declaration would only be valid with 'extern'
37        and '_Noreturn' swapped, or without the 'extern' keyword.  However, some
38        AIX system header files and several gnulib header files use precisely
39        this syntax with 'extern'.  */
40 #  define _Noreturn [[noreturn]]
41 # elif ((!defined __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          || 3 < __clang_major__ + (5 <= __clang_minor__)))
73 # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
74 #else
75 # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
76 # define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
77 # define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
78 # define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
79 # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
80 # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
81 # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
82 # define _GL_ATTR_diagnose_if 0
83 # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
84 # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
85 # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
86 # define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
87 # define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
88 # ifdef _ICC
89 #  define _GL_ATTR_may_alias 0
90 # else
91 #  define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
92 # endif
93 # define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
94 # define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
95 # define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
96 # define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
97 # define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
98 # define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
99 # define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
100 # define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
101 # define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
102 # define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
103 # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
104 #endif
105
106 #ifdef __has_c_attribute
107 # define _GL_HAS_C_ATTRIBUTE(attr) __has_c_attribute (__##attr##__)
108 #else
109 # define _GL_HAS_C_ATTRIBUTE(attr) 0
110 #endif
111
112 ]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's _Alignas instead.
113 [
114 #if _GL_HAS_ATTRIBUTE (alloc_size)
115 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
116 #else
117 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
118 #endif
119
120 #if _GL_HAS_ATTRIBUTE (always_inline)
121 # define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
122 #else
123 # define _GL_ATTRIBUTE_ALWAYS_INLINE
124 #endif
125
126 #if _GL_HAS_ATTRIBUTE (artificial)
127 # define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
128 #else
129 # define _GL_ATTRIBUTE_ARTIFICIAL
130 #endif
131
132 /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
133    <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
134    Also, Oracle Studio 12.6 requires 'cold' not '__cold__'.  */
135 #if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
136 # ifndef __SUNPRO_C
137 #  define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
138 # else
139 #  define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
140 # endif
141 #else
142 # define _GL_ATTRIBUTE_COLD
143 #endif
144
145 #if _GL_HAS_ATTRIBUTE (const)
146 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
147 #else
148 # define _GL_ATTRIBUTE_CONST
149 #endif
150
151 /* _GL_ATTRIBUTE_DEALLOC (F, I) is for functions returning pointers
152    that can be freed by passing them as the Ith argument to the
153    function F.  _GL_ATTRIBUTE_DEALLOC_FREE is for functions that
154    return pointers that can be freed via 'free'; it can be used
155    only after including stdlib.h.  */
156 #if _GL_GNUC_PREREQ (11, 0)
157 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
158 #else
159 # define _GL_ATTRIBUTE_DEALLOC(f, i)
160 #endif
161 #define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
162
163 #if _GL_HAS_C_ATTRIBUTE (deprecated)
164 # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
165 #elif _GL_HAS_ATTRIBUTE (deprecated)
166 # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
167 #else
168 # define _GL_ATTRIBUTE_DEPRECATED
169 #endif
170
171 #if _GL_HAS_ATTRIBUTE (error)
172 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
173 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
174 #elif _GL_HAS_ATTRIBUTE (diagnose_if)
175 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
176 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
177 #else
178 # define _GL_ATTRIBUTE_ERROR(msg)
179 # define _GL_ATTRIBUTE_WARNING(msg)
180 #endif
181
182 #if _GL_HAS_ATTRIBUTE (externally_visible)
183 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
184 #else
185 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
186 #endif
187
188 /* FALLTHROUGH is special, because it always expands to something.  */
189 #if _GL_HAS_C_ATTRIBUTE (fallthrough)
190 # define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
191 #elif _GL_HAS_ATTRIBUTE (fallthrough)
192 # define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
193 #else
194 # define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
195 #endif
196
197 #if _GL_HAS_ATTRIBUTE (format)
198 # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
199 #else
200 # define _GL_ATTRIBUTE_FORMAT(spec)
201 #endif
202
203 #if _GL_HAS_ATTRIBUTE (leaf)
204 # define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
205 #else
206 # define _GL_ATTRIBUTE_LEAF
207 #endif
208
209 /* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK.  */
210 #if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
211 # define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
212 #else
213 # define _GL_ATTRIBUTE_MAY_ALIAS
214 #endif
215
216 #if _GL_HAS_C_ATTRIBUTE (maybe_unused)
217 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
218 #else
219 # define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
220 #endif
221 /* Earlier spellings of this macro.  */
222 #define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
223
224 #if _GL_HAS_ATTRIBUTE (malloc)
225 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
226 #else
227 # define _GL_ATTRIBUTE_MALLOC
228 #endif
229
230 #if _GL_HAS_C_ATTRIBUTE (nodiscard)
231 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
232 #elif _GL_HAS_ATTRIBUTE (warn_unused_result)
233 # define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
234 #else
235 # define _GL_ATTRIBUTE_NODISCARD
236 #endif
237
238 #if _GL_HAS_ATTRIBUTE (noinline)
239 # define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
240 #else
241 # define _GL_ATTRIBUTE_NOINLINE
242 #endif
243
244 #if _GL_HAS_ATTRIBUTE (nonnull)
245 # define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
246 #else
247 # define _GL_ATTRIBUTE_NONNULL(args)
248 #endif
249
250 #if _GL_HAS_ATTRIBUTE (nonstring)
251 # define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
252 #else
253 # define _GL_ATTRIBUTE_NONSTRING
254 #endif
255
256 /* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead.  */
257
258 #if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
259 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
260 #else
261 # define _GL_ATTRIBUTE_NOTHROW
262 #endif
263
264 #if _GL_HAS_ATTRIBUTE (packed)
265 # define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
266 #else
267 # define _GL_ATTRIBUTE_PACKED
268 #endif
269
270 #if _GL_HAS_ATTRIBUTE (pure)
271 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
272 #else
273 # define _GL_ATTRIBUTE_PURE
274 #endif
275
276 #if _GL_HAS_ATTRIBUTE (returns_nonnull)
277 # define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
278 #else
279 # define _GL_ATTRIBUTE_RETURNS_NONNULL
280 #endif
281
282 #if _GL_HAS_ATTRIBUTE (sentinel)
283 # define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
284 #else
285 # define _GL_ATTRIBUTE_SENTINEL(pos)
286 #endif
287
288 #if _GL_HAS_ATTRIBUTE (unused)
289 # define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
290 #else
291 # define _GL_ATTRIBUTE_UNUSED
292 #endif
293 /* Earlier spellings of this macro.  */
294 #define _GL_UNUSED _GL_ATTRIBUTE_UNUSED
295
296 ]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
297 [
298 /* To support C++ as well as C, use _GL_UNUSED_LABEL with trailing ';'.  */
299 #if !defined __cplusplus || _GL_GNUC_PREREQ (4, 5)
300 # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
301 #else
302 # define _GL_UNUSED_LABEL
303 #endif
304 ])
305   AH_VERBATIM([async_safe],
306 [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
307    signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
308    invoked from such signal handlers.  Such functions have some restrictions:
309      * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
310        or should be listed as async-signal-safe in POSIX
311        <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
312        section 2.4.3.  Note that malloc(), sprintf(), and fwrite(), in
313        particular, are NOT async-signal-safe.
314      * All memory locations (variables and struct fields) that these functions
315        access must be marked 'volatile'.  This holds for both read and write
316        accesses.  Otherwise the compiler might optimize away stores to and
317        reads from such locations that occur in the program, depending on its
318        data flow analysis.  For example, when the program contains a loop
319        that is intended to inspect a variable set from within a signal handler
320            while (!signal_occurred)
321              ;
322        the compiler is allowed to transform this into an endless loop if the
323        variable 'signal_occurred' is not declared 'volatile'.
324    Additionally, recall that:
325      * A signal handler should not modify errno (except if it is a handler
326        for a fatal signal and ends by raising the same signal again, thus
327        provoking the termination of the process).  If it invokes a function
328        that may clobber errno, it needs to save and restore the value of
329        errno.  */
330 #define _GL_ASYNC_SAFE
331 ])
332   AH_VERBATIM([micro_optimizations],
333 [/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
334    n1 and n2 are expressions without side effects, that evaluate to real
335    numbers (excluding NaN).
336    It returns
337      1  if n1 > n2
338      0  if n1 == n2
339      -1 if n1 < n2
340    The naïve code   (n1 > n2 ? 1 : n1 < n2 ? -1 : 0)  produces a conditional
341    jump with nearly all GCC versions up to GCC 10.
342    This variant     (n1 < n2 ? -1 : n1 > n2)  produces a conditional with many
343    GCC versions up to GCC 9.
344    The better code  (n1 > n2) - (n1 < n2)  from Hacker's Delight Â§ 2-9
345    avoids conditional jumps in all GCC versions >= 3.4.  */
346 #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
347 ])
348   dnl Hint which direction to take regarding cross-compilation guesses:
349   dnl When a user installs a program on a platform they are not intimately
350   dnl familiar with, --enable-cross-guesses=conservative is the appropriate
351   dnl choice.  It implements the "If we don't know, assume the worst" principle.
352   dnl However, when an operating system developer (on a platform which is not
353   dnl yet known to gnulib) builds packages for their platform, they want to
354   dnl expose, not hide, possible platform bugs; in this case,
355   dnl --enable-cross-guesses=risky is the appropriate choice.
356   dnl Sets the variables
357   dnl gl_cross_guess_normal    (to be used when 'yes' is good and 'no' is bad),
358   dnl gl_cross_guess_inverted  (to be used when 'no' is good and 'yes' is bad).
359   AC_ARG_ENABLE([cross-guesses],
360     [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
361        [specify policy for cross-compilation guesses])],
362     [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
363        AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
364        enableval=conservative
365      fi
366      gl_cross_guesses="$enableval"],
367     [gl_cross_guesses=conservative])
368   if test $gl_cross_guesses = risky; then
369     gl_cross_guess_normal="guessing yes"
370     gl_cross_guess_inverted="guessing no"
371   else
372     gl_cross_guess_normal="guessing no"
373     gl_cross_guess_inverted="guessing yes"
374   fi
375   dnl Preparation for running test programs:
376   dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
377   dnl to /dev/tty, so they can be redirected to log files.  Such diagnostics
378   dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
379   LIBC_FATAL_STDERR_=1
380   export LIBC_FATAL_STDERR_
381 ])
382
383 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
384 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
385 # initializes the shell variable that indicates the presence of the given module
386 # as a C preprocessor expression.
387 AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
388 [
389   GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
390   AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
391 ])
392
393 # gl_MODULE_INDICATOR_CONDITION
394 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
395 # whether a gnulib module that has been requested shall be considered present
396 # or not.
397 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
398
399 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
400 # sets the shell variable that indicates the presence of the given module to
401 # a C preprocessor expression that will evaluate to 1.
402 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
403 [
404   gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
405     [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
406                                                        [abcdefghijklmnopqrstuvwxyz./-],
407                                                        [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
408     [gl_MODULE_INDICATOR_CONDITION])
409 ])
410
411 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
412 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
413 # The shell variable's value is a C preprocessor expression that evaluates
414 # to 0 or 1.
415 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
416 [
417   m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
418     [
419      dnl Simplify the expression VALUE || 1 to 1.
420      $1=1
421     ],
422     [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
423                                              [gl_MODULE_INDICATOR_CONDITION])])
424 ])
425
426 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
427 # modifies the shell variable to include the given condition.  The shell
428 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
429 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
430 [
431   dnl Simplify the expression 1 || CONDITION to 1.
432   if test "$[]$1" != 1; then
433     dnl Simplify the expression 0 || CONDITION to CONDITION.
434     if test "$[]$1" = 0; then
435       $1=$2
436     else
437       $1="($[]$1 || $2)"
438     fi
439   fi
440 ])
441
442 # gl_MODULE_INDICATOR([modulename])
443 # defines a C macro indicating the presence of the given module
444 # in a location where it can be used.
445 #                                             |  Value  |   Value   |
446 #                                             | in lib/ | in tests/ |
447 # --------------------------------------------+---------+-----------+
448 # Module present among main modules:          |    1    |     1     |
449 # --------------------------------------------+---------+-----------+
450 # Module present among tests-related modules: |    0    |     1     |
451 # --------------------------------------------+---------+-----------+
452 # Module not present at all:                  |    0    |     0     |
453 # --------------------------------------------+---------+-----------+
454 AC_DEFUN([gl_MODULE_INDICATOR],
455 [
456   AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
457       [abcdefghijklmnopqrstuvwxyz./-],
458       [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
459     [gl_MODULE_INDICATOR_CONDITION],
460     [Define to a C preprocessor expression that evaluates to 1 or 0,
461      depending whether the gnulib module $1 shall be considered present.])
462 ])
463
464 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
465 # defines a C macro indicating the presence of the given module
466 # in lib or tests. This is useful to determine whether the module
467 # should be tested.
468 #                                             |  Value  |   Value   |
469 #                                             | in lib/ | in tests/ |
470 # --------------------------------------------+---------+-----------+
471 # Module present among main modules:          |    1    |     1     |
472 # --------------------------------------------+---------+-----------+
473 # Module present among tests-related modules: |    1    |     1     |
474 # --------------------------------------------+---------+-----------+
475 # Module not present at all:                  |    0    |     0     |
476 # --------------------------------------------+---------+-----------+
477 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
478 [
479   AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
480       [abcdefghijklmnopqrstuvwxyz./-],
481       [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
482     [Define to 1 when the gnulib module $1 should be tested.])
483 ])
484
485 # gl_ASSERT_NO_GNULIB_POSIXCHECK
486 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
487 # and thereby enables an optimization of configure and config.h.
488 # Used by Emacs.
489 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
490 [
491   dnl Override gl_WARN_ON_USE_PREPARE.
492   dnl But hide this definition from 'aclocal'.
493   AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
494 ])
495
496 # gl_ASSERT_NO_GNULIB_TESTS
497 # asserts that there will be no gnulib tests in the scope of the configure.ac
498 # and thereby enables an optimization of config.h.
499 # Used by Emacs.
500 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
501 [
502   dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
503   AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
504 ])
505
506 # Test whether <features.h> exists.
507 # Set HAVE_FEATURES_H.
508 AC_DEFUN([gl_FEATURES_H],
509 [
510   AC_CHECK_HEADERS_ONCE([features.h])
511   if test $ac_cv_header_features_h = yes; then
512     HAVE_FEATURES_H=1
513   else
514     HAVE_FEATURES_H=0
515   fi
516   AC_SUBST([HAVE_FEATURES_H])
517 ])
518
519 # gl_PROG_CC_C99
520 # Modifies the value of the shell variable CC in an attempt to make $CC
521 # understand ISO C99 source code.
522 AC_DEFUN([gl_PROG_CC_C99],
523 [
524   dnl Just use AC_PROG_CC_C99.
525   dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
526   dnl value of CC will contain the C99 enabling options twice. But this is only
527   dnl a cosmetic problem.
528   dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
529   dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
530   m4_version_prereq([2.70],
531     [AC_REQUIRE([AC_PROG_CC])],
532     [AC_REQUIRE([AC_PROG_CC_C99])])
533 ])
534
535 # gl_PROG_AR_RANLIB
536 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
537 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
538 # the values.
539 AC_DEFUN([gl_PROG_AR_RANLIB],
540 [
541   dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
542   dnl as "cc", and GCC as "gcc". They have different object file formats and
543   dnl library formats. In particular, the GNU binutils programs ar and ranlib
544   dnl produce libraries that work only with gcc, not with cc.
545   AC_REQUIRE([AC_PROG_CC])
546   dnl The '][' hides this use from 'aclocal'.
547   AC_BEFORE([$0], [A][M_PROG_AR])
548   AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
549     [
550       AC_EGREP_CPP([Amsterdam],
551         [
552 #ifdef __ACK__
553 Amsterdam
554 #endif
555         ],
556         [gl_cv_c_amsterdam_compiler=yes],
557         [gl_cv_c_amsterdam_compiler=no])
558     ])
559
560   dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
561   dnl building with __ACK__.
562   if test $gl_cv_c_amsterdam_compiler = yes; then
563     if test -z "$AR"; then
564       AR='cc -c.a'
565     fi
566     if test -z "$ARFLAGS"; then
567       ARFLAGS='-o'
568     fi
569   else
570     dnl AM_PROG_AR was added in automake v1.11.2.  AM_PROG_AR does not AC_SUBST
571     dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
572     dnl script on-demand, if not specified by ./configure of course).
573     dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
574     dnl will be ignored.  Also, pay attention to call AM_PROG_AR in else block
575     dnl because AM_PROG_AR is written so it could re-set AR variable even for
576     dnl __ACK__.  It may seem like its easier to avoid calling the macro here,
577     dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
578     dnl default value and automake should usually know them).
579     dnl
580     dnl The '][' hides this use from 'aclocal'.
581     m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
582   fi
583
584   dnl In case the code above has not helped with setting AR/ARFLAGS, use
585   dnl Automake-documented default values for AR and ARFLAGS, but prefer
586   dnl ${host}-ar over ar (useful for cross-compiling).
587   AC_CHECK_TOOL([AR], [ar], [ar])
588   if test -z "$ARFLAGS"; then
589     ARFLAGS='cr'
590   fi
591
592   AC_SUBST([AR])
593   AC_SUBST([ARFLAGS])
594   if test -z "$RANLIB"; then
595     if test $gl_cv_c_amsterdam_compiler = yes; then
596       RANLIB=':'
597     else
598       dnl Use the ranlib program if it is available.
599       AC_PROG_RANLIB
600     fi
601   fi
602   AC_SUBST([RANLIB])
603 ])
604
605 # AC_C_RESTRICT
606 # This definition is copied from post-2.70 Autoconf and overrides the
607 # AC_C_RESTRICT macro from autoconf 2.60..2.70.
608 m4_version_prereq([2.70.1], [], [
609 AC_DEFUN([AC_C_RESTRICT],
610 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
611   [ac_cv_c_restrict=no
612    # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
613    # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
614    # Put 'restrict' last, because C++ lacks it.
615    for ac_kw in __restrict__ __restrict _Restrict restrict; do
616      AC_COMPILE_IFELSE(
617       [AC_LANG_PROGRAM(
618          [[typedef int *int_ptr;
619            int foo (int_ptr $ac_kw ip) { return ip[0]; }
620            int bar (int [$ac_kw]); /* Catch GCC bug 14050.  */
621            int bar (int ip[$ac_kw]) { return ip[0]; }
622          ]],
623          [[int s[1];
624            int *$ac_kw t = s;
625            t[0] = 0;
626            return foo (t) + bar (t);
627          ]])],
628       [ac_cv_c_restrict=$ac_kw])
629      test "$ac_cv_c_restrict" != no && break
630    done
631   ])
632  AH_VERBATIM([restrict],
633 [/* Define to the equivalent of the C99 'restrict' keyword, or to
634    nothing if this is not supported.  Do not define if restrict is
635    supported only directly.  */
636 #undef restrict
637 /* Work around a bug in older versions of Sun C++, which did not
638    #define __restrict__ or support _Restrict or __restrict__
639    even though the corresponding Sun C compiler ended up with
640    "#define restrict _Restrict" or "#define restrict __restrict__"
641    in the previous line.  This workaround can be removed once
642    we assume Oracle Developer Studio 12.5 (2016) or later.  */
643 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
644 # define _Restrict
645 # define __restrict__
646 #endif])
647  case $ac_cv_c_restrict in
648    restrict) ;;
649    no) AC_DEFINE([restrict], []) ;;
650    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
651  esac
652 ])# AC_C_RESTRICT
653 ])
654
655 # gl_BIGENDIAN
656 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
657 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
658 # macros invoke AC_C_BIGENDIAN with arguments.
659 AC_DEFUN([gl_BIGENDIAN],
660 [
661   AC_C_BIGENDIAN
662 ])
663
664 # A temporary file descriptor.
665 # Must be less than 10, because dash 0.5.8 does not support redirections
666 # with multi-digit file descriptors.
667 m4_define([GL_TMP_FD], 9)
668
669 # gl_SILENT(command)
670 # executes command, but without the normal configure output.
671 # This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
672 # inside another AC_CACHE_CHECK.
673 AC_DEFUN([gl_SILENT],
674 [
675   exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
676   $1
677   exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
678 ])
679
680 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
681 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
682 # output a spurious "(cached)" mark in the midst of other configure output.
683 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
684 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
685 AC_DEFUN([gl_CACHE_VAL_SILENT],
686 [
687   gl_SILENT([
688     AC_CACHE_VAL([$1], [$2])
689   ])
690 ])
691
692 # gl_CC_ALLOW_WARNINGS
693 # sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
694 # that reverts a preceding '-Werror' option, if available.
695 # This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
696 # and empty otherwise.
697 AC_DEFUN([gl_CC_ALLOW_WARNINGS],
698 [
699   AC_REQUIRE([AC_PROG_CC])
700   AC_CACHE_CHECK([for C compiler option to allow warnings],
701     [gl_cv_cc_wallow],
702     [rm -f conftest*
703      echo 'int dummy;' > conftest.c
704      AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
705      AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
706      dnl Test the number of error output lines, because AIX xlc accepts the
707      dnl option '-Wno-error', just to produce a warning
708      dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
709      dnl afterwards.
710      if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
711        gl_cv_cc_wallow='-Wno-error'
712      else
713        gl_cv_cc_wallow=none
714      fi
715      rm -f conftest*
716     ])
717   case "$gl_cv_cc_wallow" in
718     none) GL_CFLAG_ALLOW_WARNINGS='' ;;
719     *)    GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
720   esac
721   AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
722 ])
723
724 # gl_CXX_ALLOW_WARNINGS
725 # sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
726 # that reverts a preceding '-Werror' option, if available.
727 AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
728 [
729   dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
730   if test -n "$CXX" && test "$CXX" != no; then
731     AC_CACHE_CHECK([for C++ compiler option to allow warnings],
732       [gl_cv_cxx_wallow],
733       [rm -f conftest*
734        echo 'int dummy;' > conftest.cc
735        AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
736        AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
737        dnl Test the number of error output lines, because AIX xlC accepts the
738        dnl option '-Wno-error', just to produce a warning
739        dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
740        dnl afterwards.
741        if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
742          gl_cv_cxx_wallow='-Wno-error'
743        else
744          gl_cv_cxx_wallow=none
745        fi
746        rm -f conftest*
747       ])
748     case "$gl_cv_cxx_wallow" in
749       none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
750       *)    GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
751     esac
752   else
753     GL_CXXFLAG_ALLOW_WARNINGS=''
754   fi
755   AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
756 ])
757
758 dnl Expands to some code for use in .c programs that, on native Windows, defines
759 dnl the Microsoft deprecated alias function names to the underscore-prefixed
760 dnl actual function names. With this macro, these function names are available
761 dnl without linking with '-loldnames' and without generating warnings.
762 dnl Usage: Use it after all system header files are included.
763 dnl          #include <...>
764 dnl          #include <...>
765 dnl          ]GL_MDA_DEFINES[
766 dnl          ...
767 AC_DEFUN([GL_MDA_DEFINES],[
768 AC_REQUIRE([_GL_MDA_DEFINES])
769 [$gl_mda_defines]
770 ])
771 AC_DEFUN([_GL_MDA_DEFINES],
772 [gl_mda_defines='
773 #if defined _WIN32 && !defined __CYGWIN__
774 #define access    _access
775 #define chdir     _chdir
776 #define chmod     _chmod
777 #define close     _close
778 #define creat     _creat
779 #define dup       _dup
780 #define dup2      _dup2
781 #define ecvt      _ecvt
782 #define execl     _execl
783 #define execle    _execle
784 #define execlp    _execlp
785 #define execv     _execv
786 #define execve    _execve
787 #define execvp    _execvp
788 #define execvpe   _execvpe
789 #define fcloseall _fcloseall
790 #define fcvt      _fcvt
791 #define fdopen    _fdopen
792 #define fileno    _fileno
793 #define gcvt      _gcvt
794 #define getcwd    _getcwd
795 #define getpid    _getpid
796 #define getw      _getw
797 #define isatty    _isatty
798 #define j0        _j0
799 #define j1        _j1
800 #define jn        _jn
801 #define lfind     _lfind
802 #define lsearch   _lsearch
803 #define lseek     _lseek
804 #define memccpy   _memccpy
805 #define mkdir     _mkdir
806 #define mktemp    _mktemp
807 #define open      _open
808 #define putenv    _putenv
809 #define putw      _putw
810 #define read      _read
811 #define rmdir     _rmdir
812 #define strdup    _strdup
813 #define swab      _swab
814 #define tempnam   _tempnam
815 #define tzset     _tzset
816 #define umask     _umask
817 #define unlink    _unlink
818 #define utime     _utime
819 #define wcsdup    _wcsdup
820 #define write     _write
821 #define y0        _y0
822 #define y1        _y1
823 #define yn        _yn
824 #endif
825 '
826 ])