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