Output alists with dotted pair notation in .dir-locals.el
[emacs.git] / m4 / gnulib-common.m4
blob5f07855acf11f5062daea3eadbe9613438e4a4bc
1 # gnulib-common.m4 serial 39
2 dnl Copyright (C) 2007-2018 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.
7 # gl_COMMON
8 # is expanded unconditionally through gnulib-tool magic.
9 AC_DEFUN([gl_COMMON], [
10   dnl Use AC_REQUIRE here, so that the code is expanded once only.
11   AC_REQUIRE([gl_00GNULIB])
12   AC_REQUIRE([gl_COMMON_BODY])
14 AC_DEFUN([gl_COMMON_BODY], [
15   AH_VERBATIM([_Noreturn],
16 [/* The _Noreturn keyword of C11.  */
17 #if ! (defined _Noreturn \
18        || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
19 # if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
20       || 0x5110 <= __SUNPRO_C)
21 #  define _Noreturn __attribute__ ((__noreturn__))
22 # elif defined _MSC_VER && 1200 <= _MSC_VER
23 #  define _Noreturn __declspec (noreturn)
24 # else
25 #  define _Noreturn
26 # endif
27 #endif
29   AH_VERBATIM([isoc99_inline],
30 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
31    the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
32    earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
33    __APPLE__ && __MACH__ test for Mac OS X.
34    __APPLE_CC__ tests for the Apple compiler and its version.
35    __STDC_VERSION__ tests for the C99 mode.  */
36 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
37 # define __GNUC_STDC_INLINE__ 1
38 #endif])
39   AH_VERBATIM([unused_parameter],
40 [/* Define as a marker that can be attached to declarations that might not
41     be used.  This helps to reduce warnings, such as from
42     GCC -Wunused-parameter.  */
43 #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
44 # define _GL_UNUSED __attribute__ ((__unused__))
45 #else
46 # define _GL_UNUSED
47 #endif
48 /* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
49    is a misnomer outside of parameter lists.  */
50 #define _UNUSED_PARAMETER_ _GL_UNUSED
52 /* gcc supports the "unused" attribute on possibly unused labels, and
53    g++ has since version 4.5.  Note to support C++ as well as C,
54    _GL_UNUSED_LABEL should be used with a trailing ;  */
55 #if !defined __cplusplus || __GNUC__ > 4 \
56     || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
57 # define _GL_UNUSED_LABEL _GL_UNUSED
58 #else
59 # define _GL_UNUSED_LABEL
60 #endif
62 /* The __pure__ attribute was added in gcc 2.96.  */
63 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
64 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
65 #else
66 # define _GL_ATTRIBUTE_PURE /* empty */
67 #endif
69 /* The __const__ attribute was added in gcc 2.95.  */
70 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
71 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
72 #else
73 # define _GL_ATTRIBUTE_CONST /* empty */
74 #endif
76 /* The __malloc__ attribute was added in gcc 3.  */
77 #if 3 <= __GNUC__
78 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
79 #else
80 # define _GL_ATTRIBUTE_MALLOC /* empty */
81 #endif
83   dnl Preparation for running test programs:
84   dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
85   dnl to /dev/tty, so they can be redirected to log files.  Such diagnostics
86   dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
87   LIBC_FATAL_STDERR_=1
88   export LIBC_FATAL_STDERR_
91 # gl_MODULE_INDICATOR_CONDITION
92 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
93 # whether a gnulib module that has been requested shall be considered present
94 # or not.
95 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
97 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
98 # sets the shell variable that indicates the presence of the given module to
99 # a C preprocessor expression that will evaluate to 1.
100 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
102   gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
103     [GNULIB_[]m4_translit([[$1]],
104                           [abcdefghijklmnopqrstuvwxyz./-],
105                           [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
106     [gl_MODULE_INDICATOR_CONDITION])
109 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
110 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
111 # The shell variable's value is a C preprocessor expression that evaluates
112 # to 0 or 1.
113 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
115   m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
116     [
117      dnl Simplify the expression VALUE || 1 to 1.
118      $1=1
119     ],
120     [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
121                                              [gl_MODULE_INDICATOR_CONDITION])])
124 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
125 # modifies the shell variable to include the given condition.  The shell
126 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
127 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
129   dnl Simplify the expression 1 || CONDITION to 1.
130   if test "$[]$1" != 1; then
131     dnl Simplify the expression 0 || CONDITION to CONDITION.
132     if test "$[]$1" = 0; then
133       $1=$2
134     else
135       $1="($[]$1 || $2)"
136     fi
137   fi
140 # gl_MODULE_INDICATOR([modulename])
141 # defines a C macro indicating the presence of the given module
142 # in a location where it can be used.
143 #                                             |  Value  |   Value   |
144 #                                             | in lib/ | in tests/ |
145 # --------------------------------------------+---------+-----------+
146 # Module present among main modules:          |    1    |     1     |
147 # --------------------------------------------+---------+-----------+
148 # Module present among tests-related modules: |    0    |     1     |
149 # --------------------------------------------+---------+-----------+
150 # Module not present at all:                  |    0    |     0     |
151 # --------------------------------------------+---------+-----------+
152 AC_DEFUN([gl_MODULE_INDICATOR],
154   AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
155       [abcdefghijklmnopqrstuvwxyz./-],
156       [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
157     [gl_MODULE_INDICATOR_CONDITION],
158     [Define to a C preprocessor expression that evaluates to 1 or 0,
159      depending whether the gnulib module $1 shall be considered present.])
162 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
163 # defines a C macro indicating the presence of the given module
164 # in lib or tests. This is useful to determine whether the module
165 # should be tested.
166 #                                             |  Value  |   Value   |
167 #                                             | in lib/ | in tests/ |
168 # --------------------------------------------+---------+-----------+
169 # Module present among main modules:          |    1    |     1     |
170 # --------------------------------------------+---------+-----------+
171 # Module present among tests-related modules: |    1    |     1     |
172 # --------------------------------------------+---------+-----------+
173 # Module not present at all:                  |    0    |     0     |
174 # --------------------------------------------+---------+-----------+
175 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
177   AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
178       [abcdefghijklmnopqrstuvwxyz./-],
179       [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
180     [Define to 1 when the gnulib module $1 should be tested.])
183 # gl_ASSERT_NO_GNULIB_POSIXCHECK
184 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
185 # and thereby enables an optimization of configure and config.h.
186 # Used by Emacs.
187 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
189   dnl Override gl_WARN_ON_USE_PREPARE.
190   dnl But hide this definition from 'aclocal'.
191   AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
194 # gl_ASSERT_NO_GNULIB_TESTS
195 # asserts that there will be no gnulib tests in the scope of the configure.ac
196 # and thereby enables an optimization of config.h.
197 # Used by Emacs.
198 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
200   dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
201   AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
204 # Test whether <features.h> exists.
205 # Set HAVE_FEATURES_H.
206 AC_DEFUN([gl_FEATURES_H],
208   AC_CHECK_HEADERS_ONCE([features.h])
209   if test $ac_cv_header_features_h = yes; then
210     HAVE_FEATURES_H=1
211   else
212     HAVE_FEATURES_H=0
213   fi
214   AC_SUBST([HAVE_FEATURES_H])
217 # m4_foreach_w
218 # is a backport of autoconf-2.59c's m4_foreach_w.
219 # Remove this macro when we can assume autoconf >= 2.60.
220 m4_ifndef([m4_foreach_w],
221   [m4_define([m4_foreach_w],
222     [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
224 # AS_VAR_IF(VAR, VALUE, [IF-MATCH], [IF-NOT-MATCH])
225 # ----------------------------------------------------
226 # Backport of autoconf-2.63b's macro.
227 # Remove this macro when we can assume autoconf >= 2.64.
228 m4_ifndef([AS_VAR_IF],
229 [m4_define([AS_VAR_IF],
230 [AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
232 # gl_PROG_CC_C99
233 # Modifies the value of the shell variable CC in an attempt to make $CC
234 # understand ISO C99 source code.
235 # This is like AC_PROG_CC_C99, except that
236 # - AC_PROG_CC_C99 did not exist in Autoconf versions < 2.60,
237 # - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC
238 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00367.html>,
239 #   but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99
240 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00441.html>.
241 # Remaining problems:
242 # - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options
243 #   to CC twice
244 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00431.html>.
245 # - AC_PROG_CC_STDC is likely to change now that C11 is an ISO standard.
246 AC_DEFUN([gl_PROG_CC_C99],
248   dnl Change that version number to the minimum Autoconf version that supports
249   dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls.
250   m4_version_prereq([9.0],
251     [AC_REQUIRE([AC_PROG_CC_C99])],
252     [AC_REQUIRE([AC_PROG_CC_STDC])])
255 # gl_PROG_AR_RANLIB
256 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
257 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
258 # the values.
259 AC_DEFUN([gl_PROG_AR_RANLIB],
261   dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
262   dnl as "cc", and GCC as "gcc". They have different object file formats and
263   dnl library formats. In particular, the GNU binutils programs ar and ranlib
264   dnl produce libraries that work only with gcc, not with cc.
265   AC_REQUIRE([AC_PROG_CC])
266   dnl The '][' hides this use from 'aclocal'.
267   AC_BEFORE([$0], [A][M_PROG_AR])
268   AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
269     [
270       AC_EGREP_CPP([Amsterdam],
271         [
272 #ifdef __ACK__
273 Amsterdam
274 #endif
275         ],
276         [gl_cv_c_amsterdam_compiler=yes],
277         [gl_cv_c_amsterdam_compiler=no])
278     ])
280   dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
281   dnl building with __ACK__.
282   if test $gl_cv_c_amsterdam_compiler = yes; then
283     if test -z "$AR"; then
284       AR='cc -c.a'
285     fi
286     if test -z "$ARFLAGS"; then
287       ARFLAGS='-o'
288     fi
289   else
290     dnl AM_PROG_AR was added in automake v1.11.2.  AM_PROG_AR does not AC_SUBST
291     dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
292     dnl script on-demand, if not specified by ./configure of course).
293     dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
294     dnl will be ignored.  Also, pay attention to call AM_PROG_AR in else block
295     dnl because AM_PROG_AR is written so it could re-set AR variable even for
296     dnl __ACK__.  It may seem like its easier to avoid calling the macro here,
297     dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
298     dnl default value and automake should usually know them).
299     dnl
300     dnl The '][' hides this use from 'aclocal'.
301     m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
302   fi
304   dnl In case the code above has not helped with setting AR/ARFLAGS, use
305   dnl Automake-documented default values for AR and ARFLAGS, but prefer
306   dnl ${host}-ar over ar (useful for cross-compiling).
307   AC_CHECK_TOOL([AR], [ar], [ar])
308   if test -z "$ARFLAGS"; then
309     ARFLAGS='cr'
310   fi
312   AC_SUBST([AR])
313   AC_SUBST([ARFLAGS])
314   if test -z "$RANLIB"; then
315     if test $gl_cv_c_amsterdam_compiler = yes; then
316       RANLIB=':'
317     else
318       dnl Use the ranlib program if it is available.
319       AC_PROG_RANLIB
320     fi
321   fi
322   AC_SUBST([RANLIB])
325 # AC_PROG_MKDIR_P
326 # is a backport of autoconf-2.60's AC_PROG_MKDIR_P, with a fix
327 # for interoperability with automake-1.9.6 from autoconf-2.62.
328 # Remove this macro when we can assume autoconf >= 2.62 or
329 # autoconf >= 2.60 && automake >= 1.10.
330 # AC_AUTOCONF_VERSION was introduced in 2.62, so use that as the witness.
331 m4_ifndef([AC_AUTOCONF_VERSION],[
332 m4_ifdef([AC_PROG_MKDIR_P], [
333   dnl For automake-1.9.6 && autoconf < 2.62: Ensure MKDIR_P is AC_SUBSTed.
334   m4_define([AC_PROG_MKDIR_P],
335     m4_defn([AC_PROG_MKDIR_P])[
336     AC_SUBST([MKDIR_P])])], [
337   dnl For autoconf < 2.60: Backport of AC_PROG_MKDIR_P.
338   AC_DEFUN_ONCE([AC_PROG_MKDIR_P],
339     [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
340      MKDIR_P='$(mkdir_p)'
341      AC_SUBST([MKDIR_P])])])
344 # AC_C_RESTRICT
345 # This definition is copied from post-2.69 Autoconf and overrides the
346 # AC_C_RESTRICT macro from autoconf 2.60..2.69.  It can be removed
347 # once autoconf >= 2.70 can be assumed.  It's painful to check version
348 # numbers, and in practice this macro is more up-to-date than Autoconf
349 # is, so override Autoconf unconditionally.
350 AC_DEFUN([AC_C_RESTRICT],
351 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
352   [ac_cv_c_restrict=no
353    # The order here caters to the fact that C++ does not require restrict.
354    for ac_kw in __restrict __restrict__ _Restrict restrict; do
355      AC_COMPILE_IFELSE(
356       [AC_LANG_PROGRAM(
357          [[typedef int *int_ptr;
358            int foo (int_ptr $ac_kw ip) { return ip[0]; }
359            int bar (int [$ac_kw]); /* Catch GCC bug 14050.  */
360            int bar (int ip[$ac_kw]) { return ip[0]; }
361          ]],
362          [[int s[1];
363            int *$ac_kw t = s;
364            t[0] = 0;
365            return foo (t) + bar (t);
366          ]])],
367       [ac_cv_c_restrict=$ac_kw])
368      test "$ac_cv_c_restrict" != no && break
369    done
370   ])
371  AH_VERBATIM([restrict],
372 [/* Define to the equivalent of the C99 'restrict' keyword, or to
373    nothing if this is not supported.  Do not define if restrict is
374    supported directly.  */
375 #undef restrict
376 /* Work around a bug in Sun C++: it does not support _Restrict or
377    __restrict__, even though the corresponding Sun C compiler ends up with
378    "#define restrict _Restrict" or "#define restrict __restrict__" in the
379    previous line.  Perhaps some future version of Sun C++ will work with
380    restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
381 #if defined __SUNPRO_CC && !defined __RESTRICT
382 # define _Restrict
383 # define __restrict__
384 #endif])
385  case $ac_cv_c_restrict in
386    restrict) ;;
387    no) AC_DEFINE([restrict], []) ;;
388    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
389  esac
390 ])# AC_C_RESTRICT
392 # gl_BIGENDIAN
393 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
394 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
395 # macros invoke AC_C_BIGENDIAN with arguments.
396 AC_DEFUN([gl_BIGENDIAN],
398   AC_C_BIGENDIAN
401 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
402 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
403 # output a spurious "(cached)" mark in the midst of other configure output.
404 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
405 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
406 AC_DEFUN([gl_CACHE_VAL_SILENT],
408   saved_as_echo_n="$as_echo_n"
409   as_echo_n=':'
410   AC_CACHE_VAL([$1], [$2])
411   as_echo_n="$saved_as_echo_n"
414 # AS_VAR_COPY was added in autoconf 2.63b
415 m4_define_default([AS_VAR_COPY],
416 [AS_LITERAL_IF([$1[]$2], [$1=$$2], [eval $1=\$$2])])
418 # AC_PROG_SED was added in autoconf 2.59b
419 m4_ifndef([AC_PROG_SED],
420 [AC_DEFUN([AC_PROG_SED],
421 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
422     [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
423      dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
424      ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
425      for ac_i in 1 2 3 4 5 6 7; do
426        ac_script="$ac_script$as_nl$ac_script"
427      done
428      echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
429      AS_UNSET([ac_script])
430      if test -z "$SED"; then
431        ac_path_SED_found=false
432        _AS_PATH_WALK([], [
433          for ac_prog in sed gsed; do
434            for ac_exec_ext in '' $ac_executable_extensions; do
435              ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
436              AS_EXECUTABLE_P(["$ac_path_SED"]) || continue
437              case `"$ac_path_SED" --version 2>&1` in
438                *GNU*) ac_cv_path_SED=$ac_path_SED ac_path_SED_found=:;;
439                *)
440                  ac_count=0
441                  _AS_ECHO_N([0123456789]) >conftest.in
442                  while :
443                  do
444                    cat conftest.in conftest.in >conftest.tmp
445                    mv conftest.tmp conftest.in
446                    cp conftest.in conftest.nl
447                    echo >> conftest.nl
448                    "$ac_path_SED" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
449                    diff conftest.out conftest.nl >/dev/null 2>&1 || break
450                    ac_count=`expr $ac_count + 1`
451                    if test $ac_count -gt ${ac_path_SED_max-0}; then
452                      # Best so far, but keep looking for better
453                      ac_cv_path_SED=$ac_path_SED
454                      ac_path_SED_max=$ac_count
455                    fi
456                    test $ac_count -gt 10 && break
457                  done
458                  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
459              esac
460              $ac_path_SED_found && break 3
461            done
462          done])
463        if test -z "$ac_cv_path_SED"; then
464          AC_ERROR([no acceptable sed could be found in \$PATH])
465        fi
466      else
467        ac_cv_path_SED=$SED
468      fi
469     ])
470  SED="$ac_cv_path_SED"
471  AC_SUBST([SED])dnl
472  rm -f conftest.sed