VirtualBox

source: kBuild/trunk/src/grep/m4/gnulib-common.m4

Last change on this file was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:eol-style set to LF
File size: 29.8 KB
Line 
1# gnulib-common.m4 serial 67
2dnl Copyright (C) 2007-2021 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_PREREQ([2.62])
8
9# gl_COMMON
10# is expanded unconditionally through gnulib-tool magic.
11AC_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])
17AC_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 || (!defined __STRICT_ANSI__ \
44 && (_GL_GNUC_PREREQ (4, 7) \
45 || (defined __apple_build_version__ \
46 ? 6000000 <= __apple_build_version__ \
47 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
48 /* _Noreturn works as-is. */
49# elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
50# define _Noreturn __attribute__ ((__noreturn__))
51# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
52# define _Noreturn __declspec (noreturn)
53# else
54# define _Noreturn
55# endif
56#endif
57])
58 AH_VERBATIM([isoc99_inline],
59[/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
60 the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
61 earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
62 __APPLE__ && __MACH__ test for Mac OS X.
63 __APPLE_CC__ tests for the Apple compiler and its version.
64 __STDC_VERSION__ tests for the C99 mode. */
65#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
66# define __GNUC_STDC_INLINE__ 1
67#endif])
68 AH_VERBATIM([attribute],
69[/* Attributes. */
70#if (defined __has_attribute \
71 && (!defined __clang_minor__ \
72 || 3 < __clang_major__ + (5 <= __clang_minor__)))
73# define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
74#else
75# define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
76# define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
77# define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
78# define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
79# define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
80# define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
81# define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
82# define _GL_ATTR_diagnose_if 0
83# define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
84# define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
85# define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
86# define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
87# define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
88# define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
89# ifdef _ICC
90# define _GL_ATTR_may_alias 0
91# else
92# define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
93# endif
94# define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
95# define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
96# define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
97# define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
98# define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
99# define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
100# define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
101# define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
102# define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
103# define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
104#endif
105
106#ifdef __has_c_attribute
107# define _GL_HAS_C_ATTRIBUTE(attr) __has_c_attribute (__##attr##__)
108#else
109# define _GL_HAS_C_ATTRIBUTE(attr) 0
110#endif
111
112]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's _Alignas instead.
113[
114#if _GL_HAS_ATTRIBUTE (alloc_size)
115# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
116#else
117# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
118#endif
119
120#if _GL_HAS_ATTRIBUTE (always_inline)
121# define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
122#else
123# define _GL_ATTRIBUTE_ALWAYS_INLINE
124#endif
125
126#if _GL_HAS_ATTRIBUTE (artificial)
127# define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
128#else
129# define _GL_ATTRIBUTE_ARTIFICIAL
130#endif
131
132/* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
133 <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
134 Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
135#if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
136# ifndef __SUNPRO_C
137# define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
138# else
139# define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
140# endif
141#else
142# define _GL_ATTRIBUTE_COLD
143#endif
144
145#if _GL_HAS_ATTRIBUTE (const)
146# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
147#else
148# define _GL_ATTRIBUTE_CONST
149#endif
150
151/* _GL_ATTRIBUTE_DEALLOC (F, I) is for functions returning pointers
152 that can be freed by passing them as the Ith argument to the
153 function F. _GL_ATTRIBUTE_DEALLOC_FREE is for functions that
154 return pointers that can be freed via 'free'; it can be used
155 only after including stdlib.h. These macros cannot be used on
156 inline functions. */
157#if _GL_GNUC_PREREQ (11, 0)
158# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
159#else
160# define _GL_ATTRIBUTE_DEALLOC(f, i)
161#endif
162#define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
163
164#if _GL_HAS_C_ATTRIBUTE (deprecated)
165# define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
166#elif _GL_HAS_ATTRIBUTE (deprecated)
167# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
168#else
169# define _GL_ATTRIBUTE_DEPRECATED
170#endif
171
172#if _GL_HAS_ATTRIBUTE (error)
173# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
174# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
175#elif _GL_HAS_ATTRIBUTE (diagnose_if)
176# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
177# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
178#else
179# define _GL_ATTRIBUTE_ERROR(msg)
180# define _GL_ATTRIBUTE_WARNING(msg)
181#endif
182
183#if _GL_HAS_ATTRIBUTE (externally_visible)
184# define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
185#else
186# define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
187#endif
188
189/* FALLTHROUGH is special, because it always expands to something. */
190#if _GL_HAS_C_ATTRIBUTE (fallthrough)
191# define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
192#elif _GL_HAS_ATTRIBUTE (fallthrough)
193# define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
194#else
195# define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
196#endif
197
198#if _GL_HAS_ATTRIBUTE (format)
199# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
200#else
201# define _GL_ATTRIBUTE_FORMAT(spec)
202#endif
203
204#if _GL_HAS_ATTRIBUTE (leaf)
205# define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
206#else
207# define _GL_ATTRIBUTE_LEAF
208#endif
209
210#if _GL_HAS_ATTRIBUTE (malloc)
211# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
212#else
213# define _GL_ATTRIBUTE_MALLOC
214#endif
215
216/* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
217#if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
218# define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
219#else
220# define _GL_ATTRIBUTE_MAY_ALIAS
221#endif
222
223#if _GL_HAS_C_ATTRIBUTE (maybe_unused)
224# define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
225#else
226# define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
227#endif
228/* Earlier spellings of this macro. */
229#define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
230
231#if _GL_HAS_C_ATTRIBUTE (nodiscard)
232# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
233#elif _GL_HAS_ATTRIBUTE (warn_unused_result)
234# define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
235#else
236# define _GL_ATTRIBUTE_NODISCARD
237#endif
238
239#if _GL_HAS_ATTRIBUTE (noinline)
240# define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
241#else
242# define _GL_ATTRIBUTE_NOINLINE
243#endif
244
245#if _GL_HAS_ATTRIBUTE (nonnull)
246# define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
247#else
248# define _GL_ATTRIBUTE_NONNULL(args)
249#endif
250
251#if _GL_HAS_ATTRIBUTE (nonstring)
252# define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
253#else
254# define _GL_ATTRIBUTE_NONSTRING
255#endif
256
257/* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
258
259#if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
260# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
261#else
262# define _GL_ATTRIBUTE_NOTHROW
263#endif
264
265#if _GL_HAS_ATTRIBUTE (packed)
266# define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
267#else
268# define _GL_ATTRIBUTE_PACKED
269#endif
270
271#if _GL_HAS_ATTRIBUTE (pure)
272# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
273#else
274# define _GL_ATTRIBUTE_PURE
275#endif
276
277#if _GL_HAS_ATTRIBUTE (returns_nonnull)
278# define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
279#else
280# define _GL_ATTRIBUTE_RETURNS_NONNULL
281#endif
282
283#if _GL_HAS_ATTRIBUTE (sentinel)
284# define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
285#else
286# define _GL_ATTRIBUTE_SENTINEL(pos)
287#endif
288
289#if _GL_HAS_ATTRIBUTE (unused)
290# define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
291#else
292# define _GL_ATTRIBUTE_UNUSED
293#endif
294/* Earlier spellings of this macro. */
295#define _GL_UNUSED _GL_ATTRIBUTE_UNUSED
296
297]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
298[
299/* To support C++ as well as C, use _GL_UNUSED_LABEL with trailing ';'. */
300#if !defined __cplusplus || _GL_GNUC_PREREQ (4, 5)
301# define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
302#else
303# define _GL_UNUSED_LABEL
304#endif
305])
306 AH_VERBATIM([async_safe],
307[/* The _GL_ASYNC_SAFE marker should be attached to functions that are
308 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
309 invoked from such signal handlers. Such functions have some restrictions:
310 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
311 or should be listed as async-signal-safe in POSIX
312 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
313 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
314 particular, are NOT async-signal-safe.
315 * All memory locations (variables and struct fields) that these functions
316 access must be marked 'volatile'. This holds for both read and write
317 accesses. Otherwise the compiler might optimize away stores to and
318 reads from such locations that occur in the program, depending on its
319 data flow analysis. For example, when the program contains a loop
320 that is intended to inspect a variable set from within a signal handler
321 while (!signal_occurred)
322 ;
323 the compiler is allowed to transform this into an endless loop if the
324 variable 'signal_occurred' is not declared 'volatile'.
325 Additionally, recall that:
326 * A signal handler should not modify errno (except if it is a handler
327 for a fatal signal and ends by raising the same signal again, thus
328 provoking the termination of the process). If it invokes a function
329 that may clobber errno, it needs to save and restore the value of
330 errno. */
331#define _GL_ASYNC_SAFE
332])
333 AH_VERBATIM([micro_optimizations],
334[/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
335 n1 and n2 are expressions without side effects, that evaluate to real
336 numbers (excluding NaN).
337 It returns
338 1 if n1 > n2
339 0 if n1 == n2
340 -1 if n1 < n2
341 The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
342 jump with nearly all GCC versions up to GCC 10.
343 This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
344 GCC versions up to GCC 9.
345 The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
346 avoids conditional jumps in all GCC versions >= 3.4. */
347#define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
348])
349 dnl Hint which direction to take regarding cross-compilation guesses:
350 dnl When a user installs a program on a platform they are not intimately
351 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
352 dnl choice. It implements the "If we don't know, assume the worst" principle.
353 dnl However, when an operating system developer (on a platform which is not
354 dnl yet known to gnulib) builds packages for their platform, they want to
355 dnl expose, not hide, possible platform bugs; in this case,
356 dnl --enable-cross-guesses=risky is the appropriate choice.
357 dnl Sets the variables
358 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
359 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
360 AC_ARG_ENABLE([cross-guesses],
361 [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
362 [specify policy for cross-compilation guesses])],
363 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
364 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
365 enableval=conservative
366 fi
367 gl_cross_guesses="$enableval"],
368 [gl_cross_guesses=conservative])
369 if test $gl_cross_guesses = risky; then
370 gl_cross_guess_normal="guessing yes"
371 gl_cross_guess_inverted="guessing no"
372 else
373 gl_cross_guess_normal="guessing no"
374 gl_cross_guess_inverted="guessing yes"
375 fi
376 dnl Preparation for running test programs:
377 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
378 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
379 dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
380 LIBC_FATAL_STDERR_=1
381 export LIBC_FATAL_STDERR_
382])
383
384# gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
385# gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
386# initializes the shell variable that indicates the presence of the given module
387# as a C preprocessor expression.
388AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
389[
390 GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
391 AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
392])
393
394# gl_MODULE_INDICATOR_CONDITION
395# expands to a C preprocessor expression that evaluates to 1 or 0, depending
396# whether a gnulib module that has been requested shall be considered present
397# or not.
398m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
399
400# gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
401# sets the shell variable that indicates the presence of the given module to
402# a C preprocessor expression that will evaluate to 1.
403AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
404[
405 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
406 [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
407 [abcdefghijklmnopqrstuvwxyz./-],
408 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
409 [gl_MODULE_INDICATOR_CONDITION])
410])
411
412# gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
413# modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
414# The shell variable's value is a C preprocessor expression that evaluates
415# to 0 or 1.
416AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
417[
418 m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
419 [
420 dnl Simplify the expression VALUE || 1 to 1.
421 $1=1
422 ],
423 [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
424 [gl_MODULE_INDICATOR_CONDITION])])
425])
426
427# gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
428# modifies the shell variable to include the given condition. The shell
429# variable's value is a C preprocessor expression that evaluates to 0 or 1.
430AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
431[
432 dnl Simplify the expression 1 || CONDITION to 1.
433 if test "$[]$1" != 1; then
434 dnl Simplify the expression 0 || CONDITION to CONDITION.
435 if test "$[]$1" = 0; then
436 $1=$2
437 else
438 $1="($[]$1 || $2)"
439 fi
440 fi
441])
442
443# gl_MODULE_INDICATOR([modulename])
444# defines a C macro indicating the presence of the given module
445# in a location where it can be used.
446# | Value | Value |
447# | in lib/ | in tests/ |
448# --------------------------------------------+---------+-----------+
449# Module present among main modules: | 1 | 1 |
450# --------------------------------------------+---------+-----------+
451# Module present among tests-related modules: | 0 | 1 |
452# --------------------------------------------+---------+-----------+
453# Module not present at all: | 0 | 0 |
454# --------------------------------------------+---------+-----------+
455AC_DEFUN([gl_MODULE_INDICATOR],
456[
457 AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
458 [abcdefghijklmnopqrstuvwxyz./-],
459 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
460 [gl_MODULE_INDICATOR_CONDITION],
461 [Define to a C preprocessor expression that evaluates to 1 or 0,
462 depending whether the gnulib module $1 shall be considered present.])
463])
464
465# gl_MODULE_INDICATOR_FOR_TESTS([modulename])
466# defines a C macro indicating the presence of the given module
467# in lib or tests. This is useful to determine whether the module
468# should be tested.
469# | Value | Value |
470# | in lib/ | in tests/ |
471# --------------------------------------------+---------+-----------+
472# Module present among main modules: | 1 | 1 |
473# --------------------------------------------+---------+-----------+
474# Module present among tests-related modules: | 1 | 1 |
475# --------------------------------------------+---------+-----------+
476# Module not present at all: | 0 | 0 |
477# --------------------------------------------+---------+-----------+
478AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
479[
480 AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
481 [abcdefghijklmnopqrstuvwxyz./-],
482 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
483 [Define to 1 when the gnulib module $1 should be tested.])
484])
485
486# gl_ASSERT_NO_GNULIB_POSIXCHECK
487# asserts that there will never be a need to #define GNULIB_POSIXCHECK.
488# and thereby enables an optimization of configure and config.h.
489# Used by Emacs.
490AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
491[
492 dnl Override gl_WARN_ON_USE_PREPARE.
493 dnl But hide this definition from 'aclocal'.
494 AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
495])
496
497# gl_ASSERT_NO_GNULIB_TESTS
498# asserts that there will be no gnulib tests in the scope of the configure.ac
499# and thereby enables an optimization of config.h.
500# Used by Emacs.
501AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
502[
503 dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
504 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
505])
506
507# Test whether <features.h> exists.
508# Set HAVE_FEATURES_H.
509AC_DEFUN([gl_FEATURES_H],
510[
511 AC_CHECK_HEADERS_ONCE([features.h])
512 if test $ac_cv_header_features_h = yes; then
513 HAVE_FEATURES_H=1
514 else
515 HAVE_FEATURES_H=0
516 fi
517 AC_SUBST([HAVE_FEATURES_H])
518])
519
520# gl_PROG_CC_C99
521# Modifies the value of the shell variable CC in an attempt to make $CC
522# understand ISO C99 source code.
523AC_DEFUN([gl_PROG_CC_C99],
524[
525 dnl Just use AC_PROG_CC_C99.
526 dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
527 dnl value of CC will contain the C99 enabling options twice. But this is only
528 dnl a cosmetic problem.
529 dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
530 dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
531 m4_version_prereq([2.70],
532 [AC_REQUIRE([AC_PROG_CC])],
533 [AC_REQUIRE([AC_PROG_CC_C99])])
534])
535
536# gl_PROG_AR_RANLIB
537# Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
538# The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
539# the values.
540AC_DEFUN([gl_PROG_AR_RANLIB],
541[
542 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
543 dnl as "cc", and GCC as "gcc". They have different object file formats and
544 dnl library formats. In particular, the GNU binutils programs ar and ranlib
545 dnl produce libraries that work only with gcc, not with cc.
546 AC_REQUIRE([AC_PROG_CC])
547 dnl The '][' hides this use from 'aclocal'.
548 AC_BEFORE([$0], [A][M_PROG_AR])
549 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
550 [
551 AC_EGREP_CPP([Amsterdam],
552 [
553#ifdef __ACK__
554Amsterdam
555#endif
556 ],
557 [gl_cv_c_amsterdam_compiler=yes],
558 [gl_cv_c_amsterdam_compiler=no])
559 ])
560
561 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
562 dnl building with __ACK__.
563 if test $gl_cv_c_amsterdam_compiler = yes; then
564 if test -z "$AR"; then
565 AR='cc -c.a'
566 fi
567 if test -z "$ARFLAGS"; then
568 ARFLAGS='-o'
569 fi
570 else
571 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
572 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
573 dnl script on-demand, if not specified by ./configure of course).
574 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
575 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
576 dnl because AM_PROG_AR is written so it could re-set AR variable even for
577 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
578 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
579 dnl default value and automake should usually know them).
580 dnl
581 dnl The '][' hides this use from 'aclocal'.
582 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
583 fi
584
585 dnl In case the code above has not helped with setting AR/ARFLAGS, use
586 dnl Automake-documented default values for AR and ARFLAGS, but prefer
587 dnl ${host}-ar over ar (useful for cross-compiling).
588 AC_CHECK_TOOL([AR], [ar], [ar])
589 if test -z "$ARFLAGS"; then
590 ARFLAGS='cr'
591 fi
592
593 AC_SUBST([AR])
594 AC_SUBST([ARFLAGS])
595 if test -z "$RANLIB"; then
596 if test $gl_cv_c_amsterdam_compiler = yes; then
597 RANLIB=':'
598 else
599 dnl Use the ranlib program if it is available.
600 AC_PROG_RANLIB
601 fi
602 fi
603 AC_SUBST([RANLIB])
604])
605
606# AC_C_RESTRICT
607# This definition is copied from post-2.70 Autoconf and overrides the
608# AC_C_RESTRICT macro from autoconf 2.60..2.70.
609m4_version_prereq([2.70.1], [], [
610AC_DEFUN([AC_C_RESTRICT],
611[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
612 [ac_cv_c_restrict=no
613 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
614 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
615 # Put 'restrict' last, because C++ lacks it.
616 for ac_kw in __restrict__ __restrict _Restrict restrict; do
617 AC_COMPILE_IFELSE(
618 [AC_LANG_PROGRAM(
619 [[typedef int *int_ptr;
620 int foo (int_ptr $ac_kw ip) { return ip[0]; }
621 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
622 int bar (int ip[$ac_kw]) { return ip[0]; }
623 ]],
624 [[int s[1];
625 int *$ac_kw t = s;
626 t[0] = 0;
627 return foo (t) + bar (t);
628 ]])],
629 [ac_cv_c_restrict=$ac_kw])
630 test "$ac_cv_c_restrict" != no && break
631 done
632 ])
633 AH_VERBATIM([restrict],
634[/* Define to the equivalent of the C99 'restrict' keyword, or to
635 nothing if this is not supported. Do not define if restrict is
636 supported only directly. */
637#undef restrict
638/* Work around a bug in older versions of Sun C++, which did not
639 #define __restrict__ or support _Restrict or __restrict__
640 even though the corresponding Sun C compiler ended up with
641 "#define restrict _Restrict" or "#define restrict __restrict__"
642 in the previous line. This workaround can be removed once
643 we assume Oracle Developer Studio 12.5 (2016) or later. */
644#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
645# define _Restrict
646# define __restrict__
647#endif])
648 case $ac_cv_c_restrict in
649 restrict) ;;
650 no) AC_DEFINE([restrict], []) ;;
651 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
652 esac
653])# AC_C_RESTRICT
654])
655
656# gl_BIGENDIAN
657# is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
658# Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
659# macros invoke AC_C_BIGENDIAN with arguments.
660AC_DEFUN([gl_BIGENDIAN],
661[
662 AC_C_BIGENDIAN
663])
664
665# A temporary file descriptor.
666# Must be less than 10, because dash 0.5.8 does not support redirections
667# with multi-digit file descriptors.
668m4_define([GL_TMP_FD], 9)
669
670# gl_SILENT(command)
671# executes command, but without the normal configure output.
672# This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
673# inside another AC_CACHE_CHECK.
674AC_DEFUN([gl_SILENT],
675[
676 exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
677 $1
678 exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
679])
680
681# gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
682# is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
683# output a spurious "(cached)" mark in the midst of other configure output.
684# This macro should be used instead of AC_CACHE_VAL when it is not surrounded
685# by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
686AC_DEFUN([gl_CACHE_VAL_SILENT],
687[
688 gl_SILENT([
689 AC_CACHE_VAL([$1], [$2])
690 ])
691])
692
693# gl_CC_ALLOW_WARNINGS
694# sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
695# that reverts a preceding '-Werror' option, if available.
696# This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
697# and empty otherwise.
698AC_DEFUN([gl_CC_ALLOW_WARNINGS],
699[
700 AC_REQUIRE([AC_PROG_CC])
701 AC_CACHE_CHECK([for C compiler option to allow warnings],
702 [gl_cv_cc_wallow],
703 [rm -f conftest*
704 echo 'int dummy;' > conftest.c
705 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
706 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
707 dnl Test the number of error output lines, because AIX xlc accepts the
708 dnl option '-Wno-error', just to produce a warning
709 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
710 dnl afterwards.
711 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
712 gl_cv_cc_wallow='-Wno-error'
713 else
714 gl_cv_cc_wallow=none
715 fi
716 rm -f conftest*
717 ])
718 case "$gl_cv_cc_wallow" in
719 none) GL_CFLAG_ALLOW_WARNINGS='' ;;
720 *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
721 esac
722 AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
723])
724
725# gl_CXX_ALLOW_WARNINGS
726# sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
727# that reverts a preceding '-Werror' option, if available.
728AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
729[
730 dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
731 if test -n "$CXX" && test "$CXX" != no; then
732 AC_CACHE_CHECK([for C++ compiler option to allow warnings],
733 [gl_cv_cxx_wallow],
734 [rm -f conftest*
735 echo 'int dummy;' > conftest.cc
736 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
737 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
738 dnl Test the number of error output lines, because AIX xlC accepts the
739 dnl option '-Wno-error', just to produce a warning
740 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
741 dnl afterwards.
742 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
743 gl_cv_cxx_wallow='-Wno-error'
744 else
745 gl_cv_cxx_wallow=none
746 fi
747 rm -f conftest*
748 ])
749 case "$gl_cv_cxx_wallow" in
750 none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
751 *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
752 esac
753 else
754 GL_CXXFLAG_ALLOW_WARNINGS=''
755 fi
756 AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
757])
758
759dnl Expands to some code for use in .c programs that, on native Windows, defines
760dnl the Microsoft deprecated alias function names to the underscore-prefixed
761dnl actual function names. With this macro, these function names are available
762dnl without linking with '-loldnames' and without generating warnings.
763dnl Usage: Use it after all system header files are included.
764dnl #include <...>
765dnl #include <...>
766dnl ]GL_MDA_DEFINES[
767dnl ...
768AC_DEFUN([GL_MDA_DEFINES],[
769AC_REQUIRE([_GL_MDA_DEFINES])
770[$gl_mda_defines]
771])
772AC_DEFUN([_GL_MDA_DEFINES],
773[gl_mda_defines='
774#if defined _WIN32 && !defined __CYGWIN__
775#define access _access
776#define chdir _chdir
777#define chmod _chmod
778#define close _close
779#define creat _creat
780#define dup _dup
781#define dup2 _dup2
782#define ecvt _ecvt
783#define execl _execl
784#define execle _execle
785#define execlp _execlp
786#define execv _execv
787#define execve _execve
788#define execvp _execvp
789#define execvpe _execvpe
790#define fcloseall _fcloseall
791#define fcvt _fcvt
792#define fdopen _fdopen
793#define fileno _fileno
794#define gcvt _gcvt
795#define getcwd _getcwd
796#define getpid _getpid
797#define getw _getw
798#define isatty _isatty
799#define j0 _j0
800#define j1 _j1
801#define jn _jn
802#define lfind _lfind
803#define lsearch _lsearch
804#define lseek _lseek
805#define memccpy _memccpy
806#define mkdir _mkdir
807#define mktemp _mktemp
808#define open _open
809#define putenv _putenv
810#define putw _putw
811#define read _read
812#define rmdir _rmdir
813#define strdup _strdup
814#define swab _swab
815#define tempnam _tempnam
816#define tzset _tzset
817#define umask _umask
818#define unlink _unlink
819#define utime _utime
820#define wcsdup _wcsdup
821#define write _write
822#define y0 _y0
823#define y1 _y1
824#define yn _yn
825#endif
826'
827])
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette