Home | History | Annotate | Line # | Download | only in m4
gnulib-common.m4 revision 1.1
      1 # gnulib-common.m4 serial 50
      2 dnl Copyright (C) 2007-2020 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             || _GL_GNUC_PREREQ (4, 7) \
     44             || (defined __apple_build_version__ \
     45                 ? 6000000 <= __apple_build_version__ \
     46                 : 3 < __clang_major__ + (5 <= __clang_minor__))))
     47    /* _Noreturn works as-is.  */
     48 # elif _GL_GNUC_PREREQ (2, 8) || 0x5110 <= __SUNPRO_C
     49 #  define _Noreturn __attribute__ ((__noreturn__))
     50 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
     51 #  define _Noreturn __declspec (noreturn)
     52 # else
     53 #  define _Noreturn
     54 # endif
     55 #endif
     56 ])
     57   AH_VERBATIM([isoc99_inline],
     58 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
     59    the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
     60    earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
     61    __APPLE__ && __MACH__ test for Mac OS X.
     62    __APPLE_CC__ tests for the Apple compiler and its version.
     63    __STDC_VERSION__ tests for the C99 mode.  */
     64 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
     65 # define __GNUC_STDC_INLINE__ 1
     66 #endif])
     67   AH_VERBATIM([attribute],
     68 [/* Attributes.  */
     69 #ifdef __has_attribute
     70 # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
     71 #else
     72 # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
     73 # define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
     74 # define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
     75 # define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
     76 # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
     77 # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
     78 # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
     79 # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
     80 # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
     81 # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
     82 # define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
     83 # define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
     84 # ifdef _ICC
     85 #  define _GL_ATTR_may_alias 0
     86 # else
     87 #  define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
     88 # endif
     89 # define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
     90 # define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
     91 # define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
     92 # define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
     93 # define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
     94 # define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
     95 # define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
     96 # define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
     97 # define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
     98 # define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
     99 # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
    100 #endif
    101 
    102 ]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's _Alignas instead.
    103 [
    104 #if _GL_HAS_ATTRIBUTE (alloc_size)
    105 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
    106 #else
    107 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
    108 #endif
    109 
    110 #if _GL_HAS_ATTRIBUTE (always_inline)
    111 # define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
    112 #else
    113 # define _GL_ATTRIBUTE_ALWAYS_INLINE
    114 #endif
    115 
    116 #if _GL_HAS_ATTRIBUTE (artificial)
    117 # define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
    118 #else
    119 # define _GL_ATTRIBUTE_ARTIFICIAL
    120 #endif
    121 
    122 /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
    123    <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>. */
    124 #if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
    125 # define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
    126 #else
    127 # define _GL_ATTRIBUTE_COLD
    128 #endif
    129 
    130 #if _GL_HAS_ATTRIBUTE (const)
    131 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
    132 #else
    133 # define _GL_ATTRIBUTE_CONST
    134 #endif
    135 
    136 #if 201710L < __STDC_VERSION__
    137 # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
    138 #elif _GL_HAS_ATTRIBUTE (deprecated)
    139 # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
    140 #else
    141 # define _GL_ATTRIBUTE_DEPRECATED
    142 #endif
    143 
    144 #if _GL_HAS_ATTRIBUTE (error)
    145 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
    146 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
    147 #else
    148 # define _GL_ATTRIBUTE_ERROR(msg)
    149 # define _GL_ATTRIBUTE_WARNING(msg)
    150 #endif
    151 
    152 #if _GL_HAS_ATTRIBUTE (externally_visible)
    153 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
    154 #else
    155 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
    156 #endif
    157 
    158 /* FALLTHROUGH is special, because it always expands to something.  */
    159 #if 201710L < __STDC_VERSION__
    160 # define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
    161 #elif _GL_HAS_ATTRIBUTE (fallthrough)
    162 # define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
    163 #else
    164 # define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
    165 #endif
    166 
    167 #if _GL_HAS_ATTRIBUTE (format)
    168 # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
    169 #else
    170 # define _GL_ATTRIBUTE_FORMAT(spec)
    171 #endif
    172 
    173 #if _GL_HAS_ATTRIBUTE (leaf)
    174 # define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
    175 #else
    176 # define _GL_ATTRIBUTE_LEAF
    177 #endif
    178 
    179 #if _GL_HAS_ATTRIBUTE (may_alias)
    180 # define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
    181 #else
    182 # define _GL_ATTRIBUTE_MAY_ALIAS
    183 #endif
    184 
    185 #if 201710L < __STDC_VERSION__
    186 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
    187 #elif _GL_HAS_ATTRIBUTE (unused)
    188 # define _GL_ATTRIBUTE_MAYBE_UNUSED __attribute__ ((__unused__))
    189 #else
    190 # define _GL_ATTRIBUTE_MAYBE_UNUSED
    191 #endif
    192 /* Earlier spellings of this macro.  */
    193 #define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
    194 #define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
    195 
    196 #if _GL_HAS_ATTRIBUTE (malloc)
    197 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
    198 #else
    199 # define _GL_ATTRIBUTE_MALLOC
    200 #endif
    201 
    202 #if 201710L < __STDC_VERSION__
    203 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
    204 #elif _GL_HAS_ATTRIBUTE (warn_unused_result)
    205 # define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
    206 #else
    207 # define _GL_ATTRIBUTE_NODISCARD
    208 #endif
    209 
    210 #if _GL_HAS_ATTRIBUTE (noinline)
    211 # define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
    212 #else
    213 # define _GL_ATTRIBUTE_NOINLINE
    214 #endif
    215 
    216 #if _GL_HAS_ATTRIBUTE (nonnull)
    217 # define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
    218 #else
    219 # define _GL_ATTRIBUTE_NONNULL(args)
    220 #endif
    221 
    222 #if _GL_HAS_ATTRIBUTE (nonstring)
    223 # define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
    224 #else
    225 # define _GL_ATTRIBUTE_NONSTRING
    226 #endif
    227 
    228 /* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead.  */
    229 
    230 #if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
    231 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
    232 #else
    233 # define _GL_ATTRIBUTE_NOTHROW
    234 #endif
    235 
    236 #if _GL_HAS_ATTRIBUTE (packed)
    237 # define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
    238 #else
    239 # define _GL_ATTRIBUTE_PACKED
    240 #endif
    241 
    242 #if _GL_HAS_ATTRIBUTE (pure)
    243 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
    244 #else
    245 # define _GL_ATTRIBUTE_PURE
    246 #endif
    247 
    248 #if _GL_HAS_ATTRIBUTE (returns_nonnull)
    249 # define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
    250 #else
    251 # define _GL_ATTRIBUTE_RETURNS_NONNULL
    252 #endif
    253 
    254 #if _GL_HAS_ATTRIBUTE (sentinel)
    255 # define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
    256 #else
    257 # define _GL_ATTRIBUTE_SENTINEL(pos)
    258 #endif
    259 
    260 ]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
    261 [
    262 /* To support C++ as well as C, use _GL_UNUSED_LABEL with trailing ';'.  */
    263 #if !defined __cplusplus || _GL_GNUC_PREREQ (4, 5)
    264 # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_MAYBE_UNUSED
    265 #else
    266 # define _GL_UNUSED_LABEL
    267 #endif
    268 ])
    269   AH_VERBATIM([async_safe],
    270 [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
    271    signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
    272    invoked from such signal handlers.  Such functions have some restrictions:
    273      * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
    274        or should be listed as async-signal-safe in POSIX
    275        <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
    276        section 2.4.3.  Note that malloc(), sprintf(), and fwrite(), in
    277        particular, are NOT async-signal-safe.
    278      * All memory locations (variables and struct fields) that these functions
    279        access must be marked 'volatile'.  This holds for both read and write
    280        accesses.  Otherwise the compiler might optimize away stores to and
    281        reads from such locations that occur in the program, depending on its
    282        data flow analysis.  For example, when the program contains a loop
    283        that is intended to inspect a variable set from within a signal handler
    284            while (!signal_occurred)
    285              ;
    286        the compiler is allowed to transform this into an endless loop if the
    287        variable 'signal_occurred' is not declared 'volatile'.
    288    Additionally, recall that:
    289      * A signal handler should not modify errno (except if it is a handler
    290        for a fatal signal and ends by raising the same signal again, thus
    291        provoking the termination of the process).  If it invokes a function
    292        that may clobber errno, it needs to save and restore the value of
    293        errno.  */
    294 #define _GL_ASYNC_SAFE
    295 ])
    296   dnl Hint which direction to take regarding cross-compilation guesses:
    297   dnl When a user installs a program on a platform they are not intimately
    298   dnl familiar with, --enable-cross-guesses=conservative is the appropriate
    299   dnl choice.  It implements the "If we don't know, assume the worst" principle.
    300   dnl However, when an operating system developer (on a platform which is not
    301   dnl yet known to gnulib) builds packages for their platform, they want to
    302   dnl expose, not hide, possible platform bugs; in this case,
    303   dnl --enable-cross-guesses=risky is the appropriate choice.
    304   dnl Sets the variables
    305   dnl gl_cross_guess_normal    (to be used when 'yes' is good and 'no' is bad),
    306   dnl gl_cross_guess_inverted  (to be used when 'no' is good and 'yes' is bad).
    307   AC_ARG_ENABLE([cross-guesses],
    308     [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
    309        [specify policy for cross-compilation guesses])],
    310     [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
    311        AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
    312        enableval=conservative
    313      fi
    314      gl_cross_guesses="$enableval"],
    315     [gl_cross_guesses=conservative])
    316   if test $gl_cross_guesses = risky; then
    317     gl_cross_guess_normal="guessing yes"
    318     gl_cross_guess_inverted="guessing no"
    319   else
    320     gl_cross_guess_normal="guessing no"
    321     gl_cross_guess_inverted="guessing yes"
    322   fi
    323   dnl Preparation for running test programs:
    324   dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
    325   dnl to /dev/tty, so they can be redirected to log files.  Such diagnostics
    326   dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
    327   LIBC_FATAL_STDERR_=1
    328   export LIBC_FATAL_STDERR_
    329 ])
    330 
    331 # gl_MODULE_INDICATOR_CONDITION
    332 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
    333 # whether a gnulib module that has been requested shall be considered present
    334 # or not.
    335 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
    336 
    337 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
    338 # sets the shell variable that indicates the presence of the given module to
    339 # a C preprocessor expression that will evaluate to 1.
    340 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
    341 [
    342   gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
    343     [GNULIB_[]m4_translit([[$1]],
    344                           [abcdefghijklmnopqrstuvwxyz./-],
    345                           [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
    346     [gl_MODULE_INDICATOR_CONDITION])
    347 ])
    348 
    349 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
    350 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
    351 # The shell variable's value is a C preprocessor expression that evaluates
    352 # to 0 or 1.
    353 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
    354 [
    355   m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
    356     [
    357      dnl Simplify the expression VALUE || 1 to 1.
    358      $1=1
    359     ],
    360     [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
    361                                              [gl_MODULE_INDICATOR_CONDITION])])
    362 ])
    363 
    364 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
    365 # modifies the shell variable to include the given condition.  The shell
    366 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
    367 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
    368 [
    369   dnl Simplify the expression 1 || CONDITION to 1.
    370   if test "$[]$1" != 1; then
    371     dnl Simplify the expression 0 || CONDITION to CONDITION.
    372     if test "$[]$1" = 0; then
    373       $1=$2
    374     else
    375       $1="($[]$1 || $2)"
    376     fi
    377   fi
    378 ])
    379 
    380 # gl_MODULE_INDICATOR([modulename])
    381 # defines a C macro indicating the presence of the given module
    382 # in a location where it can be used.
    383 #                                             |  Value  |   Value   |
    384 #                                             | in lib/ | in tests/ |
    385 # --------------------------------------------+---------+-----------+
    386 # Module present among main modules:          |    1    |     1     |
    387 # --------------------------------------------+---------+-----------+
    388 # Module present among tests-related modules: |    0    |     1     |
    389 # --------------------------------------------+---------+-----------+
    390 # Module not present at all:                  |    0    |     0     |
    391 # --------------------------------------------+---------+-----------+
    392 AC_DEFUN([gl_MODULE_INDICATOR],
    393 [
    394   AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
    395       [abcdefghijklmnopqrstuvwxyz./-],
    396       [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
    397     [gl_MODULE_INDICATOR_CONDITION],
    398     [Define to a C preprocessor expression that evaluates to 1 or 0,
    399      depending whether the gnulib module $1 shall be considered present.])
    400 ])
    401 
    402 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
    403 # defines a C macro indicating the presence of the given module
    404 # in lib or tests. This is useful to determine whether the module
    405 # should be tested.
    406 #                                             |  Value  |   Value   |
    407 #                                             | in lib/ | in tests/ |
    408 # --------------------------------------------+---------+-----------+
    409 # Module present among main modules:          |    1    |     1     |
    410 # --------------------------------------------+---------+-----------+
    411 # Module present among tests-related modules: |    1    |     1     |
    412 # --------------------------------------------+---------+-----------+
    413 # Module not present at all:                  |    0    |     0     |
    414 # --------------------------------------------+---------+-----------+
    415 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
    416 [
    417   AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
    418       [abcdefghijklmnopqrstuvwxyz./-],
    419       [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
    420     [Define to 1 when the gnulib module $1 should be tested.])
    421 ])
    422 
    423 # gl_ASSERT_NO_GNULIB_POSIXCHECK
    424 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
    425 # and thereby enables an optimization of configure and config.h.
    426 # Used by Emacs.
    427 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
    428 [
    429   dnl Override gl_WARN_ON_USE_PREPARE.
    430   dnl But hide this definition from 'aclocal'.
    431   AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
    432 ])
    433 
    434 # gl_ASSERT_NO_GNULIB_TESTS
    435 # asserts that there will be no gnulib tests in the scope of the configure.ac
    436 # and thereby enables an optimization of config.h.
    437 # Used by Emacs.
    438 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
    439 [
    440   dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
    441   AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
    442 ])
    443 
    444 # Test whether <features.h> exists.
    445 # Set HAVE_FEATURES_H.
    446 AC_DEFUN([gl_FEATURES_H],
    447 [
    448   AC_CHECK_HEADERS_ONCE([features.h])
    449   if test $ac_cv_header_features_h = yes; then
    450     HAVE_FEATURES_H=1
    451   else
    452     HAVE_FEATURES_H=0
    453   fi
    454   AC_SUBST([HAVE_FEATURES_H])
    455 ])
    456 
    457 # AS_VAR_IF(VAR, VALUE, [IF-MATCH], [IF-NOT-MATCH])
    458 # ----------------------------------------------------
    459 # Backport of autoconf-2.63b's macro.
    460 # Remove this macro when we can assume autoconf >= 2.64.
    461 m4_ifndef([AS_VAR_IF],
    462 [m4_define([AS_VAR_IF],
    463 [AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
    464 
    465 # gl_PROG_CC_C99
    466 # Modifies the value of the shell variable CC in an attempt to make $CC
    467 # understand ISO C99 source code.
    468 # This is like AC_PROG_CC_C99, except that
    469 # - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC
    470 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00367.html>,
    471 #   but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99
    472 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00441.html>.
    473 # Remaining problems:
    474 # - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options
    475 #   to CC twice
    476 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00431.html>.
    477 # - AC_PROG_CC_STDC is likely to change now that C11 is an ISO standard.
    478 AC_DEFUN([gl_PROG_CC_C99],
    479 [
    480   dnl Change that version number to the minimum Autoconf version that supports
    481   dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls.
    482   m4_version_prereq([9.0],
    483     [AC_REQUIRE([AC_PROG_CC_C99])],
    484     [AC_REQUIRE([AC_PROG_CC_STDC])])
    485 ])
    486 
    487 # gl_PROG_AR_RANLIB
    488 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
    489 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
    490 # the values.
    491 AC_DEFUN([gl_PROG_AR_RANLIB],
    492 [
    493   dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
    494   dnl as "cc", and GCC as "gcc". They have different object file formats and
    495   dnl library formats. In particular, the GNU binutils programs ar and ranlib
    496   dnl produce libraries that work only with gcc, not with cc.
    497   AC_REQUIRE([AC_PROG_CC])
    498   dnl The '][' hides this use from 'aclocal'.
    499   AC_BEFORE([$0], [A][M_PROG_AR])
    500   AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
    501     [
    502       AC_EGREP_CPP([Amsterdam],
    503         [
    504 #ifdef __ACK__
    505 Amsterdam
    506 #endif
    507         ],
    508         [gl_cv_c_amsterdam_compiler=yes],
    509         [gl_cv_c_amsterdam_compiler=no])
    510     ])
    511 
    512   dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
    513   dnl building with __ACK__.
    514   if test $gl_cv_c_amsterdam_compiler = yes; then
    515     if test -z "$AR"; then
    516       AR='cc -c.a'
    517     fi
    518     if test -z "$ARFLAGS"; then
    519       ARFLAGS='-o'
    520     fi
    521   else
    522     dnl AM_PROG_AR was added in automake v1.11.2.  AM_PROG_AR does not AC_SUBST
    523     dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
    524     dnl script on-demand, if not specified by ./configure of course).
    525     dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
    526     dnl will be ignored.  Also, pay attention to call AM_PROG_AR in else block
    527     dnl because AM_PROG_AR is written so it could re-set AR variable even for
    528     dnl __ACK__.  It may seem like its easier to avoid calling the macro here,
    529     dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
    530     dnl default value and automake should usually know them).
    531     dnl
    532     dnl The '][' hides this use from 'aclocal'.
    533     m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
    534   fi
    535 
    536   dnl In case the code above has not helped with setting AR/ARFLAGS, use
    537   dnl Automake-documented default values for AR and ARFLAGS, but prefer
    538   dnl ${host}-ar over ar (useful for cross-compiling).
    539   AC_CHECK_TOOL([AR], [ar], [ar])
    540   if test -z "$ARFLAGS"; then
    541     ARFLAGS='cr'
    542   fi
    543 
    544   AC_SUBST([AR])
    545   AC_SUBST([ARFLAGS])
    546   if test -z "$RANLIB"; then
    547     if test $gl_cv_c_amsterdam_compiler = yes; then
    548       RANLIB=':'
    549     else
    550       dnl Use the ranlib program if it is available.
    551       AC_PROG_RANLIB
    552     fi
    553   fi
    554   AC_SUBST([RANLIB])
    555 ])
    556 
    557 # AC_C_RESTRICT
    558 # This definition is copied from post-2.69 Autoconf and overrides the
    559 # AC_C_RESTRICT macro from autoconf 2.60..2.69.  It can be removed
    560 # once autoconf >= 2.70 can be assumed.  It's painful to check version
    561 # numbers, and in practice this macro is more up-to-date than Autoconf
    562 # is, so override Autoconf unconditionally.
    563 AC_DEFUN([AC_C_RESTRICT],
    564 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
    565   [ac_cv_c_restrict=no
    566    # The order here caters to the fact that C++ does not require restrict.
    567    for ac_kw in __restrict __restrict__ _Restrict restrict; do
    568      AC_COMPILE_IFELSE(
    569       [AC_LANG_PROGRAM(
    570          [[typedef int *int_ptr;
    571            int foo (int_ptr $ac_kw ip) { return ip[0]; }
    572            int bar (int [$ac_kw]); /* Catch GCC bug 14050.  */
    573            int bar (int ip[$ac_kw]) { return ip[0]; }
    574          ]],
    575          [[int s[1];
    576            int *$ac_kw t = s;
    577            t[0] = 0;
    578            return foo (t) + bar (t);
    579          ]])],
    580       [ac_cv_c_restrict=$ac_kw])
    581      test "$ac_cv_c_restrict" != no && break
    582    done
    583   ])
    584  AH_VERBATIM([restrict],
    585 [/* Define to the equivalent of the C99 'restrict' keyword, or to
    586    nothing if this is not supported.  Do not define if restrict is
    587    supported directly.  */
    588 #undef restrict
    589 /* Work around a bug in older versions of Sun C++, which did not
    590    #define __restrict__ or support _Restrict or __restrict__
    591    even though the corresponding Sun C compiler ended up with
    592    "#define restrict _Restrict" or "#define restrict __restrict__"
    593    in the previous line.  This workaround can be removed once
    594    we assume Oracle Developer Studio 12.5 (2016) or later.  */
    595 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
    596 # define _Restrict
    597 # define __restrict__
    598 #endif])
    599  case $ac_cv_c_restrict in
    600    restrict) ;;
    601    no) AC_DEFINE([restrict], []) ;;
    602    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
    603  esac
    604 ])# AC_C_RESTRICT
    605 
    606 # gl_BIGENDIAN
    607 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
    608 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
    609 # macros invoke AC_C_BIGENDIAN with arguments.
    610 AC_DEFUN([gl_BIGENDIAN],
    611 [
    612   AC_C_BIGENDIAN
    613 ])
    614 
    615 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
    616 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
    617 # output a spurious "(cached)" mark in the midst of other configure output.
    618 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
    619 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
    620 AC_DEFUN([gl_CACHE_VAL_SILENT],
    621 [
    622   saved_as_echo_n="$as_echo_n"
    623   as_echo_n=':'
    624   AC_CACHE_VAL([$1], [$2])
    625   as_echo_n="$saved_as_echo_n"
    626 ])
    627 
    628 # AS_VAR_COPY was added in autoconf 2.63b
    629 m4_define_default([AS_VAR_COPY],
    630 [AS_LITERAL_IF([$1[]$2], [$1=$$2], [eval $1=\$$2])])
    631