document mingw linker fix and close associated bug
[debian/gzip] / m4 / gnulib-common.m4
1 # gnulib-common.m4 serial 41
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.
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 ])
16 AC_DEFUN([gl_COMMON_BODY], [
17   AH_VERBATIM([_Noreturn],
18 [/* The _Noreturn keyword of C11.  */
19 #ifndef _Noreturn
20 # if 201103 <= (defined __cplusplus ? __cplusplus : 0)
21 #  define _Noreturn [[noreturn]]
22 # elif (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
23         || 4 < __GNUC__ + (7 <= __GNUC_MINOR__))
24    /* _Noreturn works as-is.  */
25 # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
26 #  define _Noreturn __attribute__ ((__noreturn__))
27 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
28 #  define _Noreturn __declspec (noreturn)
29 # else
30 #  define _Noreturn
31 # endif
32 #endif
33 ])
34   AH_VERBATIM([isoc99_inline],
35 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
36    the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
37    earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
38    __APPLE__ && __MACH__ test for Mac OS X.
39    __APPLE_CC__ tests for the Apple compiler and its version.
40    __STDC_VERSION__ tests for the C99 mode.  */
41 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
42 # define __GNUC_STDC_INLINE__ 1
43 #endif])
44   AH_VERBATIM([unused_parameter],
45 [/* Define as a marker that can be attached to declarations that might not
46     be used.  This helps to reduce warnings, such as from
47     GCC -Wunused-parameter.  */
48 #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
49 # define _GL_UNUSED __attribute__ ((__unused__))
50 #else
51 # define _GL_UNUSED
52 #endif
53 /* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
54    is a misnomer outside of parameter lists.  */
55 #define _UNUSED_PARAMETER_ _GL_UNUSED
56
57 /* gcc supports the "unused" attribute on possibly unused labels, and
58    g++ has since version 4.5.  Note to support C++ as well as C,
59    _GL_UNUSED_LABEL should be used with a trailing ;  */
60 #if !defined __cplusplus || __GNUC__ > 4 \
61     || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
62 # define _GL_UNUSED_LABEL _GL_UNUSED
63 #else
64 # define _GL_UNUSED_LABEL
65 #endif
66
67 /* The __pure__ attribute was added in gcc 2.96.  */
68 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
69 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
70 #else
71 # define _GL_ATTRIBUTE_PURE /* empty */
72 #endif
73
74 /* The __const__ attribute was added in gcc 2.95.  */
75 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
76 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
77 #else
78 # define _GL_ATTRIBUTE_CONST /* empty */
79 #endif
80
81 /* The __malloc__ attribute was added in gcc 3.  */
82 #if 3 <= __GNUC__
83 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
84 #else
85 # define _GL_ATTRIBUTE_MALLOC /* empty */
86 #endif
87 ])
88   dnl Preparation for running test programs:
89   dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
90   dnl to /dev/tty, so they can be redirected to log files.  Such diagnostics
91   dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
92   LIBC_FATAL_STDERR_=1
93   export LIBC_FATAL_STDERR_
94 ])
95
96 # gl_MODULE_INDICATOR_CONDITION
97 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
98 # whether a gnulib module that has been requested shall be considered present
99 # or not.
100 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
101
102 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
103 # sets the shell variable that indicates the presence of the given module to
104 # a C preprocessor expression that will evaluate to 1.
105 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
106 [
107   gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
108     [GNULIB_[]m4_translit([[$1]],
109                           [abcdefghijklmnopqrstuvwxyz./-],
110                           [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
111     [gl_MODULE_INDICATOR_CONDITION])
112 ])
113
114 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
115 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
116 # The shell variable's value is a C preprocessor expression that evaluates
117 # to 0 or 1.
118 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
119 [
120   m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
121     [
122      dnl Simplify the expression VALUE || 1 to 1.
123      $1=1
124     ],
125     [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
126                                              [gl_MODULE_INDICATOR_CONDITION])])
127 ])
128
129 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
130 # modifies the shell variable to include the given condition.  The shell
131 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
132 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
133 [
134   dnl Simplify the expression 1 || CONDITION to 1.
135   if test "$[]$1" != 1; then
136     dnl Simplify the expression 0 || CONDITION to CONDITION.
137     if test "$[]$1" = 0; then
138       $1=$2
139     else
140       $1="($[]$1 || $2)"
141     fi
142   fi
143 ])
144
145 # gl_MODULE_INDICATOR([modulename])
146 # defines a C macro indicating the presence of the given module
147 # in a location where it can be used.
148 #                                             |  Value  |   Value   |
149 #                                             | in lib/ | in tests/ |
150 # --------------------------------------------+---------+-----------+
151 # Module present among main modules:          |    1    |     1     |
152 # --------------------------------------------+---------+-----------+
153 # Module present among tests-related modules: |    0    |     1     |
154 # --------------------------------------------+---------+-----------+
155 # Module not present at all:                  |    0    |     0     |
156 # --------------------------------------------+---------+-----------+
157 AC_DEFUN([gl_MODULE_INDICATOR],
158 [
159   AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
160       [abcdefghijklmnopqrstuvwxyz./-],
161       [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
162     [gl_MODULE_INDICATOR_CONDITION],
163     [Define to a C preprocessor expression that evaluates to 1 or 0,
164      depending whether the gnulib module $1 shall be considered present.])
165 ])
166
167 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
168 # defines a C macro indicating the presence of the given module
169 # in lib or tests. This is useful to determine whether the module
170 # should be tested.
171 #                                             |  Value  |   Value   |
172 #                                             | in lib/ | in tests/ |
173 # --------------------------------------------+---------+-----------+
174 # Module present among main modules:          |    1    |     1     |
175 # --------------------------------------------+---------+-----------+
176 # Module present among tests-related modules: |    1    |     1     |
177 # --------------------------------------------+---------+-----------+
178 # Module not present at all:                  |    0    |     0     |
179 # --------------------------------------------+---------+-----------+
180 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
181 [
182   AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
183       [abcdefghijklmnopqrstuvwxyz./-],
184       [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
185     [Define to 1 when the gnulib module $1 should be tested.])
186 ])
187
188 # gl_ASSERT_NO_GNULIB_POSIXCHECK
189 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
190 # and thereby enables an optimization of configure and config.h.
191 # Used by Emacs.
192 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
193 [
194   dnl Override gl_WARN_ON_USE_PREPARE.
195   dnl But hide this definition from 'aclocal'.
196   AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
197 ])
198
199 # gl_ASSERT_NO_GNULIB_TESTS
200 # asserts that there will be no gnulib tests in the scope of the configure.ac
201 # and thereby enables an optimization of config.h.
202 # Used by Emacs.
203 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
204 [
205   dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
206   AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
207 ])
208
209 # Test whether <features.h> exists.
210 # Set HAVE_FEATURES_H.
211 AC_DEFUN([gl_FEATURES_H],
212 [
213   AC_CHECK_HEADERS_ONCE([features.h])
214   if test $ac_cv_header_features_h = yes; then
215     HAVE_FEATURES_H=1
216   else
217     HAVE_FEATURES_H=0
218   fi
219   AC_SUBST([HAVE_FEATURES_H])
220 ])
221
222 # AS_VAR_IF(VAR, VALUE, [IF-MATCH], [IF-NOT-MATCH])
223 # ----------------------------------------------------
224 # Backport of autoconf-2.63b's macro.
225 # Remove this macro when we can assume autoconf >= 2.64.
226 m4_ifndef([AS_VAR_IF],
227 [m4_define([AS_VAR_IF],
228 [AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
229
230 # gl_PROG_CC_C99
231 # Modifies the value of the shell variable CC in an attempt to make $CC
232 # understand ISO C99 source code.
233 # This is like AC_PROG_CC_C99, except that
234 # - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC
235 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00367.html>,
236 #   but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99
237 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00441.html>.
238 # Remaining problems:
239 # - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options
240 #   to CC twice
241 #   <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00431.html>.
242 # - AC_PROG_CC_STDC is likely to change now that C11 is an ISO standard.
243 AC_DEFUN([gl_PROG_CC_C99],
244 [
245   dnl Change that version number to the minimum Autoconf version that supports
246   dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls.
247   m4_version_prereq([9.0],
248     [AC_REQUIRE([AC_PROG_CC_C99])],
249     [AC_REQUIRE([AC_PROG_CC_STDC])])
250 ])
251
252 # gl_PROG_AR_RANLIB
253 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
254 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
255 # the values.
256 AC_DEFUN([gl_PROG_AR_RANLIB],
257 [
258   dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
259   dnl as "cc", and GCC as "gcc". They have different object file formats and
260   dnl library formats. In particular, the GNU binutils programs ar and ranlib
261   dnl produce libraries that work only with gcc, not with cc.
262   AC_REQUIRE([AC_PROG_CC])
263   dnl The '][' hides this use from 'aclocal'.
264   AC_BEFORE([$0], [A][M_PROG_AR])
265   AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
266     [
267       AC_EGREP_CPP([Amsterdam],
268         [
269 #ifdef __ACK__
270 Amsterdam
271 #endif
272         ],
273         [gl_cv_c_amsterdam_compiler=yes],
274         [gl_cv_c_amsterdam_compiler=no])
275     ])
276
277   dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
278   dnl building with __ACK__.
279   if test $gl_cv_c_amsterdam_compiler = yes; then
280     if test -z "$AR"; then
281       AR='cc -c.a'
282     fi
283     if test -z "$ARFLAGS"; then
284       ARFLAGS='-o'
285     fi
286   else
287     dnl AM_PROG_AR was added in automake v1.11.2.  AM_PROG_AR does not AC_SUBST
288     dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
289     dnl script on-demand, if not specified by ./configure of course).
290     dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
291     dnl will be ignored.  Also, pay attention to call AM_PROG_AR in else block
292     dnl because AM_PROG_AR is written so it could re-set AR variable even for
293     dnl __ACK__.  It may seem like its easier to avoid calling the macro here,
294     dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
295     dnl default value and automake should usually know them).
296     dnl
297     dnl The '][' hides this use from 'aclocal'.
298     m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
299   fi
300
301   dnl In case the code above has not helped with setting AR/ARFLAGS, use
302   dnl Automake-documented default values for AR and ARFLAGS, but prefer
303   dnl ${host}-ar over ar (useful for cross-compiling).
304   AC_CHECK_TOOL([AR], [ar], [ar])
305   if test -z "$ARFLAGS"; then
306     ARFLAGS='cr'
307   fi
308
309   AC_SUBST([AR])
310   AC_SUBST([ARFLAGS])
311   if test -z "$RANLIB"; then
312     if test $gl_cv_c_amsterdam_compiler = yes; then
313       RANLIB=':'
314     else
315       dnl Use the ranlib program if it is available.
316       AC_PROG_RANLIB
317     fi
318   fi
319   AC_SUBST([RANLIB])
320 ])
321
322 # AC_C_RESTRICT
323 # This definition is copied from post-2.69 Autoconf and overrides the
324 # AC_C_RESTRICT macro from autoconf 2.60..2.69.  It can be removed
325 # once autoconf >= 2.70 can be assumed.  It's painful to check version
326 # numbers, and in practice this macro is more up-to-date than Autoconf
327 # is, so override Autoconf unconditionally.
328 AC_DEFUN([AC_C_RESTRICT],
329 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
330   [ac_cv_c_restrict=no
331    # The order here caters to the fact that C++ does not require restrict.
332    for ac_kw in __restrict __restrict__ _Restrict restrict; do
333      AC_COMPILE_IFELSE(
334       [AC_LANG_PROGRAM(
335          [[typedef int *int_ptr;
336            int foo (int_ptr $ac_kw ip) { return ip[0]; }
337            int bar (int [$ac_kw]); /* Catch GCC bug 14050.  */
338            int bar (int ip[$ac_kw]) { return ip[0]; }
339          ]],
340          [[int s[1];
341            int *$ac_kw t = s;
342            t[0] = 0;
343            return foo (t) + bar (t);
344          ]])],
345       [ac_cv_c_restrict=$ac_kw])
346      test "$ac_cv_c_restrict" != no && break
347    done
348   ])
349  AH_VERBATIM([restrict],
350 [/* Define to the equivalent of the C99 'restrict' keyword, or to
351    nothing if this is not supported.  Do not define if restrict is
352    supported directly.  */
353 #undef restrict
354 /* Work around a bug in Sun C++: it does not support _Restrict or
355    __restrict__, even though the corresponding Sun C compiler ends up with
356    "#define restrict _Restrict" or "#define restrict __restrict__" in the
357    previous line.  Perhaps some future version of Sun C++ will work with
358    restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
359 #if defined __SUNPRO_CC && !defined __RESTRICT
360 # define _Restrict
361 # define __restrict__
362 #endif])
363  case $ac_cv_c_restrict in
364    restrict) ;;
365    no) AC_DEFINE([restrict], []) ;;
366    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
367  esac
368 ])# AC_C_RESTRICT
369
370 # gl_BIGENDIAN
371 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
372 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
373 # macros invoke AC_C_BIGENDIAN with arguments.
374 AC_DEFUN([gl_BIGENDIAN],
375 [
376   AC_C_BIGENDIAN
377 ])
378
379 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
380 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
381 # output a spurious "(cached)" mark in the midst of other configure output.
382 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
383 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
384 AC_DEFUN([gl_CACHE_VAL_SILENT],
385 [
386   saved_as_echo_n="$as_echo_n"
387   as_echo_n=':'
388   AC_CACHE_VAL([$1], [$2])
389   as_echo_n="$saved_as_echo_n"
390 ])
391
392 # AS_VAR_COPY was added in autoconf 2.63b
393 m4_define_default([AS_VAR_COPY],
394 [AS_LITERAL_IF([$1[]$2], [$1=$$2], [eval $1=\$$2])])