Improve AC_C_BIGENDIAN.
[autoconf.git] / lib / autoconf / c.m4
blob6e250eedc38801ecf6d30afb1feef70713a2a96e
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free
4 # Software 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 # Table of Contents:
56 # 1. Language selection
57 #    and routines to produce programs in a given language.
58 #      1a. C   1b. C++   1c. Objective C
60 # 2. Producing programs in a given language.
61 #      2a. C   2b. C++   2c. Objective C
63 # 3. Looking for a compiler
64 #    And possibly the associated preprocessor.
65 #      3a. C   3b. C++   3c. Objective C
67 # 4. Compilers' characteristics.
68 #      4a. C
72 ## ----------------------- ##
73 ## 1. Language selection.  ##
74 ## ----------------------- ##
76 # -------------------- #
77 # 1a. The C language.  #
78 # -------------------- #
81 # AC_LANG(C)
82 # ----------
83 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
84 m4_define([AC_LANG(C)],
85 [ac_ext=c
86 ac_cpp='$CPP $CPPFLAGS'
87 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
88 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
89 ac_compiler_gnu=$ac_cv_c_compiler_gnu
93 # AC_LANG_C
94 # ---------
95 AU_DEFUN([AC_LANG_C], [AC_LANG(C)])
98 # _AC_LANG_ABBREV(C)
99 # ------------------
100 m4_define([_AC_LANG_ABBREV(C)], [c])
103 # _AC_LANG_PREFIX(C)
104 # ------------------
105 m4_define([_AC_LANG_PREFIX(C)], [C])
109 # ---------------------- #
110 # 1b. The C++ language.  #
111 # ---------------------- #
114 # AC_LANG(C++)
115 # ------------
116 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
117 m4_define([AC_LANG(C++)],
118 [ac_ext=cpp
119 ac_cpp='$CXXCPP $CPPFLAGS'
120 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
121 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
122 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
126 # AC_LANG_CPLUSPLUS
127 # -----------------
128 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
131 # _AC_LANG_ABBREV(C++)
132 # --------------------
133 m4_define([_AC_LANG_ABBREV(C++)], [cxx])
136 # _AC_LANG_PREFIX(C++)
137 # --------------------
138 m4_define([_AC_LANG_PREFIX(C++)], [CXX])
142 # ------------------------------ #
143 # 1c. The Objective C language.  #
144 # ------------------------------ #
147 # AC_LANG(Objective C)
148 # --------------------
149 m4_define([AC_LANG(Objective C)],
150 [ac_ext=m
151 ac_cpp='$OBJCPP $CPPFLAGS'
152 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
153 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
154 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
158 # AC_LANG_OBJC
159 # ------------
160 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
163 # _AC_LANG_ABBREV(Objective C)
164 # ----------------------------
165 m4_define([_AC_LANG_ABBREV(Objective C)], [objc])
168 # _AC_LANG_PREFIX(Objective C)
169 # ----------------------------
170 m4_define([_AC_LANG_PREFIX(Objective C)], [OBJC])
174 ## ----------------------- ##
175 ## 2. Producing programs.  ##
176 ## ----------------------- ##
178 # --------------- #
179 # 2a. C sources.  #
180 # --------------- #
183 # AC_LANG_SOURCE(C)(BODY)
184 # -----------------------
185 # We can't use '#line $LINENO "configure"' here, since
186 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
187 # rejects $LINENO greater than 32767, and some configure scripts
188 # are longer than 32767 lines.
189 m4_define([AC_LANG_SOURCE(C)],
190 [/* confdefs.h.  */
191 _ACEOF
192 cat confdefs.h >>conftest.$ac_ext
193 cat >>conftest.$ac_ext <<_ACEOF
194 /* end confdefs.h.  */
195 $1])
198 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
199 # --------------------------------------
200 m4_define([AC_LANG_PROGRAM(C)],
202 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
203 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
205 main ()
207 dnl Do *not* indent the following line: there may be CPP directives.
208 dnl Don't move the `;' right after for the same reason.
210   ;
211   return 0;
215 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
216 # -----------------------------------
217 # Avoid conflicting decl of main.
218 m4_define([AC_LANG_CALL(C)],
219 [AC_LANG_PROGRAM([$1
220 m4_if([$2], [main], ,
221 [/* Override any GCC internal prototype to avoid an error.
222    Use char because int might match the return type of a GCC
223    builtin and then its argument prototype would still apply.  */
224 #ifdef __cplusplus
225 extern "C"
226 #endif
227 char $2 ();])], [return $2 ();])])
230 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
231 # ----------------------------------
232 # Don't include <ctype.h> because on OSF/1 3.0 it includes
233 # <sys/types.h> which includes <sys/select.h> which contains a
234 # prototype for select.  Similarly for bzero.
236 # This test used to merely assign f=$1 in main(), but that was
237 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
238 # presumably on the basis that there's no need to do that store if the
239 # program is about to exit.  Conversely, the AIX linker optimizes an
240 # unused external declaration that initializes f=$1.  So this test
241 # program has both an external initialization of f, and a use of f in
242 # main that affects the exit status.
244 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
245 [AC_LANG_PROGRAM(
246 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
247    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
248 #define $1 innocuous_$1
250 /* System header to define __stub macros and hopefully few prototypes,
251     which can conflict with char $1 (); below.
252     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
253     <limits.h> exists even on freestanding compilers.  */
255 #ifdef __STDC__
256 # include <limits.h>
257 #else
258 # include <assert.h>
259 #endif
261 #undef $1
263 /* Override any GCC internal prototype to avoid an error.
264    Use char because int might match the return type of a GCC
265    builtin and then its argument prototype would still apply.  */
266 #ifdef __cplusplus
267 extern "C"
268 #endif
269 char $1 ();
270 /* The GNU C library defines this for functions which it implements
271     to always fail with ENOSYS.  Some functions are actually named
272     something starting with __ and the normal name is an alias.  */
273 #if defined __stub_$1 || defined __stub___$1
274 choke me
275 #endif
276 ], [return $1 ();])])
279 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
280 # -------------------------------------------------
281 # Return a program that is valid if EXPRESSION is nonzero.
282 # EXPRESSION must be an integer constant expression.
283 # Be sure to use this array to avoid `unused' warnings, which are even
284 # errors with `-W error'.
285 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
286 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
287 test_array @<:@0@:>@ = 0
288 ])])
291 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
292 # -----------------------------------------
293 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
294 # But we include them only after the EXPRESSION has been evaluated.
295 m4_define([AC_LANG_INT_SAVE(C)],
296 [AC_LANG_PROGRAM([$1
297 static long int longval () { return $2; }
298 static unsigned long int ulongval () { return $2; }
299 @%:@include <stdio.h>
300 @%:@include <stdlib.h>],
302   FILE *f = fopen ("conftest.val", "w");
303   if (! f)
304     return 1;
305   if (($2) < 0)
306     {
307       long int i = longval ();
308       if (i != ($2))
309         return 1;
310       fprintf (f, "%ld", i);
311     }
312   else
313     {
314       unsigned long int i = ulongval ();
315       if (i != ($2))
316         return 1;
317       fprintf (f, "%lu", i);
318     }
319   /* Do not output a trailing newline, as this causes \r\n confusion
320      on some platforms.  */
321   return ferror (f) || fclose (f) != 0;
322 ])])
326 # ----------------- #
327 # 2b. C++ sources.  #
328 # ----------------- #
331 # AC_LANG_SOURCE(C++)(BODY)
332 # -------------------------
333 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(C++)])
336 # AC_LANG_PROGRAM(C++)([PROLOGUE], [BODY])
337 # ----------------------------------------
338 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(C++)])
341 # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
342 # -------------------------------------
343 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(C++)])
346 # AC_LANG_FUNC_LINK_TRY(C++)(FUNCTION)
347 # ------------------------------------
348 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(C++)])
351 # AC_LANG_BOOL_COMPILE_TRY(C++)(PROLOGUE, EXPRESSION)
352 # ---------------------------------------------------
353 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])
356 # AC_LANG_INT_SAVE(C++)(PROLOGUE, EXPRESSION)
357 # -------------------------------------------
358 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(C++)])
362 # ------------------------- #
363 # 2c. Objective C sources.  #
364 # ------------------------- #
367 # AC_LANG_SOURCE(Objective C)(BODY)
368 # ---------------------------------
369 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(Objective C)])
372 # AC_LANG_PROGRAM(Objective C)([PROLOGUE], [BODY])
373 # ------------------------------------------------
374 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(Objective C)])
377 # AC_LANG_CALL(Objective C)(PROLOGUE, FUNCTION)
378 # ---------------------------------------------
379 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(Objective C)])
382 # AC_LANG_FUNC_LINK_TRY(Objective C)(FUNCTION)
383 # --------------------------------------------
384 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(Objective C)])
387 # AC_LANG_BOOL_COMPILE_TRY(Objective C)(PROLOGUE, EXPRESSION)
388 # -----------------------------------------------------------
389 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(Objective C)])
392 # AC_LANG_INT_SAVE(Objective C)(PROLOGUE, EXPRESSION)
393 # ---------------------------------------------------
394 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(Objective C)])
398 ## -------------------------------------------- ##
399 ## 3. Looking for Compilers and Preprocessors.  ##
400 ## -------------------------------------------- ##
402 # -------------------- #
403 # 3a. The C compiler.  #
404 # -------------------- #
407 # _AC_ARG_VAR_CPPFLAGS
408 # --------------------
409 # Document and register CPPFLAGS, which is used by
410 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP}.
411 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
412 [AC_ARG_VAR([CPPFLAGS],
413             [C/C++/Objective C preprocessor flags, e.g. -I<include dir>
414              if you have headers in a nonstandard directory <include dir>])])
417 # _AC_ARG_VAR_LDFLAGS
418 # -------------------
419 # Document and register LDFLAGS, which is used by
420 # AC_PROG_{CC, CXX, F77, FC, OBJC}.
421 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
422 [AC_ARG_VAR([LDFLAGS],
423             [linker flags, e.g. -L<lib dir> if you have libraries in a
424              nonstandard directory <lib dir>])])
427 # _AC_ARG_VAR_LIBS
428 # ----------------
429 # Document and register LIBS, which is used by
430 # AC_PROG_{CC, CXX, F77, FC, OBJS}.
431 AC_DEFUN([_AC_ARG_VAR_LIBS],
432 [AC_ARG_VAR([LIBS],
433             [libraries to pass to the linker, e.g. -l<library>])])
436 # AC_LANG_PREPROC(C)
437 # -------------------
438 # Find the C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
439 AC_DEFUN([AC_LANG_PREPROC(C)],
440 [AC_REQUIRE([AC_PROG_CPP])])
443 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
444 # -----------------------------------------------
445 # Check if $ac_cpp is a working preprocessor that can flag absent
446 # includes either by the exit status or by warnings.
447 # This macro is for all languages, not only C.
448 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
449 [ac_preproc_ok=false
450 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
452   # Use a header file that comes with gcc, so configuring glibc
453   # with a fresh cross-compiler works.
454   # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
455   # <limits.h> exists even on freestanding compilers.
456   # On the NeXT, cc -E runs the code through the compiler's parser,
457   # not just through cpp. "Syntax error" is here to catch this case.
458   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@ifdef __STDC__
459 @%:@ include <limits.h>
460 @%:@else
461 @%:@ include <assert.h>
462 @%:@endif
463                      Syntax error]])],
464                      [],
465                      [# Broken: fails on valid input.
466 continue])
468   # OK, works on sane cases.  Now check whether nonexistent headers
469   # can be detected and how.
470   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
471                      [# Broken: success on invalid input.
472 continue],
473                      [# Passes both tests.
474 ac_preproc_ok=:
475 break])
477 done
478 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
479 rm -f conftest.err conftest.$ac_ext
480 AS_IF([$ac_preproc_ok], [$1], [$2])])# _AC_PROG_PREPROC_WORKS_IFELSE
483 # AC_PROG_CPP
484 # -----------
485 # Find a working C preprocessor.
486 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
487 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
488 AN_MAKEVAR([CPP], [AC_PROG_CPP])
489 AN_PROGRAM([cpp], [AC_PROG_CPP])
490 AC_DEFUN([AC_PROG_CPP],
491 [AC_REQUIRE([AC_PROG_CC])dnl
492 AC_ARG_VAR([CPP],      [C preprocessor])dnl
493 _AC_ARG_VAR_CPPFLAGS()dnl
494 AC_LANG_PUSH(C)dnl
495 AC_MSG_CHECKING([how to run the C preprocessor])
496 # On Suns, sometimes $CPP names a directory.
497 if test -n "$CPP" && test -d "$CPP"; then
498   CPP=
500 if test -z "$CPP"; then
501   AC_CACHE_VAL([ac_cv_prog_CPP],
502   [dnl
503     # Double quotes because CPP needs to be expanded
504     for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
505     do
506       _AC_PROG_PREPROC_WORKS_IFELSE([break])
507     done
508     ac_cv_prog_CPP=$CPP
509   ])dnl
510   CPP=$ac_cv_prog_CPP
511 else
512   ac_cv_prog_CPP=$CPP
514 AC_MSG_RESULT([$CPP])
515 _AC_PROG_PREPROC_WORKS_IFELSE([],
516                 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
517 AC_SUBST(CPP)dnl
518 AC_LANG_POP(C)dnl
519 ])# AC_PROG_CPP
521 # AC_PROG_CPP_WERROR
522 # ------------------
523 # Treat warnings from the preprocessor as errors.
524 AC_DEFUN([AC_PROG_CPP_WERROR],
525 [AC_REQUIRE([AC_PROG_CPP])dnl
526 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
528 # AC_LANG_COMPILER(C)
529 # -------------------
530 # Find the C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
531 AC_DEFUN([AC_LANG_COMPILER(C)],
532 [AC_REQUIRE([AC_PROG_CC])])
535 # ac_cv_prog_gcc
536 # --------------
537 # We used to name the cache variable this way.
538 AU_DEFUN([ac_cv_prog_gcc],
539 [ac_cv_c_compiler_gnu])
542 # AC_PROG_CC([COMPILER ...])
543 # --------------------------
544 # COMPILER ... is a space separated list of C compilers to search for.
545 # This just gives the user an opportunity to specify an alternative
546 # search list for the C compiler.
547 AN_MAKEVAR([CC],  [AC_PROG_CC])
548 AN_PROGRAM([cc],  [AC_PROG_CC])
549 AN_PROGRAM([gcc], [AC_PROG_CC])
550 AC_DEFUN([AC_PROG_CC],
551 [AC_LANG_PUSH(C)dnl
552 AC_ARG_VAR([CC],     [C compiler command])dnl
553 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
554 _AC_ARG_VAR_LDFLAGS()dnl
555 _AC_ARG_VAR_LIBS()dnl
556 _AC_ARG_VAR_CPPFLAGS()dnl
557 m4_ifval([$1],
558       [AC_CHECK_TOOLS(CC, [$1])],
559 [AC_CHECK_TOOL(CC, gcc)
560 if test -z "$CC"; then
561   dnl Here we want:
562   dnl   AC_CHECK_TOOL(CC, cc)
563   dnl but without the check for a tool without the prefix.
564   dnl Until the check is removed from there, copy the code:
565   if test -n "$ac_tool_prefix"; then
566     AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
567   fi
569 if test -z "$CC"; then
570   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
572 if test -z "$CC"; then
573   AC_CHECK_TOOLS(CC, cl.exe)
577 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
579 # Provide some information about the compiler.
580 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
581 set X $ac_compile
582 ac_compiler=$[2]
583 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
584 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
585 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
587 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
588 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
589 _AC_LANG_COMPILER_GNU
590 if test $ac_compiler_gnu = yes; then
591   GCC=yes
592 else
593   GCC=
595 _AC_PROG_CC_G
596 _AC_PROG_CC_C89
597 AC_LANG_POP(C)dnl
598 ])# AC_PROG_CC
601 # _AC_PROG_CC_G
602 # -------------
603 # Check whether -g works, even if CFLAGS is set, in case the package
604 # plays around with CFLAGS (such as to build both debugging and normal
605 # versions of a library), tasteless as that idea is.
606 # Don't consider -g to work if it generates warnings when plain compiles don't.
607 m4_define([_AC_PROG_CC_G],
608 [ac_test_CFLAGS=${CFLAGS+set}
609 ac_save_CFLAGS=$CFLAGS
610 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
611   [ac_save_c_werror_flag=$ac_c_werror_flag
612    ac_c_werror_flag=yes
613    ac_cv_prog_cc_g=no
614    CFLAGS="-g"
615    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
616      [ac_cv_prog_cc_g=yes],
617      [CFLAGS=""
618       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
619         [],
620         [ac_c_werror_flag=$ac_save_c_werror_flag
621          CFLAGS="-g"
622          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
623            [ac_cv_prog_cc_g=yes])])])
624    ac_c_werror_flag=$ac_save_c_werror_flag])
625 if test "$ac_test_CFLAGS" = set; then
626   CFLAGS=$ac_save_CFLAGS
627 elif test $ac_cv_prog_cc_g = yes; then
628   if test "$GCC" = yes; then
629     CFLAGS="-g -O2"
630   else
631     CFLAGS="-g"
632   fi
633 else
634   if test "$GCC" = yes; then
635     CFLAGS="-O2"
636   else
637     CFLAGS=
638   fi
639 fi[]dnl
640 ])# _AC_PROG_CC_G
643 # AC_PROG_GCC_TRADITIONAL
644 # -----------------------
645 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
646 [AC_REQUIRE([AC_PROG_CC])dnl
647 if test $ac_cv_c_compiler_gnu = yes; then
648     AC_CACHE_CHECK(whether $CC needs -traditional,
649       ac_cv_prog_gcc_traditional,
650 [  ac_pattern="Autoconf.*'x'"
651   AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
652 Autoconf TIOCGETP],
653   ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
655   if test $ac_cv_prog_gcc_traditional = no; then
656     AC_EGREP_CPP($ac_pattern, [#include <termio.h>
657 Autoconf TCGETA],
658     ac_cv_prog_gcc_traditional=yes)
659   fi])
660   if test $ac_cv_prog_gcc_traditional = yes; then
661     CC="$CC -traditional"
662   fi
664 ])# AC_PROG_GCC_TRADITIONAL
667 # AC_PROG_CC_C_O
668 # --------------
669 AC_DEFUN([AC_PROG_CC_C_O],
670 [AC_REQUIRE([AC_PROG_CC])dnl
671 if test "x$CC" != xcc; then
672   AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
673 else
674   AC_MSG_CHECKING([whether cc understands -c and -o together])
676 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
677                       sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
678 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
679 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
680 # Make sure it works both with $CC and with simple cc.
681 # We do the test twice because some compilers refuse to overwrite an
682 # existing .o file with -o, though they will create one.
683 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
684 rm -f conftest2.*
685 if _AC_DO_VAR(ac_try) &&
686    test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
687 then
688   eval ac_cv_prog_cc_${ac_cc}_c_o=yes
689   if test "x$CC" != xcc; then
690     # Test first that cc exists at all.
691     if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
692       ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
693       rm -f conftest2.*
694       if _AC_DO_VAR(ac_try) &&
695          test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
696       then
697         # cc works too.
698         :
699       else
700         # cc exists but doesn't like -o.
701         eval ac_cv_prog_cc_${ac_cc}_c_o=no
702       fi
703     fi
704   fi
705 else
706   eval ac_cv_prog_cc_${ac_cc}_c_o=no
708 rm -f core conftest*
709 ])dnl
710 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
711   AC_MSG_RESULT([yes])
712 else
713   AC_MSG_RESULT([no])
714   AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
715            [Define to 1 if your C compiler doesn't accept -c and -o together.])
717 ])# AC_PROG_CC_C_O
721 # ---------------------- #
722 # 3b. The C++ compiler.  #
723 # ---------------------- #
726 # AC_LANG_PREPROC(C++)
727 # ---------------------
728 # Find the C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
729 AC_DEFUN([AC_LANG_PREPROC(C++)],
730 [AC_REQUIRE([AC_PROG_CXXCPP])])
733 # AC_PROG_CXXCPP
734 # --------------
735 # Find a working C++ preprocessor.
736 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
737 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
738 AC_DEFUN([AC_PROG_CXXCPP],
739 [AC_REQUIRE([AC_PROG_CXX])dnl
740 AC_ARG_VAR([CXXCPP],   [C++ preprocessor])dnl
741 _AC_ARG_VAR_CPPFLAGS()dnl
742 AC_LANG_PUSH(C++)dnl
743 AC_MSG_CHECKING([how to run the C++ preprocessor])
744 if test -z "$CXXCPP"; then
745   AC_CACHE_VAL(ac_cv_prog_CXXCPP,
746   [dnl
747     # Double quotes because CXXCPP needs to be expanded
748     for CXXCPP in "$CXX -E" "/lib/cpp"
749     do
750       _AC_PROG_PREPROC_WORKS_IFELSE([break])
751     done
752     ac_cv_prog_CXXCPP=$CXXCPP
753   ])dnl
754   CXXCPP=$ac_cv_prog_CXXCPP
755 else
756   ac_cv_prog_CXXCPP=$CXXCPP
758 AC_MSG_RESULT([$CXXCPP])
759 _AC_PROG_PREPROC_WORKS_IFELSE([],
760           [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
761 AC_SUBST(CXXCPP)dnl
762 AC_LANG_POP(C++)dnl
763 ])# AC_PROG_CXXCPP
766 # AC_LANG_COMPILER(C++)
767 # ---------------------
768 # Find the C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
769 AC_DEFUN([AC_LANG_COMPILER(C++)],
770 [AC_REQUIRE([AC_PROG_CXX])])
773 # ac_cv_prog_gxx
774 # --------------
775 # We used to name the cache variable this way.
776 AU_DEFUN([ac_cv_prog_gxx],
777 [ac_cv_cxx_compiler_gnu])
780 # AC_PROG_CXX([LIST-OF-COMPILERS])
781 # --------------------------------
782 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
783 # for (if not specified, a default list is used).  This just gives the
784 # user an opportunity to specify an alternative search list for the C++
785 # compiler.
786 # aCC   HP-UX C++ compiler much better than `CC', so test before.
787 # FCC   Fujitsu C++ compiler
788 # KCC   KAI C++ compiler
789 # RCC   Rational C++
790 # xlC_r AIX C Set++ (with support for reentrant code)
791 # xlC   AIX C Set++
792 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
793 AN_PROGRAM([CC],   [AC_PROG_CXX])
794 AN_PROGRAM([c++],  [AC_PROG_CXX])
795 AN_PROGRAM([g++],  [AC_PROG_CXX])
796 AC_DEFUN([AC_PROG_CXX],
797 [AC_LANG_PUSH(C++)dnl
798 AC_ARG_VAR([CXX],      [C++ compiler command])dnl
799 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
800 _AC_ARG_VAR_LDFLAGS()dnl
801 _AC_ARG_VAR_LIBS()dnl
802 _AC_ARG_VAR_CPPFLAGS()dnl
803 _AC_ARG_VAR_PRECIOUS([CCC])dnl
804 if test -z "$CXX"; then
805   if test -n "$CCC"; then
806     CXX=$CCC
807   else
808     AC_CHECK_TOOLS(CXX,
809                    [m4_default([$1],
810                                [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
811                    g++)
812   fi
814 # Provide some information about the compiler.
815 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
816 set X $ac_compile
817 ac_compiler=$[2]
818 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
819 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
820 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
822 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
823 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
824 _AC_LANG_COMPILER_GNU
825 if test $ac_compiler_gnu = yes; then
826   GXX=yes
827 else
828   GXX=
830 _AC_PROG_CXX_G
831 AC_LANG_POP(C++)dnl
832 ])# AC_PROG_CXX
835 # _AC_PROG_CXX_G
836 # --------------
837 # Check whether -g works, even if CXXFLAGS is set, in case the package
838 # plays around with CXXFLAGS (such as to build both debugging and
839 # normal versions of a library), tasteless as that idea is.
840 # Don't consider -g to work if it generates warnings when plain compiles don't.
841 m4_define([_AC_PROG_CXX_G],
842 [ac_test_CXXFLAGS=${CXXFLAGS+set}
843 ac_save_CXXFLAGS=$CXXFLAGS
844 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
845   [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
846    ac_cxx_werror_flag=yes
847    ac_cv_prog_cxx_g=no
848    CXXFLAGS="-g"
849    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
850      [ac_cv_prog_cxx_g=yes],
851      [CXXFLAGS=""
852       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
853         [],
854         [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
855          CXXFLAGS="-g"
856          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
857            [ac_cv_prog_cxx_g=yes])])])
858    ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
859 if test "$ac_test_CXXFLAGS" = set; then
860   CXXFLAGS=$ac_save_CXXFLAGS
861 elif test $ac_cv_prog_cxx_g = yes; then
862   if test "$GXX" = yes; then
863     CXXFLAGS="-g -O2"
864   else
865     CXXFLAGS="-g"
866   fi
867 else
868   if test "$GXX" = yes; then
869     CXXFLAGS="-O2"
870   else
871     CXXFLAGS=
872   fi
873 fi[]dnl
874 ])# _AC_PROG_CXX_G
877 # AC_PROG_CXX_C_O
878 # ---------------
879 # Test if the C++ compiler accepts the options `-c' and `-o'
880 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
881 AC_DEFUN([AC_PROG_CXX_C_O],
882 [AC_REQUIRE([AC_PROG_CXX])dnl
883 AC_LANG_PUSH([C++])dnl
884 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
885                [ac_cv_prog_cxx_c_o],
886 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
887 # We test twice because some compilers refuse to overwrite an existing
888 # `.o' file with `-o', although they will create one.
889 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
890 rm -f conftest2.*
891 if _AC_DO_VAR(ac_try) &&
892      test -f conftest2.$ac_objext &&
893      _AC_DO_VAR(ac_try); then
894   ac_cv_prog_cxx_c_o=yes
895 else
896   ac_cv_prog_cxx_c_o=no
898 rm -f conftest*])
899 if test $ac_cv_prog_cxx_c_o = no; then
900   AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
901             [Define to 1 if your C++ compiler doesn't accept
902              -c and -o together.])
904 AC_LANG_POP([C++])dnl
905 ])# AC_PROG_CXX_C_O
909 # ------------------------------ #
910 # 3c. The Objective C compiler.  #
911 # ------------------------------ #
914 # AC_LANG_PREPROC(Objective C)
915 # ----------------------------
916 # Find the Objective C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
917 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
918 [AC_REQUIRE([AC_PROG_OBJCPP])])
921 # AC_PROG_OBJCPP
922 # --------------
923 # Find a working Objective C preprocessor.
924 AC_DEFUN([AC_PROG_OBJCPP],
925 [AC_REQUIRE([AC_PROG_OBJC])dnl
926 AC_ARG_VAR([OBJCPP],   [Objective C preprocessor])dnl
927 _AC_ARG_VAR_CPPFLAGS()dnl
928 AC_LANG_PUSH(Objective C)dnl
929 AC_MSG_CHECKING([how to run the Objective C preprocessor])
930 if test -z "$OBJCPP"; then
931   AC_CACHE_VAL(ac_cv_prog_OBJCPP,
932   [dnl
933     # Double quotes because OBJCPP needs to be expanded
934     for OBJCPP in "$OBJC -E" "/lib/cpp"
935     do
936       _AC_PROG_PREPROC_WORKS_IFELSE([break])
937     done
938     ac_cv_prog_OBJCPP=$OBJCPP
939   ])dnl
940   OBJCPP=$ac_cv_prog_OBJCPP
941 else
942   ac_cv_prog_OBJCPP=$OBJCPP
944 AC_MSG_RESULT([$OBJCPP])
945 _AC_PROG_PREPROC_WORKS_IFELSE([],
946           [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
947 AC_SUBST(OBJCPP)dnl
948 AC_LANG_POP(Objective C)dnl
949 ])# AC_PROG_OBJCPP
952 # AC_LANG_COMPILER(Objective C)
953 # -----------------------------
954 # Find the Objective C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
955 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
956 [AC_REQUIRE([AC_PROG_OBJC])])
960 # AC_PROG_OBJC([LIST-OF-COMPILERS])
961 # ---------------------------------
962 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
963 # search for (if not specified, a default list is used).  This just gives
964 # the user an opportunity to specify an alternative search list for the
965 # Objective C compiler.
966 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
967 # objc  David Stes' POC.  If you installed this, you likely want it.
968 # cc    Native C compiler (for instance, Apple).
969 # CC    You never know.
970 AN_MAKEVAR([OBJC],  [AC_PROG_OBJC])
971 AN_PROGRAM([objcc],  [AC_PROG_OBJC])
972 AN_PROGRAM([objc],  [AC_PROG_OBJC])
973 AC_DEFUN([AC_PROG_OBJC],
974 [AC_LANG_PUSH(Objective C)dnl
975 AC_ARG_VAR([OBJC],      [Objective C compiler command])dnl
976 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
977 _AC_ARG_VAR_LDFLAGS()dnl
978 _AC_ARG_VAR_LIBS()dnl
979 _AC_ARG_VAR_CPPFLAGS()dnl
980 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
981 AC_CHECK_TOOLS(OBJC,
982                [m4_default([$1], [gcc objcc objc cc CC])],
983                gcc)
984 # Provide some information about the compiler.
985 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
986 set X $ac_compile
987 ac_compiler=$[2]
988 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
989 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
990 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
992 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
993 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
994 _AC_LANG_COMPILER_GNU
995 if test $ac_compiler_gnu = yes; then
996   GOBJC=yes
997 else
998   GOBJC=
1000 _AC_PROG_OBJC_G
1001 AC_LANG_POP(Objective C)dnl
1002 ])# AC_PROG_OBJC
1005 # _AC_PROG_OBJC_G
1006 # ---------------
1007 # Check whether -g works, even if OBJCFLAGS is set, in case the package
1008 # plays around with OBJCFLAGS (such as to build both debugging and
1009 # normal versions of a library), tasteless as that idea is.
1010 # Don't consider -g to work if it generates warnings when plain compiles don't.
1011 m4_define([_AC_PROG_OBJC_G],
1012 [ac_test_OBJCFLAGS=${OBJCFLAGS+set}
1013 ac_save_OBJCFLAGS=$OBJCFLAGS
1014 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
1015   [ac_save_objc_werror_flag=$ac_objc_werror_flag
1016    ac_objc_werror_flag=yes
1017    ac_cv_prog_objc_g=no
1018    OBJCFLAGS="-g"
1019    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1020      [ac_cv_prog_objc_g=yes],
1021      [OBJCFLAGS=""
1022       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1023         [],
1024         [ac_objc_werror_flag=$ac_save_objc_werror_flag
1025          OBJCFLAGS="-g"
1026          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1027            [ac_cv_prog_objc_g=yes])])])
1028    ac_objc_werror_flag=$ac_save_objc_werror_flag])
1029 if test "$ac_test_OBJCFLAGS" = set; then
1030   OBJCFLAGS=$ac_save_OBJCFLAGS
1031 elif test $ac_cv_prog_objc_g = yes; then
1032   if test "$GOBJC" = yes; then
1033     OBJCFLAGS="-g -O2"
1034   else
1035     OBJCFLAGS="-g"
1036   fi
1037 else
1038   if test "$GOBJC" = yes; then
1039     OBJCFLAGS="-O2"
1040   else
1041     OBJCFLAGS=
1042   fi
1043 fi[]dnl
1044 ])# _AC_PROG_OBJC_G
1048 ## ------------------------------- ##
1049 ## 4. Compilers' characteristics.  ##
1050 ## ------------------------------- ##
1052 # -------------------------------- #
1053 # 4a. C compiler characteristics.  #
1054 # -------------------------------- #
1057 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1058 # ----------------------------------------------------------------
1059 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1060 # to add an option to output variable CC to make it so.  This macro
1061 # tries various options that select ANSI C89 on some system or
1062 # another.  It considers the compiler to be in ANSI C89 mode if it
1063 # handles function prototypes correctly.
1064 AC_DEFUN([_AC_PROG_CC_C89],
1065 [_AC_C_STD_TRY([c89],
1066 [[#include <stdarg.h>
1067 #include <stdio.h>
1068 #include <sys/types.h>
1069 #include <sys/stat.h>
1070 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
1071 struct buf { int x; };
1072 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1073 static char *e (p, i)
1074      char **p;
1075      int i;
1077   return p[i];
1079 static char *f (char * (*g) (char **, int), char **p, ...)
1081   char *s;
1082   va_list v;
1083   va_start (v,p);
1084   s = g (p, va_arg (v,int));
1085   va_end (v);
1086   return s;
1089 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
1090    function prototypes and stuff, but not '\xHH' hex character constants.
1091    These don't provoke an error unfortunately, instead are silently treated
1092    as 'x'.  The following induces an error, until -std is added to get
1093    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
1094    array size at least.  It's necessary to write '\x00'==0 to get something
1095    that's true only with -std.  */
1096 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1098 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1099    inside strings and character constants.  */
1100 #define FOO(x) 'x'
1101 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1103 int test (int i, double x);
1104 struct s1 {int (*f) (int a);};
1105 struct s2 {int (*f) (double a);};
1106 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1107 int argc;
1108 char **argv;]],
1109 [[return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];]],
1110 dnl Don't try gcc -ansi; that turns off useful extensions and
1111 dnl breaks some systems' header files.
1112 dnl AIX circa 2003      -qlanglvl=extc89
1113 dnl old AIX             -qlanglvl=ansi
1114 dnl Ultrix, OSF/1, Tru64        -std
1115 dnl HP-UX 10.20 and later       -Ae
1116 dnl HP-UX older versions        -Aa -D_HPUX_SOURCE
1117 dnl SVR4                        -Xc -D__EXTENSIONS__
1118 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1119         -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1120 ])# _AC_PROG_CC_C89
1123 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1124 #               ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1125 # --------------------------------------------------------------
1126 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1127 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
1128 # try again with each compiler option in the space-separated OPTION-LIST; if one
1129 # helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
1130 # else ACTION-IF-UNAVAILABLE.
1131 AC_DEFUN([_AC_C_STD_TRY],
1132 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
1133 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1134 [ac_cv_prog_cc_$1=no
1135 ac_save_CC=$CC
1136 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1137 for ac_arg in '' $4
1139   CC="$ac_save_CC $ac_arg"
1140   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1141   test "x$ac_cv_prog_cc_$1" != "xno" && break
1142 done
1143 rm -f conftest.$ac_ext
1144 CC=$ac_save_CC
1145 ])# AC_CACHE_VAL
1146 case "x$ac_cv_prog_cc_$1" in
1147   x)
1148     AC_MSG_RESULT([none needed]) ;;
1149   xno)
1150     AC_MSG_RESULT([unsupported]) ;;
1151   *)
1152     CC="$CC $ac_cv_prog_cc_$1"
1153     AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1154 esac
1155 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1156 ])# _AC_C_STD_TRY
1159 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1160 # ----------------------------------------------------------------
1161 # If the C compiler is not in ISO C99 mode by default, try to add an
1162 # option to output variable CC to make it so.  This macro tries
1163 # various options that select ISO C99 on some system or another.  It
1164 # considers the compiler to be in ISO C99 mode if it handles _Bool,
1165 # // comments, flexible array members, inline, long long int, mixed
1166 # code and declarations, named initialization of structs, restrict,
1167 # va_copy, varargs macros, variable declarations in for loops and
1168 # variable length arrays.
1169 AC_DEFUN([_AC_PROG_CC_C99],
1170 [_AC_C_STD_TRY([c99],
1171 [[#include <stdarg.h>
1172 #include <stdbool.h>
1173 #include <stdlib.h>
1174 #include <wchar.h>
1175 #include <stdio.h>
1177 // Check varargs macros.  These examples are taken from C99 6.10.3.5.
1178 #define debug(...) fprintf (stderr, __VA_ARGS__)
1179 #define showlist(...) puts (#__VA_ARGS__)
1180 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1181 static void
1182 test_varargs_macros (void)
1184   int x = 1234;
1185   int y = 5678;
1186   debug ("Flag");
1187   debug ("X = %d\n", x);
1188   showlist (The first, second, and third items.);
1189   report (x>y, "x is %d but y is %d", x, y);
1192 // Check long long types.
1193 #define BIG64 18446744073709551615ull
1194 #define BIG32 4294967295ul
1195 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1196 #if !BIG_OK
1197   your preprocessor is broken;
1198 #endif
1199 #if BIG_OK
1200 #else
1201   your preprocessor is broken;
1202 #endif
1203 static long long int bignum = -9223372036854775807LL;
1204 static unsigned long long int ubignum = BIG64;
1206 struct incomplete_array
1208   int datasize;
1209   double data[];
1212 struct named_init {
1213   int number;
1214   const wchar_t *name;
1215   double average;
1218 typedef const char *ccp;
1220 static inline int
1221 test_restrict (ccp restrict text)
1223   // See if C++-style comments work.
1224   // Iterate through items via the restricted pointer.
1225   // Also check for declarations in for loops.
1226   for (unsigned int i = 0; *(text+i) != '\0'; ++i)
1227     continue;
1228   return 0;
1231 // Check varargs and va_copy.
1232 static void
1233 test_varargs (const char *format, ...)
1235   va_list args;
1236   va_start (args, format);
1237   va_list args_copy;
1238   va_copy (args_copy, args);
1240   const char *str;
1241   int number;
1242   float fnumber;
1244   while (*format)
1245     {
1246       switch (*format++)
1247         {
1248         case 's': // string
1249           str = va_arg (args_copy, const char *);
1250           break;
1251         case 'd': // int
1252           number = va_arg (args_copy, int);
1253           break;
1254         case 'f': // float
1255           fnumber = va_arg (args_copy, double);
1256           break;
1257         default:
1258           break;
1259         }
1260     }
1261   va_end (args_copy);
1262   va_end (args);
1266   // Check bool.
1267   _Bool success = false;
1269   // Check restrict.
1270   if (test_restrict ("String literal") == 0)
1271     success = true;
1272   char *restrict newvar = "Another string";
1274   // Check varargs.
1275   test_varargs ("s, d' f .", "string", 65, 34.234);
1276   test_varargs_macros ();
1278   // Check flexible array members.
1279   struct incomplete_array *ia =
1280     malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1281   ia->datasize = 10;
1282   for (int i = 0; i < ia->datasize; ++i)
1283     ia->data[i] = i * 1.234;
1285   // Check named initializers.
1286   struct named_init ni = {
1287     .number = 34,
1288     .name = L"Test wide string",
1289     .average = 543.34343,
1290   };
1292   ni.number = 58;
1294   int dynamic_array[ni.number];
1295   dynamic_array[ni.number - 1] = 543;
1297   // work around unused variable warnings
1298   return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
1299           || dynamic_array[ni.number - 1] != 543);
1301 dnl Try
1302 dnl GCC         -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1303 dnl AIX         -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
1304 dnl HP cc       -AC99
1305 dnl Intel ICC   -std=c99, -c99 (deprecated)
1306 dnl IRIX        -c99
1307 dnl Solaris     -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
1308 dnl             as it incorrectly assumes C99 semantics for library functions)
1309 dnl Tru64       -c99
1310 dnl with extended modes being tried first.
1311 [[-std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
1312 ])# _AC_PROG_CC_C99
1315 # AC_PROG_CC_C89
1316 # --------------
1317 AC_DEFUN([AC_PROG_CC_C89],
1318 [ AC_REQUIRE([AC_PROG_CC])dnl
1319   _AC_PROG_CC_C89
1323 # AC_PROG_CC_C99
1324 # --------------
1325 AC_DEFUN([AC_PROG_CC_C99],
1326 [ AC_REQUIRE([AC_PROG_CC])dnl
1327   _AC_PROG_CC_C99
1331 # AC_PROG_CC_STDC
1332 # ---------------
1333 AC_DEFUN([AC_PROG_CC_STDC],
1334 [ AC_REQUIRE([AC_PROG_CC])dnl
1335   AS_CASE([$ac_cv_prog_cc_stdc],
1336     [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
1337           [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1338              [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
1339                               [ac_cv_prog_cc_stdc=no])])])dnl
1340   AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1341   AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1342   AS_CASE([$ac_cv_prog_cc_stdc],
1343     [no], [AC_MSG_RESULT([unsupported])],
1344     [''], [AC_MSG_RESULT([none needed])],
1345           [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
1349 # AC_C_BACKSLASH_A
1350 # ----------------
1351 AC_DEFUN([AC_C_BACKSLASH_A],
1353   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1354    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1355      [[
1356 #if '\a' == 'a'
1357       syntax error;
1358 #endif
1359       char buf['\a' == 'a' ? -1 : 1];
1360       buf[0] = '\a';
1361       return buf[0] != "\a"[0];
1362      ]])],
1363      [ac_cv_c_backslash_a=yes],
1364      [ac_cv_c_backslash_a=no])])
1365   if test $ac_cv_c_backslash_a = yes; then
1366     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1367       [Define if backslash-a works in C strings.])
1368   fi
1372 # AC_C_CROSS
1373 # ----------
1374 # Has been merged into AC_PROG_CC.
1375 AU_DEFUN([AC_C_CROSS], [])
1378 # AC_C_CHAR_UNSIGNED
1379 # ------------------
1380 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1381 [AH_VERBATIM([__CHAR_UNSIGNED__],
1382 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1383 #ifndef __CHAR_UNSIGNED__
1384 # undef __CHAR_UNSIGNED__
1385 #endif])dnl
1386 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1387 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1388                                              [((char) -1) < 0])],
1389                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1390 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1391   AC_DEFINE(__CHAR_UNSIGNED__)
1393 ])# AC_C_CHAR_UNSIGNED
1396 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1397 #                 [ACTION-IF-UNIVERSAL])
1398 # -------------------------------------------------------------------------
1399 AC_DEFUN([AC_C_BIGENDIAN],
1400 [AH_VERBATIM([WORDS_BIGENDIAN],
1401 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1402    significant byte first (like Motorola and SPARC, unlike Intel). */
1403 #if defined AC_APPLE_UNIVERSAL_BUILD
1404 # if defined __BIG_ENDIAN__
1405 #  define WORDS_BIGENDIAN 1
1406 # endif
1407 #else
1408 # ifndef WORDS_BIGENDIAN
1409 #  undef WORDS_BIGENDIAN
1410 # endif
1411 #endif])dnl
1412  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1413    [ac_cv_c_bigendian=unknown
1414     # See if we're dealing with a universal compiler.
1415     AC_COMPILE_IFELSE(
1416          [AC_LANG_SOURCE(
1417             [[#ifndef __APPLE_CC__
1418                not a universal capable compiler
1419              #endif
1420              typedef int dummy;
1421             ]])],
1422          [
1423         # Check for potential -arch flags.  It is not universal unless
1424         # there are some -arch flags.  Note that *ppc* also matches
1425         # ppc64.  This check is also rather less than ideal.
1426         case "${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}" in  #(
1427           *-arch*ppc*|*-arch*i386*|*-arch*x86_64*) ac_cv_c_bigendian=universal;;
1428         esac])
1429     if test $ac_cv_c_bigendian = unknown; then
1430       # See if sys/param.h defines the BYTE_ORDER macro.
1431       AC_COMPILE_IFELSE(
1432         [AC_LANG_PROGRAM(
1433            [[#include <sys/types.h>
1434              #include <sys/param.h>
1435            ]],
1436            [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1437                      && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1438                      && LITTLE_ENDIAN)
1439               bogus endian macros
1440              #endif
1441            ]])],
1442         [# It does; now see whether it defined to BIG_ENDIAN or not.
1443          AC_COMPILE_IFELSE(
1444            [AC_LANG_PROGRAM(
1445               [[#include <sys/types.h>
1446                 #include <sys/param.h>
1447               ]],
1448               [[#if BYTE_ORDER != BIG_ENDIAN
1449                  not big endian
1450                 #endif
1451               ]])],
1452            [ac_cv_c_bigendian=yes],
1453            [ac_cv_c_bigendian=no])])
1454     fi
1455     if test $ac_cv_c_bigendian = unknown; then
1456       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1457       AC_COMPILE_IFELSE(
1458         [AC_LANG_PROGRAM(
1459            [[#include <limits.h>
1460            ]],
1461            [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1462               bogus endian macros
1463              #endif
1464            ]])],
1465         [# It does; now see whether it defined to _BIG_ENDIAN or not.
1466          AC_COMPILE_IFELSE(
1467            [AC_LANG_PROGRAM(
1468               [[#include <limits.h>
1469               ]],
1470               [[#ifndef _BIG_ENDIAN
1471                  not big endian
1472                 #endif
1473               ]])],
1474            [ac_cv_c_bigendian=yes],
1475            [ac_cv_c_bigendian=no])])
1476     fi
1477     if test $ac_cv_c_bigendian = unknown; then
1478       # Compile a test program.
1479       AC_RUN_IFELSE(
1480         [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1481            [[
1482              /* Are we little or big endian?  From Harbison&Steele.  */
1483              union
1484              {
1485                long int l;
1486                char c[sizeof (long int)];
1487              } u;
1488              u.l = 1;
1489              return u.c[sizeof (long int) - 1] == 1;
1490            ]])],
1491         [ac_cv_c_bigendian=no],
1492         [ac_cv_c_bigendian=yes],
1493         [# Try to guess by grepping values from an object file.
1494          AC_COMPILE_IFELSE(
1495            [AC_LANG_PROGRAM(
1496               [[short int ascii_mm[] =
1497                   { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1498                 short int ascii_ii[] =
1499                   { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1500                 int use_ascii (int i) {
1501                   return ascii_mm[i] + ascii_ii[i];
1502                 }
1503                 short int ebcdic_ii[] =
1504                   { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1505                 short int ebcdic_mm[] =
1506                   { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1507                 int use_ebcdic (int i) {
1508                   return ebcdic_mm[i] + ebcdic_ii[i];
1509                 }
1510                 extern int foo;
1511               ]],
1512               [[return use_ascii (foo) == use_ebcdic (foo);]])],
1513            [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1514               ac_cv_c_bigendian=yes
1515             fi
1516             if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1517               if test "$ac_cv_c_bigendian" = unknown; then
1518                 ac_cv_c_bigendian=no
1519               else
1520                 # finding both strings is unlikely to happen, but who knows?
1521                 ac_cv_c_bigendian=unknown
1522               fi
1523             fi])])
1524     fi])
1525  case $ac_cv_c_bigendian in #(
1526    yes)
1527      m4_default([$1],
1528        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1529    no)
1530      $2 ;; #(
1531    universal)
1532 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
1533 dnl this is a necessity for proper config header operation.  Warn if
1534 dnl the user did not specify a config header but is relying on the
1535 dnl default behavior for universal builds.
1536      m4_default([$4],
1537        [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
1538          [AC_DIAGNOSE([obsolete],
1539            [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
1540         AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
1541           [Define if building universal (internal helper macro)])])
1542      ;; #(
1543    *)
1544      m4_default([$3],
1545        [AC_MSG_ERROR([unknown endianness
1546  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1547  esac
1548 ])# AC_C_BIGENDIAN
1551 # AC_C_INLINE
1552 # -----------
1553 # Do nothing if the compiler accepts the inline keyword.
1554 # Otherwise define inline to __inline__ or __inline if one of those work,
1555 # otherwise define inline to be empty.
1557 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1558 # inline function, only builtin types.
1560 AN_IDENTIFIER([inline], [AC_C_INLINE])
1561 AC_DEFUN([AC_C_INLINE],
1562 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1563 [ac_cv_c_inline=no
1564 for ac_kw in inline __inline__ __inline; do
1565   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1566 [#ifndef __cplusplus
1567 typedef int foo_t;
1568 static $ac_kw foo_t static_foo () {return 0; }
1569 $ac_kw foo_t foo () {return 0; }
1570 #endif
1571 ])],
1572                     [ac_cv_c_inline=$ac_kw])
1573   test "$ac_cv_c_inline" != no && break
1574 done
1576 AH_VERBATIM([inline],
1577 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1578    calls it, or to nothing if 'inline' is not supported under any name.  */
1579 #ifndef __cplusplus
1580 #undef inline
1581 #endif])
1582 case $ac_cv_c_inline in
1583   inline | yes) ;;
1584   *)
1585     case $ac_cv_c_inline in
1586       no) ac_val=;;
1587       *) ac_val=$ac_cv_c_inline;;
1588     esac
1589     cat >>confdefs.h <<_ACEOF
1590 #ifndef __cplusplus
1591 #define inline $ac_val
1592 #endif
1593 _ACEOF
1594     ;;
1595 esac
1596 ])# AC_C_INLINE
1599 # AC_C_CONST
1600 # ----------
1601 AC_DEFUN([AC_C_CONST],
1602 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1603 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1604 [[/* FIXME: Include the comments suggested by Paul. */
1605 #ifndef __cplusplus
1606   /* Ultrix mips cc rejects this.  */
1607   typedef int charset[2];
1608   const charset cs;
1609   /* SunOS 4.1.1 cc rejects this.  */
1610   char const *const *pcpcc;
1611   char **ppc;
1612   /* NEC SVR4.0.2 mips cc rejects this.  */
1613   struct point {int x, y;};
1614   static struct point const zero = {0,0};
1615   /* AIX XL C 1.02.0.0 rejects this.
1616      It does not let you subtract one const X* pointer from another in
1617      an arm of an if-expression whose if-part is not a constant
1618      expression */
1619   const char *g = "string";
1620   pcpcc = &g + (g ? g-g : 0);
1621   /* HPUX 7.0 cc rejects these. */
1622   ++pcpcc;
1623   ppc = (char**) pcpcc;
1624   pcpcc = (char const *const *) ppc;
1625   { /* SCO 3.2v4 cc rejects this.  */
1626     char *t;
1627     char const *s = 0 ? (char *) 0 : (char const *) 0;
1629     *t++ = 0;
1630     if (s) return 0;
1631   }
1632   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1633     int x[] = {25, 17};
1634     const int *foo = &x[0];
1635     ++foo;
1636   }
1637   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1638     typedef const int *iptr;
1639     iptr p = 0;
1640     ++p;
1641   }
1642   { /* AIX XL C 1.02.0.0 rejects this saying
1643        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1644     struct s { int j; const int *ap[3]; };
1645     struct s *b; b->j = 5;
1646   }
1647   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1648     const int foo = 10;
1649     if (!foo) return 0;
1650   }
1651   return !cs[0] && !zero.x;
1652 #endif
1653 ]])],
1654                    [ac_cv_c_const=yes],
1655                    [ac_cv_c_const=no])])
1656 if test $ac_cv_c_const = no; then
1657   AC_DEFINE(const,,
1658             [Define to empty if `const' does not conform to ANSI C.])
1660 ])# AC_C_CONST
1663 # AC_C_RESTRICT
1664 # -------------
1665 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1666 # http://autoconf-archive.cryp.to/acx_restrict.html
1668 # Determine whether the C/C++ compiler supports the "restrict" keyword
1669 # introduced in ANSI C99, or an equivalent.  Define "restrict" to the alternate
1670 # spelling, if any; these are more likely to work in both C and C++ compilers of
1671 # the same family, and in the presence of varying compiler options.  If only
1672 # plain "restrict" works, do nothing.  Here are some variants:
1673 # - GCC supports both __restrict and __restrict__
1674 # - older DEC Alpha C compilers support only __restrict
1675 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1676 # Otherwise, define "restrict" to be empty.
1677 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1678 AC_DEFUN([AC_C_RESTRICT],
1679 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1680   [ac_cv_c_restrict=no
1681    # The order here caters to the fact that C++ does not require restrict.
1682    for ac_kw in __restrict __restrict__ _Restrict restrict; do
1683      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1684       [[typedef int * int_ptr;
1685         int foo (int_ptr $ac_kw ip) {
1686         return ip[0];
1687        }]],
1688       [[int s[1];
1689         int * $ac_kw t = s;
1690         t[0] = 0;
1691         return foo(t)]])],
1692       [ac_cv_c_restrict=$ac_kw])
1693      test "$ac_cv_c_restrict" != no && break
1694    done
1695   ])
1696  AH_VERBATIM([restrict],
1697 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1698    nothing if this is not supported.  Do not define if restrict is
1699    supported directly.  */
1700 #undef restrict
1701 /* Work around a bug in Sun C++: it does not support _Restrict, even
1702    though the corresponding Sun C compiler does, which causes
1703    "#define restrict _Restrict" in the previous line.  Perhaps some future
1704    version of Sun C++ will work with _Restrict; if so, it'll probably
1705    define __RESTRICT, just as Sun C does.  */
1706 #if defined __SUNPRO_CC && !defined __RESTRICT
1707 # define _Restrict
1708 #endif])
1709  case $ac_cv_c_restrict in
1710    restrict) ;;
1711    no) AC_DEFINE([restrict], []) ;;
1712    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1713  esac
1714 ])# AC_C_RESTRICT
1717 # AC_C_VOLATILE
1718 # -------------
1719 # Note that, unlike const, #defining volatile to be the empty string can
1720 # actually turn a correct program into an incorrect one, since removing
1721 # uses of volatile actually grants the compiler permission to perform
1722 # optimizations that could break the user's code.  So, do not #define
1723 # volatile away unless it is really necessary to allow the user's code
1724 # to compile cleanly.  Benign compiler failures should be tolerated.
1725 AC_DEFUN([AC_C_VOLATILE],
1726 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1727 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1728 volatile int x;
1729 int * volatile y = (int *) 0;
1730 return !x && !y;])],
1731                    [ac_cv_c_volatile=yes],
1732                    [ac_cv_c_volatile=no])])
1733 if test $ac_cv_c_volatile = no; then
1734   AC_DEFINE(volatile,,
1735             [Define to empty if the keyword `volatile' does not work.
1736              Warning: valid code using `volatile' can become incorrect
1737              without.  Disable with care.])
1739 ])# AC_C_VOLATILE
1742 # AC_C_STRINGIZE
1743 # --------------
1744 # Checks if `#' can be used to glue strings together at the CPP level.
1745 # Defines HAVE_STRINGIZE if positive.
1746 AC_DEFUN([AC_C_STRINGIZE],
1747 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1748                 [ac_cv_c_stringize],
1749 [AC_EGREP_CPP([@%:@teststring],
1750               [@%:@define x(y) #y
1752 char *s = x(teststring);],
1753               [ac_cv_c_stringize=no],
1754               [ac_cv_c_stringize=yes])])
1755 if test $ac_cv_c_stringize = yes; then
1756   AC_DEFINE(HAVE_STRINGIZE, 1,
1757             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1759 ])# AC_C_STRINGIZE
1762 # AC_C_PROTOTYPES
1763 # ---------------
1764 # Check if the C compiler supports prototypes, included if it needs
1765 # options.
1766 AC_DEFUN([AC_C_PROTOTYPES],
1767 [AC_REQUIRE([AC_PROG_CC])dnl
1768 AC_MSG_CHECKING([for function prototypes])
1769 if test "$ac_cv_prog_cc_c89" != no; then
1770   AC_MSG_RESULT([yes])
1771   AC_DEFINE(PROTOTYPES, 1,
1772             [Define to 1 if the C compiler supports function prototypes.])
1773   AC_DEFINE(__PROTOTYPES, 1,
1774             [Define like PROTOTYPES; this can be used by system headers.])
1775 else
1776   AC_MSG_RESULT([no])
1778 ])# AC_C_PROTOTYPES
1781 # AC_C_FLEXIBLE_ARRAY_MEMBER
1782 # --------------------------
1783 # Check whether the C compiler supports flexible array members.
1784 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1786   AC_CACHE_CHECK([for flexible array members],
1787     ac_cv_c_flexmember,
1788     [AC_COMPILE_IFELSE(
1789        [AC_LANG_PROGRAM(
1790           [[#include <stdlib.h>
1791             #include <stdio.h>
1792             #include <stddef.h>
1793             struct s { int n; double d[]; };]],
1794           [[int m = getchar ();
1795             struct s *p = malloc (offsetof (struct s, d)
1796                                   + m * sizeof (double));
1797             p->d[0] = 0.0;
1798             return p->d != (double *) NULL;]])],
1799        [ac_cv_c_flexmember=yes],
1800        [ac_cv_c_flexmember=no])])
1801   if test $ac_cv_c_flexmember = yes; then
1802     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1803       [Define to nothing if C supports flexible array members, and to
1804        1 if it does not.  That way, with a declaration like `struct s
1805        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1806        can be used with pre-C99 compilers.
1807        When computing the size of such an object, don't use 'sizeof (struct s)'
1808        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
1809        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1810        MSVC and with C++ compilers.])
1811   else
1812     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1813   fi
1817 # AC_C_VARARRAYS
1818 # --------------
1819 # Check whether the C compiler supports variable-length arrays.
1820 AC_DEFUN([AC_C_VARARRAYS],
1822   AC_CACHE_CHECK([for variable-length arrays],
1823     ac_cv_c_vararrays,
1824     [AC_COMPILE_IFELSE(
1825        [AC_LANG_PROGRAM([],
1826           [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1827        [ac_cv_c_vararrays=yes],
1828        [ac_cv_c_vararrays=no])])
1829   if test $ac_cv_c_vararrays = yes; then
1830     AC_DEFINE([HAVE_C_VARARRAYS], 1,
1831       [Define to 1 if C supports variable-length arrays.])
1832   fi
1836 # AC_C_TYPEOF
1837 # -----------
1838 # Check if the C compiler supports GCC's typeof syntax.
1839 # The test case provokes incompatibilities in the Sun C compilers
1840 # (both Solaris 8 and Solaris 10).
1841 AC_DEFUN([AC_C_TYPEOF],
1843   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1844     [ac_cv_c_typeof=no
1845      for ac_kw in typeof __typeof__ no; do
1846        test $ac_kw = no && break
1847        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1848          [[
1849            int value;
1850            typedef struct {
1851                    char a [1
1852                            + ! (($ac_kw (value))
1853                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1854                                  ? ($ac_kw (value)) - 1
1855                                  : ~ (~ ($ac_kw (value)) 0
1856                                       << sizeof ($ac_kw (value)))))]; }
1857               ac__typeof_type_;
1858            return
1859              (! ((void) ((ac__typeof_type_ *) 0), 0));
1860          ]])],
1861          [ac_cv_c_typeof=$ac_kw])
1862        test $ac_cv_c_typeof != no && break
1863      done])
1864   if test $ac_cv_c_typeof != no; then
1865     AC_DEFINE([HAVE_TYPEOF], 1,
1866       [Define to 1 if typeof works with your compiler.])
1867     if test $ac_cv_c_typeof != typeof; then
1868       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1869         [Define to __typeof__ if your compiler spells it that way.])
1870     fi
1871   fi
1875 # _AC_LANG_OPENMP
1876 # ---------------
1877 # Expands to some language dependent source code for testing the presence of
1878 # OpenMP.
1879 AC_DEFUN([_AC_LANG_OPENMP],
1880 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
1882 # _AC_LANG_OPENMP(C)
1883 # ------------------
1884 m4_define([_AC_LANG_OPENMP(C)],
1886 #ifndef _OPENMP
1887  choke me
1888 #endif
1889 #include <omp.h>
1890 int main () { return omp_get_num_threads (); }
1893 # _AC_LANG_OPENMP(C++)
1894 # --------------------
1895 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
1897 # _AC_LANG_OPENMP(Fortran 77)
1898 # ---------------------------
1899 m4_define([_AC_LANG_OPENMP(Fortran 77)],
1900 [AC_LANG_FUNC_LINK_TRY([omp_get_num_threads])])
1902 # _AC_LANG_OPENMP(Fortran)
1903 # ---------------------------
1904 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
1906 # AC_OPENMP
1907 # ---------
1908 # Check which options need to be passed to the C compiler to support OpenMP.
1909 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
1910 # options.
1911 # The options are necessary at compile time (so the #pragmas are understood)
1912 # and at link time (so the appropriate library is linked with).
1913 # This macro takes care to not produce redundant options if $CC $CFLAGS already
1914 # supports OpenMP. It also is careful to not pass options to compilers that
1915 # misinterpret them; for example, most compilers accept "-openmp" and create
1916 # an output file called 'penmp' rather than activating OpenMP support.
1917 AC_DEFUN([AC_OPENMP],
1919   OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
1920   AC_ARG_ENABLE([openmp],
1921     [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
1922   if test "$enable_openmp" != no; then
1923     AC_CACHE_CHECK([for $CC option to support OpenMP],
1924       [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
1925       [AC_LINK_IFELSE([_AC_LANG_OPENMP],
1926          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
1927          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
1928           dnl Try these flags:
1929           dnl   GCC >= 4.2           -fopenmp
1930           dnl   SunPRO C             -xopenmp
1931           dnl   Intel C              -openmp
1932           dnl   SGI C, PGI C         -mp
1933           dnl   Tru64 Compaq C       -omp
1934           dnl   IBM C (AIX, Linux)   -qsmp=omp
1935           dnl If in this loop a compiler is passed an option that it doesn't
1936           dnl understand or that it misinterprets, the AC_LINK_IFELSE test
1937           dnl will fail (since we know that it failed without the option),
1938           dnl therefore the loop will continue searching for an option, and
1939           dnl no output file called 'penmp' or 'mp' is created.
1940           for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
1941             ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
1942             _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
1943             AC_LINK_IFELSE([_AC_LANG_OPENMP],
1944               [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
1945             _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
1946             if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
1947               break
1948             fi
1949           done])])
1950     case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
1951       "none needed" | unsupported)
1952         ;; #(
1953       *)
1954         OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
1955     esac
1956   fi
1957   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])