extensions.m4 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # serial 13 -*- Autoconf -*-
  2. # Enable extensions on systems that normally disable them.
  3. # Copyright (C) 2003, 2006-2013 Free Software Foundation, Inc.
  4. # This file is free software; the Free Software Foundation
  5. # gives unlimited permission to copy and/or distribute it,
  6. # with or without modifications, as long as this notice is preserved.
  7. # This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS
  8. # Autoconf. Perhaps we can remove this once we can assume Autoconf
  9. # 2.70 or later everywhere, but since Autoconf mutates rapidly
  10. # enough in this area it's likely we'll need to redefine
  11. # AC_USE_SYSTEM_EXTENSIONS for quite some time.
  12. # If autoconf reports a warning
  13. # warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
  14. # or warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
  15. # the fix is
  16. # 1) to ensure that AC_USE_SYSTEM_EXTENSIONS is never directly invoked
  17. # but always AC_REQUIREd,
  18. # 2) to ensure that for each occurrence of
  19. # AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  20. # or
  21. # AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  22. # the corresponding gnulib module description has 'extensions' among
  23. # its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS
  24. # invocation occurs in gl_EARLY, not in gl_INIT.
  25. # AC_USE_SYSTEM_EXTENSIONS
  26. # ------------------------
  27. # Enable extensions on systems that normally disable them,
  28. # typically due to standards-conformance issues.
  29. #
  30. # Remember that #undef in AH_VERBATIM gets replaced with #define by
  31. # AC_DEFINE. The goal here is to define all known feature-enabling
  32. # macros, then, if reports of conflicts are made, disable macros that
  33. # cause problems on some platforms (such as __EXTENSIONS__).
  34. AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS],
  35. [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
  36. AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
  37. AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
  38. if test "$MINIX" = yes; then
  39. AC_DEFINE([_POSIX_SOURCE], [1],
  40. [Define to 1 if you need to in order for 'stat' and other
  41. things to work.])
  42. AC_DEFINE([_POSIX_1_SOURCE], [2],
  43. [Define to 2 if the system does not provide POSIX.1 features
  44. except with this defined.])
  45. AC_DEFINE([_MINIX], [1],
  46. [Define to 1 if on MINIX.])
  47. AC_DEFINE([_NETBSD_SOURCE], [1],
  48. [Define to 1 to make NetBSD features available. MINIX 3 needs this.])
  49. fi
  50. dnl Use a different key than __EXTENSIONS__, as that name broke existing
  51. dnl configure.ac when using autoheader 2.62.
  52. AH_VERBATIM([USE_SYSTEM_EXTENSIONS],
  53. [/* Enable extensions on AIX 3, Interix. */
  54. #ifndef _ALL_SOURCE
  55. # undef _ALL_SOURCE
  56. #endif
  57. /* Enable general extensions on OS X. */
  58. #ifndef _DARWIN_C_SOURCE
  59. # undef _DARWIN_C_SOURCE
  60. #endif
  61. /* Enable GNU extensions on systems that have them. */
  62. #ifndef _GNU_SOURCE
  63. # undef _GNU_SOURCE
  64. #endif
  65. /* Enable threading extensions on Solaris. */
  66. #ifndef _POSIX_PTHREAD_SEMANTICS
  67. # undef _POSIX_PTHREAD_SEMANTICS
  68. #endif
  69. /* Enable extensions on HP NonStop. */
  70. #ifndef _TANDEM_SOURCE
  71. # undef _TANDEM_SOURCE
  72. #endif
  73. /* Enable X/Open extensions if necessary. HP-UX 11.11 defines
  74. mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of
  75. whether compiling with -Ae or -D_HPUX_SOURCE=1. */
  76. #ifndef _XOPEN_SOURCE
  77. # undef _XOPEN_SOURCE
  78. #endif
  79. /* Enable general extensions on Solaris. */
  80. #ifndef __EXTENSIONS__
  81. # undef __EXTENSIONS__
  82. #endif
  83. ])
  84. AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
  85. [ac_cv_safe_to_define___extensions__],
  86. [AC_COMPILE_IFELSE(
  87. [AC_LANG_PROGRAM([[
  88. # define __EXTENSIONS__ 1
  89. ]AC_INCLUDES_DEFAULT])],
  90. [ac_cv_safe_to_define___extensions__=yes],
  91. [ac_cv_safe_to_define___extensions__=no])])
  92. test $ac_cv_safe_to_define___extensions__ = yes &&
  93. AC_DEFINE([__EXTENSIONS__])
  94. AC_DEFINE([_ALL_SOURCE])
  95. AC_DEFINE([_DARWIN_C_SOURCE])
  96. AC_DEFINE([_GNU_SOURCE])
  97. AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
  98. AC_DEFINE([_TANDEM_SOURCE])
  99. AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined],
  100. [ac_cv_should_define__xopen_source],
  101. [ac_cv_should_define__xopen_source=no
  102. AC_COMPILE_IFELSE(
  103. [AC_LANG_PROGRAM([[
  104. #include <wchar.h>
  105. mbstate_t x;]])],
  106. [],
  107. [AC_COMPILE_IFELSE(
  108. [AC_LANG_PROGRAM([[
  109. #define _XOPEN_SOURCE 500
  110. #include <wchar.h>
  111. mbstate_t x;]])],
  112. [ac_cv_should_define__xopen_source=yes])])])
  113. test $ac_cv_should_define__xopen_source = yes &&
  114. AC_DEFINE([_XOPEN_SOURCE], [500])
  115. ])# AC_USE_SYSTEM_EXTENSIONS
  116. # gl_USE_SYSTEM_EXTENSIONS
  117. # ------------------------
  118. # Enable extensions on systems that normally disable them,
  119. # typically due to standards-conformance issues.
  120. AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS],
  121. [
  122. dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS.
  123. dnl gnulib does not need it. But if it gets required by third-party macros
  124. dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a
  125. dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
  126. dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE,
  127. dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck.
  128. AC_REQUIRE([AC_GNU_SOURCE])
  129. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  130. ])