[gdb/testsuite] Update psym-external-decl.exp for gcc-10/clang
[deliverable/binutils-gdb.git] / gnulib / import / m4 / gnulib-common.m4
1 # gnulib-common.m4 serial 48
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([_Noreturn],
19 [/* The _Noreturn keyword of C11. */
20 #ifndef _Noreturn
21 # if (defined __cplusplus \
22 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
23 || (defined _MSC_VER && 1900 <= _MSC_VER)) \
24 && 0)
25 /* [[noreturn]] is not practically usable, because with it the syntax
26 extern _Noreturn void func (...);
27 would not be valid; such a declaration would only be valid with 'extern'
28 and '_Noreturn' swapped, or without the 'extern' keyword. However, some
29 AIX system header files and several gnulib header files use precisely
30 this syntax with 'extern'. */
31 # define _Noreturn [[noreturn]]
32 # elif ((!defined __cplusplus || defined __clang__) \
33 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
34 || 4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
35 || (defined __apple_build_version__ \
36 ? 6000000 <= __apple_build_version__ \
37 : 3 < __clang_major__ + (5 <= __clang_minor__))))
38 /* _Noreturn works as-is. */
39 # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
40 # define _Noreturn __attribute__ ((__noreturn__))
41 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
42 # define _Noreturn __declspec (noreturn)
43 # else
44 # define _Noreturn
45 # endif
46 #endif
47 ])
48 AH_VERBATIM([isoc99_inline],
49 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
50 the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
51 earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
52 __APPLE__ && __MACH__ test for Mac OS X.
53 __APPLE_CC__ tests for the Apple compiler and its version.
54 __STDC_VERSION__ tests for the C99 mode. */
55 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
56 # define __GNUC_STDC_INLINE__ 1
57 #endif])
58 AH_VERBATIM([unused_parameter],
59 [/* Define as a marker that can be attached to declarations that might not
60 be used. This helps to reduce warnings, such as from
61 GCC -Wunused-parameter. */
62 #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
63 # define _GL_UNUSED __attribute__ ((__unused__))
64 #else
65 # define _GL_UNUSED
66 #endif
67 /* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
68 is a misnomer outside of parameter lists. */
69 #define _UNUSED_PARAMETER_ _GL_UNUSED
70
71 /* gcc supports the "unused" attribute on possibly unused labels, and
72 g++ has since version 4.5. Note to support C++ as well as C,
73 _GL_UNUSED_LABEL should be used with a trailing ; */
74 #if !defined __cplusplus || __GNUC__ > 4 \
75 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
76 # define _GL_UNUSED_LABEL _GL_UNUSED
77 #else
78 # define _GL_UNUSED_LABEL
79 #endif
80
81 /* The __pure__ attribute was added in gcc 2.96. */
82 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
83 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
84 #else
85 # define _GL_ATTRIBUTE_PURE /* empty */
86 #endif
87
88 /* The __const__ attribute was added in gcc 2.95. */
89 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
90 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
91 #else
92 # define _GL_ATTRIBUTE_CONST /* empty */
93 #endif
94
95 /* The __malloc__ attribute was added in gcc 3. */
96 #if 3 <= __GNUC__
97 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
98 #else
99 # define _GL_ATTRIBUTE_MALLOC /* empty */
100 #endif
101 ])
102 AH_VERBATIM([async_safe],
103 [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
104 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
105 invoked from such signal handlers. Such functions have some restrictions:
106 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
107 or should be listed as async-signal-safe in POSIX
108 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
109 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
110 particular, are NOT async-signal-safe.
111 * All memory locations (variables and struct fields) that these functions
112 access must be marked 'volatile'. This holds for both read and write
113 accesses. Otherwise the compiler might optimize away stores to and
114 reads from such locations that occur in the program, depending on its
115 data flow analysis. For example, when the program contains a loop
116 that is intended to inspect a variable set from within a signal handler
117 while (!signal_occurred)
118 ;
119 the compiler is allowed to transform this into an endless loop if the
120 variable 'signal_occurred' is not declared 'volatile'.
121 Additionally, recall that:
122 * A signal handler should not modify errno (except if it is a handler
123 for a fatal signal and ends by raising the same signal again, thus
124 provoking the termination of the process). If it invokes a function
125 that may clobber errno, it needs to save and restore the value of
126 errno. */
127 #define _GL_ASYNC_SAFE
128 ])
129 dnl Hint which direction to take regarding cross-compilation guesses:
130 dnl When a user installs a program on a platform they are not intimately
131 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
132 dnl choice. It implements the "If we don't know, assume the worst" principle.
133 dnl However, when an operating system developer (on a platform which is not
134 dnl yet known to gnulib) builds packages for their platform, they want to
135 dnl expose, not hide, possible platform bugs; in this case,
136 dnl --enable-cross-guesses=risky is the appropriate choice.
137 dnl Sets the variables
138 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
139 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
140 AC_ARG_ENABLE([cross-guesses],
141 [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
142 [specify policy for cross-compilation guesses])],
143 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
144 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
145 enableval=conservative
146 fi
147 gl_cross_guesses="$enableval"],
148 [gl_cross_guesses=conservative])
149 if test $gl_cross_guesses = risky; then
150 gl_cross_guess_normal="guessing yes"
151 gl_cross_guess_inverted="guessing no"
152 else
153 gl_cross_guess_normal="guessing no"
154 gl_cross_guess_inverted="guessing yes"
155 fi
156 dnl Preparation for running test programs:
157 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
158 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
159 dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
160 LIBC_FATAL_STDERR_=1
161 export LIBC_FATAL_STDERR_
162 ])
163
164 # gl_MODULE_INDICATOR_CONDITION
165 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
166 # whether a gnulib module that has been requested shall be considered present
167 # or not.
168 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
169
170 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
171 # sets the shell variable that indicates the presence of the given module to
172 # a C preprocessor expression that will evaluate to 1.
173 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
174 [
175 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
176 [GNULIB_[]m4_translit([[$1]],
177 [abcdefghijklmnopqrstuvwxyz./-],
178 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
179 [gl_MODULE_INDICATOR_CONDITION])
180 ])
181
182 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
183 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
184 # The shell variable's value is a C preprocessor expression that evaluates
185 # to 0 or 1.
186 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
187 [
188 m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
189 [
190 dnl Simplify the expression VALUE || 1 to 1.
191 $1=1
192 ],
193 [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
194 [gl_MODULE_INDICATOR_CONDITION])])
195 ])
196
197 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
198 # modifies the shell variable to include the given condition. The shell
199 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
200 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
201 [
202 dnl Simplify the expression 1 || CONDITION to 1.
203 if test "$[]$1" != 1; then
204 dnl Simplify the expression 0 || CONDITION to CONDITION.
205 if test "$[]$1" = 0; then
206 $1=$2
207 else
208 $1="($[]$1 || $2)"
209 fi
210 fi
211 ])
212
213 # gl_MODULE_INDICATOR([modulename])
214 # defines a C macro indicating the presence of the given module
215 # in a location where it can be used.
216 # | Value | Value |
217 # | in lib/ | in tests/ |
218 # --------------------------------------------+---------+-----------+
219 # Module present among main modules: | 1 | 1 |
220 # --------------------------------------------+---------+-----------+
221 # Module present among tests-related modules: | 0 | 1 |
222 # --------------------------------------------+---------+-----------+
223 # Module not present at all: | 0 | 0 |
224 # --------------------------------------------+---------+-----------+
225 AC_DEFUN([gl_MODULE_INDICATOR],
226 [
227 AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
228 [abcdefghijklmnopqrstuvwxyz./-],
229 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
230 [gl_MODULE_INDICATOR_CONDITION],
231 [Define to a C preprocessor expression that evaluates to 1 or 0,
232 depending whether the gnulib module $1 shall be considered present.])
233 ])
234
235 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
236 # defines a C macro indicating the presence of the given module
237 # in lib or tests. This is useful to determine whether the module
238 # should be tested.
239 # | Value | Value |
240 # | in lib/ | in tests/ |
241 # --------------------------------------------+---------+-----------+
242 # Module present among main modules: | 1 | 1 |
243 # --------------------------------------------+---------+-----------+
244 # Module present among tests-related modules: | 1 | 1 |
245 # --------------------------------------------+---------+-----------+
246 # Module not present at all: | 0 | 0 |
247 # --------------------------------------------+---------+-----------+
248 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
249 [
250 AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
251 [abcdefghijklmnopqrstuvwxyz./-],
252 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
253 [Define to 1 when the gnulib module $1 should be tested.])
254 ])
255
256 # gl_ASSERT_NO_GNULIB_POSIXCHECK
257 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
258 # and thereby enables an optimization of configure and config.h.
259 # Used by Emacs.
260 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
261 [
262 dnl Override gl_WARN_ON_USE_PREPARE.
263 dnl But hide this definition from 'aclocal'.
264 AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
265 ])
266
267 # gl_ASSERT_NO_GNULIB_TESTS
268 # asserts that there will be no gnulib tests in the scope of the configure.ac
269 # and thereby enables an optimization of config.h.
270 # Used by Emacs.
271 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
272 [
273 dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
274 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
275 ])
276
277 # Test whether <features.h> exists.
278 # Set HAVE_FEATURES_H.
279 AC_DEFUN([gl_FEATURES_H],
280 [
281 AC_CHECK_HEADERS_ONCE([features.h])
282 if test $ac_cv_header_features_h = yes; then
283 HAVE_FEATURES_H=1
284 else
285 HAVE_FEATURES_H=0
286 fi
287 AC_SUBST([HAVE_FEATURES_H])
288 ])
289
290 # AS_VAR_IF(VAR, VALUE, [IF-MATCH], [IF-NOT-MATCH])
291 # ----------------------------------------------------
292 # Backport of autoconf-2.63b's macro.
293 # Remove this macro when we can assume autoconf >= 2.64.
294 m4_ifndef([AS_VAR_IF],
295 [m4_define([AS_VAR_IF],
296 [AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
297
298 # gl_PROG_CC_C99
299 # Modifies the value of the shell variable CC in an attempt to make $CC
300 # understand ISO C99 source code.
301 # This is like AC_PROG_CC_C99, except that
302 # - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC
303 # <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00367.html>,
304 # but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99
305 # <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00441.html>.
306 # Remaining problems:
307 # - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options
308 # to CC twice
309 # <https://lists.gnu.org/r/bug-gnulib/2011-09/msg00431.html>.
310 # - AC_PROG_CC_STDC is likely to change now that C11 is an ISO standard.
311 AC_DEFUN([gl_PROG_CC_C99],
312 [
313 dnl Change that version number to the minimum Autoconf version that supports
314 dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls.
315 m4_version_prereq([9.0],
316 [AC_REQUIRE([AC_PROG_CC_C99])],
317 [AC_REQUIRE([AC_PROG_CC_STDC])])
318 ])
319
320 # gl_PROG_AR_RANLIB
321 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
322 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
323 # the values.
324 AC_DEFUN([gl_PROG_AR_RANLIB],
325 [
326 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
327 dnl as "cc", and GCC as "gcc". They have different object file formats and
328 dnl library formats. In particular, the GNU binutils programs ar and ranlib
329 dnl produce libraries that work only with gcc, not with cc.
330 AC_REQUIRE([AC_PROG_CC])
331 dnl The '][' hides this use from 'aclocal'.
332 AC_BEFORE([$0], [A][M_PROG_AR])
333 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
334 [
335 AC_EGREP_CPP([Amsterdam],
336 [
337 #ifdef __ACK__
338 Amsterdam
339 #endif
340 ],
341 [gl_cv_c_amsterdam_compiler=yes],
342 [gl_cv_c_amsterdam_compiler=no])
343 ])
344
345 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
346 dnl building with __ACK__.
347 if test $gl_cv_c_amsterdam_compiler = yes; then
348 if test -z "$AR"; then
349 AR='cc -c.a'
350 fi
351 if test -z "$ARFLAGS"; then
352 ARFLAGS='-o'
353 fi
354 else
355 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
356 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
357 dnl script on-demand, if not specified by ./configure of course).
358 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
359 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
360 dnl because AM_PROG_AR is written so it could re-set AR variable even for
361 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
362 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
363 dnl default value and automake should usually know them).
364 dnl
365 dnl The '][' hides this use from 'aclocal'.
366 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
367 fi
368
369 dnl In case the code above has not helped with setting AR/ARFLAGS, use
370 dnl Automake-documented default values for AR and ARFLAGS, but prefer
371 dnl ${host}-ar over ar (useful for cross-compiling).
372 AC_CHECK_TOOL([AR], [ar], [ar])
373 if test -z "$ARFLAGS"; then
374 ARFLAGS='cr'
375 fi
376
377 AC_SUBST([AR])
378 AC_SUBST([ARFLAGS])
379 if test -z "$RANLIB"; then
380 if test $gl_cv_c_amsterdam_compiler = yes; then
381 RANLIB=':'
382 else
383 dnl Use the ranlib program if it is available.
384 AC_PROG_RANLIB
385 fi
386 fi
387 AC_SUBST([RANLIB])
388 ])
389
390 # AC_C_RESTRICT
391 # This definition is copied from post-2.69 Autoconf and overrides the
392 # AC_C_RESTRICT macro from autoconf 2.60..2.69. It can be removed
393 # once autoconf >= 2.70 can be assumed. It's painful to check version
394 # numbers, and in practice this macro is more up-to-date than Autoconf
395 # is, so override Autoconf unconditionally.
396 AC_DEFUN([AC_C_RESTRICT],
397 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
398 [ac_cv_c_restrict=no
399 # The order here caters to the fact that C++ does not require restrict.
400 for ac_kw in __restrict __restrict__ _Restrict restrict; do
401 AC_COMPILE_IFELSE(
402 [AC_LANG_PROGRAM(
403 [[typedef int *int_ptr;
404 int foo (int_ptr $ac_kw ip) { return ip[0]; }
405 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
406 int bar (int ip[$ac_kw]) { return ip[0]; }
407 ]],
408 [[int s[1];
409 int *$ac_kw t = s;
410 t[0] = 0;
411 return foo (t) + bar (t);
412 ]])],
413 [ac_cv_c_restrict=$ac_kw])
414 test "$ac_cv_c_restrict" != no && break
415 done
416 ])
417 AH_VERBATIM([restrict],
418 [/* Define to the equivalent of the C99 'restrict' keyword, or to
419 nothing if this is not supported. Do not define if restrict is
420 supported directly. */
421 #undef restrict
422 /* Work around a bug in older versions of Sun C++, which did not
423 #define __restrict__ or support _Restrict or __restrict__
424 even though the corresponding Sun C compiler ended up with
425 "#define restrict _Restrict" or "#define restrict __restrict__"
426 in the previous line. This workaround can be removed once
427 we assume Oracle Developer Studio 12.5 (2016) or later. */
428 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
429 # define _Restrict
430 # define __restrict__
431 #endif])
432 case $ac_cv_c_restrict in
433 restrict) ;;
434 no) AC_DEFINE([restrict], []) ;;
435 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
436 esac
437 ])# AC_C_RESTRICT
438
439 # gl_BIGENDIAN
440 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
441 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
442 # macros invoke AC_C_BIGENDIAN with arguments.
443 AC_DEFUN([gl_BIGENDIAN],
444 [
445 AC_C_BIGENDIAN
446 ])
447
448 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
449 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
450 # output a spurious "(cached)" mark in the midst of other configure output.
451 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
452 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
453 AC_DEFUN([gl_CACHE_VAL_SILENT],
454 [
455 saved_as_echo_n="$as_echo_n"
456 as_echo_n=':'
457 AC_CACHE_VAL([$1], [$2])
458 as_echo_n="$saved_as_echo_n"
459 ])
460
461 # AS_VAR_COPY was added in autoconf 2.63b
462 m4_define_default([AS_VAR_COPY],
463 [AS_LITERAL_IF([$1[]$2], [$1=$$2], [eval $1=\$$2])])
This page took 0.047887 seconds and 4 git commands to generate.