* doc/autoconf.texi (C Compiler): Warn that AC_C_BIGENDIAN
[autoconf.git] / lib / autoconf / c.m4
bloba5b7348fd94f3c77494581db149ff082e2f8e953
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
4 # Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 # As a special exception, the Free Software Foundation gives unlimited
22 # permission to copy, distribute and modify the configure scripts that
23 # are the output of Autoconf.  You need not follow the terms of the GNU
24 # General Public License when using or distributing such scripts, even
25 # though portions of the text of Autoconf appear in them.  The GNU
26 # General Public License (GPL) does govern all other use of the material
27 # that constitutes the Autoconf program.
29 # Certain portions of the Autoconf source text are designed to be copied
30 # (in certain cases, depending on the input) into the output of
31 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
32 # source text consists of comments plus executable code that decides which
33 # of the data portions to output in any given case.  We call these
34 # comments and executable code the "non-data" portions.  Autoconf never
35 # copies any of the non-data portions into its output.
37 # This special exception to the GPL applies to versions of Autoconf
38 # released by the Free Software Foundation.  When you make and
39 # distribute a modified version of Autoconf, you may extend this special
40 # exception to the GPL to apply to your modified version as well, *unless*
41 # your modified version has the potential to copy into its output some
42 # of the text that was the non-data portion of the version that you started
43 # with.  (In other words, unless your change moves or copies text from
44 # the non-data portions to the data portions.)  If your modification has
45 # such potential, you must delete any notice of this special exception
46 # to the GPL from your modified version.
48 # Written by David MacKenzie, with help from
49 # Akim Demaille, Paul Eggert,
50 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
51 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
54 # -------------------- #
55 # 1b. The C language.  #
56 # -------------------- #
59 # AC_LANG(C)
60 # ----------
61 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
62 m4_define([AC_LANG(C)],
63 [ac_ext=c
64 ac_cpp='$CPP $CPPFLAGS'
65 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
66 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
67 ac_compiler_gnu=$ac_cv_c_compiler_gnu
71 # AC_LANG_C
72 # ---------
73 AU_DEFUN([AC_LANG_C], [AC_LANG(C)])
76 # _AC_LANG_ABBREV(C)
77 # ------------------
78 m4_define([_AC_LANG_ABBREV(C)], [c])
81 # _AC_LANG_PREFIX(C)
82 # ------------------
83 m4_define([_AC_LANG_PREFIX(C)], [C])
86 # ---------------------- #
87 # 1c. The C++ language.  #
88 # ---------------------- #
91 # AC_LANG(C++)
92 # ------------
93 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
94 m4_define([AC_LANG(C++)],
95 [ac_ext=cpp
96 ac_cpp='$CXXCPP $CPPFLAGS'
97 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
98 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
99 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
103 # AC_LANG_CPLUSPLUS
104 # -----------------
105 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
108 # _AC_LANG_ABBREV(C++)
109 # --------------------
110 m4_define([_AC_LANG_ABBREV(C++)], [cxx])
113 # _AC_LANG_PREFIX(C++)
114 # --------------------
115 m4_define([_AC_LANG_PREFIX(C++)], [CXX])
119 # ------------------------------ #
120 # 1d. The Objective C language.  #
121 # ------------------------------ #
124 # AC_LANG(Objective C)
125 # --------------------
126 m4_define([AC_LANG(Objective C)],
127 [ac_ext=m
128 ac_cpp='$OBJCPP $CPPFLAGS'
129 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
130 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
131 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
135 # AC_LANG_OBJC
136 # ------------
137 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
140 # _AC_LANG_ABBREV(Objective C)
141 # ----------------------------
142 m4_define([_AC_LANG_ABBREV(Objective C)], [objc])
145 # _AC_LANG_PREFIX(Objective C)
146 # ----------------------------
147 m4_define([_AC_LANG_PREFIX(Objective C)], [OBJC])
151 ## ---------------------- ##
152 ## 2.Producing programs.  ##
153 ## ---------------------- ##
156 # --------------- #
157 # 2b. C sources.  #
158 # --------------- #
160 # AC_LANG_SOURCE(C)(BODY)
161 # -----------------------
162 # We can't use '#line $LINENO "configure"' here, since
163 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
164 # rejects $LINENO greater than 32767, and some configure scripts
165 # are longer than 32767 lines.
166 m4_define([AC_LANG_SOURCE(C)],
167 [/* confdefs.h.  */
168 _ACEOF
169 cat confdefs.h >>conftest.$ac_ext
170 cat >>conftest.$ac_ext <<_ACEOF
171 /* end confdefs.h.  */
172 $1])
175 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
176 # --------------------------------------
177 m4_define([AC_LANG_PROGRAM(C)],
179 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
180 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
182 main ()
184 dnl Do *not* indent the following line: there may be CPP directives.
185 dnl Don't move the `;' right after for the same reason.
187   ;
188   return 0;
192 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
193 # -----------------------------------
194 # Avoid conflicting decl of main.
195 m4_define([AC_LANG_CALL(C)],
196 [AC_LANG_PROGRAM([$1
197 m4_if([$2], [main], ,
198 [/* Override any GCC internal prototype to avoid an error.
199    Use char because int might match the return type of a GCC
200    builtin and then its argument prototype would still apply.  */
201 #ifdef __cplusplus
202 extern "C"
203 #endif
204 char $2 ();])], [return $2 ();])])
207 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
208 # ----------------------------------
209 # Don't include <ctype.h> because on OSF/1 3.0 it includes
210 # <sys/types.h> which includes <sys/select.h> which contains a
211 # prototype for select.  Similarly for bzero.
213 # This test used to merely assign f=$1 in main(), but that was
214 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
215 # presumably on the basis that there's no need to do that store if the
216 # program is about to exit.  Conversely, the AIX linker optimizes an
217 # unused external declaration that initializes f=$1.  So this test
218 # program has both an external initialization of f, and a use of f in
219 # main that affects the exit status.
221 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
222 [AC_LANG_PROGRAM(
223 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
224    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
225 #define $1 innocuous_$1
227 /* System header to define __stub macros and hopefully few prototypes,
228     which can conflict with char $1 (); below.
229     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
230     <limits.h> exists even on freestanding compilers.  */
232 #ifdef __STDC__
233 # include <limits.h>
234 #else
235 # include <assert.h>
236 #endif
238 #undef $1
240 /* Override any GCC internal prototype to avoid an error.
241    Use char because int might match the return type of a GCC
242    builtin and then its argument prototype would still apply.  */
243 #ifdef __cplusplus
244 extern "C"
245 #endif
246 char $1 ();
247 /* The GNU C library defines this for functions which it implements
248     to always fail with ENOSYS.  Some functions are actually named
249     something starting with __ and the normal name is an alias.  */
250 #if defined __stub_$1 || defined __stub___$1
251 choke me
252 #endif
253 ], [return $1 ();])])
256 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
257 # -------------------------------------------------
258 # Return a program that is valid if EXPRESSION is nonzero.
259 # EXPRESSION must be an integer constant expression.
260 # Be sure to use this array to avoid `unused' warnings, which are even
261 # errors with `-W error'.
262 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
263 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
264 test_array @<:@0@:>@ = 0
265 ])])
268 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
269 # -----------------------------------------
270 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
271 # But we include them only after the EXPRESSION has been evaluated.
272 m4_define([AC_LANG_INT_SAVE(C)],
273 [AC_LANG_PROGRAM([$1
274 static long int longval () { return $2; }
275 static unsigned long int ulongval () { return $2; }
276 @%:@include <stdio.h>
277 @%:@include <stdlib.h>],
279   FILE *f = fopen ("conftest.val", "w");
280   if (! f)
281     return 1;
282   if (($2) < 0)
283     {
284       long int i = longval ();
285       if (i != ($2))
286         return 1;
287       fprintf (f, "%ld", i);
288     }
289   else
290     {
291       unsigned long int i = ulongval ();
292       if (i != ($2))
293         return 1;
294       fprintf (f, "%lu", i);
295     }
296   /* Do not output a trailing newline, as this causes \r\n confusion
297      on some platforms.  */
298   return ferror (f) || fclose (f) != 0;
299 ])])
302 # ----------------- #
303 # 2c. C++ sources.  #
304 # ----------------- #
306 # AC_LANG_SOURCE(C++)(BODY)
307 # -------------------------
308 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(C++)])
311 # AC_LANG_PROGRAM(C++)([PROLOGUE], [BODY])
312 # ----------------------------------------
313 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(C++)])
316 # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
317 # -------------------------------------
318 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(C++)])
321 # AC_LANG_FUNC_LINK_TRY(C++)(FUNCTION)
322 # ------------------------------------
323 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(C++)])
326 # AC_LANG_BOOL_COMPILE_TRY(C++)(PROLOGUE, EXPRESSION)
327 # ---------------------------------------------------
328 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])
331 # AC_LANG_INT_SAVE(C++)(PROLOGUE, EXPRESSION)
332 # -------------------------------------------
333 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(C++)])
337 # ------------------------- #
338 # 2d. Objective C sources.  #
339 # ------------------------- #
341 # AC_LANG_SOURCE(Objective C)(BODY)
342 # ---------------------------------
343 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(Objective C)])
346 # AC_LANG_PROGRAM(Objective C)([PROLOGUE], [BODY])
347 # ------------------------------------------------
348 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(Objective C)])
351 # AC_LANG_CALL(Objective C)(PROLOGUE, FUNCTION)
352 # ---------------------------------------------
353 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(Objective C)])
356 # AC_LANG_FUNC_LINK_TRY(Objective C)(FUNCTION)
357 # --------------------------------------------
358 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(Objective C)])
361 # AC_LANG_BOOL_COMPILE_TRY(Objective C)(PROLOGUE, EXPRESSION)
362 # -----------------------------------------------------------
363 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(Objective C)])
366 # AC_LANG_INT_SAVE(Objective C)(PROLOGUE, EXPRESSION)
367 # ---------------------------------------------------
368 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(Objective C)])
372 ## -------------------------------------------- ##
373 ## 3. Looking for Compilers and Preprocessors.  ##
374 ## -------------------------------------------- ##
376 # -------------------- #
377 # 3b. The C compiler.  #
378 # -------------------- #
381 # _AC_ARG_VAR_CPPFLAGS
382 # --------------------
383 # Document and register CPPFLAGS, which is used by
384 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP}.
385 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
386 [AC_ARG_VAR([CPPFLAGS],
387             [C/C++/Objective C preprocessor flags, e.g. -I<include dir>
388              if you have headers in a nonstandard directory <include dir>])])
391 # _AC_ARG_VAR_LDFLAGS
392 # -------------------
393 # Document and register LDFLAGS, which is used by
394 # AC_PROG_{CC, CXX, F77, FC, OBJC}.
395 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
396 [AC_ARG_VAR([LDFLAGS],
397             [linker flags, e.g. -L<lib dir> if you have libraries in a
398              nonstandard directory <lib dir>])])
401 # _AC_ARG_VAR_LIBS
402 # ----------------
403 # Document and register LIBS, which is used by
404 # AC_PROG_{CC, CXX, F77, FC, OBJS}.
405 AC_DEFUN([_AC_ARG_VAR_LIBS],
406 [AC_ARG_VAR([LIBS],
407             [libraries to pass to the linker, e.g. -l<library>])])
410 # AC_LANG_PREPROC(C)
411 # -------------------
412 # Find the C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
413 AC_DEFUN([AC_LANG_PREPROC(C)],
414 [AC_REQUIRE([AC_PROG_CPP])])
417 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
418 # -----------------------------------------------
419 # Check if $ac_cpp is a working preprocessor that can flag absent
420 # includes either by the exit status or by warnings.
421 # This macro is for all languages, not only C.
422 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
423 [ac_preproc_ok=false
424 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
426   # Use a header file that comes with gcc, so configuring glibc
427   # with a fresh cross-compiler works.
428   # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
429   # <limits.h> exists even on freestanding compilers.
430   # On the NeXT, cc -E runs the code through the compiler's parser,
431   # not just through cpp. "Syntax error" is here to catch this case.
432   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@ifdef __STDC__
433 @%:@ include <limits.h>
434 @%:@else
435 @%:@ include <assert.h>
436 @%:@endif
437                      Syntax error]])],
438                      [],
439                      [# Broken: fails on valid input.
440 continue])
442   # OK, works on sane cases.  Now check whether nonexistent headers
443   # can be detected and how.
444   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
445                      [# Broken: success on invalid input.
446 continue],
447                      [# Passes both tests.
448 ac_preproc_ok=:
449 break])
451 done
452 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
453 rm -f conftest.err conftest.$ac_ext
454 AS_IF([$ac_preproc_ok], [$1], [$2])])# _AC_PROG_PREPROC_WORKS_IFELSE
457 # AC_PROG_CPP
458 # -----------
459 # Find a working C preprocessor.
460 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
461 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
462 AN_MAKEVAR([CPP], [AC_PROG_CPP])
463 AN_PROGRAM([cpp], [AC_PROG_CPP])
464 AC_DEFUN([AC_PROG_CPP],
465 [AC_REQUIRE([AC_PROG_CC])dnl
466 AC_ARG_VAR([CPP],      [C preprocessor])dnl
467 _AC_ARG_VAR_CPPFLAGS()dnl
468 AC_LANG_PUSH(C)dnl
469 AC_MSG_CHECKING([how to run the C preprocessor])
470 # On Suns, sometimes $CPP names a directory.
471 if test -n "$CPP" && test -d "$CPP"; then
472   CPP=
474 if test -z "$CPP"; then
475   AC_CACHE_VAL([ac_cv_prog_CPP],
476   [dnl
477     # Double quotes because CPP needs to be expanded
478     for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
479     do
480       _AC_PROG_PREPROC_WORKS_IFELSE([break])
481     done
482     ac_cv_prog_CPP=$CPP
483   ])dnl
484   CPP=$ac_cv_prog_CPP
485 else
486   ac_cv_prog_CPP=$CPP
488 AC_MSG_RESULT([$CPP])
489 _AC_PROG_PREPROC_WORKS_IFELSE([],
490                 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
491 AC_SUBST(CPP)dnl
492 AC_LANG_POP(C)dnl
493 ])# AC_PROG_CPP
495 # AC_PROG_CPP_WERROR
496 # ------------------
497 # Treat warnings from the preprocessor as errors.
498 AC_DEFUN([AC_PROG_CPP_WERROR],
499 [AC_REQUIRE([AC_PROG_CPP])dnl
500 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
502 # AC_LANG_COMPILER(C)
503 # -------------------
504 # Find the C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
505 AC_DEFUN([AC_LANG_COMPILER(C)],
506 [AC_REQUIRE([AC_PROG_CC])])
509 # ac_cv_prog_gcc
510 # --------------
511 # We used to name the cache variable this way.
512 AU_DEFUN([ac_cv_prog_gcc],
513 [ac_cv_c_compiler_gnu])
516 # AC_PROG_CC([COMPILER ...])
517 # --------------------------
518 # COMPILER ... is a space separated list of C compilers to search for.
519 # This just gives the user an opportunity to specify an alternative
520 # search list for the C compiler.
521 AN_MAKEVAR([CC],  [AC_PROG_CC])
522 AN_PROGRAM([cc],  [AC_PROG_CC])
523 AN_PROGRAM([gcc], [AC_PROG_CC])
524 AC_DEFUN([AC_PROG_CC],
525 [AC_LANG_PUSH(C)dnl
526 AC_ARG_VAR([CC],     [C compiler command])dnl
527 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
528 _AC_ARG_VAR_LDFLAGS()dnl
529 _AC_ARG_VAR_LIBS()dnl
530 _AC_ARG_VAR_CPPFLAGS()dnl
531 m4_ifval([$1],
532       [AC_CHECK_TOOLS(CC, [$1])],
533 [AC_CHECK_TOOL(CC, gcc)
534 if test -z "$CC"; then
535   dnl Here we want:
536   dnl   AC_CHECK_TOOL(CC, cc)
537   dnl but without the check for a tool without the prefix.
538   dnl Until the check is removed from there, copy the code:
539   if test -n "$ac_tool_prefix"; then
540     AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
541   fi
543 if test -z "$CC"; then
544   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
546 if test -z "$CC"; then
547   AC_CHECK_TOOLS(CC, cl.exe)
551 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
553 # Provide some information about the compiler.
554 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
555 set X $ac_compile
556 ac_compiler=$[2]
557 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
558 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
559 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
561 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
562 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
563 _AC_LANG_COMPILER_GNU
564 if test $ac_compiler_gnu = yes; then
565   GCC=yes
566 else
567   GCC=
569 _AC_PROG_CC_G
570 _AC_PROG_CC_C89
571 AC_LANG_POP(C)dnl
572 ])# AC_PROG_CC
575 # _AC_PROG_CC_G
576 # -------------
577 # Check whether -g works, even if CFLAGS is set, in case the package
578 # plays around with CFLAGS (such as to build both debugging and normal
579 # versions of a library), tasteless as that idea is.
580 # Don't consider -g to work if it generates warnings when plain compiles don't.
581 m4_define([_AC_PROG_CC_G],
582 [ac_test_CFLAGS=${CFLAGS+set}
583 ac_save_CFLAGS=$CFLAGS
584 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
585   [ac_save_c_werror_flag=$ac_c_werror_flag
586    ac_c_werror_flag=yes
587    ac_cv_prog_cc_g=no
588    CFLAGS="-g"
589    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
590      [ac_cv_prog_cc_g=yes],
591      [CFLAGS=""
592       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
593         [],
594         [ac_c_werror_flag=$ac_save_c_werror_flag
595          CFLAGS="-g"
596          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
597            [ac_cv_prog_cc_g=yes])])])
598    ac_c_werror_flag=$ac_save_c_werror_flag])
599 if test "$ac_test_CFLAGS" = set; then
600   CFLAGS=$ac_save_CFLAGS
601 elif test $ac_cv_prog_cc_g = yes; then
602   if test "$GCC" = yes; then
603     CFLAGS="-g -O2"
604   else
605     CFLAGS="-g"
606   fi
607 else
608   if test "$GCC" = yes; then
609     CFLAGS="-O2"
610   else
611     CFLAGS=
612   fi
613 fi[]dnl
614 ])# _AC_PROG_CC_G
617 # AC_PROG_GCC_TRADITIONAL
618 # -----------------------
619 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
620 [AC_REQUIRE([AC_PROG_CC])dnl
621 if test $ac_cv_c_compiler_gnu = yes; then
622     AC_CACHE_CHECK(whether $CC needs -traditional,
623       ac_cv_prog_gcc_traditional,
624 [  ac_pattern="Autoconf.*'x'"
625   AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
626 Autoconf TIOCGETP],
627   ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
629   if test $ac_cv_prog_gcc_traditional = no; then
630     AC_EGREP_CPP($ac_pattern, [#include <termio.h>
631 Autoconf TCGETA],
632     ac_cv_prog_gcc_traditional=yes)
633   fi])
634   if test $ac_cv_prog_gcc_traditional = yes; then
635     CC="$CC -traditional"
636   fi
638 ])# AC_PROG_GCC_TRADITIONAL
641 # AC_PROG_CC_C_O
642 # --------------
643 AC_DEFUN([AC_PROG_CC_C_O],
644 [AC_REQUIRE([AC_PROG_CC])dnl
645 if test "x$CC" != xcc; then
646   AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
647 else
648   AC_MSG_CHECKING([whether cc understands -c and -o together])
650 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
651                       sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
652 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
653 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
654 # Make sure it works both with $CC and with simple cc.
655 # We do the test twice because some compilers refuse to overwrite an
656 # existing .o file with -o, though they will create one.
657 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
658 rm -f conftest2.*
659 if _AC_DO_VAR(ac_try) &&
660    test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
661 then
662   eval ac_cv_prog_cc_${ac_cc}_c_o=yes
663   if test "x$CC" != xcc; then
664     # Test first that cc exists at all.
665     if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
666       ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
667       rm -f conftest2.*
668       if _AC_DO_VAR(ac_try) &&
669          test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
670       then
671         # cc works too.
672         :
673       else
674         # cc exists but doesn't like -o.
675         eval ac_cv_prog_cc_${ac_cc}_c_o=no
676       fi
677     fi
678   fi
679 else
680   eval ac_cv_prog_cc_${ac_cc}_c_o=no
682 rm -f core conftest*
683 ])dnl
684 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
685   AC_MSG_RESULT([yes])
686 else
687   AC_MSG_RESULT([no])
688   AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
689            [Define to 1 if your C compiler doesn't accept -c and -o together.])
691 ])# AC_PROG_CC_C_O
694 # ---------------------- #
695 # 3c. The C++ compiler.  #
696 # ---------------------- #
699 # AC_LANG_PREPROC(C++)
700 # ---------------------
701 # Find the C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
702 AC_DEFUN([AC_LANG_PREPROC(C++)],
703 [AC_REQUIRE([AC_PROG_CXXCPP])])
706 # AC_PROG_CXXCPP
707 # --------------
708 # Find a working C++ preprocessor.
709 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
710 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
711 AC_DEFUN([AC_PROG_CXXCPP],
712 [AC_REQUIRE([AC_PROG_CXX])dnl
713 AC_ARG_VAR([CXXCPP],   [C++ preprocessor])dnl
714 _AC_ARG_VAR_CPPFLAGS()dnl
715 AC_LANG_PUSH(C++)dnl
716 AC_MSG_CHECKING([how to run the C++ preprocessor])
717 if test -z "$CXXCPP"; then
718   AC_CACHE_VAL(ac_cv_prog_CXXCPP,
719   [dnl
720     # Double quotes because CXXCPP needs to be expanded
721     for CXXCPP in "$CXX -E" "/lib/cpp"
722     do
723       _AC_PROG_PREPROC_WORKS_IFELSE([break])
724     done
725     ac_cv_prog_CXXCPP=$CXXCPP
726   ])dnl
727   CXXCPP=$ac_cv_prog_CXXCPP
728 else
729   ac_cv_prog_CXXCPP=$CXXCPP
731 AC_MSG_RESULT([$CXXCPP])
732 _AC_PROG_PREPROC_WORKS_IFELSE([],
733           [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
734 AC_SUBST(CXXCPP)dnl
735 AC_LANG_POP(C++)dnl
736 ])# AC_PROG_CXXCPP
739 # AC_LANG_COMPILER(C++)
740 # ---------------------
741 # Find the C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
742 AC_DEFUN([AC_LANG_COMPILER(C++)],
743 [AC_REQUIRE([AC_PROG_CXX])])
746 # ac_cv_prog_gxx
747 # --------------
748 # We used to name the cache variable this way.
749 AU_DEFUN([ac_cv_prog_gxx],
750 [ac_cv_cxx_compiler_gnu])
753 # AC_PROG_CXX([LIST-OF-COMPILERS])
754 # --------------------------------
755 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
756 # for (if not specified, a default list is used).  This just gives the
757 # user an opportunity to specify an alternative search list for the C++
758 # compiler.
759 # aCC   HP-UX C++ compiler much better than `CC', so test before.
760 # FCC   Fujitsu C++ compiler
761 # KCC   KAI C++ compiler
762 # RCC   Rational C++
763 # xlC_r AIX C Set++ (with support for reentrant code)
764 # xlC   AIX C Set++
765 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
766 AN_PROGRAM([CC],   [AC_PROG_CXX])
767 AN_PROGRAM([c++],  [AC_PROG_CXX])
768 AN_PROGRAM([g++],  [AC_PROG_CXX])
769 AC_DEFUN([AC_PROG_CXX],
770 [AC_LANG_PUSH(C++)dnl
771 AC_ARG_VAR([CXX],      [C++ compiler command])dnl
772 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
773 _AC_ARG_VAR_LDFLAGS()dnl
774 _AC_ARG_VAR_LIBS()dnl
775 _AC_ARG_VAR_CPPFLAGS()dnl
776 _AC_ARG_VAR_PRECIOUS([CCC])dnl
777 if test -z "$CXX"; then
778   if test -n "$CCC"; then
779     CXX=$CCC
780   else
781     AC_CHECK_TOOLS(CXX,
782                    [m4_default([$1],
783                                [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
784                    g++)
785   fi
787 # Provide some information about the compiler.
788 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
789 set X $ac_compile
790 ac_compiler=$[2]
791 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
792 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
793 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
795 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
796 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
797 _AC_LANG_COMPILER_GNU
798 if test $ac_compiler_gnu = yes; then
799   GXX=yes
800 else
801   GXX=
803 _AC_PROG_CXX_G
804 AC_LANG_POP(C++)dnl
805 ])# AC_PROG_CXX
808 # _AC_PROG_CXX_G
809 # --------------
810 # Check whether -g works, even if CXXFLAGS is set, in case the package
811 # plays around with CXXFLAGS (such as to build both debugging and
812 # normal versions of a library), tasteless as that idea is.
813 # Don't consider -g to work if it generates warnings when plain compiles don't.
814 m4_define([_AC_PROG_CXX_G],
815 [ac_test_CXXFLAGS=${CXXFLAGS+set}
816 ac_save_CXXFLAGS=$CXXFLAGS
817 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
818   [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
819    ac_cxx_werror_flag=yes
820    ac_cv_prog_cxx_g=no
821    CXXFLAGS="-g"
822    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
823      [ac_cv_prog_cxx_g=yes],
824      [CXXFLAGS=""
825       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
826         [],
827         [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
828          CXXFLAGS="-g"
829          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
830            [ac_cv_prog_cxx_g=yes])])])
831    ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
832 if test "$ac_test_CXXFLAGS" = set; then
833   CXXFLAGS=$ac_save_CXXFLAGS
834 elif test $ac_cv_prog_cxx_g = yes; then
835   if test "$GXX" = yes; then
836     CXXFLAGS="-g -O2"
837   else
838     CXXFLAGS="-g"
839   fi
840 else
841   if test "$GXX" = yes; then
842     CXXFLAGS="-O2"
843   else
844     CXXFLAGS=
845   fi
846 fi[]dnl
847 ])# _AC_PROG_CXX_G
850 # AC_PROG_CXX_C_O
851 # ---------------
852 # Test if the C++ compiler accepts the options `-c' and `-o'
853 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
854 AC_DEFUN([AC_PROG_CXX_C_O],
855 [AC_REQUIRE([AC_PROG_CXX])dnl
856 AC_LANG_PUSH([C++])dnl
857 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
858                [ac_cv_prog_cxx_c_o],
859 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
860 # We test twice because some compilers refuse to overwrite an existing
861 # `.o' file with `-o', although they will create one.
862 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
863 rm -f conftest2.*
864 if _AC_DO_VAR(ac_try) &&
865      test -f conftest2.$ac_objext &&
866      _AC_DO_VAR(ac_try); then
867   ac_cv_prog_cxx_c_o=yes
868 else
869   ac_cv_prog_cxx_c_o=no
871 rm -f conftest*])
872 if test $ac_cv_prog_cxx_c_o = no; then
873   AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
874             [Define to 1 if your C++ compiler doesn't accept
875              -c and -o together.])
877 AC_LANG_POP([C++])dnl
878 ])# AC_PROG_CXX_C_O
881 # ------------------------------ #
882 # 3d. The Objective C compiler.  #
883 # ------------------------------ #
886 # AC_LANG_PREPROC(Objective C)
887 # ----------------------------
888 # Find the Objective C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
889 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
890 [AC_REQUIRE([AC_PROG_OBJCPP])])
893 # AC_PROG_OBJCPP
894 # --------------
895 # Find a working Objective C preprocessor.
896 AC_DEFUN([AC_PROG_OBJCPP],
897 [AC_REQUIRE([AC_PROG_OBJC])dnl
898 AC_ARG_VAR([OBJCPP],   [Objective C preprocessor])dnl
899 _AC_ARG_VAR_CPPFLAGS()dnl
900 AC_LANG_PUSH(Objective C)dnl
901 AC_MSG_CHECKING([how to run the Objective C preprocessor])
902 if test -z "$OBJCPP"; then
903   AC_CACHE_VAL(ac_cv_prog_OBJCPP,
904   [dnl
905     # Double quotes because OBJCPP needs to be expanded
906     for OBJCPP in "$OBJC -E" "/lib/cpp"
907     do
908       _AC_PROG_PREPROC_WORKS_IFELSE([break])
909     done
910     ac_cv_prog_OBJCPP=$OBJCPP
911   ])dnl
912   OBJCPP=$ac_cv_prog_OBJCPP
913 else
914   ac_cv_prog_OBJCPP=$OBJCPP
916 AC_MSG_RESULT([$OBJCPP])
917 _AC_PROG_PREPROC_WORKS_IFELSE([],
918           [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
919 AC_SUBST(OBJCPP)dnl
920 AC_LANG_POP(Objective C)dnl
921 ])# AC_PROG_OBJCPP
924 # AC_LANG_COMPILER(Objective C)
925 # -----------------------------
926 # Find the Objective C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
927 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
928 [AC_REQUIRE([AC_PROG_OBJC])])
932 # AC_PROG_OBJC([LIST-OF-COMPILERS])
933 # ---------------------------------
934 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
935 # search for (if not specified, a default list is used).  This just gives
936 # the user an opportunity to specify an alternative search list for the
937 # Objective C compiler.
938 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
939 # objc  David Stes' POC.  If you installed this, you likely want it.
940 # cc    Native C compiler (for instance, Apple).
941 # CC    You never know.
942 AN_MAKEVAR([OBJC],  [AC_PROG_OBJC])
943 AN_PROGRAM([objcc],  [AC_PROG_OBJC])
944 AN_PROGRAM([objc],  [AC_PROG_OBJC])
945 AC_DEFUN([AC_PROG_OBJC],
946 [AC_LANG_PUSH(Objective C)dnl
947 AC_ARG_VAR([OBJC],      [Objective C compiler command])dnl
948 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
949 _AC_ARG_VAR_LDFLAGS()dnl
950 _AC_ARG_VAR_LIBS()dnl
951 _AC_ARG_VAR_CPPFLAGS()dnl
952 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
953 AC_CHECK_TOOLS(OBJC,
954                [m4_default([$1], [gcc objcc objc cc CC])],
955                gcc)
956 # Provide some information about the compiler.
957 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
958 set X $ac_compile
959 ac_compiler=$[2]
960 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
961 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
962 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
964 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
965 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
966 _AC_LANG_COMPILER_GNU
967 if test $ac_compiler_gnu = yes; then
968   GOBJC=yes
969 else
970   GOBJC=
972 _AC_PROG_OBJC_G
973 AC_LANG_POP(Objective C)dnl
974 ])# AC_PROG_OBJC
977 # _AC_PROG_OBJC_G
978 # ---------------
979 # Check whether -g works, even if OBJCFLAGS is set, in case the package
980 # plays around with OBJCFLAGS (such as to build both debugging and
981 # normal versions of a library), tasteless as that idea is.
982 # Don't consider -g to work if it generates warnings when plain compiles don't.
983 m4_define([_AC_PROG_OBJC_G],
984 [ac_test_OBJCFLAGS=${OBJCFLAGS+set}
985 ac_save_OBJCFLAGS=$OBJCFLAGS
986 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
987   [ac_save_objc_werror_flag=$ac_objc_werror_flag
988    ac_objc_werror_flag=yes
989    ac_cv_prog_objc_g=no
990    OBJCFLAGS="-g"
991    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
992      [ac_cv_prog_objc_g=yes],
993      [OBJCFLAGS=""
994       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
995         [],
996         [ac_objc_werror_flag=$ac_save_objc_werror_flag
997          OBJCFLAGS="-g"
998          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
999            [ac_cv_prog_objc_g=yes])])])
1000    ac_objc_werror_flag=$ac_save_objc_werror_flag])
1001 if test "$ac_test_OBJCFLAGS" = set; then
1002   OBJCFLAGS=$ac_save_OBJCFLAGS
1003 elif test $ac_cv_prog_objc_g = yes; then
1004   if test "$GOBJC" = yes; then
1005     OBJCFLAGS="-g -O2"
1006   else
1007     OBJCFLAGS="-g"
1008   fi
1009 else
1010   if test "$GOBJC" = yes; then
1011     OBJCFLAGS="-O2"
1012   else
1013     OBJCFLAGS=
1014   fi
1015 fi[]dnl
1016 ])# _AC_PROG_OBJC_G
1023 ## ------------------------------- ##
1024 ## 4. Compilers' characteristics.  ##
1025 ## ------------------------------- ##
1028 # -------------------------------- #
1029 # 4b. C compiler characteristics.  #
1030 # -------------------------------- #
1032 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1033 # ----------------------------------------------------------------
1034 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1035 # to add an option to output variable CC to make it so.  This macro
1036 # tries various options that select ANSI C89 on some system or
1037 # another.  It considers the compiler to be in ANSI C89 mode if it
1038 # handles function prototypes correctly.
1039 AC_DEFUN([_AC_PROG_CC_C89],
1040 [_AC_C_STD_TRY([c89],
1041 [[#include <stdarg.h>
1042 #include <stdio.h>
1043 #include <sys/types.h>
1044 #include <sys/stat.h>
1045 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
1046 struct buf { int x; };
1047 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1048 static char *e (p, i)
1049      char **p;
1050      int i;
1052   return p[i];
1054 static char *f (char * (*g) (char **, int), char **p, ...)
1056   char *s;
1057   va_list v;
1058   va_start (v,p);
1059   s = g (p, va_arg (v,int));
1060   va_end (v);
1061   return s;
1064 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
1065    function prototypes and stuff, but not '\xHH' hex character constants.
1066    These don't provoke an error unfortunately, instead are silently treated
1067    as 'x'.  The following induces an error, until -std is added to get
1068    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
1069    array size at least.  It's necessary to write '\x00'==0 to get something
1070    that's true only with -std.  */
1071 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1073 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1074    inside strings and character constants.  */
1075 #define FOO(x) 'x'
1076 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1078 int test (int i, double x);
1079 struct s1 {int (*f) (int a);};
1080 struct s2 {int (*f) (double a);};
1081 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1082 int argc;
1083 char **argv;]],
1084 [[return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];]],
1085 dnl Don't try gcc -ansi; that turns off useful extensions and
1086 dnl breaks some systems' header files.
1087 dnl AIX circa 2003      -qlanglvl=extc89
1088 dnl old AIX             -qlanglvl=ansi
1089 dnl Ultrix, OSF/1, Tru64        -std
1090 dnl HP-UX 10.20 and later       -Ae
1091 dnl HP-UX older versions        -Aa -D_HPUX_SOURCE
1092 dnl SVR4                        -Xc -D__EXTENSIONS__
1093 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1094         -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1095 ])# _AC_PROG_CC_C89
1098 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1099 #               ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1100 # --------------------------------------------------------------
1101 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1102 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
1103 # try again with each compiler option in the space-separated OPTION-LIST; if one
1104 # helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
1105 # else ACTION-IF-UNAVAILABLE.
1106 AC_DEFUN([_AC_C_STD_TRY],
1107 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
1108 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1109 [ac_cv_prog_cc_$1=no
1110 ac_save_CC=$CC
1111 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1112 for ac_arg in '' $4
1114   CC="$ac_save_CC $ac_arg"
1115   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1116   test "x$ac_cv_prog_cc_$1" != "xno" && break
1117 done
1118 rm -f conftest.$ac_ext
1119 CC=$ac_save_CC
1120 ])# AC_CACHE_VAL
1121 case "x$ac_cv_prog_cc_$1" in
1122   x)
1123     AC_MSG_RESULT([none needed]) ;;
1124   xno)
1125     AC_MSG_RESULT([unsupported]) ;;
1126   *)
1127     CC="$CC $ac_cv_prog_cc_$1"
1128     AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1129 esac
1130 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1131 ])# _AC_C_STD_TRY
1134 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1135 # ----------------------------------------------------------------
1136 # If the C compiler is not in ISO C99 mode by default, try to add an
1137 # option to output variable CC to make it so.  This macro tries
1138 # various options that select ISO C99 on some system or another.  It
1139 # considers the compiler to be in ISO C99 mode if it handles _Bool,
1140 # // comments, flexible array members, inline, long long int, mixed
1141 # code and declarations, named initialization of structs, restrict,
1142 # va_copy, varargs macros, variable declarations in for loops and
1143 # variable length arrays.
1144 AC_DEFUN([_AC_PROG_CC_C99],
1145 [_AC_C_STD_TRY([c99],
1146 [[#include <stdarg.h>
1147 #include <stdbool.h>
1148 #include <stdlib.h>
1149 #include <wchar.h>
1150 #include <stdio.h>
1152 // Check varargs macros.  These examples are taken from C99 6.10.3.5.
1153 #define debug(...) fprintf (stderr, __VA_ARGS__)
1154 #define showlist(...) puts (#__VA_ARGS__)
1155 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1156 static void
1157 test_varargs_macros (void)
1159   int x = 1234;
1160   int y = 5678;
1161   debug ("Flag");
1162   debug ("X = %d\n", x);
1163   showlist (The first, second, and third items.);
1164   report (x>y, "x is %d but y is %d", x, y);
1167 // Check long long types.
1168 #define BIG64 18446744073709551615ull
1169 #define BIG32 4294967295ul
1170 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1171 #if !BIG_OK
1172   your preprocessor is broken;
1173 #endif
1174 #if BIG_OK
1175 #else
1176   your preprocessor is broken;
1177 #endif
1178 static long long int bignum = -9223372036854775807LL;
1179 static unsigned long long int ubignum = BIG64;
1181 struct incomplete_array
1183   int datasize;
1184   double data[];
1187 struct named_init {
1188   int number;
1189   const wchar_t *name;
1190   double average;
1193 typedef const char *ccp;
1195 static inline int
1196 test_restrict (ccp restrict text)
1198   // See if C++-style comments work.
1199   // Iterate through items via the restricted pointer.
1200   // Also check for declarations in for loops.
1201   for (unsigned int i = 0; *(text+i) != '\0'; ++i)
1202     continue;
1203   return 0;
1206 // Check varargs and va_copy.
1207 static void
1208 test_varargs (const char *format, ...)
1210   va_list args;
1211   va_start (args, format);
1212   va_list args_copy;
1213   va_copy (args_copy, args);
1215   const char *str;
1216   int number;
1217   float fnumber;
1219   while (*format)
1220     {
1221       switch (*format++)
1222         {
1223         case 's': // string
1224           str = va_arg (args_copy, const char *);
1225           break;
1226         case 'd': // int
1227           number = va_arg (args_copy, int);
1228           break;
1229         case 'f': // float
1230           fnumber = va_arg (args_copy, double);
1231           break;
1232         default:
1233           break;
1234         }
1235     }
1236   va_end (args_copy);
1237   va_end (args);
1241   // Check bool.
1242   _Bool success = false;
1244   // Check restrict.
1245   if (test_restrict ("String literal") == 0)
1246     success = true;
1247   char *restrict newvar = "Another string";
1249   // Check varargs.
1250   test_varargs ("s, d' f .", "string", 65, 34.234);
1251   test_varargs_macros ();
1253   // Check flexible array members.
1254   struct incomplete_array *ia =
1255     malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1256   ia->datasize = 10;
1257   for (int i = 0; i < ia->datasize; ++i)
1258     ia->data[i] = i * 1.234;
1260   // Check named initializers.
1261   struct named_init ni = {
1262     .number = 34,
1263     .name = L"Test wide string",
1264     .average = 543.34343,
1265   };
1267   ni.number = 58;
1269   int dynamic_array[ni.number];
1270   dynamic_array[ni.number - 1] = 543;
1272   // work around unused variable warnings
1273   return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
1274           || dynamic_array[ni.number - 1] != 543);
1276 dnl Try
1277 dnl GCC         -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1278 dnl AIX         -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
1279 dnl Intel ICC   -c99
1280 dnl IRIX        -c99
1281 dnl Solaris     -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
1282 dnl             as it incorrectly assumes C99 semantics for library functions)
1283 dnl Tru64       -c99
1284 dnl with extended modes being tried first.
1285 [[-std=gnu99 -c99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
1286 ])# _AC_PROG_CC_C99
1289 # AC_PROG_CC_C89
1290 # --------------
1291 AC_DEFUN([AC_PROG_CC_C89],
1292 [ AC_REQUIRE([AC_PROG_CC])dnl
1293   _AC_PROG_CC_C89
1297 # AC_PROG_CC_C99
1298 # --------------
1299 AC_DEFUN([AC_PROG_CC_C99],
1300 [ AC_REQUIRE([AC_PROG_CC])dnl
1301   _AC_PROG_CC_C99
1305 # AC_PROG_CC_STDC
1306 # ---------------
1307 AC_DEFUN([AC_PROG_CC_STDC],
1308 [ AC_REQUIRE([AC_PROG_CC])dnl
1309   AS_CASE([$ac_cv_prog_cc_stdc],
1310     [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
1311           [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1312              [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
1313                               [ac_cv_prog_cc_stdc=no])])])dnl
1314   AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1315   AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1316   AS_CASE([$ac_cv_prog_cc_stdc],
1317     [no], [AC_MSG_RESULT([unsupported])],
1318     [''], [AC_MSG_RESULT([none needed])],
1319           [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
1323 # AC_C_BACKSLASH_A
1324 # ----------------
1325 AC_DEFUN([AC_C_BACKSLASH_A],
1327   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1328    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1329      [[
1330 #if '\a' == 'a'
1331       syntax error;
1332 #endif
1333       char buf['\a' == 'a' ? -1 : 1];
1334       buf[0] = '\a';
1335       return buf[0] != "\a"[0];
1336      ]])],
1337      [ac_cv_c_backslash_a=yes],
1338      [ac_cv_c_backslash_a=no])])
1339   if test $ac_cv_c_backslash_a = yes; then
1340     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1341       [Define if backslash-a works in C strings.])
1342   fi
1346 # AC_C_CROSS
1347 # ----------
1348 # Has been merged into AC_PROG_CC.
1349 AU_DEFUN([AC_C_CROSS], [])
1352 # AC_C_CHAR_UNSIGNED
1353 # ------------------
1354 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1355 [AH_VERBATIM([__CHAR_UNSIGNED__],
1356 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1357 #ifndef __CHAR_UNSIGNED__
1358 # undef __CHAR_UNSIGNED__
1359 #endif])dnl
1360 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1361 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1362                                              [((char) -1) < 0])],
1363                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1364 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1365   AC_DEFINE(__CHAR_UNSIGNED__)
1367 ])# AC_C_CHAR_UNSIGNED
1370 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1371 #                 [ACTION-IF-UNIVERSAL])
1372 # -------------------------------------------------------------------------
1373 AC_DEFUN([AC_C_BIGENDIAN],
1374 [AH_VERBATIM([WORDS_BIGENDIAN],
1375 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1376    significant byte first (like Motorola and SPARC, unlike Intel and VAX). */
1377 #if defined __BIG_ENDIAN__
1378 # define WORDS_BIGENDIAN 1
1379 #elif ! defined __LITTLE_ENDIAN__
1380 /* #undef WORDS_BIGENDIAN */
1381 #endif])dnl
1382  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1383    [ac_cv_c_bigendian=unknown
1384     m4_ifval(m4_ifdef([AH_HEADER], 1)[$4],
1385       [# See if __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined.
1386        AC_COMPILE_IFELSE(
1387          [AC_LANG_SOURCE(
1388             [[#if ! (defined __BIG_ENDIAN__ || defined __LITTLE_ENDIAN__)
1389                neither is defined;
1390              #endif
1391              typedef int dummy;
1392             ]])],
1393          [ac_cv_c_bigendian=universal])],
1394       [AC_DIAGNOSE([obsolete], [AC_C_BIGENDIAN suggests AC_CONFIG_HEADERS])])
1395     if test $ac_cv_c_bigendian = unknown; then
1396       # See if sys/param.h defines the BYTE_ORDER macro.
1397       AC_COMPILE_IFELSE(
1398         [AC_LANG_PROGRAM(
1399            [[#include <sys/types.h>
1400              #include <sys/param.h>
1401            ]],
1402            [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1403                      && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1404                      && LITTLE_ENDIAN)
1405               bogus endian macros
1406              #endif
1407            ]])],
1408         [# It does; now see whether it defined to BIG_ENDIAN or not.
1409          AC_COMPILE_IFELSE(
1410            [AC_LANG_PROGRAM(
1411               [[#include <sys/types.h>
1412                 #include <sys/param.h>
1413               ]],
1414               [[#if BYTE_ORDER != BIG_ENDIAN
1415                  not big endian
1416                 #endif
1417               ]])],
1418            [ac_cv_c_bigendian=yes],
1419            [ac_cv_c_bigendian=no])])
1420     fi
1421     if test $ac_cv_c_bigendian = unknown; then
1422       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1423       AC_COMPILE_IFELSE(
1424         [AC_LANG_PROGRAM(
1425            [[#include <limits.h>
1426            ]],
1427            [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1428               bogus endian macros
1429              #endif
1430            ]])],
1431         [# It does; now see whether it defined to _BIG_ENDIAN or not.
1432          AC_COMPILE_IFELSE(
1433            [AC_LANG_PROGRAM(
1434               [[#include <limits.h>
1435               ]],
1436               [[#ifndef _BIG_ENDIAN
1437                  not big endian
1438                 #endif
1439               ]])],
1440            [ac_cv_c_bigendian=yes],
1441            [ac_cv_c_bigendian=no])])
1442     fi
1443     if test $ac_cv_c_bigendian = unknown; then
1444       # Compile a test program.
1445       AC_RUN_IFELSE(
1446         [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1447            [[
1448              /* Are we little or big endian?  From Harbison&Steele.  */
1449              union
1450              {
1451                long int l;
1452                char c[sizeof (long int)];
1453              } u;
1454              u.l = 1;
1455              return u.c[sizeof (long int) - 1] == 1;
1456            ]])],
1457         [ac_cv_c_bigendian=no],
1458         [ac_cv_c_bigendian=yes],
1459         [# Try to guess by grepping values from an object file.
1460          AC_COMPILE_IFELSE(
1461            [AC_LANG_PROGRAM(
1462               [[short int ascii_mm[] =
1463                   { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1464                 short int ascii_ii[] =
1465                   { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1466                 int use_ascii (int i) {
1467                   return ascii_mm[i] + ascii_ii[i];
1468                 }
1469                 short int ebcdic_ii[] =
1470                   { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1471                 short int ebcdic_mm[] =
1472                   { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1473                 int use_ebcdic (int i) {
1474                   return ebcdic_mm[i] + ebcdic_ii[i];
1475                 }
1476                 extern int foo;
1477               ]],
1478               [[return use_ascii (foo) == use_ebcdic (foo);]])],
1479            [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1480               ac_cv_c_bigendian=yes
1481             fi
1482             if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1483               if test "$ac_cv_c_bigendian" = unknown; then
1484                 ac_cv_c_bigendian=no
1485               else
1486                 # finding both strings is unlikely to happen, but who knows?
1487                 ac_cv_c_bigendian=unknown
1488               fi
1489             fi])])
1490     fi])
1491  case $ac_cv_c_bigendian in #(
1492    yes)
1493      m4_default([$1],
1494        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1495    no)
1496      $2 ;; #(
1497    universal)
1498      $4 ;; #(
1499    *)
1500      m4_default([$3],
1501        [AC_MSG_ERROR([unknown endianness
1502  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1503  esac
1504 ])# AC_C_BIGENDIAN
1507 # AC_C_INLINE
1508 # -----------
1509 # Do nothing if the compiler accepts the inline keyword.
1510 # Otherwise define inline to __inline__ or __inline if one of those work,
1511 # otherwise define inline to be empty.
1513 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1514 # inline function, only builtin types.
1516 AN_IDENTIFIER([inline], [AC_C_INLINE])
1517 AC_DEFUN([AC_C_INLINE],
1518 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1519 [ac_cv_c_inline=no
1520 for ac_kw in inline __inline__ __inline; do
1521   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1522 [#ifndef __cplusplus
1523 typedef int foo_t;
1524 static $ac_kw foo_t static_foo () {return 0; }
1525 $ac_kw foo_t foo () {return 0; }
1526 #endif
1527 ])],
1528                     [ac_cv_c_inline=$ac_kw])
1529   test "$ac_cv_c_inline" != no && break
1530 done
1532 AH_VERBATIM([inline],
1533 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1534    calls it, or to nothing if 'inline' is not supported under any name.  */
1535 #ifndef __cplusplus
1536 #undef inline
1537 #endif])
1538 case $ac_cv_c_inline in
1539   inline | yes) ;;
1540   *)
1541     case $ac_cv_c_inline in
1542       no) ac_val=;;
1543       *) ac_val=$ac_cv_c_inline;;
1544     esac
1545     cat >>confdefs.h <<_ACEOF
1546 #ifndef __cplusplus
1547 #define inline $ac_val
1548 #endif
1549 _ACEOF
1550     ;;
1551 esac
1552 ])# AC_C_INLINE
1555 # AC_C_CONST
1556 # ----------
1557 AC_DEFUN([AC_C_CONST],
1558 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1559 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1560 [[/* FIXME: Include the comments suggested by Paul. */
1561 #ifndef __cplusplus
1562   /* Ultrix mips cc rejects this.  */
1563   typedef int charset[2];
1564   const charset cs;
1565   /* SunOS 4.1.1 cc rejects this.  */
1566   char const *const *pcpcc;
1567   char **ppc;
1568   /* NEC SVR4.0.2 mips cc rejects this.  */
1569   struct point {int x, y;};
1570   static struct point const zero = {0,0};
1571   /* AIX XL C 1.02.0.0 rejects this.
1572      It does not let you subtract one const X* pointer from another in
1573      an arm of an if-expression whose if-part is not a constant
1574      expression */
1575   const char *g = "string";
1576   pcpcc = &g + (g ? g-g : 0);
1577   /* HPUX 7.0 cc rejects these. */
1578   ++pcpcc;
1579   ppc = (char**) pcpcc;
1580   pcpcc = (char const *const *) ppc;
1581   { /* SCO 3.2v4 cc rejects this.  */
1582     char *t;
1583     char const *s = 0 ? (char *) 0 : (char const *) 0;
1585     *t++ = 0;
1586     if (s) return 0;
1587   }
1588   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1589     int x[] = {25, 17};
1590     const int *foo = &x[0];
1591     ++foo;
1592   }
1593   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1594     typedef const int *iptr;
1595     iptr p = 0;
1596     ++p;
1597   }
1598   { /* AIX XL C 1.02.0.0 rejects this saying
1599        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1600     struct s { int j; const int *ap[3]; };
1601     struct s *b; b->j = 5;
1602   }
1603   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1604     const int foo = 10;
1605     if (!foo) return 0;
1606   }
1607   return !cs[0] && !zero.x;
1608 #endif
1609 ]])],
1610                    [ac_cv_c_const=yes],
1611                    [ac_cv_c_const=no])])
1612 if test $ac_cv_c_const = no; then
1613   AC_DEFINE(const,,
1614             [Define to empty if `const' does not conform to ANSI C.])
1616 ])# AC_C_CONST
1619 # AC_C_RESTRICT
1620 # -------------
1621 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1622 # http://autoconf-archive.cryp.to/acx_restrict.html
1624 # Determine whether the C/C++ compiler supports the "restrict" keyword
1625 # introduced in ANSI C99, or an equivalent.  Do nothing if the compiler
1626 # accepts it.  Otherwise, if the compiler supports an equivalent,
1627 # define "restrict" to be that.  Here are some variants:
1628 # - GCC supports both __restrict and __restrict__
1629 # - older DEC Alpha C compilers support only __restrict
1630 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1631 # Otherwise, define "restrict" to be empty.
1632 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1633 AC_DEFUN([AC_C_RESTRICT],
1634 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1635   [ac_cv_c_restrict=no
1636    # Try the official restrict keyword, then gcc's __restrict, and
1637    # the less common variants.
1638    for ac_kw in restrict __restrict __restrict__ _Restrict; do
1639      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1640       [[typedef int * int_ptr;
1641         int foo (int_ptr $ac_kw ip) {
1642         return ip[0];
1643        }]],
1644       [[int s[1];
1645         int * $ac_kw t = s;
1646         t[0] = 0;
1647         return foo(t)]])],
1648       [ac_cv_c_restrict=$ac_kw])
1649      test "$ac_cv_c_restrict" != no && break
1650    done
1651   ])
1652  case $ac_cv_c_restrict in
1653    restrict) ;;
1654    no) AC_DEFINE(restrict,,
1655         [Define to equivalent of C99 restrict keyword, or to nothing if this
1656         is not supported.  Do not define if restrict is supported directly.]) ;;
1657    *)  AC_DEFINE_UNQUOTED(restrict, $ac_cv_c_restrict) ;;
1658  esac
1659 ])# AC_C_RESTRICT
1662 # AC_C_VOLATILE
1663 # -------------
1664 # Note that, unlike const, #defining volatile to be the empty string can
1665 # actually turn a correct program into an incorrect one, since removing
1666 # uses of volatile actually grants the compiler permission to perform
1667 # optimizations that could break the user's code.  So, do not #define
1668 # volatile away unless it is really necessary to allow the user's code
1669 # to compile cleanly.  Benign compiler failures should be tolerated.
1670 AC_DEFUN([AC_C_VOLATILE],
1671 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1672 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1673 volatile int x;
1674 int * volatile y = (int *) 0;
1675 return !x && !y;])],
1676                    [ac_cv_c_volatile=yes],
1677                    [ac_cv_c_volatile=no])])
1678 if test $ac_cv_c_volatile = no; then
1679   AC_DEFINE(volatile,,
1680             [Define to empty if the keyword `volatile' does not work.
1681              Warning: valid code using `volatile' can become incorrect
1682              without.  Disable with care.])
1684 ])# AC_C_VOLATILE
1687 # AC_C_STRINGIZE
1688 # --------------
1689 # Checks if `#' can be used to glue strings together at the CPP level.
1690 # Defines HAVE_STRINGIZE if positive.
1691 AC_DEFUN([AC_C_STRINGIZE],
1692 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1693                 [ac_cv_c_stringize],
1694 [AC_EGREP_CPP([@%:@teststring],
1695               [@%:@define x(y) #y
1697 char *s = x(teststring);],
1698               [ac_cv_c_stringize=no],
1699               [ac_cv_c_stringize=yes])])
1700 if test $ac_cv_c_stringize = yes; then
1701   AC_DEFINE(HAVE_STRINGIZE, 1,
1702             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1704 ])# AC_C_STRINGIZE
1707 # AC_C_PROTOTYPES
1708 # ---------------
1709 # Check if the C compiler supports prototypes, included if it needs
1710 # options.
1711 AC_DEFUN([AC_C_PROTOTYPES],
1712 [AC_REQUIRE([AC_PROG_CC])dnl
1713 AC_MSG_CHECKING([for function prototypes])
1714 if test "$ac_cv_prog_cc_c89" != no; then
1715   AC_MSG_RESULT([yes])
1716   AC_DEFINE(PROTOTYPES, 1,
1717             [Define to 1 if the C compiler supports function prototypes.])
1718   AC_DEFINE(__PROTOTYPES, 1,
1719             [Define like PROTOTYPES; this can be used by system headers.])
1720 else
1721   AC_MSG_RESULT([no])
1723 ])# AC_C_PROTOTYPES
1726 # AC_C_FLEXIBLE_ARRAY_MEMBER
1727 # --------------------------
1728 # Check whether the C compiler supports flexible array members.
1729 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1731   AC_CACHE_CHECK([for flexible array members],
1732     ac_cv_c_flexmember,
1733     [AC_COMPILE_IFELSE(
1734        [AC_LANG_PROGRAM(
1735           [[#include <stdlib.h>
1736             #include <stdio.h>
1737             #include <stddef.h>
1738             struct s { int n; double d[]; };]],
1739           [[int m = getchar ();
1740             struct s *p = malloc (offsetof (struct s, d)
1741                                   + m * sizeof (double));
1742             p->d[0] = 0.0;
1743             return p->d != (double *) NULL;]])],
1744        [ac_cv_c_flexmember=yes],
1745        [ac_cv_c_flexmember=no])])
1746   if test $ac_cv_c_flexmember = yes; then
1747     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1748       [Define to nothing if C supports flexible array members, and to
1749        1 if it does not.  That way, with a declaration like `struct s
1750        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1751        can be used with pre-C99 compilers.
1752        When computing the size of such an object, don't use 'sizeof (struct s)'
1753        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
1754        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1755        MSVC and with C++ compilers.])
1756   else
1757     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1758   fi
1762 # AC_C_VARARRAYS
1763 # --------------
1764 # Check whether the C compiler supports variable-length arrays.
1765 AC_DEFUN([AC_C_VARARRAYS],
1767   AC_CACHE_CHECK([for variable-length arrays],
1768     ac_cv_c_vararrays,
1769     [AC_COMPILE_IFELSE(
1770        [AC_LANG_PROGRAM([],
1771           [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1772        [ac_cv_c_vararrays=yes],
1773        [ac_cv_c_vararrays=no])])
1774   if test $ac_cv_c_vararrays = yes; then
1775     AC_DEFINE([HAVE_C_VARARRAYS], 1,
1776       [Define to 1 if C supports variable-length arrays.])
1777   fi
1781 # AC_C_TYPEOF
1782 # -----------
1783 # Check if the C compiler supports GCC's typeof syntax.
1784 # The test case provokes incompatibilities in the Sun C compilers
1785 # (both Solaris 8 and Solaris 10).
1786 AC_DEFUN([AC_C_TYPEOF],
1788   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1789     [ac_cv_c_typeof=no
1790      for ac_kw in typeof __typeof__ no; do
1791        test $ac_kw = no && break
1792        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1793          [[
1794            int value;
1795            typedef struct {
1796                    char a [1
1797                            + ! (($ac_kw (value))
1798                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1799                                  ? ($ac_kw (value)) - 1
1800                                  : ~ (~ ($ac_kw (value)) 0
1801                                       << sizeof ($ac_kw (value)))))]; }
1802               ac__typeof_type_;
1803            return
1804              (! ((void) ((ac__typeof_type_ *) 0), 0));
1805          ]])],
1806          [ac_cv_c_typeof=$ac_kw])
1807        test $ac_cv_c_typeof != no && break
1808      done])
1809   if test $ac_cv_c_typeof != no; then
1810     AC_DEFINE([HAVE_TYPEOF], 1,
1811       [Define to 1 if typeof works with your compiler.])
1812     if test $ac_cv_c_typeof != typeof; then
1813       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1814         [Define to __typeof__ if your compiler spells it that way.])
1815     fi
1816   fi