extensions.m4 6.96 KB
Newer Older
1
# serial 18  -*- Autoconf -*-
2 3
# Enable extensions on systems that normally disable them.

4
# Copyright (C) 2003, 2006-2018 Free Software Foundation, Inc.
5 6 7
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
8

9
# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from git
10
# Autoconf.  Perhaps we can remove this once we can assume Autoconf
11
# 2.70 or later everywhere, but since Autoconf mutates rapidly
12 13
# enough in this area it's likely we'll need to redefine
# AC_USE_SYSTEM_EXTENSIONS for quite some time.
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28
# If autoconf reports a warning
#     warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
# or  warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
# the fix is
#   1) to ensure that AC_USE_SYSTEM_EXTENSIONS is never directly invoked
#      but always AC_REQUIREd,
#   2) to ensure that for each occurrence of
#        AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
#      or
#        AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
#      the corresponding gnulib module description has 'extensions' among
#      its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS
#      invocation occurs in gl_EARLY, not in gl_INIT.

29
# AC_USE_SYSTEM_EXTENSIONS
30 31 32
# ------------------------
# Enable extensions on systems that normally disable them,
# typically due to standards-conformance issues.
33
#
34 35 36 37
# Remember that #undef in AH_VERBATIM gets replaced with #define by
# AC_DEFINE.  The goal here is to define all known feature-enabling
# macros, then, if reports of conflicts are made, disable macros that
# cause problems on some platforms (such as __EXTENSIONS__).
38
AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS],
39 40
[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
41

42 43 44
  AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
  if test "$MINIX" = yes; then
    AC_DEFINE([_POSIX_SOURCE], [1],
45
      [Define to 1 if you need to in order for 'stat' and other
46 47 48 49 50 51
       things to work.])
    AC_DEFINE([_POSIX_1_SOURCE], [2],
      [Define to 2 if the system does not provide POSIX.1 features
       except with this defined.])
    AC_DEFINE([_MINIX], [1],
      [Define to 1 if on MINIX.])
52 53
    AC_DEFINE([_NETBSD_SOURCE], [1],
      [Define to 1 to make NetBSD features available.  MINIX 3 needs this.])
54
  fi
55

56 57 58
dnl Use a different key than __EXTENSIONS__, as that name broke existing
dnl configure.ac when using autoheader 2.62.
  AH_VERBATIM([USE_SYSTEM_EXTENSIONS],
59 60 61 62
[/* Enable extensions on AIX 3, Interix.  */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
63
/* Enable general extensions on macOS.  */
64 65 66
#ifndef _DARWIN_C_SOURCE
# undef _DARWIN_C_SOURCE
#endif
67 68 69
/* Enable GNU extensions on systems that have them.  */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
70
#endif
71 72 73 74
/* Enable NetBSD extensions on NetBSD.  */
#ifndef _NETBSD_SOURCE
# undef _NETBSD_SOURCE
#endif
75 76 77 78
/* Enable OpenBSD extensions on NetBSD.  */
#ifndef _OPENBSD_SOURCE
# undef _OPENBSD_SOURCE
#endif
79
/* Enable threading extensions on Solaris.  */
80 81
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
82
#endif
83 84 85 86
/* Enable extensions specified by ISO/IEC TS 18661-5:2014.  */
#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
# undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
#endif
87 88 89 90
/* Enable extensions specified by ISO/IEC TS 18661-1:2014.  */
#ifndef __STDC_WANT_IEC_60559_BFP_EXT__
# undef __STDC_WANT_IEC_60559_BFP_EXT__
#endif
91 92 93 94
/* Enable extensions specified by ISO/IEC TS 18661-2:2015.  */
#ifndef __STDC_WANT_IEC_60559_DFP_EXT__
# undef __STDC_WANT_IEC_60559_DFP_EXT__
#endif
95 96 97 98
/* Enable extensions specified by ISO/IEC TS 18661-4:2015.  */
#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
# undef __STDC_WANT_IEC_60559_FUNCS_EXT__
#endif
99 100 101 102
/* Enable extensions specified by ISO/IEC TS 18661-3:2015.  */
#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
# undef __STDC_WANT_IEC_60559_TYPES_EXT__
#endif
103 104 105 106
/* Enable extensions specified by ISO/IEC TR 24731-2:2010.  */
#ifndef __STDC_WANT_LIB_EXT2__
# undef __STDC_WANT_LIB_EXT2__
#endif
107
/* Enable extensions specified by ISO/IEC 24747:2009.  */
108 109 110
#ifndef __STDC_WANT_MATH_SPEC_FUNCS__
# undef __STDC_WANT_MATH_SPEC_FUNCS__
#endif
111
/* Enable extensions on HP NonStop.  */
112 113
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
114
#endif
115 116 117 118 119 120
/* Enable X/Open extensions if necessary.  HP-UX 11.11 defines
   mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of
   whether compiling with -Ae or -D_HPUX_SOURCE=1.  */
#ifndef _XOPEN_SOURCE
# undef _XOPEN_SOURCE
#endif
121 122 123 124 125
/* Enable X/Open compliant socket functions that do not require linking
   with -lxnet on HP-UX 11.11.  */
#ifndef _HPUX_ALT_XOPEN_SOCKET_API
# undef _HPUX_ALT_XOPEN_SOCKET_API
#endif
126 127 128 129 130
/* Enable general extensions on Solaris.  */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
])
131
  AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
132
    [ac_cv_safe_to_define___extensions__],
133
    [AC_COMPILE_IFELSE(
134
       [AC_LANG_PROGRAM([[
135 136
#         define __EXTENSIONS__ 1
          ]AC_INCLUDES_DEFAULT])],
137 138 139
       [ac_cv_safe_to_define___extensions__=yes],
       [ac_cv_safe_to_define___extensions__=no])])
  test $ac_cv_safe_to_define___extensions__ = yes &&
140
    AC_DEFINE([__EXTENSIONS__])
141
  AC_DEFINE([_ALL_SOURCE])
142
  AC_DEFINE([_DARWIN_C_SOURCE])
143
  AC_DEFINE([_GNU_SOURCE])
144
  AC_DEFINE([_NETBSD_SOURCE])
145
  AC_DEFINE([_OPENBSD_SOURCE])
146
  AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
147
  AC_DEFINE([__STDC_WANT_IEC_60559_ATTRIBS_EXT__])
148
  AC_DEFINE([__STDC_WANT_IEC_60559_BFP_EXT__])
149
  AC_DEFINE([__STDC_WANT_IEC_60559_DFP_EXT__])
150
  AC_DEFINE([__STDC_WANT_IEC_60559_FUNCS_EXT__])
151
  AC_DEFINE([__STDC_WANT_IEC_60559_TYPES_EXT__])
152
  AC_DEFINE([__STDC_WANT_LIB_EXT2__])
153
  AC_DEFINE([__STDC_WANT_MATH_SPEC_FUNCS__])
154
  AC_DEFINE([_TANDEM_SOURCE])
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
  AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined],
    [ac_cv_should_define__xopen_source],
    [ac_cv_should_define__xopen_source=no
     AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM([[
          #include <wchar.h>
          mbstate_t x;]])],
       [],
       [AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM([[
             #define _XOPEN_SOURCE 500
             #include <wchar.h>
             mbstate_t x;]])],
          [ac_cv_should_define__xopen_source=yes])])])
  test $ac_cv_should_define__xopen_source = yes &&
    AC_DEFINE([_XOPEN_SOURCE], [500])
171
  AC_DEFINE([_HPUX_ALT_XOPEN_SOCKET_API])
172
])# AC_USE_SYSTEM_EXTENSIONS
173 174 175 176 177

# gl_USE_SYSTEM_EXTENSIONS
# ------------------------
# Enable extensions on systems that normally disable them,
# typically due to standards-conformance issues.
178
AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS],
179 180 181 182 183 184 185 186 187 188 189
[
  dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS.
  dnl gnulib does not need it. But if it gets required by third-party macros
  dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a
  dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
  dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE,
  dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck.
  AC_REQUIRE([AC_GNU_SOURCE])

  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
])