Debian Codegraph @

gnulib/m4/gnulib-common.m4

raw
1 # gnulib-common.m4
2 # serial 96.2
3 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 AC_PREREQ([2.62])
9
10 # gl_COMMON
11 # is expanded unconditionally through gnulib-tool magic.
12 AC_DEFUN([gl_COMMON], [
13 dnl Use AC_REQUIRE here, so that the code is expanded once only.
14 AC_REQUIRE([gl_00GNULIB])
15 AC_REQUIRE([gl_COMMON_BODY])
16 AC_REQUIRE([gl_ZZGNULIB])
17 ])
18 AC_DEFUN([gl_COMMON_BODY], [
19 AH_VERBATIM([0witness],
20 [/* Witness that <config.h> has been included. */
21 #define _GL_CONFIG_H_INCLUDED 1
22 ])
23 AH_VERBATIM([_GL_GNUC_PREREQ],
24 [/* True if the compiler says it groks GNU C version MAJOR.MINOR.
25 Except that
26 - clang groks GNU C 4.2, even on Windows, where it does not define
27 __GNUC__.
28 - The OpenMandriva-modified clang compiler pretends that it groks
29 GNU C version 13.1, but it doesn't: It does not support
30 __attribute__ ((__malloc__ (f, i))), nor does it support
31 __attribute__ ((__warning__ (message))) on a function redeclaration.
32 - Users can make clang lie as well, through the -fgnuc-version option. */
33 #if defined __GNUC__ && defined __GNUC_MINOR__ && !defined __clang__
34 # define _GL_GNUC_PREREQ(major, minor) \
35 ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__))
36 #elif defined __clang__
37 /* clang really only groks GNU C 4.2. */
38 # define _GL_GNUC_PREREQ(major, minor) \
39 ((major) < 4 + ((minor) <= 2))
40 #else
41 # define _GL_GNUC_PREREQ(major, minor) 0
42 #endif
43 ])
44 AH_VERBATIM([_Noreturn],
45 [/* The _Noreturn keyword of C11. */
46 #ifndef _Noreturn
47 # if (defined __cplusplus \
48 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
49 || (defined _MSC_VER && 1900 <= _MSC_VER)) \
50 && 0)
51 /* [[noreturn]] is not practically usable, because with it the syntax
52 extern _Noreturn void func (...);
53 would not be valid; such a declaration would only be valid with 'extern'
54 and '_Noreturn' swapped, or without the 'extern' keyword. However, some
55 AIX system header files and several gnulib header files use precisely
56 this syntax with 'extern'. */
57 # define _Noreturn [[noreturn]]
58 # elif (defined __clang__ && __clang_major__ < 16 \
59 && defined _GL_WORK_AROUND_LLVM_BUG_59792)
60 /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around
61 that rare LLVM bug, though you may get many false-alarm warnings. */
62 # define _Noreturn
63 # elif ((!defined __cplusplus || defined __clang__) \
64 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
65 || (!defined __STRICT_ANSI__ \
66 && (_GL_GNUC_PREREQ (4, 7) \
67 || (defined __apple_build_version__ \
68 ? 6000000 <= __apple_build_version__ \
69 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
70 /* _Noreturn works as-is. */
71 # elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
72 # define _Noreturn __attribute__ ((__noreturn__))
73 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
74 # define _Noreturn __declspec (noreturn)
75 # else
76 # define _Noreturn
77 # endif
78 #endif
79 ])
80 AH_VERBATIM([isoc99_inline],
81 [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
82 the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
83 earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
84 __APPLE__ && __MACH__ test for Mac OS X.
85 __APPLE_CC__ tests for the Apple compiler and its version.
86 __STDC_VERSION__ tests for the C99 mode. */
87 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
88 # define __GNUC_STDC_INLINE__ 1
89 #endif])
90 AH_VERBATIM([attribute],
91 [/* Attributes. */
92 /* Define _GL_HAS_ATTRIBUTE only once, because on FreeBSD, with gcc < 5, if
93 <config.h> gets included once again after <sys/cdefs.h>, __has_attribute(x)
94 expands to 0 always, and redefining _GL_HAS_ATTRIBUTE would turn off all
95 attributes. */
96 #ifndef _GL_HAS_ATTRIBUTE
97 # if (defined __has_attribute \
98 && (!defined __clang_minor__ \
99 || (defined __apple_build_version__ \
100 ? 7000000 <= __apple_build_version__ \
101 : 5 <= __clang_major__)))
102 # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
103 # else
104 # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
105 # define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
106 # define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
107 # define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
108 # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
109 # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
110 # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
111 # define _GL_ATTR_diagnose_if 0
112 # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
113 # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
114 # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
115 # define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
116 # define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
117 # define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
118 # ifdef _ICC
119 # define _GL_ATTR_may_alias 0
120 # else
121 # define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
122 # endif
123 # define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
124 # define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
125 # define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
126 # define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
127 # define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
128 # define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
129 # define _GL_ATTR_reproducible 0 /* not yet supported, as of GCC 14 */
130 # define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
131 # define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
132 # define _GL_ATTR_unsequenced 0 /* not yet supported, as of GCC 14 */
133 # define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
134 # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
135 # endif
136 #endif
137
138 /* Use __has_c_attribute if available. However, do not use with
139 pre-C23 GCC, which can issue false positives if -Wpedantic. */
140 #if (defined __has_c_attribute \
141 && ! (_GL_GNUC_PREREQ (4, 6) \
142 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710))
143 # define _GL_HAVE___HAS_C_ATTRIBUTE 1
144 #else
145 # define _GL_HAVE___HAS_C_ATTRIBUTE 0
146 #endif
147
148 /* Define if, in a function declaration, the attributes in bracket syntax
149 [[...]] must come before the attributes in __attribute__((...)) syntax.
150 If this is defined, it is best to avoid the bracket syntax, so that the
151 various _GL_ATTRIBUTE_* can be cumulated on the same declaration in any
152 order. */
153 #ifdef __cplusplus
154 # if defined __clang__
155 # define _GL_BRACKET_BEFORE_ATTRIBUTE 1
156 # endif
157 #else
158 # if defined __GNUC__ && !defined __clang__
159 # define _GL_BRACKET_BEFORE_ATTRIBUTE 1
160 # endif
161 #endif
162 ]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead.
163 [
164 /* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
165 is the size of the returned memory block.
166 _GL_ATTRIBUTE_ALLOC_SIZE ((M, N)) declares that the Mth argument multiplied
167 by the Nth argument of the function is the size of the returned memory block.
168 */
169 /* Applies to: functions, pointer to functions, function types. */
170 #ifndef _GL_ATTRIBUTE_ALLOC_SIZE
171 # if _GL_HAS_ATTRIBUTE (alloc_size)
172 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
173 # else
174 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
175 # endif
176 #endif
177
178 /* _GL_ATTRIBUTE_ALWAYS_INLINE tells that the compiler should always inline the
179 function and report an error if it cannot do so. */
180 /* Applies to: functions. */
181 #ifndef _GL_ATTRIBUTE_ALWAYS_INLINE
182 # if _GL_HAS_ATTRIBUTE (always_inline)
183 # define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
184 # else
185 # define _GL_ATTRIBUTE_ALWAYS_INLINE
186 # endif
187 #endif
188
189 /* _GL_ATTRIBUTE_ARTIFICIAL declares that the function is not important to show
190 in stack traces when debugging. The compiler should omit the function from
191 stack traces. */
192 /* Applies to: functions. */
193 #ifndef _GL_ATTRIBUTE_ARTIFICIAL
194 # if _GL_HAS_ATTRIBUTE (artificial)
195 # define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
196 # else
197 # define _GL_ATTRIBUTE_ARTIFICIAL
198 # endif
199 #endif
200
201 /* _GL_ATTRIBUTE_COLD declares that the function is rarely executed. */
202 /* Applies to: functions. */
203 /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
204 <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
205 Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
206 #ifndef _GL_ATTRIBUTE_COLD
207 # if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
208 # ifndef __SUNPRO_C
209 # define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
210 # else
211 # define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
212 # endif
213 # else
214 # define _GL_ATTRIBUTE_COLD
215 # endif
216 #endif
217
218 /* _GL_ATTRIBUTE_CONST declares:
219 It is OK for a compiler to move calls to the function and to omit
220 calls to the function if another call has the same arguments or the
221 result is not used.
222 This attribute is safe for a function that neither depends on
223 nor affects state, and always returns exactly once -
224 e.g., does not raise an exception, call longjmp, or loop forever.
225 (This attribute is stricter than _GL_ATTRIBUTE_PURE because the
226 function cannot observe state. It is stricter than
227 _GL_ATTRIBUTE_UNSEQUENCED because the function must return exactly
228 once and cannot depend on state addressed by its arguments.) */
229 /* Applies to: functions. */
230 #ifndef _GL_ATTRIBUTE_CONST
231 # if _GL_HAS_ATTRIBUTE (const)
232 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
233 # else
234 # define _GL_ATTRIBUTE_CONST _GL_ATTRIBUTE_UNSEQUENCED
235 # endif
236 #endif
237
238 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
239 that can be freed by passing them as the Ith argument to the
240 function F.
241 _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
242 can be freed via 'free'; it can be used only after declaring 'free'. */
243 /* Applies to: functions. Cannot be used on inline functions. */
244 #ifndef _GL_ATTRIBUTE_DEALLOC
245 # if _GL_GNUC_PREREQ (11, 0)
246 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
247 # else
248 # define _GL_ATTRIBUTE_DEALLOC(f, i)
249 # endif
250 #endif
251 /* If gnulib's <string.h> or <wchar.h> has already defined this macro, continue
252 to use this earlier definition, since <stdlib.h> may not have been included
253 yet. */
254 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
255 # if defined __cplusplus && defined __GNUC__ && !defined __clang__
256 /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
257 # define _GL_ATTRIBUTE_DEALLOC_FREE \
258 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
259 # else
260 # define _GL_ATTRIBUTE_DEALLOC_FREE \
261 _GL_ATTRIBUTE_DEALLOC (free, 1)
262 # endif
263 #endif
264
265 /* _GL_ATTRIBUTE_DEPRECATED: Declares that an entity is deprecated.
266 The compiler may warn if the entity is used. */
267 /* Applies to:
268 - function, variable,
269 - struct, union, struct/union member,
270 - enumeration, enumeration item,
271 - typedef,
272 in C++ also: namespace, class, template specialization. */
273 #ifndef _GL_ATTRIBUTE_DEPRECATED
274 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
275 # if _GL_HAVE___HAS_C_ATTRIBUTE
276 # if __has_c_attribute (__deprecated__)
277 # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
278 # endif
279 # endif
280 # endif
281 # if !defined _GL_ATTRIBUTE_DEPRECATED && _GL_HAS_ATTRIBUTE (deprecated)
282 # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
283 # endif
284 # ifndef _GL_ATTRIBUTE_DEPRECATED
285 # define _GL_ATTRIBUTE_DEPRECATED
286 # endif
287 #endif
288
289 /* _GL_ATTRIBUTE_ERROR(msg) requests an error if a function is called and
290 the function call is not optimized away.
291 _GL_ATTRIBUTE_WARNING(msg) requests a warning if a function is called and
292 the function call is not optimized away. */
293 /* Applies to: functions. */
294 #if !(defined _GL_ATTRIBUTE_ERROR && defined _GL_ATTRIBUTE_WARNING)
295 # if _GL_HAS_ATTRIBUTE (error)
296 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
297 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
298 # elif _GL_HAS_ATTRIBUTE (diagnose_if)
299 # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
300 # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
301 # else
302 # define _GL_ATTRIBUTE_ERROR(msg)
303 # define _GL_ATTRIBUTE_WARNING(msg)
304 # endif
305 #endif
306
307 /* _GL_ATTRIBUTE_EXTERNALLY_VISIBLE declares that the entity should remain
308 visible to debuggers etc., even with '-fwhole-program'. */
309 /* Applies to: functions, variables. */
310 #ifndef _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
311 # if _GL_HAS_ATTRIBUTE (externally_visible)
312 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
313 # else
314 # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
315 # endif
316 #endif
317
318 /* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if
319 the control flow falls through to the immediately following 'case' or
320 'default' label. The compiler should not warn in this case. */
321 /* Applies to: Empty statement (;), inside a 'switch' statement. */
322 /* Always expands to something. */
323 #ifndef _GL_ATTRIBUTE_FALLTHROUGH
324 # if _GL_HAVE___HAS_C_ATTRIBUTE
325 # if __has_c_attribute (__fallthrough__)
326 # define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
327 # endif
328 # endif
329 # if !defined _GL_ATTRIBUTE_FALLTHROUGH && _GL_HAS_ATTRIBUTE (fallthrough)
330 # define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
331 # endif
332 # ifndef _GL_ATTRIBUTE_FALLTHROUGH
333 # define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
334 # endif
335 #endif
336
337 /* _GL_ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK))
338 declares that the STRING-INDEXth function argument is a format string of
339 style ARCHETYPE, which is one of:
340 printf, gnu_printf
341 scanf, gnu_scanf,
342 strftime, gnu_strftime,
343 strfmon,
344 or the same thing prefixed and suffixed with '__'.
345 If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
346 are suitable for the format string. */
347 /* Applies to: functions. */
348 #ifndef _GL_ATTRIBUTE_FORMAT
349 # if _GL_HAS_ATTRIBUTE (format)
350 # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
351 # else
352 # define _GL_ATTRIBUTE_FORMAT(spec)
353 # endif
354 #endif
355
356 /* _GL_ATTRIBUTE_LEAF declares that if the function is called from some other
357 compilation unit, it executes code from that unit only by return or by
358 exception handling. This declaration lets the compiler optimize that unit
359 more aggressively. */
360 /* Applies to: functions. */
361 #ifndef _GL_ATTRIBUTE_LEAF
362 # if _GL_HAS_ATTRIBUTE (leaf)
363 # define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
364 # else
365 # define _GL_ATTRIBUTE_LEAF
366 # endif
367 #endif
368
369 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
370 allocated memory. */
371 /* Applies to: functions. */
372 #ifndef _GL_ATTRIBUTE_MALLOC
373 # if _GL_HAS_ATTRIBUTE (malloc)
374 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
375 # else
376 # define _GL_ATTRIBUTE_MALLOC
377 # endif
378 #endif
379
380 /* _GL_ATTRIBUTE_MAY_ALIAS declares that pointers to the type may point to the
381 same storage as pointers to other types. Thus this declaration disables
382 strict aliasing optimization. */
383 /* Applies to: types. */
384 /* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
385 #ifndef _GL_ATTRIBUTE_MAY_ALIAS
386 # if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
387 # define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
388 # else
389 # define _GL_ATTRIBUTE_MAY_ALIAS
390 # endif
391 #endif
392
393 /* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if
394 the entity is not used. The compiler should not warn if the entity is not
395 used. */
396 /* Applies to:
397 - function, variable,
398 - struct, union, struct/union member,
399 - enumeration, enumeration item,
400 - typedef,
401 in C++ also: class. */
402 /* In C++ and C23, this is spelled [[__maybe_unused__]].
403 GCC's syntax is __attribute__ ((__unused__)).
404 clang supports both syntaxes. Except that with clang ≥ 6, < 10, in C++ mode,
405 __has_c_attribute (__maybe_unused__) yields true but the use of
406 [[__maybe_unused__]] nevertheless produces a warning. */
407 #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
408 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
409 # if defined __clang__ && defined __cplusplus
410 # if !defined __apple_build_version__ && __clang_major__ >= 10
411 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
412 # endif
413 # elif _GL_HAVE___HAS_C_ATTRIBUTE
414 # if __has_c_attribute (__maybe_unused__)
415 # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
416 # endif
417 # endif
418 # endif
419 # ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
420 # define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
421 # endif
422 #endif
423 /* Alternative spelling of this macro, for convenience and for
424 compatibility with glibc/include/libc-symbols.h. */
425 #define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
426 /* Earlier spellings of this macro. */
427 #define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
428
429 /* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not
430 discard the return value. The compiler may warn if the caller does not use
431 the return value, unless the caller uses something like ignore_value. */
432 /* Applies to: function, enumeration, class. */
433 #ifndef _GL_ATTRIBUTE_NODISCARD
434 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
435 # if defined __clang__ && defined __cplusplus
436 /* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]] produces
437 a warning.
438 The 1000 below means a yet unknown threshold. When clang++ version X
439 starts supporting [[__nodiscard__]] without warning about it, you can
440 replace the 1000 with X. */
441 # if __clang_major__ >= 1000
442 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
443 # endif
444 # elif _GL_HAVE___HAS_C_ATTRIBUTE
445 # if __has_c_attribute (__nodiscard__)
446 # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
447 # endif
448 # endif
449 # endif
450 # if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE (warn_unused_result)
451 # define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
452 # endif
453 # ifndef _GL_ATTRIBUTE_NODISCARD
454 # define _GL_ATTRIBUTE_NODISCARD
455 # endif
456 #endif
457
458 /* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the
459 function. */
460 /* Applies to: functions. */
461 #ifndef _GL_ATTRIBUTE_NOINLINE
462 # if _GL_HAS_ATTRIBUTE (noinline)
463 # define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
464 # else
465 # define _GL_ATTRIBUTE_NOINLINE
466 # endif
467 #endif
468
469 /* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,...
470 must not be NULL.
471 _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be
472 null. */
473 /* Applies to: functions. */
474 #ifndef _GL_ATTRIBUTE_NONNULL
475 # if _GL_HAS_ATTRIBUTE (nonnull)
476 # define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
477 # else
478 # define _GL_ATTRIBUTE_NONNULL(args)
479 # endif
480 #endif
481
482 /* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
483 not meant to be NUL-terminated. */
484 /* Applies to: struct/union members and variables that are arrays of element
485 type '[[un]signed] char'. */
486 #ifndef _GL_ATTRIBUTE_NONSTRING
487 # if _GL_HAS_ATTRIBUTE (nonstring)
488 # define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
489 # else
490 # define _GL_ATTRIBUTE_NONSTRING
491 # endif
492 #endif
493
494 /* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
495
496 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
497 */
498 /* Applies to: functions. */
499 /* After a function's parameter list, this attribute must come first, before
500 other attributes. */
501 #ifndef _GL_ATTRIBUTE_NOTHROW
502 # if defined __cplusplus
503 # if _GL_GNUC_PREREQ (2, 8) || __clang_major__ >= 4
504 # if __cplusplus >= 201103L
505 # define _GL_ATTRIBUTE_NOTHROW noexcept (true)
506 # else
507 # define _GL_ATTRIBUTE_NOTHROW throw ()
508 # endif
509 # else
510 # define _GL_ATTRIBUTE_NOTHROW
511 # endif
512 # else
513 # if _GL_HAS_ATTRIBUTE (nothrow)
514 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
515 # else
516 # define _GL_ATTRIBUTE_NOTHROW
517 # endif
518 # endif
519 #endif
520
521 /* _GL_ATTRIBUTE_PACKED declares:
522 For struct members: The member has the smallest possible alignment.
523 For struct, union, class: All members have the smallest possible alignment,
524 minimizing the memory required. */
525 /* Applies to: struct members, struct, union,
526 in C++ also: class. */
527 #ifndef _GL_ATTRIBUTE_PACKED
528 /* Oracle Studio 12.6 miscompiles code with __attribute__ ((__packed__)) despite
529 __has_attribute OK. */
530 # if _GL_HAS_ATTRIBUTE (packed) && !defined __SUNPRO_C
531 # define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
532 # else
533 # define _GL_ATTRIBUTE_PACKED
534 # endif
535 #endif
536
537 /* _GL_ATTRIBUTE_PURE declares:
538 It is OK for a compiler to move calls to the function and to omit
539 calls to the function if another call has the same arguments or the
540 result is not used, and if observable state is the same.
541 This attribute is safe for a function that does not affect observable state
542 and always returns exactly once.
543 (This attribute is looser than _GL_ATTRIBUTE_CONST because the function
544 can depend on observable state. It is stricter than
545 _GL_ATTRIBUTE_REPRODUCIBLE because the function must return exactly
546 once and cannot affect state addressed by its arguments.) */
547 /* Applies to: functions. */
548 #ifndef _GL_ATTRIBUTE_PURE
549 # if _GL_HAS_ATTRIBUTE (pure)
550 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
551 # else
552 # define _GL_ATTRIBUTE_PURE _GL_ATTRIBUTE_REPRODUCIBLE
553 # endif
554 #endif
555
556 /* _GL_ATTRIBUTE_REPRODUCIBLE declares:
557 It is OK for a compiler to move calls to the function and to omit duplicate
558 calls to the function with the same arguments, so long as the state
559 addressed by its arguments is the same and is updated in time for
560 the rest of the program.
561 This attribute is safe for a function that is effectless and idempotent; see
562 ISO C 23 § 6.7.12.7 for a definition of these terms.
563 (This attribute is looser than _GL_ATTRIBUTE_UNSEQUENCED because
564 the function need not be stateless and idempotent. It is looser
565 than _GL_ATTRIBUTE_PURE because the function need not return
566 exactly once and can affect state addressed by its arguments.)
567 See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
568 <https://stackoverflow.com/questions/76847905/>. */
569 /* Applies to: functions, pointer to functions, function types. */
570 #ifndef _GL_ATTRIBUTE_REPRODUCIBLE
571 /* This may be revisited when gcc and clang support [[reproducible]] or possibly
572 __attribute__ ((__reproducible__)). */
573 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
574 # if _GL_HAS_ATTRIBUTE (reproducible)
575 # define _GL_ATTRIBUTE_REPRODUCIBLE [[reproducible]]
576 # endif
577 # endif
578 # ifndef _GL_ATTRIBUTE_REPRODUCIBLE
579 # define _GL_ATTRIBUTE_REPRODUCIBLE
580 # endif
581 #endif
582
583 /* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is
584 a non-NULL pointer. */
585 /* Applies to: functions. */
586 #ifndef _GL_ATTRIBUTE_RETURNS_NONNULL
587 # if _GL_HAS_ATTRIBUTE (returns_nonnull)
588 # define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
589 # else
590 # define _GL_ATTRIBUTE_RETURNS_NONNULL
591 # endif
592 #endif
593
594 /* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a
595 trailing NULL argument.
596 _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
597 _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
598 /* Applies to: functions. */
599 #ifndef _GL_ATTRIBUTE_SENTINEL
600 # if _GL_HAS_ATTRIBUTE (sentinel)
601 # define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
602 # else
603 # define _GL_ATTRIBUTE_SENTINEL(pos)
604 # endif
605 #endif
606
607 /* _GL_ATTRIBUTE_UNSEQUENCED declares:
608 It is OK for a compiler to move calls to the function and to omit duplicate
609 calls to the function with the same arguments, so long as the state
610 addressed by its arguments is the same.
611 This attribute is safe for a function that is effectless, idempotent,
612 stateless, and independent; see ISO C 23 § 6.7.12.7 for a definition of
613 these terms.
614 (This attribute is stricter than _GL_ATTRIBUTE_REPRODUCIBLE because
615 the function must be stateless and independent. It is looser than
616 _GL_ATTRIBUTE_CONST because the function need not return exactly
617 once and can depend on state addressed by its arguments.)
618 See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
619 <https://stackoverflow.com/questions/76847905/>. */
620 /* Applies to: functions, pointer to functions, function types. */
621 #ifndef _GL_ATTRIBUTE_UNSEQUENCED
622 /* This may be revisited when gcc and clang support [[unsequenced]] or possibly
623 __attribute__ ((__unsequenced__)). */
624 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
625 # if _GL_HAS_ATTRIBUTE (unsequenced)
626 # define _GL_ATTRIBUTE_UNSEQUENCED [[unsequenced]]
627 # endif
628 # endif
629 # ifndef _GL_ATTRIBUTE_UNSEQUENCED
630 # define _GL_ATTRIBUTE_UNSEQUENCED
631 # endif
632 #endif
633
634 /* A helper macro. Don't use it directly. */
635 #ifndef _GL_ATTRIBUTE_UNUSED
636 # if _GL_HAS_ATTRIBUTE (unused)
637 # define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
638 # else
639 # define _GL_ATTRIBUTE_UNUSED
640 # endif
641 #endif
642
643 ]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
644 [
645 /* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the
646 immediately preceding label is not used. The compiler should not warn
647 if the label is not used. */
648 /* Applies to: label (both in C and C++). */
649 /* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;'
650 syntax. But clang does. */
651 #ifndef _GL_UNUSED_LABEL
652 # if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__
653 # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
654 # else
655 # define _GL_UNUSED_LABEL
656 # endif
657 #endif
658 ])
659 AH_VERBATIM([c_linkage],
660 [/* In C++, there is the concept of "language linkage", that encompasses
661 name mangling and function calling conventions.
662 The following macros start and end a block of "C" linkage. */
663 #ifdef __cplusplus
664 # define _GL_BEGIN_C_LINKAGE extern "C" {
665 # define _GL_END_C_LINKAGE }
666 #else
667 # define _GL_BEGIN_C_LINKAGE
668 # define _GL_END_C_LINKAGE
669 #endif
670 ])
671 AH_VERBATIM([async_safe],
672 [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
673 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
674 invoked from such signal handlers. Such functions have some restrictions:
675 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
676 or should be listed as async-signal-safe in POSIX
677 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
678 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
679 particular, are NOT async-signal-safe.
680 * All memory locations (variables and struct fields) that these functions
681 access must be marked 'volatile'. This holds for both read and write
682 accesses. Otherwise the compiler might optimize away stores to and
683 reads from such locations that occur in the program, depending on its
684 data flow analysis. For example, when the program contains a loop
685 that is intended to inspect a variable set from within a signal handler
686 while (!signal_occurred)
687 ;
688 the compiler is allowed to transform this into an endless loop if the
689 variable 'signal_occurred' is not declared 'volatile'.
690 Additionally, recall that:
691 * A signal handler should not modify errno (except if it is a handler
692 for a fatal signal and ends by raising the same signal again, thus
693 provoking the termination of the process). If it invokes a function
694 that may clobber errno, it needs to save and restore the value of
695 errno. */
696 #define _GL_ASYNC_SAFE
697 ])
698 AH_VERBATIM([micro_optimizations],
699 [/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
700 n1 and n2 are expressions without side effects, that evaluate to real
701 numbers (excluding NaN).
702 It returns
703 1 if n1 > n2
704 0 if n1 == n2
705 -1 if n1 < n2
706 The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
707 jump with nearly all GCC versions up to GCC 10.
708 This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
709 GCC versions up to GCC 9.
710 The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
711 avoids conditional jumps in all GCC versions >= 3.4. */
712 #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
713 ])
714 dnl Hint which direction to take regarding cross-compilation guesses:
715 dnl When a user installs a program on a platform they are not intimately
716 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
717 dnl choice. It implements the "If we don't know, assume the worst" principle.
718 dnl However, when an operating system developer (on a platform which is not
719 dnl yet known to gnulib) builds packages for their platform, they want to
720 dnl expose, not hide, possible platform bugs; in this case,
721 dnl --enable-cross-guesses=risky is the appropriate choice.
722 dnl Sets the variables
723 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
724 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
725 AC_ARG_ENABLE([cross-guesses],
726 [AS_HELP_STRING([[--enable-cross-guesses={conservative|risky}]],
727 [specify policy for cross-compilation guesses])],
728 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
729 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
730 enableval=conservative
731 fi
732 gl_cross_guesses="$enableval"],
733 [gl_cross_guesses=conservative])
734 if test $gl_cross_guesses = risky; then
735 gl_cross_guess_normal="guessing yes"
736 gl_cross_guess_inverted="guessing no"
737 else
738 gl_cross_guess_normal="guessing no"
739 gl_cross_guess_inverted="guessing yes"
740 fi
741 dnl Preparation for running test programs:
742 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
743 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
744 dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
745 LIBC_FATAL_STDERR_=1
746 export LIBC_FATAL_STDERR_
747 ])
748
749 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
750 # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
751 # initializes the shell variable that indicates the presence of the given module
752 # as a C preprocessor expression.
753 AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
754 [
755 GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
756 AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
757 ])
758
759 # gl_MODULE_INDICATOR_CONDITION
760 # expands to a C preprocessor expression that evaluates to 1 or 0, depending
761 # whether a gnulib module that has been requested shall be considered present
762 # or not.
763 m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
764
765 # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
766 # sets the shell variable that indicates the presence of the given module to
767 # a C preprocessor expression that will evaluate to 1.
768 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
769 [
770 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
771 [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
772 [abcdefghijklmnopqrstuvwxyz./-],
773 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
774 [gl_MODULE_INDICATOR_CONDITION])
775 ])
776
777 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
778 # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
779 # The shell variable's value is a C preprocessor expression that evaluates
780 # to 0 or 1.
781 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
782 [
783 m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
784 [
785 dnl Simplify the expression VALUE || 1 to 1.
786 $1=1
787 ],
788 [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
789 [gl_MODULE_INDICATOR_CONDITION])])
790 ])
791
792 # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
793 # modifies the shell variable to include the given condition. The shell
794 # variable's value is a C preprocessor expression that evaluates to 0 or 1.
795 AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
796 [
797 dnl Simplify the expression 1 || CONDITION to 1.
798 if test "$[]$1" != 1; then
799 dnl Simplify the expression 0 || CONDITION to CONDITION.
800 if test "$[]$1" = 0; then
801 $1=$2
802 else
803 $1="($[]$1 || $2)"
804 fi
805 fi
806 ])
807
808 # gl_MODULE_INDICATOR([modulename])
809 # defines a C macro indicating the presence of the given module
810 # in a location where it can be used.
811 # | Value | Value |
812 # | in lib/ | in tests/ |
813 # --------------------------------------------+---------+-----------+
814 # Module present among main modules: | 1 | 1 |
815 # --------------------------------------------+---------+-----------+
816 # Module present among tests-related modules: | 0 | 1 |
817 # --------------------------------------------+---------+-----------+
818 # Module not present at all: | 0 | 0 |
819 # --------------------------------------------+---------+-----------+
820 AC_DEFUN([gl_MODULE_INDICATOR],
821 [
822 AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
823 [abcdefghijklmnopqrstuvwxyz./-],
824 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
825 [gl_MODULE_INDICATOR_CONDITION],
826 [Define to a C preprocessor expression that evaluates to 1 or 0,
827 depending whether the gnulib module $1 shall be considered present.])
828 ])
829
830 # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
831 # defines a C macro indicating the presence of the given module
832 # in lib or tests. This is useful to determine whether the module
833 # should be tested.
834 # | Value | Value |
835 # | in lib/ | in tests/ |
836 # --------------------------------------------+---------+-----------+
837 # Module present among main modules: | 1 | 1 |
838 # --------------------------------------------+---------+-----------+
839 # Module present among tests-related modules: | 1 | 1 |
840 # --------------------------------------------+---------+-----------+
841 # Module not present at all: | 0 | 0 |
842 # --------------------------------------------+---------+-----------+
843 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
844 [
845 AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
846 [abcdefghijklmnopqrstuvwxyz./-],
847 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
848 [Define to 1 when the gnulib module $1 should be tested.])
849 ])
850
851 # gl_ASSERT_NO_GNULIB_POSIXCHECK
852 # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
853 # and thereby enables an optimization of configure and config.h.
854 # Used by Emacs.
855 AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
856 [
857 dnl Override gl_WARN_ON_USE_PREPARE.
858 dnl But hide this definition from 'aclocal'.
859 AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
860 ])
861
862 # gl_ASSERT_NO_GNULIB_TESTS
863 # asserts that there will be no gnulib tests in the scope of the configure.ac
864 # and thereby enables an optimization of config.h.
865 # Used by Emacs.
866 AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
867 [
868 dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
869 AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
870 ])
871
872 # Test whether <features.h> exists.
873 # Set HAVE_FEATURES_H.
874 AC_DEFUN([gl_FEATURES_H],
875 [
876 AC_CHECK_HEADERS_ONCE([features.h])
877 if test $ac_cv_header_features_h = yes; then
878 HAVE_FEATURES_H=1
879 else
880 HAVE_FEATURES_H=0
881 fi
882 AC_SUBST([HAVE_FEATURES_H])
883 ])
884
885 # gl_PROG_CC_C99
886 # Modifies the value of the shell variable CC in an attempt to make $CC
887 # understand ISO C99 source code.
888 AC_DEFUN([gl_PROG_CC_C99],
889 [
890 dnl Just use AC_PROG_CC_C99.
891 dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
892 dnl value of CC will contain the C99 enabling options twice. But this is only
893 dnl a cosmetic problem.
894 dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
895 dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
896 m4_version_prereq([2.70],
897 [AC_REQUIRE([AC_PROG_CC])],
898 [AC_REQUIRE([AC_PROG_CC_C99])])
899 ])
900
901 # gl_PROG_AR_RANLIB
902 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
903 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
904 # the values.
905 AC_DEFUN([gl_PROG_AR_RANLIB],
906 [
907 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
908 dnl as "cc", and GCC as "gcc". They have different object file formats and
909 dnl library formats. In particular, the GNU binutils programs ar and ranlib
910 dnl produce libraries that work only with gcc, not with cc.
911 AC_REQUIRE([AC_PROG_CC])
912 dnl The '][' hides this use from 'aclocal'.
913 AC_BEFORE([$0], [A][M_PROG_AR])
914 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
915 [
916 AC_EGREP_CPP([Amsterdam],
917 [
918 #ifdef __ACK__
919 Amsterdam
920 #endif
921 ],
922 [gl_cv_c_amsterdam_compiler=yes],
923 [gl_cv_c_amsterdam_compiler=no])
924 ])
925
926 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
927 dnl building with __ACK__.
928 if test $gl_cv_c_amsterdam_compiler = yes; then
929 if test -z "$AR"; then
930 AR='cc -c.a'
931 fi
932 if test -z "$ARFLAGS"; then
933 ARFLAGS='-o'
934 fi
935 else
936 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
937 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
938 dnl script on-demand, if not specified by ./configure of course).
939 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
940 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
941 dnl because AM_PROG_AR is written so it could re-set AR variable even for
942 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
943 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
944 dnl default value and automake should usually know them).
945 dnl
946 dnl The '][' hides this use from 'aclocal'.
947 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
948 fi
949
950 dnl In case the code above has not helped with setting AR/ARFLAGS, use
951 dnl Automake-documented default values for AR and ARFLAGS, but prefer
952 dnl ${host}-ar over ar (useful for cross-compiling).
953 AC_CHECK_TOOL([AR], [ar], [ar])
954 if test -z "$ARFLAGS"; then
955 ARFLAGS='cr'
956 fi
957
958 AC_SUBST([AR])
959 AC_SUBST([ARFLAGS])
960 if test -z "$RANLIB"; then
961 if test $gl_cv_c_amsterdam_compiler = yes; then
962 RANLIB=':'
963 else
964 dnl Use the ranlib program if it is available.
965 AC_PROG_RANLIB
966 fi
967 fi
968 AC_SUBST([RANLIB])
969 ])
970
971 # AC_C_RESTRICT
972 # This definition is copied from post-2.70 Autoconf and overrides the
973 # AC_C_RESTRICT macro from autoconf 2.60..2.70.
974 m4_version_prereq([2.70.1], [], [
975 AC_DEFUN([AC_C_RESTRICT],
976 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
977 [ac_cv_c_restrict=no
978 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
979 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
980 # Put 'restrict' last, because C++ lacks it.
981 for ac_kw in __restrict__ __restrict _Restrict restrict; do
982 AC_COMPILE_IFELSE(
983 [AC_LANG_PROGRAM(
984 [[typedef int *int_ptr;
985 int foo (int_ptr $ac_kw ip) { return ip[0]; }
986 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
987 int bar (int ip[$ac_kw]) { return ip[0]; }
988 ]],
989 [[int s[1];
990 int *$ac_kw t = s;
991 t[0] = 0;
992 return foo (t) + bar (t);
993 ]])],
994 [ac_cv_c_restrict=$ac_kw])
995 test "$ac_cv_c_restrict" != no && break
996 done
997 ])
998 AH_VERBATIM([restrict],
999 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1000 nothing if this is not supported. Do not define if restrict is
1001 supported only directly. */
1002 #undef restrict
1003 /* Work around a bug in older versions of Sun C++, which did not
1004 #define __restrict__ or support _Restrict or __restrict__
1005 even though the corresponding Sun C compiler ended up with
1006 "#define restrict _Restrict" or "#define restrict __restrict__"
1007 in the previous line. This workaround can be removed once
1008 we assume Oracle Developer Studio 12.5 (2016) or later. */
1009 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
1010 # define _Restrict
1011 # define __restrict__
1012 #endif])
1013 case $ac_cv_c_restrict in
1014 restrict) ;;
1015 no) AC_DEFINE([restrict], []) ;;
1016 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1017 esac
1018 ])# AC_C_RESTRICT
1019 ])
1020
1021 # gl_BIGENDIAN
1022 # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
1023 # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
1024 # macros invoke AC_C_BIGENDIAN with arguments.
1025 AC_DEFUN([gl_BIGENDIAN],
1026 [
1027 AC_C_BIGENDIAN
1028 ])
1029
1030 # A temporary file descriptor.
1031 # Must be less than 10, because dash 0.5.8 does not support redirections
1032 # with multi-digit file descriptors.
1033 m4_define([GL_TMP_FD], 9)
1034
1035 # gl_SILENT(command)
1036 # executes command, but without the normal configure output.
1037 # This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
1038 # inside another AC_CACHE_CHECK.
1039 AC_DEFUN([gl_SILENT],
1040 [
1041 exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
1042 $1
1043 exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
1044 ])
1045
1046 # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
1047 # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
1048 # output a spurious "(cached)" mark in the midst of other configure output.
1049 # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
1050 # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
1051 AC_DEFUN([gl_CACHE_VAL_SILENT],
1052 [
1053 gl_SILENT([
1054 AC_CACHE_VAL([$1], [$2])
1055 ])
1056 ])
1057
1058 # gl_CONDITIONAL(conditional, condition)
1059 # is like AM_CONDITIONAL(conditional, condition), except that it does not
1060 # produce an error
1061 # configure: error: conditional "..." was never defined.
1062 # Usually this means the macro was only invoked conditionally.
1063 # when only invoked conditionally. Instead, in that case, both the _TRUE
1064 # and the _FALSE case are disabled.
1065 AC_DEFUN([gl_CONDITIONAL],
1066 [
1067 pushdef([AC_CONFIG_COMMANDS_PRE], [:])dnl
1068 AM_CONDITIONAL([$1], [$2])
1069 popdef([AC_CONFIG_COMMANDS_PRE])dnl
1070 if test -z "${[$1]_TRUE}" && test -z "${[$1]_FALSE}"; then
1071 [$1]_TRUE='#'
1072 [$1]_FALSE='#'
1073 fi
1074 ])
1075
1076 # gl_CC_ALLOW_WARNINGS
1077 # sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
1078 # that reverts a preceding '-Werror' option, if available.
1079 # This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
1080 # and empty otherwise.
1081 AC_DEFUN([gl_CC_ALLOW_WARNINGS],
1082 [
1083 AC_REQUIRE([AC_PROG_CC])
1084 AC_CACHE_CHECK([for C compiler option to allow warnings],
1085 [gl_cv_cc_wallow],
1086 [rm -f conftest*
1087 echo 'int dummy;' > conftest.c
1088 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
1089 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
1090 dnl Test the number of error output lines, because AIX xlc accepts the
1091 dnl option '-Wno-error', just to produce a warning
1092 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
1093 dnl afterwards.
1094 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
1095 gl_cv_cc_wallow='-Wno-error'
1096 else
1097 gl_cv_cc_wallow=none
1098 fi
1099 rm -f conftest*
1100 ])
1101 case "$gl_cv_cc_wallow" in
1102 none) GL_CFLAG_ALLOW_WARNINGS='' ;;
1103 *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
1104 esac
1105 AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
1106 ])
1107
1108 # gl_CXX_ALLOW_WARNINGS
1109 # sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
1110 # that reverts a preceding '-Werror' option, if available.
1111 AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
1112 [
1113 dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
1114 if test -n "$CXX" && test "$CXX" != no; then
1115 AC_CACHE_CHECK([for C++ compiler option to allow warnings],
1116 [gl_cv_cxx_wallow],
1117 [rm -f conftest*
1118 echo 'int dummy;' > conftest.cc
1119 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
1120 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
1121 dnl Test the number of error output lines, because AIX xlC accepts the
1122 dnl option '-Wno-error', just to produce a warning
1123 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
1124 dnl afterwards.
1125 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
1126 gl_cv_cxx_wallow='-Wno-error'
1127 else
1128 gl_cv_cxx_wallow=none
1129 fi
1130 rm -f conftest*
1131 ])
1132 case "$gl_cv_cxx_wallow" in
1133 none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
1134 *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
1135 esac
1136 else
1137 GL_CXXFLAG_ALLOW_WARNINGS=''
1138 fi
1139 AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
1140 ])
1141
1142 # gl_CC_GNULIB_WARNINGS
1143 # sets and substitutes a variable GL_CFLAG_GNULIB_WARNINGS, to a $(CC) option
1144 # set that enables or disables warnings as suitable for the Gnulib coding style.
1145 AC_DEFUN([gl_CC_GNULIB_WARNINGS],
1146 [
1147 AC_REQUIRE([gl_CC_ALLOW_WARNINGS])
1148 dnl Assume that the compiler supports -Wno-* options only if it also supports
1149 dnl -Wno-error.
1150 GL_CFLAG_GNULIB_WARNINGS=''
1151 if test -n "$GL_CFLAG_ALLOW_WARNINGS"; then
1152 dnl Enable these warning options:
1153 dnl
1154 dnl GCC clang
1155 dnl -Wno-cast-qual >= 3 >= 3.9
1156 dnl -Wno-conversion >= 3 >= 3.9
1157 dnl -Wno-float-conversion >= 4.9 >= 3.9
1158 dnl -Wno-float-equal >= 3 >= 3.9
1159 dnl -Wimplicit-fallthrough >= 7 >= 3.9
1160 dnl -Wno-pedantic >= 4.8 >= 3.9
1161 dnl -Wno-sign-compare >= 3 >= 3.9
1162 dnl -Wno-sign-conversion >= 4.3 >= 3.9
1163 dnl -Wno-tautological-out-of-range-compare - >= 3.9
1164 dnl -Wno-type-limits >= 4.3 >= 3.9
1165 dnl -Wno-undef >= 3 >= 3.9
1166 dnl -Wno-unsuffixed-float-constants >= 4.5
1167 dnl -Wno-unused-function >= 3 >= 3.9
1168 dnl -Wno-unused-parameter >= 3 >= 3.9
1169 dnl
1170 cat > conftest.c <<\EOF
1171 #if (__GNUC__ >= 3 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1172 -Wno-cast-qual
1173 -Wno-conversion
1174 -Wno-float-equal
1175 -Wno-sign-compare
1176 -Wno-undef
1177 -Wno-unused-function
1178 -Wno-unused-parameter
1179 #endif
1180 #if (__GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1181 -Wno-float-conversion
1182 #endif
1183 #if (__GNUC__ >= 7 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1184 -Wimplicit-fallthrough
1185 #endif
1186 #if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1187 -Wno-pedantic
1188 #endif
1189 #if 3 < __clang_major__ + (9 <= __clang_minor__)
1190 -Wno-tautological-constant-out-of-range-compare
1191 #endif
1192 #if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1193 -Wno-sign-conversion
1194 -Wno-type-limits
1195 #endif
1196 #if (__GNUC__ + (__GNUC_MINOR__ >= 5) > 4 && !defined __clang__)
1197 -Wno-unsuffixed-float-constants
1198 #endif
1199 EOF
1200 gl_command="$CC $CFLAGS $CPPFLAGS -E conftest.c > conftest.out"
1201 if AC_TRY_EVAL([gl_command]); then
1202 gl_options=`grep -v '#' conftest.out`
1203 for word in $gl_options; do
1204 GL_CFLAG_GNULIB_WARNINGS="$GL_CFLAG_GNULIB_WARNINGS $word"
1205 done
1206 fi
1207 rm -f conftest.c conftest.out
1208 fi
1209 AC_SUBST([GL_CFLAG_GNULIB_WARNINGS])
1210 ])
1211
1212 dnl gl_CONDITIONAL_HEADER([foo.h])
1213 dnl takes a shell variable GL_GENERATE_FOO_H (with value true or false) as input
1214 dnl and produces
1215 dnl - an AC_SUBSTed variable FOO_H that is either a file name or empty, based
1216 dnl on whether GL_GENERATE_FOO_H is true or false,
1217 dnl - an Automake conditional GL_GENERATE_FOO_H that evaluates to the value of
1218 dnl the shell variable GL_GENERATE_FOO_H.
1219 AC_DEFUN([gl_CONDITIONAL_HEADER],
1220 [
1221 m4_pushdef([gl_header_name], AS_TR_SH(m4_toupper($1)))
1222 m4_pushdef([gl_generate_var], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1223 m4_pushdef([gl_generate_cond], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1224 case "$gl_generate_var" in
1225 false) gl_header_name='' ;;
1226 true)
1227 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
1228 dnl versa.
1229 if test -z "$gl_header_name"; then
1230 gl_header_name="${gl_source_base_prefix}$1"
1231 fi
1232 ;;
1233 *) echo "*** gl_generate_var is not set correctly" 1>&2; exit 1 ;;
1234 esac
1235 AC_SUBST(gl_header_name)
1236 gl_CONDITIONAL(gl_generate_cond, [$gl_generate_var])
1237 m4_popdef([gl_generate_cond])
1238 m4_popdef([gl_generate_var])
1239 m4_popdef([gl_header_name])
1240 ])
1241
1242 dnl Preparations for gl_CHECK_FUNCS_MACOS.
1243 AC_DEFUN([gl_PREPARE_CHECK_FUNCS_MACOS],
1244 [
1245 AC_REQUIRE([AC_CANONICAL_HOST])
1246 AC_REQUIRE([gl_COMPILER_CLANG])
1247 AC_CACHE_CHECK([for compiler option needed when checking for future declarations],
1248 [gl_cv_compiler_check_future_option],
1249 [case "$host_os" in
1250 dnl This is only needed on macOS.
1251 darwin*)
1252 if test $gl_cv_compiler_clang = yes; then
1253 dnl Test whether the compiler supports the option
1254 dnl '-Werror=unguarded-availability-new'.
1255 saved_ac_compile="$ac_compile"
1256 ac_compile="$ac_compile -Werror=unguarded-availability-new"
1257 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
1258 [gl_cv_compiler_check_future_option='-Werror=unguarded-availability-new'],
1259 [gl_cv_compiler_check_future_option=none])
1260 ac_compile="$saved_ac_compile"
1261 else
1262 gl_cv_compiler_check_future_option=none
1263 fi
1264 ;;
1265 *) gl_cv_compiler_check_future_option=none ;;
1266 esac
1267 ])
1268 ])
1269
1270 dnl Pieces of the expansion of
1271 dnl gl_CHECK_FUNCS_ANDROID
1272 dnl gl_CHECK_FUNCS_MACOS
1273 dnl gl_CHECK_FUNCS_ANDROID_MACOS
1274
1275 AC_DEFUN([gl_CHECK_FUNCS_DEFAULT_CASE],
1276 [
1277 *)
1278 AC_CHECK_FUNC([$1])
1279 [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
1280 ;;
1281 ])
1282
1283 AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_ANDROID],
1284 [
1285 linux*-android*)
1286 AC_CHECK_DECL([$1], , , [$2])
1287 if test $[ac_cv_have_decl_][$1] = yes; then
1288 AC_CHECK_FUNC([[$1]])
1289 if test $[ac_cv_func_][$1] = yes; then
1290 [gl_cv_onwards_func_][$1]=yes
1291 else
1292 dnl The function is declared but does not exist. This should not
1293 dnl happen normally. But anyway, we know that a future version
1294 dnl of Android will have the function.
1295 [gl_cv_onwards_func_][$1]='future OS version'
1296 fi
1297 else
1298 [gl_cv_onwards_func_][$1]='future OS version'
1299 fi
1300 ;;
1301 ])
1302
1303 AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_MACOS],
1304 [
1305 darwin*)
1306 if test "x$gl_cv_compiler_check_future_option" != "xnone"; then
1307 dnl Use a compile test, not a link test.
1308 saved_ac_compile="$ac_compile"
1309 ac_compile="$ac_compile $gl_cv_compiler_check_future_option"
1310 saved_ac_compile_for_check_decl="$ac_compile_for_check_decl"
1311 ac_compile_for_check_decl="$ac_compile_for_check_decl $gl_cv_compiler_check_future_option"
1312 unset [ac_cv_have_decl_][$1]
1313 AC_CHECK_DECL([$1], , , [$2])
1314 ac_compile="$saved_ac_compile"
1315 ac_compile_for_check_decl="$saved_ac_compile_for_check_decl"
1316 [ac_cv_func_][$1]="$[ac_cv_have_decl_][$1]"
1317 if test $[ac_cv_func_][$1] = yes; then
1318 [gl_cv_onwards_func_][$1]=yes
1319 else
1320 unset [ac_cv_have_decl_][$1]
1321 AC_CHECK_DECL([$1], , , [$2])
1322 if test $[ac_cv_have_decl_][$1] = yes; then
1323 [gl_cv_onwards_func_][$1]='future OS version'
1324 else
1325 [gl_cv_onwards_func_][$1]=no
1326 fi
1327 fi
1328 else
1329 AC_CHECK_FUNC([$1])
1330 [gl_cv_onwards_func_][$1]=$[ac_cv_func_][$1]
1331 fi
1332 ;;
1333 ])
1334
1335 AC_DEFUN([gl_CHECK_FUNCS_SET_RESULTS],
1336 [
1337 case "$[gl_cv_onwards_func_][$1]" in
1338 future*) [ac_cv_func_][$1]=no ;;
1339 *) [ac_cv_func_][$1]=$[gl_cv_onwards_func_][$1] ;;
1340 esac
1341 if test $[ac_cv_func_][$1] = yes; then
1342 AC_DEFINE([HAVE_]m4_translit([[$1]],
1343 [abcdefghijklmnopqrstuvwxyz],
1344 [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
1345 [1], [Define to 1 if you have the `$1' function.])
1346 fi
1347 ])
1348
1349 dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
1350 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1351 dnl on Android.
1352 dnl
1353 dnl When code is compiled on Android, it is in the context of a certain
1354 dnl "Android API level", which indicates the minimum version of Android on
1355 dnl which the app can be installed. In other words, you don't compile for a
1356 dnl specific version of Android. You compile for all versions of Android,
1357 dnl onwards from the given API level.
1358 dnl Thus, the question "does the OS have the function func" has three possible
1359 dnl answers:
1360 dnl - yes, in all versions starting from the given API level,
1361 dnl - no, in no version,
1362 dnl - not in the given API level, but in a later version of Android.
1363 dnl
1364 dnl In detail, this works as follows:
1365 dnl If func was added to Android API level, say, 28, then the libc.so has the
1366 dnl symbol func always, whereas the header file <foo.h> declares func
1367 dnl conditionally:
1368 dnl #if __ANDROID_API__ >= 28
1369 dnl ... func (...) __INTRODUCED_IN(28);
1370 dnl #endif
1371 dnl Thus, when compiling with "clang -target armv7a-unknown-linux-android28",
1372 dnl the function func is declared and exists in libc.
1373 dnl Whereas when compiling with "clang -target armv7a-unknown-linux-android27",
1374 dnl the function func is not declared but exists in libc.
1375 dnl
1376 dnl This macro sets two variables:
1377 dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
1378 dnl - ac_cv_func_<func> to yes / no / no
1379 dnl The first variable allows to distinguish all three cases.
1380 dnl The second variable is set, so that an invocation
1381 dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
1382 dnl can be used as a drop-in replacement for
1383 dnl AC_CHECK_FUNCS([func]).
1384 AC_DEFUN([gl_CHECK_FUNCS_ANDROID],
1385 [
1386 AC_REQUIRE([AC_CANONICAL_HOST])
1387 AC_CACHE_CHECK([for [$1]],
1388 [[gl_cv_onwards_func_][$1]],
1389 [gl_SILENT([
1390 case "$host_os" in
1391 gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
1392 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1393 esac
1394 ])
1395 ])
1396 gl_CHECK_FUNCS_SET_RESULTS([$1])
1397 ])
1398
1399 dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
1400 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1401 dnl on macOS.
1402 dnl
1403 dnl When code is compiled on macOS, it is in the context of a certain minimum
1404 dnl macOS version, that can be set through the option '-mmacosx-version-min='.
1405 dnl In other words, you don't compile for a specific version of macOS. You
1406 dnl compile for all versions of macOS, onwards from the given version.
1407 dnl Thus, the question "does the OS have the function func" has three possible
1408 dnl answers:
1409 dnl - yes, in all versions starting from the given version,
1410 dnl - no, in no version,
1411 dnl - not in the given version, but in a later version of macOS.
1412 dnl
1413 dnl In detail, this works as follows:
1414 dnl If func was added to, say, macOS version 13, then the libc has the
1415 dnl symbol func always, whereas the header file <foo.h> declares func
1416 dnl conditionally with a special availability attribute:
1417 dnl ... func (...) __attribute__((availability(macos,introduced=13.0)));
1418 dnl Thus, when compiling with "clang mmacosx-version-min=13", there is no
1419 dnl warning about the use of func, and the resulting binary
1420 dnl - runs fine on macOS 13,
1421 dnl - aborts with a dyld "Symbol not found" message on macOS 12.
1422 dnl Whereas, when compiling with "clang mmacosx-version-min=12", there is a
1423 dnl warning: 'func' is only available on macOS 13.0 or newer
1424 dnl [-Wunguarded-availability-new],
1425 dnl and the resulting binary
1426 dnl - runs fine on macOS 13,
1427 dnl - crashes with a SIGSEGV (signal 11) on macOS 12.
1428 dnl
1429 dnl This macro sets two variables:
1430 dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
1431 dnl - ac_cv_func_<func> to yes / no / no
1432 dnl The first variable allows to distinguish all three cases.
1433 dnl The second variable is set, so that an invocation
1434 dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
1435 dnl can be used as a drop-in replacement for
1436 dnl AC_CHECK_FUNCS([func]).
1437 AC_DEFUN([gl_CHECK_FUNCS_MACOS],
1438 [
1439 AC_REQUIRE([AC_CANONICAL_HOST])
1440 AC_REQUIRE([gl_PREPARE_CHECK_FUNCS_MACOS])
1441 AC_CACHE_CHECK([for [$1]],
1442 [[gl_cv_onwards_func_][$1]],
1443 [gl_SILENT([
1444 case "$host_os" in
1445 gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
1446 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1447 esac
1448 ])
1449 ])
1450 gl_CHECK_FUNCS_SET_RESULTS([$1])
1451 ])
1452
1453 dnl gl_CHECK_FUNCS_ANDROID_MACOS([func], [[#include <foo.h>]])
1454 dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
1455 dnl on Android and on macOS.
1456 dnl It is the combination of gl_CHECK_FUNCS_ANDROID and gl_CHECK_FUNCS_MACOS.
1457 AC_DEFUN([gl_CHECK_FUNCS_ANDROID_MACOS],
1458 [
1459 AC_REQUIRE([AC_CANONICAL_HOST])
1460 AC_REQUIRE([gl_PREPARE_CHECK_FUNCS_MACOS])
1461 AC_CACHE_CHECK([for [$1]],
1462 [[gl_cv_onwards_func_][$1]],
1463 [gl_SILENT([
1464 case "$host_os" in
1465 gl_CHECK_FUNCS_CASE_FOR_ANDROID([$1], [$2])
1466 gl_CHECK_FUNCS_CASE_FOR_MACOS([$1], [$2])
1467 gl_CHECK_FUNCS_DEFAULT_CASE([$1])
1468 esac
1469 ])
1470 ])
1471 gl_CHECK_FUNCS_SET_RESULTS([$1])
1472 ])
1473
1474 dnl Expands to some code for use in .c programs that, on native Windows, defines
1475 dnl the Microsoft deprecated alias function names to the underscore-prefixed
1476 dnl actual function names. With this macro, these function names are available
1477 dnl without linking with '-loldnames' and without generating warnings.
1478 dnl Usage: Use it after all system header files are included.
1479 dnl #include <...>
1480 dnl #include <...>
1481 dnl ]GL_MDA_DEFINES[
1482 dnl ...
1483 AC_DEFUN([GL_MDA_DEFINES],[
1484 AC_REQUIRE([_GL_MDA_DEFINES])
1485 [$gl_mda_defines]
1486 ])
1487 AC_DEFUN([_GL_MDA_DEFINES],
1488 [gl_mda_defines='
1489 #if defined _WIN32 && !defined __CYGWIN__
1490 #define access _access
1491 #define chdir _chdir
1492 #define chmod _chmod
1493 #define close _close
1494 #define creat _creat
1495 #define dup _dup
1496 #define dup2 _dup2
1497 #define ecvt _ecvt
1498 #define execl _execl
1499 #define execle _execle
1500 #define execlp _execlp
1501 #define execv _execv
1502 #define execve _execve
1503 #define execvp _execvp
1504 #define execvpe _execvpe
1505 #define fcloseall _fcloseall
1506 #define fcvt _fcvt
1507 #define fdopen _fdopen
1508 #define fileno _fileno
1509 #define gcvt _gcvt
1510 #define getcwd _getcwd
1511 #define getpid _getpid
1512 #define getw _getw
1513 #define isatty _isatty
1514 #define j0 _j0
1515 #define j1 _j1
1516 #define jn _jn
1517 #define lfind _lfind
1518 #define lsearch _lsearch
1519 #define lseek _lseek
1520 #define memccpy _memccpy
1521 #define mkdir _mkdir
1522 #define mktemp _mktemp
1523 #define open _open
1524 #define putenv _putenv
1525 #define putw _putw
1526 #define read _read
1527 #define rmdir _rmdir
1528 #define strdup _strdup
1529 #define swab _swab
1530 #define tempnam _tempnam
1531 #define tzset _tzset
1532 #define umask _umask
1533 #define unlink _unlink
1534 #define utime _utime
1535 #define wcsdup _wcsdup
1536 #define write _write
1537 #define y0 _y0
1538 #define y1 _y1
1539 #define yn _yn
1540 #endif
1541 '
1542 ])