* lib/autoconf/c.m4 (_AC_PROG_CC_C89): Check for C89 incompatibility
[autoconf.git] / lib / autoconf / c.m4
blobdead340b40a85bb8f9ccc448d4919d6e7601117f
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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\n", i);
288     }
289   else
290     {
291       unsigned long int i = ulongval ();
292       if (i != ($2))
293         return 1;
294       fprintf (f, "%lu\n", i);
295     }
296   return ferror (f) || fclose (f) != 0;
297 ])])
300 # ----------------- #
301 # 2c. C++ sources.  #
302 # ----------------- #
304 # AC_LANG_SOURCE(C++)(BODY)
305 # -------------------------
306 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(C++)])
309 # AC_LANG_PROGRAM(C++)([PROLOGUE], [BODY])
310 # ----------------------------------------
311 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(C++)])
314 # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
315 # -------------------------------------
316 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(C++)])
319 # AC_LANG_FUNC_LINK_TRY(C++)(FUNCTION)
320 # ------------------------------------
321 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(C++)])
324 # AC_LANG_BOOL_COMPILE_TRY(C++)(PROLOGUE, EXPRESSION)
325 # ---------------------------------------------------
326 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])
329 # AC_LANG_INT_SAVE(C++)(PROLOGUE, EXPRESSION)
330 # -------------------------------------------
331 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(C++)])
335 # ------------------------- #
336 # 2d. Objective C sources.  #
337 # ------------------------- #
339 # AC_LANG_SOURCE(Objective C)(BODY)
340 # ---------------------------------
341 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(Objective C)])
344 # AC_LANG_PROGRAM(Objective C)([PROLOGUE], [BODY])
345 # ------------------------------------------------
346 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(Objective C)])
349 # AC_LANG_CALL(Objective C)(PROLOGUE, FUNCTION)
350 # ---------------------------------------------
351 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(Objective C)])
354 # AC_LANG_FUNC_LINK_TRY(Objective C)(FUNCTION)
355 # --------------------------------------------
356 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(Objective C)])
359 # AC_LANG_BOOL_COMPILE_TRY(Objective C)(PROLOGUE, EXPRESSION)
360 # -----------------------------------------------------------
361 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(Objective C)])
364 # AC_LANG_INT_SAVE(Objective C)(PROLOGUE, EXPRESSION)
365 # ---------------------------------------------------
366 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(Objective C)])
370 ## -------------------------------------------- ##
371 ## 3. Looking for Compilers and Preprocessors.  ##
372 ## -------------------------------------------- ##
374 # -------------------- #
375 # 3b. The C compiler.  #
376 # -------------------- #
379 # _AC_ARG_VAR_CPPFLAGS
380 # --------------------
381 # Document and register CPPFLAGS, which is used by
382 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP}.
383 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
384 [AC_ARG_VAR([CPPFLAGS],
385             [C/C++/Objective C preprocessor flags, e.g. -I<include dir>
386              if you have headers in a nonstandard directory <include dir>])])
389 # _AC_ARG_VAR_LDFLAGS
390 # -------------------
391 # Document and register LDFLAGS, which is used by
392 # AC_PROG_{CC, CXX, F77}.
393 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
394 [AC_ARG_VAR([LDFLAGS],
395             [linker flags, e.g. -L<lib dir> if you have libraries in a
396              nonstandard directory <lib dir>])])
400 # AC_LANG_PREPROC(C)
401 # -------------------
402 # Find the C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
403 AC_DEFUN([AC_LANG_PREPROC(C)],
404 [AC_REQUIRE([AC_PROG_CPP])])
407 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
408 # -----------------------------------------------
409 # Check if $ac_cpp is a working preprocessor that can flag absent
410 # includes either by the exit status or by warnings.
411 # Set ac_cpp_err to a non-empty value if the preprocessor failed.
412 # This macro is for all languages, not only C.
413 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
414 [ac_preproc_ok=false
415 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
417   # Use a header file that comes with gcc, so configuring glibc
418   # with a fresh cross-compiler works.
419   # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
420   # <limits.h> exists even on freestanding compilers.
421   # On the NeXT, cc -E runs the code through the compiler's parser,
422   # not just through cpp. "Syntax error" is here to catch this case.
423   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@ifdef __STDC__
424 @%:@ include <limits.h>
425 @%:@else
426 @%:@ include <assert.h>
427 @%:@endif
428                      Syntax error]])],
429                      [],
430                      [# Broken: fails on valid input.
431 continue])
433   # OK, works on sane cases.  Now check whether nonexistent headers
434   # can be detected and how.
435   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
436                      [# Broken: success on invalid input.
437 continue],
438                      [# Passes both tests.
439 ac_preproc_ok=:
440 break])
442 done
443 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
444 rm -f conftest.err conftest.$ac_ext
445 AS_IF([$ac_preproc_ok], [$1], [$2])])# _AC_PROG_PREPROC_WORKS_IFELSE
448 # AC_PROG_CPP
449 # -----------
450 # Find a working C preprocessor.
451 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
452 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
453 AN_MAKEVAR([CPP], [AC_PROG_CPP])
454 AN_PROGRAM([cpp], [AC_PROG_CPP])
455 AC_DEFUN([AC_PROG_CPP],
456 [AC_REQUIRE([AC_PROG_CC])dnl
457 AC_ARG_VAR([CPP],      [C preprocessor])dnl
458 _AC_ARG_VAR_CPPFLAGS()dnl
459 AC_LANG_PUSH(C)dnl
460 AC_MSG_CHECKING([how to run the C preprocessor])
461 # On Suns, sometimes $CPP names a directory.
462 if test -n "$CPP" && test -d "$CPP"; then
463   CPP=
465 if test -z "$CPP"; then
466   AC_CACHE_VAL([ac_cv_prog_CPP],
467   [dnl
468     # Double quotes because CPP needs to be expanded
469     for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
470     do
471       _AC_PROG_PREPROC_WORKS_IFELSE([break])
472     done
473     ac_cv_prog_CPP=$CPP
474   ])dnl
475   CPP=$ac_cv_prog_CPP
476 else
477   ac_cv_prog_CPP=$CPP
479 AC_MSG_RESULT([$CPP])
480 _AC_PROG_PREPROC_WORKS_IFELSE([],
481                 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
482 AC_SUBST(CPP)dnl
483 AC_LANG_POP(C)dnl
484 ])# AC_PROG_CPP
486 # AC_PROG_CPP_WERROR
487 # ------------------
488 # Treat warnings from the preprocessor as errors.
489 AC_DEFUN([AC_PROG_CPP_WERROR],
490 [AC_REQUIRE([AC_PROG_CPP])dnl
491 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
493 # AC_LANG_COMPILER(C)
494 # -------------------
495 # Find the C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
496 AC_DEFUN([AC_LANG_COMPILER(C)],
497 [AC_REQUIRE([AC_PROG_CC])])
500 # ac_cv_prog_gcc
501 # --------------
502 # We used to name the cache variable this way.
503 AU_DEFUN([ac_cv_prog_gcc],
504 [ac_cv_c_compiler_gnu])
507 # AC_PROG_CC([COMPILER ...])
508 # --------------------------
509 # COMPILER ... is a space separated list of C compilers to search for.
510 # This just gives the user an opportunity to specify an alternative
511 # search list for the C compiler.
512 AN_MAKEVAR([CC],  [AC_PROG_CC])
513 AN_PROGRAM([cc],  [AC_PROG_CC])
514 AN_PROGRAM([gcc], [AC_PROG_CC])
515 AC_DEFUN([AC_PROG_CC],
516 [AC_LANG_PUSH(C)dnl
517 AC_ARG_VAR([CC],     [C compiler command])dnl
518 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
519 _AC_ARG_VAR_LDFLAGS()dnl
520 _AC_ARG_VAR_CPPFLAGS()dnl
521 m4_ifval([$1],
522       [AC_CHECK_TOOLS(CC, [$1])],
523 [AC_CHECK_TOOL(CC, gcc)
524 if test -z "$CC"; then
525   dnl Here we want:
526   dnl   AC_CHECK_TOOL(CC, cc)
527   dnl but without the check for a tool without the prefix.
528   dnl Until the check is removed from there, copy the code:
529   if test -n "$ac_tool_prefix"; then
530     AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
531   fi
533 if test -z "$CC"; then
534   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
536 if test -z "$CC"; then
537   AC_CHECK_TOOLS(CC, cl.exe)
541 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
543 # Provide some information about the compiler.
544 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
545 ac_compiler=`set X $ac_compile; echo $[2]`
546 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
547 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
548 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
550 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
551 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
552 _AC_LANG_COMPILER_GNU
553 GCC=`test $ac_compiler_gnu = yes && echo yes`
554 _AC_PROG_CC_G
555 _AC_PROG_CC_C89
556 AC_LANG_POP(C)dnl
557 ])# AC_PROG_CC
560 # _AC_PROG_CC_G
561 # -------------
562 # Check whether -g works, even if CFLAGS is set, in case the package
563 # plays around with CFLAGS (such as to build both debugging and normal
564 # versions of a library), tasteless as that idea is.
565 # Don't consider -g to work if it generates warnings when plain compiles don't.
566 m4_define([_AC_PROG_CC_G],
567 [ac_test_CFLAGS=${CFLAGS+set}
568 ac_save_CFLAGS=$CFLAGS
569 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
570   [ac_save_c_werror_flag=$ac_c_werror_flag
571    ac_c_werror_flag=yes
572    ac_cv_prog_cc_g=no
573    CFLAGS="-g"
574    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
575      [ac_cv_prog_cc_g=yes],
576      [CFLAGS=""
577       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
578         [],
579         [ac_c_werror_flag=$ac_save_c_werror_flag
580          CFLAGS="-g"
581          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
582            [ac_cv_prog_cc_g=yes])])])
583    ac_c_werror_flag=$ac_save_c_werror_flag])
584 if test "$ac_test_CFLAGS" = set; then
585   CFLAGS=$ac_save_CFLAGS
586 elif test $ac_cv_prog_cc_g = yes; then
587   if test "$GCC" = yes; then
588     CFLAGS="-g -O2"
589   else
590     CFLAGS="-g"
591   fi
592 else
593   if test "$GCC" = yes; then
594     CFLAGS="-O2"
595   else
596     CFLAGS=
597   fi
598 fi[]dnl
599 ])# _AC_PROG_CC_G
602 # AC_PROG_GCC_TRADITIONAL
603 # -----------------------
604 AN_FUNCTION([ioctl],   [AC_PROG_GCC_TRADITIONAL])
605 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
606 [if test $ac_cv_c_compiler_gnu = yes; then
607     AC_CACHE_CHECK(whether $CC needs -traditional,
608       ac_cv_prog_gcc_traditional,
609 [  ac_pattern="Autoconf.*'x'"
610   AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
611 Autoconf TIOCGETP],
612   ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
614   if test $ac_cv_prog_gcc_traditional = no; then
615     AC_EGREP_CPP($ac_pattern, [#include <termio.h>
616 Autoconf TCGETA],
617     ac_cv_prog_gcc_traditional=yes)
618   fi])
619   if test $ac_cv_prog_gcc_traditional = yes; then
620     CC="$CC -traditional"
621   fi
623 ])# AC_PROG_GCC_TRADITIONAL
626 # AC_PROG_CC_C_O
627 # --------------
628 AC_DEFUN([AC_PROG_CC_C_O],
629 [AC_REQUIRE([AC_PROG_CC])dnl
630 if test "x$CC" != xcc; then
631   AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
632 else
633   AC_MSG_CHECKING([whether cc understands -c and -o together])
635 set dummy $CC; ac_cc=`echo $[2] |
636                       sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
637 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
638 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
639 # Make sure it works both with $CC and with simple cc.
640 # We do the test twice because some compilers refuse to overwrite an
641 # existing .o file with -o, though they will create one.
642 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
643 rm -f conftest2.*
644 if _AC_DO_VAR(ac_try) &&
645    test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
646 then
647   eval ac_cv_prog_cc_${ac_cc}_c_o=yes
648   if test "x$CC" != xcc; then
649     # Test first that cc exists at all.
650     if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
651       ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
652       rm -f conftest2.*
653       if _AC_DO_VAR(ac_try) &&
654          test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
655       then
656         # cc works too.
657         :
658       else
659         # cc exists but doesn't like -o.
660         eval ac_cv_prog_cc_${ac_cc}_c_o=no
661       fi
662     fi
663   fi
664 else
665   eval ac_cv_prog_cc_${ac_cc}_c_o=no
667 rm -f core conftest*
668 ])dnl
669 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
670   AC_MSG_RESULT([yes])
671 else
672   AC_MSG_RESULT([no])
673   AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
674            [Define to 1 if your C compiler doesn't accept -c and -o together.])
676 ])# AC_PROG_CC_C_O
679 # ---------------------- #
680 # 3c. The C++ compiler.  #
681 # ---------------------- #
684 # AC_LANG_PREPROC(C++)
685 # ---------------------
686 # Find the C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
687 AC_DEFUN([AC_LANG_PREPROC(C++)],
688 [AC_REQUIRE([AC_PROG_CXXCPP])])
691 # AC_PROG_CXXCPP
692 # --------------
693 # Find a working C++ preprocessor.
694 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
695 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
696 AC_DEFUN([AC_PROG_CXXCPP],
697 [AC_REQUIRE([AC_PROG_CXX])dnl
698 AC_ARG_VAR([CXXCPP],   [C++ preprocessor])dnl
699 _AC_ARG_VAR_CPPFLAGS()dnl
700 AC_LANG_PUSH(C++)dnl
701 AC_MSG_CHECKING([how to run the C++ preprocessor])
702 if test -z "$CXXCPP"; then
703   AC_CACHE_VAL(ac_cv_prog_CXXCPP,
704   [dnl
705     # Double quotes because CXXCPP needs to be expanded
706     for CXXCPP in "$CXX -E" "/lib/cpp"
707     do
708       _AC_PROG_PREPROC_WORKS_IFELSE([break])
709     done
710     ac_cv_prog_CXXCPP=$CXXCPP
711   ])dnl
712   CXXCPP=$ac_cv_prog_CXXCPP
713 else
714   ac_cv_prog_CXXCPP=$CXXCPP
716 AC_MSG_RESULT([$CXXCPP])
717 _AC_PROG_PREPROC_WORKS_IFELSE([],
718           [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
719 AC_SUBST(CXXCPP)dnl
720 AC_LANG_POP(C++)dnl
721 ])# AC_PROG_CXXCPP
724 # AC_LANG_COMPILER(C++)
725 # ---------------------
726 # Find the C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
727 AC_DEFUN([AC_LANG_COMPILER(C++)],
728 [AC_REQUIRE([AC_PROG_CXX])])
731 # ac_cv_prog_gxx
732 # --------------
733 # We used to name the cache variable this way.
734 AU_DEFUN([ac_cv_prog_gxx],
735 [ac_cv_cxx_compiler_gnu])
738 # AC_PROG_CXX([LIST-OF-COMPILERS])
739 # --------------------------------
740 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
741 # for (if not specified, a default list is used).  This just gives the
742 # user an opportunity to specify an alternative search list for the C++
743 # compiler.
744 # aCC   HP-UX C++ compiler much better than `CC', so test before.
745 # FCC   Fujitsu C++ compiler
746 # KCC   KAI C++ compiler
747 # RCC   Rational C++
748 # xlC_r AIX C Set++ (with support for reentrant code)
749 # xlC   AIX C Set++
750 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
751 AN_PROGRAM([CC],   [AC_PROG_CXX])
752 AN_PROGRAM([c++],  [AC_PROG_CXX])
753 AN_PROGRAM([g++],  [AC_PROG_CXX])
754 AC_DEFUN([AC_PROG_CXX],
755 [AC_LANG_PUSH(C++)dnl
756 AC_ARG_VAR([CXX],      [C++ compiler command])dnl
757 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
758 _AC_ARG_VAR_LDFLAGS()dnl
759 _AC_ARG_VAR_CPPFLAGS()dnl
760 _AC_ARG_VAR_PRECIOUS([CCC])dnl
761 if test -z "$CXX"; then
762   if test -n "$CCC"; then
763     CXX=$CCC
764   else
765     AC_CHECK_TOOLS(CXX,
766                    [m4_default([$1],
767                                [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
768                    g++)
769   fi
771 # Provide some information about the compiler.
772 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
773 ac_compiler=`set X $ac_compile; echo $[2]`
774 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
775 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
776 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
778 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
779 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
780 _AC_LANG_COMPILER_GNU
781 GXX=`test $ac_compiler_gnu = yes && echo yes`
782 _AC_PROG_CXX_G
783 AC_LANG_POP(C++)dnl
784 ])# AC_PROG_CXX
787 # _AC_PROG_CXX_G
788 # --------------
789 # Check whether -g works, even if CXXFLAGS is set, in case the package
790 # plays around with CXXFLAGS (such as to build both debugging and
791 # normal versions of a library), tasteless as that idea is.
792 # Don't consider -g to work if it generates warnings when plain compiles don't.
793 m4_define([_AC_PROG_CXX_G],
794 [ac_test_CXXFLAGS=${CXXFLAGS+set}
795 ac_save_CXXFLAGS=$CXXFLAGS
796 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
797   [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
798    ac_cxx_werror_flag=yes
799    ac_cv_prog_cxx_g=no
800    CXXFLAGS="-g"
801    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
802      [ac_cv_prog_cxx_g=yes],
803      [CXXFLAGS=""
804       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
805         [],
806         [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
807          CXXFLAGS="-g"
808          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
809            [ac_cv_prog_cxx_g=yes])])])
810    ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
811 if test "$ac_test_CXXFLAGS" = set; then
812   CXXFLAGS=$ac_save_CXXFLAGS
813 elif test $ac_cv_prog_cxx_g = yes; then
814   if test "$GXX" = yes; then
815     CXXFLAGS="-g -O2"
816   else
817     CXXFLAGS="-g"
818   fi
819 else
820   if test "$GXX" = yes; then
821     CXXFLAGS="-O2"
822   else
823     CXXFLAGS=
824   fi
825 fi[]dnl
826 ])# _AC_PROG_CXX_G
829 # AC_PROG_CXX_C_O
830 # ---------------
831 # Test if the C++ compiler accepts the options `-c' and `-o'
832 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
833 AC_DEFUN([AC_PROG_CXX_C_O],
834 [AC_REQUIRE([AC_PROG_CXX])dnl
835 AC_LANG_PUSH([C++])dnl
836 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
837                [ac_cv_prog_cxx_c_o],
838 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
839 # We test twice because some compilers refuse to overwrite an existing
840 # `.o' file with `-o', although they will create one.
841 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
842 rm -f conftest2.*
843 if _AC_DO_VAR(ac_try) &&
844      test -f conftest2.$ac_objext &&
845      _AC_DO_VAR(ac_try); then
846   ac_cv_prog_cxx_c_o=yes
847 else
848   ac_cv_prog_cxx_c_o=no
850 rm -f conftest*])
851 if test $ac_cv_prog_cxx_c_o = no; then
852   AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
853             [Define to 1 if your C++ compiler doesn't accept
854              -c and -o together.])
856 AC_LANG_POP([C++])dnl
857 ])# AC_PROG_CXX_C_O
860 # ------------------------------ #
861 # 3d. The Objective C compiler.  #
862 # ------------------------------ #
865 # AC_LANG_PREPROC(Objective C)
866 # ----------------------------
867 # Find the Objective C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
868 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
869 [AC_REQUIRE([AC_PROG_OBJCPP])])
872 # AC_PROG_OBJCPP
873 # --------------
874 # Find a working Objective C preprocessor.
875 AC_DEFUN([AC_PROG_OBJCPP],
876 [AC_REQUIRE([AC_PROG_OBJC])dnl
877 AC_ARG_VAR([OBJCPP],   [Objective C preprocessor])dnl
878 _AC_ARG_VAR_CPPFLAGS()dnl
879 AC_LANG_PUSH(Objective C)dnl
880 AC_MSG_CHECKING([how to run the Objective C preprocessor])
881 if test -z "$OBJCPP"; then
882   AC_CACHE_VAL(ac_cv_prog_OBJCPP,
883   [dnl
884     # Double quotes because OBJCPP needs to be expanded
885     for OBJCPP in "$OBJC -E" "/lib/cpp"
886     do
887       _AC_PROG_PREPROC_WORKS_IFELSE([break])
888     done
889     ac_cv_prog_OBJCPP=$OBJCPP
890   ])dnl
891   OBJCPP=$ac_cv_prog_OBJCPP
892 else
893   ac_cv_prog_OBJCPP=$OBJCPP
895 AC_MSG_RESULT([$OBJCPP])
896 _AC_PROG_PREPROC_WORKS_IFELSE([],
897           [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
898 AC_SUBST(OBJCPP)dnl
899 AC_LANG_POP(Objective C)dnl
900 ])# AC_PROG_OBJCPP
903 # AC_LANG_COMPILER(Objective C)
904 # -----------------------------
905 # Find the Objective C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
906 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
907 [AC_REQUIRE([AC_PROG_OBJC])])
911 # AC_PROG_OBJC([LIST-OF-COMPILERS])
912 # ---------------------------------
913 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
914 # search for (if not specified, a default list is used).  This just gives
915 # the user an opportunity to specify an alternative search list for the
916 # Objective C compiler.
917 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
918 # objc  David Stes' POC.  If you installed this, you likely want it.
919 # cc    Native C compiler (for instance, Apple).
920 # CC    You never know.
921 AN_MAKEVAR([OBJC],  [AC_PROG_OBJC])
922 AN_PROGRAM([objcc],  [AC_PROG_OBJC])
923 AN_PROGRAM([objc],  [AC_PROG_OBJC])
924 AC_DEFUN([AC_PROG_OBJC],
925 [AC_LANG_PUSH(Objective C)dnl
926 AC_ARG_VAR([OBJC],      [Objective C compiler command])dnl
927 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
928 _AC_ARG_VAR_LDFLAGS()dnl
929 _AC_ARG_VAR_CPPFLAGS()dnl
930 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
931 AC_CHECK_TOOLS(OBJC,
932                [m4_default([$1], [gcc objcc objc cc CC])],
933                gcc)
934 # Provide some information about the compiler.
935 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
936 ac_compiler=`set X $ac_compile; echo $[2]`
937 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
938 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
939 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
941 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
942 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
943 _AC_LANG_COMPILER_GNU
944 GOBJC=`test $ac_compiler_gnu = yes && echo yes`
945 _AC_PROG_OBJC_G
946 AC_LANG_POP(Objective C)dnl
947 ])# AC_PROG_OBJC
950 # _AC_PROG_OBJC_G
951 # ---------------
952 # Check whether -g works, even if OBJCFLAGS is set, in case the package
953 # plays around with OBJCFLAGS (such as to build both debugging and
954 # normal versions of a library), tasteless as that idea is.
955 # Don't consider -g to work if it generates warnings when plain compiles don't.
956 m4_define([_AC_PROG_OBJC_G],
957 [ac_test_OBJCFLAGS=${OBJCFLAGS+set}
958 ac_save_OBJCFLAGS=$OBJCFLAGS
959 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
960   [ac_save_objc_werror_flag=$ac_objc_werror_flag
961    ac_objc_werror_flag=yes
962    ac_cv_prog_objc_g=no
963    OBJCFLAGS="-g"
964    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
965      [ac_cv_prog_objc_g=yes],
966      [OBJCFLAGS=""
967       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
968         [],
969         [ac_objc_werror_flag=$ac_save_objc_werror_flag
970          OBJCFLAGS="-g"
971          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
972            [ac_cv_prog_objc_g=yes])])])
973    ac_objc_werror_flag=$ac_save_objc_werror_flag])
974 if test "$ac_test_OBJCFLAGS" = set; then
975   OBJCFLAGS=$ac_save_OBJCFLAGS
976 elif test $ac_cv_prog_objc_g = yes; then
977   if test "$GOBJC" = yes; then
978     OBJCFLAGS="-g -O2"
979   else
980     OBJCFLAGS="-g"
981   fi
982 else
983   if test "$GOBJC" = yes; then
984     OBJCFLAGS="-O2"
985   else
986     OBJCFLAGS=
987   fi
988 fi[]dnl
989 ])# _AC_PROG_OBJC_G
996 ## ------------------------------- ##
997 ## 4. Compilers' characteristics.  ##
998 ## ------------------------------- ##
1001 # -------------------------------- #
1002 # 4b. C compiler characteristics.  #
1003 # -------------------------------- #
1005 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1006 # ----------------------------------------------------------------
1007 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1008 # to add an option to output variable CC to make it so.  This macro
1009 # tries various options that select ANSI C89 on some system or
1010 # another.  It considers the compiler to be in ANSI C89 mode if it
1011 # handles function prototypes correctly.
1012 AC_DEFUN([_AC_PROG_CC_C89],
1013 [_AC_C_STD_TRY([c89],
1014 [[#include <stdarg.h>
1015 #include <stdio.h>
1016 #include <sys/types.h>
1017 #include <sys/stat.h>
1018 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
1019 struct buf { int x; };
1020 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1021 static char *e (p, i)
1022      char **p;
1023      int i;
1025   return p[i];
1027 static char *f (char * (*g) (char **, int), char **p, ...)
1029   char *s;
1030   va_list v;
1031   va_start (v,p);
1032   s = g (p, va_arg (v,int));
1033   va_end (v);
1034   return s;
1037 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
1038    function prototypes and stuff, but not '\xHH' hex character constants.
1039    These don't provoke an error unfortunately, instead are silently treated
1040    as 'x'.  The following induces an error, until -std is added to get
1041    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
1042    array size at least.  It's necessary to write '\x00'==0 to get something
1043    that's true only with -std.  */
1044 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1046 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1047    inside strings and character constants.  */
1048 #define FOO(x) 'x'
1049 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1051 int test (int i, double x);
1052 struct s1 {int (*f) (int a);};
1053 struct s2 {int (*f) (double a);};
1054 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1055 int argc;
1056 char **argv;]],
1057 [[return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];]],
1058 dnl Don't try gcc -ansi; that turns off useful extensions and
1059 dnl breaks some systems' header files.
1060 dnl AIX circa 2003      -qlanglvl=extc89
1061 dnl old AIX             -qlanglvl=ansi
1062 dnl Ultrix, OSF/1, Tru64        -std
1063 dnl HP-UX 10.20 and later       -Ae
1064 dnl HP-UX older versions        -Aa -D_HPUX_SOURCE
1065 dnl SVR4                        -Xc -D__EXTENSIONS__
1066 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1067         -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1068 ])# _AC_PROG_CC_C89
1071 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1072 #               ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1073 # --------------------------------------------------------------
1074 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1075 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
1076 # try again with each compiler option in the space-separated OPTION-LIST; if one
1077 # helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
1078 # else ACTION-IF-UNAVAILABLE.
1079 AC_DEFUN([_AC_C_STD_TRY],
1080 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
1081 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1082 [ac_cv_prog_cc_$1=no
1083 ac_save_CC=$CC
1084 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1085 for ac_arg in '' $4
1087   CC="$ac_save_CC $ac_arg"
1088   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1089   test "x$ac_cv_prog_cc_$1" != "xno" && break
1090 done
1091 rm -f conftest.$ac_ext
1092 CC=$ac_save_CC
1093 ])# AC_CACHE_VAL
1094 case "x$ac_cv_prog_cc_$1" in
1095   x)
1096     AC_MSG_RESULT([none needed]) ;;
1097   xno)
1098     AC_MSG_RESULT([unsupported]) ;;
1099   *)
1100     CC="$CC $ac_cv_prog_cc_$1"
1101     AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1102 esac
1103 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1104 ])# _AC_C_STD_TRY
1107 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1108 # ----------------------------------------------------------------
1109 # If the C compiler is not in ISO C99 mode by default, try to add an
1110 # option to output variable CC to make it so.  This macro tries
1111 # various options that select ISO C99 on some system or another.  It
1112 # considers the compiler to be in ISO C99 mode if it handles mixed
1113 # code and declarations, _Bool, inline and restrict.
1114 AC_DEFUN([_AC_PROG_CC_C99],
1115 [_AC_C_STD_TRY([c99],
1116 [[#include <stdarg.h>
1117 #include <stdbool.h>
1118 #include <stdlib.h>
1119 #include <wchar.h>
1120 #include <stdio.h>
1122 struct incomplete_array
1124   int datasize;
1125   double data[];
1128 struct named_init {
1129   int number;
1130   const wchar_t *name;
1131   double average;
1134 typedef const char *ccp;
1136 static inline int
1137 test_restrict(ccp restrict text)
1139   // See if C++-style comments work.
1140   // Iterate through items via the restricted pointer.
1141   // Also check for declarations in for loops.
1142   for (unsigned int i = 0; *(text+i) != '\0'; ++i)
1143     continue;
1144   return 0;
1147 // Check varargs and va_copy work.
1148 static void
1149 test_varargs(const char *format, ...)
1151   va_list args;
1152   va_start(args, format);
1153   va_list args_copy;
1154   va_copy(args_copy, args);
1156   const char *str;
1157   int number;
1158   float fnumber;
1160   while (*format)
1161     {
1162       switch (*format++)
1163         {
1164         case 's': // string
1165           str = va_arg(args_copy, const char *);
1166           break;
1167         case 'd': // int
1168           number = va_arg(args_copy, int);
1169           break;
1170         case 'f': // float
1171           fnumber = (float) va_arg(args_copy, double);
1172           break;
1173         default:
1174           break;
1175         }
1176     }
1177   va_end(args_copy);
1178   va_end(args);
1182   // Check bool and long long datatypes.
1183   _Bool success = false;
1184   long long int bignum = -1234567890LL;
1185   unsigned long long int ubignum = 1234567890uLL;
1187   // Check restrict.
1188   if (test_restrict("String literal") != 0)
1189     success = true;
1190   char *restrict newvar = "Another string";
1192   // Check varargs.
1193   test_varargs("s, d' f .", "string", 65, 34.234);
1195   // Check incomplete arrays work.
1196   struct incomplete_array *ia =
1197     malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
1198   ia->datasize = 10;
1199   for (int i = 0; i < ia->datasize; ++i)
1200     ia->data[i] = (double) i * 1.234;
1202   // Check named initialisers.
1203   struct named_init ni = {
1204     .number = 34,
1205     .name = L"Test wide string",
1206     .average = 543.34343,
1207   };
1209   ni.number = 58;
1211   int dynamic_array[ni.number];
1212   dynamic_array[43] = 543;
1214   // work around unused variable warnings
1215   return  bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x';
1217 dnl Try
1218 dnl GCC         -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1219 dnl AIX         -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
1220 dnl Intel ICC   -c99
1221 dnl IRIX        -c99
1222 dnl Solaris     (unused because it causes the compiler to assume C99 semantics for
1223 dnl             library functions, and this is invalid before Solaris 10: -xc99)
1224 dnl Tru64       -c99
1225 dnl with extended modes being tried first.
1226 [[-std=gnu99 -c99 -qlanglvl=extc99]], [$1], [$2])[]dnl
1227 ])# _AC_PROG_CC_C99
1230 # AC_PROG_CC_C89
1231 # --------------
1232 AC_DEFUN([AC_PROG_CC_C89],
1233 [ AC_REQUIRE([AC_PROG_CC])dnl
1234   _AC_PROG_CC_C89
1238 # AC_PROG_CC_C99
1239 # --------------
1240 AC_DEFUN([AC_PROG_CC_C99],
1241 [ AC_REQUIRE([AC_PROG_CC])dnl
1242   _AC_PROG_CC_C99
1246 # AC_PROG_CC_STDC
1247 # ---------------
1248 AC_DEFUN([AC_PROG_CC_STDC],
1249 [ AC_REQUIRE([AC_PROG_CC])dnl
1250   AS_CASE([$ac_cv_prog_cc_stdc],
1251     [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
1252           [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1253              [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
1254                               [ac_cv_prog_cc_stdc=no])])])dnl
1255   AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1256   AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1257   AS_CASE([$ac_cv_prog_cc_stdc],
1258     [no], [AC_MSG_RESULT([unsupported])],
1259     [''], [AC_MSG_RESULT([none needed])],
1260           [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
1264 # AC_C_BACKSLASH_A
1265 # ----------------
1266 AC_DEFUN([AC_C_BACKSLASH_A],
1268   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1269    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1270      [[
1271 #if '\a' == 'a'
1272       syntax error;
1273 #endif
1274       char buf['\a' == 'a' ? -1 : 1];
1275       buf[0] = '\a';
1276       return buf[0] != "\a"[0];
1277      ]])],
1278      [ac_cv_c_backslash_a=yes],
1279      [ac_cv_c_backslash_a=no])])
1280   if test $ac_cv_c_backslash_a = yes; then
1281     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1282       [Define if backslash-a works in C strings.])
1283   fi
1287 # AC_C_CROSS
1288 # ----------
1289 # Has been merged into AC_PROG_CC.
1290 AU_DEFUN([AC_C_CROSS], [])
1293 # AC_C_CHAR_UNSIGNED
1294 # ------------------
1295 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1296 [AH_VERBATIM([__CHAR_UNSIGNED__],
1297 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1298 #ifndef __CHAR_UNSIGNED__
1299 # undef __CHAR_UNSIGNED__
1300 #endif])dnl
1301 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1302 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1303                                              [((char) -1) < 0])],
1304                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1305 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1306   AC_DEFINE(__CHAR_UNSIGNED__)
1308 ])# AC_C_CHAR_UNSIGNED
1311 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN])
1312 # -------------------------------------------------------------------------
1313 AC_DEFUN([AC_C_BIGENDIAN],
1314 [AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian,
1315 [# See if sys/param.h defines the BYTE_ORDER macro.
1316 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1317 #include <sys/param.h>
1319 [#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
1320  bogus endian macros
1321 #endif
1322 ])],
1323 [# It does; now see whether it defined to BIG_ENDIAN or not.
1324 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1325 #include <sys/param.h>
1326 ], [#if BYTE_ORDER != BIG_ENDIAN
1327  not big endian
1328 #endif
1329 ])], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=no])],
1330 [# It does not; compile a test program.
1331 AC_RUN_IFELSE(
1332 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
1333   /* Are we little or big endian?  From Harbison&Steele.  */
1334   union
1335   {
1336     long int l;
1337     char c[sizeof (long int)];
1338   } u;
1339   u.l = 1;
1340   return u.c[sizeof (long int) - 1] == 1;
1341 ]])],
1342               [ac_cv_c_bigendian=no],
1343               [ac_cv_c_bigendian=yes],
1344 [# try to guess the endianness by grepping values into an object file
1345   ac_cv_c_bigendian=unknown
1346   AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1347 [[short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1348 short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1349 void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; }
1350 short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1351 short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1352 void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; }]],
1353 [[ _ascii (); _ebcdic (); ]])],
1354 [if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then
1355   ac_cv_c_bigendian=yes
1357 if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1358   if test "$ac_cv_c_bigendian" = unknown; then
1359     ac_cv_c_bigendian=no
1360   else
1361     # finding both strings is unlikely to happen, but who knows?
1362     ac_cv_c_bigendian=unknown
1363   fi
1364 fi])])])])
1365 case $ac_cv_c_bigendian in
1366   yes)
1367     m4_default([$1],
1368       [AC_DEFINE([WORDS_BIGENDIAN], 1,
1369         [Define to 1 if your processor stores words with the most significant
1370          byte first (like Motorola and SPARC, unlike Intel and VAX).])]) ;;
1371   no)
1372     $2 ;;
1373   *)
1374     m4_default([$3],
1375       [AC_MSG_ERROR([unknown endianness
1376 presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1377 esac
1378 ])# AC_C_BIGENDIAN
1381 # AC_C_INLINE
1382 # -----------
1383 # Do nothing if the compiler accepts the inline keyword.
1384 # Otherwise define inline to __inline__ or __inline if one of those work,
1385 # otherwise define inline to be empty.
1387 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1388 # inline function, only builtin types.
1390 AN_IDENTIFIER([inline], [AC_C_INLINE])
1391 AC_DEFUN([AC_C_INLINE],
1392 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1393 [ac_cv_c_inline=no
1394 for ac_kw in inline __inline__ __inline; do
1395   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1396 [#ifndef __cplusplus
1397 typedef int foo_t;
1398 static $ac_kw foo_t static_foo () {return 0; }
1399 $ac_kw foo_t foo () {return 0; }
1400 #endif
1401 ])],
1402                     [ac_cv_c_inline=$ac_kw])
1403   test "$ac_cv_c_inline" != no && break
1404 done
1406 AH_VERBATIM([inline],
1407 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1408    calls it, or to nothing if 'inline' is not supported under any name.  */
1409 #ifndef __cplusplus
1410 #undef inline
1411 #endif])
1412 case $ac_cv_c_inline in
1413   inline | yes) ;;
1414   *)
1415     case $ac_cv_c_inline in
1416       no) ac_val=;;
1417       *) ac_val=$ac_cv_c_inline;;
1418     esac
1419     cat >>confdefs.h <<_ACEOF
1420 #ifndef __cplusplus
1421 #define inline $ac_val
1422 #endif
1423 _ACEOF
1424     ;;
1425 esac
1426 ])# AC_C_INLINE
1429 # AC_C_CONST
1430 # ----------
1431 AN_IDENTIFIER([const],  [AC_C_CONST])
1432 AC_DEFUN([AC_C_CONST],
1433 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1434 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1435 [[/* FIXME: Include the comments suggested by Paul. */
1436 #ifndef __cplusplus
1437   /* Ultrix mips cc rejects this.  */
1438   typedef int charset[2];
1439   const charset x;
1440   /* SunOS 4.1.1 cc rejects this.  */
1441   char const *const *ccp;
1442   char **p;
1443   /* NEC SVR4.0.2 mips cc rejects this.  */
1444   struct point {int x, y;};
1445   static struct point const zero = {0,0};
1446   /* AIX XL C 1.02.0.0 rejects this.
1447      It does not let you subtract one const X* pointer from another in
1448      an arm of an if-expression whose if-part is not a constant
1449      expression */
1450   const char *g = "string";
1451   ccp = &g + (g ? g-g : 0);
1452   /* HPUX 7.0 cc rejects these. */
1453   ++ccp;
1454   p = (char**) ccp;
1455   ccp = (char const *const *) p;
1456   { /* SCO 3.2v4 cc rejects this.  */
1457     char *t;
1458     char const *s = 0 ? (char *) 0 : (char const *) 0;
1460     *t++ = 0;
1461     if (s) return 0;
1462   }
1463   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1464     int x[] = {25, 17};
1465     const int *foo = &x[0];
1466     ++foo;
1467   }
1468   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1469     typedef const int *iptr;
1470     iptr p = 0;
1471     ++p;
1472   }
1473   { /* AIX XL C 1.02.0.0 rejects this saying
1474        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1475     struct s { int j; const int *ap[3]; };
1476     struct s *b; b->j = 5;
1477   }
1478   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1479     const int foo = 10;
1480     if (!foo) return 0;
1481   }
1482   return !x[0] && !zero.x;
1483 #endif
1484 ]])],
1485                    [ac_cv_c_const=yes],
1486                    [ac_cv_c_const=no])])
1487 if test $ac_cv_c_const = no; then
1488   AC_DEFINE(const,,
1489             [Define to empty if `const' does not conform to ANSI C.])
1491 ])# AC_C_CONST
1494 # AC_C_RESTRICT
1495 # -------------
1496 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1497 # http://autoconf-archive.cryp.to/acx_restrict.html
1499 # Determine whether the C/C++ compiler supports the "restrict" keyword
1500 # introduced in ANSI C99, or an equivalent.  Do nothing if the compiler
1501 # accepts it.  Otherwise, if the compiler supports an equivalent,
1502 # define "restrict" to be that.  Here are some variants:
1503 # - GCC supports both __restrict and __restrict__
1504 # - older DEC Alpha C compilers support only __restrict
1505 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1506 # Otherwise, define "restrict" to be empty.
1507 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1508 AC_DEFUN([AC_C_RESTRICT],
1509 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1510   [ac_cv_c_restrict=no
1511    # Try the official restrict keyword, then gcc's __restrict, and
1512    # the less common variants.
1513    for ac_kw in restrict __restrict __restrict__ _Restrict; do
1514      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1515       [[typedef int * int_ptr;
1516         int foo (int_ptr $ac_kw ip) {
1517         return ip[0];
1518        }]],
1519       [[int s[1];
1520         int * $ac_kw t = s;
1521         t[0] = 0;
1522         return foo(t)]])],
1523       [ac_cv_c_restrict=$ac_kw])
1524      test "$ac_cv_c_restrict" != no && break
1525    done
1526   ])
1527  case $ac_cv_c_restrict in
1528    restrict) ;;
1529    no) AC_DEFINE(restrict,,
1530         [Define to equivalent of C99 restrict keyword, or to nothing if this
1531         is not supported.  Do not define if restrict is supported directly.]) ;;
1532    *)  AC_DEFINE_UNQUOTED(restrict, $ac_cv_c_restrict) ;;
1533  esac
1534 ])# AC_C_RESTRICT
1537 # AC_C_VOLATILE
1538 # -------------
1539 # Note that, unlike const, #defining volatile to be the empty string can
1540 # actually turn a correct program into an incorrect one, since removing
1541 # uses of volatile actually grants the compiler permission to perform
1542 # optimizations that could break the user's code.  So, do not #define
1543 # volatile away unless it is really necessary to allow the user's code
1544 # to compile cleanly.  Benign compiler failures should be tolerated.
1545 AN_IDENTIFIER([volatile], [AC_C_VOLATILE])
1546 AC_DEFUN([AC_C_VOLATILE],
1547 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1548 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1549 volatile int x;
1550 int * volatile y = (int *) 0;
1551 return !x && !y;])],
1552                    [ac_cv_c_volatile=yes],
1553                    [ac_cv_c_volatile=no])])
1554 if test $ac_cv_c_volatile = no; then
1555   AC_DEFINE(volatile,,
1556             [Define to empty if the keyword `volatile' does not work.
1557              Warning: valid code using `volatile' can become incorrect
1558              without.  Disable with care.])
1560 ])# AC_C_VOLATILE
1563 # AC_C_STRINGIZE
1564 # --------------
1565 # Checks if `#' can be used to glue strings together at the CPP level.
1566 # Defines HAVE_STRINGIZE if positive.
1567 AC_DEFUN([AC_C_STRINGIZE],
1568 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1569                 [ac_cv_c_stringize],
1570 [AC_EGREP_CPP([@%:@teststring],
1571               [@%:@define x(y) #y
1573 char *s = x(teststring);],
1574               [ac_cv_c_stringize=no],
1575               [ac_cv_c_stringize=yes])])
1576 if test $ac_cv_c_stringize = yes; then
1577   AC_DEFINE(HAVE_STRINGIZE, 1,
1578             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1580 ])# AC_C_STRINGIZE
1583 # AC_C_PROTOTYPES
1584 # ---------------
1585 # Check if the C compiler supports prototypes, included if it needs
1586 # options.
1587 AC_DEFUN([AC_C_PROTOTYPES],
1588 [AC_REQUIRE([AC_PROG_CC])dnl
1589 AC_MSG_CHECKING([for function prototypes])
1590 if test "$ac_cv_prog_cc_c89" != no; then
1591   AC_MSG_RESULT([yes])
1592   AC_DEFINE(PROTOTYPES, 1,
1593             [Define to 1 if the C compiler supports function prototypes.])
1594   AC_DEFINE(__PROTOTYPES, 1,
1595             [Define like PROTOTYPES; this can be used by system headers.])
1596 else
1597   AC_MSG_RESULT([no])
1599 ])# AC_C_PROTOTYPES
1602 # AC_C_TYPEOF
1603 # -----------
1604 # Check if the C compiler supports GCC's typeof syntax.
1605 # The test case provokes incompatibilities in the Sun C compilers
1606 # (both Solaris 8 and Solaris 10).
1607 AC_DEFUN([AC_C_TYPEOF],
1609   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1610     [ac_cv_c_typeof=no
1611      for ac_kw in typeof __typeof__ no; do
1612        test $ac_kw = no && break
1613        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1614          [[
1615            int value;
1616            typedef struct {
1617                    char a [1
1618                            + ! (($ac_kw (value))
1619                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1620                                  ? ($ac_kw (value)) - 1
1621                                  : ~ (~ ($ac_kw (value)) 0
1622                                       << sizeof ($ac_kw (value)))))]; }
1623               ac__typeof_type_;
1624            return
1625              (! ((void) ((ac__typeof_type_ *) 0), 0));
1626          ]])],
1627          [ac_cv_c_typeof=$ac_kw])
1628        test $ac_cv_c_typeof != no && break
1629      done])
1630   if test $ac_cv_c_typeof != no; then
1631     AC_DEFINE([HAVE_TYPEOF], 1,
1632       [Define to 1 if typeof works with your compiler.])
1633     if test $ac_cv_c_typeof != typeof; then
1634       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1635         [Define to __typeof__ if your compiler spells it that way.])
1636     fi
1637   fi