1 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
2 # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
3 # --------------------------------------------------------------
4 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
5 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
6 # try again with each compiler option in the space-separated OPTION-LIST; if one
7 # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
8 # else ACTION-IF-UNAVAILABLE.
9 AC_DEFUN([_AC_C_STD_TRY],
10 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
11 AC_CACHE_VAL(ac_cv_prog_cc_$1,
14 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
17 CC="$ac_save_CC $ac_arg"
18 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
19 test "x$ac_cv_prog_cc_$1" != "xno" && break
21 rm -f conftest.$ac_ext
24 case "x$ac_cv_prog_cc_$1" in
26 AC_MSG_RESULT([none needed]) ;;
28 AC_MSG_RESULT([unsupported]) ;;
30 CC="$CC $ac_cv_prog_cc_$1"
31 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
33 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
36 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
37 # ----------------------------------------------------------------
38 # If the C compiler is not in ISO C99 mode by default, try to add an
39 # option to output variable CC to make it so. This macro tries
40 # various options that select ISO C99 on some system or another. It
41 # considers the compiler to be in ISO C99 mode if it handles mixed
42 # code and declarations, _Bool, inline and restrict.
43 AC_DEFUN([_AC_PROG_CC_C99],
51 struct incomplete_array
63 typedef const char *ccp;
66 test_restrict(ccp restrict text)
68 // See if C++-style comments work.
69 // Iterate through items via the restricted pointer.
70 // Also check for declarations in for loops.
71 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
76 // Check varargs and va_copy work.
78 test_varargs(const char *format, ...)
81 va_start(args, format);
83 va_copy(args_copy, args);
94 str = va_arg(args_copy, const char *);
97 number = va_arg(args_copy, int);
100 fnumber = (float) va_arg(args_copy, double);
111 // Check bool and long long datatypes.
112 _Bool success = false;
113 long long int bignum = -1234567890LL;
114 unsigned long long int ubignum = 1234567890uLL;
117 if (test_restrict("String literal") != 0)
119 char *restrict newvar = "Another string";
122 test_varargs("s, d' f .", "string", 65, 34.234);
124 // Check incomplete arrays work.
125 struct incomplete_array *ia =
126 malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
128 for (int i = 0; i < ia->datasize; ++i)
129 ia->data[i] = (double) i * 1.234;
131 // Check named initialisers.
132 struct named_init ni = {
134 .name = L"Test wide string",
135 .average = 543.34343,
140 int dynamic_array[ni.number];
141 dynamic_array[43] = 543;
143 // work around unused variable warnings
144 return bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x';
147 dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
148 dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
151 dnl Solaris (unused because it causes the compiler to assume C99 semantics for
152 dnl library functions, and this is invalid before Solaris 10: -xc99)
154 dnl with extended modes being tried first.
155 [[-std=gnu99 -c99 -qlanglvl=extc99]], [$1], [$2])[]dnl
160 AC_DEFUN([AC_PROG_CC_C99],
161 [ AC_REQUIRE([AC_PROG_CC])dnl
165 # AC_USE_SYSTEM_EXTENSIONS
166 # ------------------------
167 # Enable extensions on systems that normally disable them,
168 # typically due to standards-conformance issues.
169 AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
171 AC_BEFORE([$0], [AC_COMPILE_IFELSE])
172 AC_BEFORE([$0], [AC_RUN_IFELSE])
174 AC_REQUIRE([AC_GNU_SOURCE])
176 AC_REQUIRE([AC_MINIX])
178 AH_VERBATIM([__EXTENSIONS__],
179 [/* Enable extensions on Solaris. */
180 #ifndef __EXTENSIONS__
181 # undef __EXTENSIONS__
183 #ifndef _POSIX_PTHREAD_SEMANTICS
184 # undef _POSIX_PTHREAD_SEMANTICS
186 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
187 [ac_cv_safe_to_define___extensions__],
190 # define __EXTENSIONS__ 1
191 AC_INCLUDES_DEFAULT])],
192 [ac_cv_safe_to_define___extensions__=yes],
193 [ac_cv_safe_to_define___extensions__=no])])
194 test $ac_cv_safe_to_define___extensions__ = yes &&
195 AC_DEFINE([__EXTENSIONS__])
196 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])