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],
185 AC_BEFORE([$0], [AC_COMPILE_IFELSE])
186 AC_BEFORE([$0], [AC_RUN_IFELSE])
188 AC_REQUIRE([AC_GNU_SOURCE])
190 AC_REQUIRE([AC_MINIX])
192 AH_VERBATIM([__EXTENSIONS__],
193 [/* Enable extensions on Solaris. */
194 #ifndef __EXTENSIONS__
195 # undef __EXTENSIONS__
197 #ifndef _POSIX_PTHREAD_SEMANTICS
198 # undef _POSIX_PTHREAD_SEMANTICS
200 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
201 [ac_cv_safe_to_define___extensions__],
204 # define __EXTENSIONS__ 1
205 AC_INCLUDES_DEFAULT])],
206 [ac_cv_safe_to_define___extensions__=yes],
207 [ac_cv_safe_to_define___extensions__=no])])
208 test $ac_cv_safe_to_define___extensions__ = yes &&
209 AC_DEFINE([__EXTENSIONS__])
210 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])