3 AC_DEFUN([AC_GNU_SOURCE],
4 [AH_VERBATIM([_GNU_SOURCE],
5 [/* Enable GNU extensions on systems that have them. */
9 AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
10 AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
11 AC_DEFINE([_GNU_SOURCE])
14 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
15 # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
16 # --------------------------------------------------------------
17 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
18 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
19 # try again with each compiler option in the space-separated OPTION-LIST; if one
20 # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
21 # else ACTION-IF-UNAVAILABLE.
22 AC_DEFUN([_AC_C_STD_TRY],
23 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
24 AC_CACHE_VAL(ac_cv_prog_cc_$1,
27 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
30 CC="$ac_save_CC $ac_arg"
31 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
32 test "x$ac_cv_prog_cc_$1" != "xno" && break
34 rm -f conftest.$ac_ext
37 case "x$ac_cv_prog_cc_$1" in
39 AC_MSG_RESULT([none needed]) ;;
41 AC_MSG_RESULT([unsupported]) ;;
43 CC="$CC $ac_cv_prog_cc_$1"
44 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
46 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
49 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
50 # ----------------------------------------------------------------
51 # If the C compiler is not in ISO C99 mode by default, try to add an
52 # option to output variable CC to make it so. This macro tries
53 # various options that select ISO C99 on some system or another. It
54 # considers the compiler to be in ISO C99 mode if it handles mixed
55 # code and declarations, _Bool, inline and restrict.
56 AC_DEFUN([_AC_PROG_CC_C99],
64 struct incomplete_array
76 typedef const char *ccp;
79 test_restrict(ccp restrict text)
81 // See if C++-style comments work.
82 // Iterate through items via the restricted pointer.
83 // Also check for declarations in for loops.
84 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
89 // Check varargs and va_copy work.
91 test_varargs(const char *format, ...)
94 va_start(args, format);
96 va_copy(args_copy, args);
107 str = va_arg(args_copy, const char *);
110 number = va_arg(args_copy, int);
113 fnumber = (float) va_arg(args_copy, double);
124 // Check bool and long long datatypes.
125 _Bool success = false;
126 long long int bignum = -1234567890LL;
127 unsigned long long int ubignum = 1234567890uLL;
130 if (test_restrict("String literal") != 0)
132 char *restrict newvar = "Another string";
135 test_varargs("s, d' f .", "string", 65, 34.234);
137 // Check incomplete arrays work.
138 struct incomplete_array *ia =
139 malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
141 for (int i = 0; i < ia->datasize; ++i)
142 ia->data[i] = (double) i * 1.234;
144 // Check named initialisers.
145 struct named_init ni = {
147 .name = L"Test wide string",
148 .average = 543.34343,
153 int dynamic_array[ni.number];
154 dynamic_array[43] = 543;
156 // work around unused variable warnings
157 return bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x';
160 dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
161 dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
164 dnl Solaris (unused because it causes the compiler to assume C99 semantics for
165 dnl library functions, and this is invalid before Solaris 10: -xc99)
167 dnl with extended modes being tried first.
168 [[-std=gnu99 -c99 -qlanglvl=extc99]], [$1], [$2])[]dnl
173 AC_DEFUN([AC_PROG_CC_C99],
174 [ AC_REQUIRE([AC_PROG_CC])dnl
178 # AC_USE_SYSTEM_EXTENSIONS
179 # ------------------------
180 # Enable extensions on systems that normally disable them,
181 # typically due to standards-conformance issues.
182 m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[
183 AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
184 [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
185 AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
187 AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
188 if test "$MINIX" = yes; then
189 AC_DEFINE([_POSIX_SOURCE], [1],
190 [Define to 1 if you need to in order for `stat' and other
192 AC_DEFINE([_POSIX_1_SOURCE], [2],
193 [Define to 2 if the system does not provide POSIX.1 features
194 except with this defined.])
195 AC_DEFINE([_MINIX], [1],
196 [Define to 1 if on MINIX.])
199 AH_VERBATIM([__EXTENSIONS__],
200 [/* Enable extensions on AIX 3, Interix. */
204 /* Enable GNU extensions on systems that have them. */
208 /* Enable threading extensions on Solaris. */
209 #ifndef _POSIX_PTHREAD_SEMANTICS
210 # undef _POSIX_PTHREAD_SEMANTICS
212 /* Enable extensions on HP NonStop. */
213 #ifndef _TANDEM_SOURCE
214 # undef _TANDEM_SOURCE
216 /* Enable general extensions on Solaris. */
217 #ifndef __EXTENSIONS__
218 # undef __EXTENSIONS__
221 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
222 [ac_cv_safe_to_define___extensions__],
225 # define __EXTENSIONS__ 1
226 ]AC_INCLUDES_DEFAULT])],
227 [ac_cv_safe_to_define___extensions__=yes],
228 [ac_cv_safe_to_define___extensions__=no])])
229 test $ac_cv_safe_to_define___extensions__ = yes &&
230 AC_DEFINE([__EXTENSIONS__])
231 AC_DEFINE([_ALL_SOURCE])
232 AC_DEFINE([_GNU_SOURCE])
233 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
234 AC_DEFINE([_TANDEM_SOURCE])
235 ])# AC_USE_SYSTEM_EXTENSIONS