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