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