* doc/autoconf.texi (C Compiler): Tweak OpenMP documentation a bit.
[autoconf.git] / lib / autoconf / c.m4
blobd860189aebc6bb1596d6c911d306d10e56be44a6
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
4 # Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 # As a special exception, the Free Software Foundation gives unlimited
22 # permission to copy, distribute and modify the configure scripts that
23 # are the output of Autoconf.  You need not follow the terms of the GNU
24 # General Public License when using or distributing such scripts, even
25 # though portions of the text of Autoconf appear in them.  The GNU
26 # General Public License (GPL) does govern all other use of the material
27 # that constitutes the Autoconf program.
29 # Certain portions of the Autoconf source text are designed to be copied
30 # (in certain cases, depending on the input) into the output of
31 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
32 # source text consists of comments plus executable code that decides which
33 # of the data portions to output in any given case.  We call these
34 # comments and executable code the "non-data" portions.  Autoconf never
35 # copies any of the non-data portions into its output.
37 # This special exception to the GPL applies to versions of Autoconf
38 # released by the Free Software Foundation.  When you make and
39 # distribute a modified version of Autoconf, you may extend this special
40 # exception to the GPL to apply to your modified version as well, *unless*
41 # your modified version has the potential to copy into its output some
42 # of the text that was the non-data portion of the version that you started
43 # with.  (In other words, unless your change moves or copies text from
44 # the non-data portions to the data portions.)  If your modification has
45 # such potential, you must delete any notice of this special exception
46 # to the GPL from your modified version.
48 # Written by David MacKenzie, with help from
49 # Akim Demaille, Paul Eggert,
50 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
51 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
54 # 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 Intel ICC   -c99
1305 dnl IRIX        -c99
1306 dnl Solaris     -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
1307 dnl             as it incorrectly assumes C99 semantics for library functions)
1308 dnl Tru64       -c99
1309 dnl with extended modes being tried first.
1310 [[-std=gnu99 -c99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
1311 ])# _AC_PROG_CC_C99
1314 # AC_PROG_CC_C89
1315 # --------------
1316 AC_DEFUN([AC_PROG_CC_C89],
1317 [ AC_REQUIRE([AC_PROG_CC])dnl
1318   _AC_PROG_CC_C89
1322 # AC_PROG_CC_C99
1323 # --------------
1324 AC_DEFUN([AC_PROG_CC_C99],
1325 [ AC_REQUIRE([AC_PROG_CC])dnl
1326   _AC_PROG_CC_C99
1330 # AC_PROG_CC_STDC
1331 # ---------------
1332 AC_DEFUN([AC_PROG_CC_STDC],
1333 [ AC_REQUIRE([AC_PROG_CC])dnl
1334   AS_CASE([$ac_cv_prog_cc_stdc],
1335     [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
1336           [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1337              [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
1338                               [ac_cv_prog_cc_stdc=no])])])dnl
1339   AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1340   AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1341   AS_CASE([$ac_cv_prog_cc_stdc],
1342     [no], [AC_MSG_RESULT([unsupported])],
1343     [''], [AC_MSG_RESULT([none needed])],
1344           [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
1348 # AC_C_BACKSLASH_A
1349 # ----------------
1350 AC_DEFUN([AC_C_BACKSLASH_A],
1352   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1353    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1354      [[
1355 #if '\a' == 'a'
1356       syntax error;
1357 #endif
1358       char buf['\a' == 'a' ? -1 : 1];
1359       buf[0] = '\a';
1360       return buf[0] != "\a"[0];
1361      ]])],
1362      [ac_cv_c_backslash_a=yes],
1363      [ac_cv_c_backslash_a=no])])
1364   if test $ac_cv_c_backslash_a = yes; then
1365     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1366       [Define if backslash-a works in C strings.])
1367   fi
1371 # AC_C_CROSS
1372 # ----------
1373 # Has been merged into AC_PROG_CC.
1374 AU_DEFUN([AC_C_CROSS], [])
1377 # AC_C_CHAR_UNSIGNED
1378 # ------------------
1379 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1380 [AH_VERBATIM([__CHAR_UNSIGNED__],
1381 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1382 #ifndef __CHAR_UNSIGNED__
1383 # undef __CHAR_UNSIGNED__
1384 #endif])dnl
1385 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1386 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1387                                              [((char) -1) < 0])],
1388                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1389 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1390   AC_DEFINE(__CHAR_UNSIGNED__)
1392 ])# AC_C_CHAR_UNSIGNED
1395 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1396 #                 [ACTION-IF-UNIVERSAL])
1397 # -------------------------------------------------------------------------
1398 AC_DEFUN([AC_C_BIGENDIAN],
1399 [AH_VERBATIM([WORDS_BIGENDIAN],
1400 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1401    significant byte first (like Motorola and SPARC, unlike Intel and VAX). */
1402 #if defined __BIG_ENDIAN__
1403 # define WORDS_BIGENDIAN 1
1404 #elif ! defined __LITTLE_ENDIAN__
1405 /* #undef WORDS_BIGENDIAN */
1406 #endif])dnl
1407  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1408    [ac_cv_c_bigendian=unknown
1409     m4_ifval(m4_ifdef([AH_HEADER], 1)[$4],
1410       [# See if __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined.
1411        AC_COMPILE_IFELSE(
1412          [AC_LANG_SOURCE(
1413             [[#if ! (defined __BIG_ENDIAN__ || defined __LITTLE_ENDIAN__)
1414                neither is defined;
1415              #endif
1416              typedef int dummy;
1417             ]])],
1418          [ac_cv_c_bigendian=universal])],
1419       [AC_DIAGNOSE([obsolete], [AC_C_BIGENDIAN suggests AC_CONFIG_HEADERS])])
1420     if test $ac_cv_c_bigendian = unknown; then
1421       # See if sys/param.h defines the BYTE_ORDER macro.
1422       AC_COMPILE_IFELSE(
1423         [AC_LANG_PROGRAM(
1424            [[#include <sys/types.h>
1425              #include <sys/param.h>
1426            ]],
1427            [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1428                      && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1429                      && LITTLE_ENDIAN)
1430               bogus endian macros
1431              #endif
1432            ]])],
1433         [# It does; now see whether it defined to BIG_ENDIAN or not.
1434          AC_COMPILE_IFELSE(
1435            [AC_LANG_PROGRAM(
1436               [[#include <sys/types.h>
1437                 #include <sys/param.h>
1438               ]],
1439               [[#if BYTE_ORDER != BIG_ENDIAN
1440                  not big endian
1441                 #endif
1442               ]])],
1443            [ac_cv_c_bigendian=yes],
1444            [ac_cv_c_bigendian=no])])
1445     fi
1446     if test $ac_cv_c_bigendian = unknown; then
1447       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1448       AC_COMPILE_IFELSE(
1449         [AC_LANG_PROGRAM(
1450            [[#include <limits.h>
1451            ]],
1452            [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1453               bogus endian macros
1454              #endif
1455            ]])],
1456         [# It does; now see whether it defined to _BIG_ENDIAN or not.
1457          AC_COMPILE_IFELSE(
1458            [AC_LANG_PROGRAM(
1459               [[#include <limits.h>
1460               ]],
1461               [[#ifndef _BIG_ENDIAN
1462                  not big endian
1463                 #endif
1464               ]])],
1465            [ac_cv_c_bigendian=yes],
1466            [ac_cv_c_bigendian=no])])
1467     fi
1468     if test $ac_cv_c_bigendian = unknown; then
1469       # Compile a test program.
1470       AC_RUN_IFELSE(
1471         [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1472            [[
1473              /* Are we little or big endian?  From Harbison&Steele.  */
1474              union
1475              {
1476                long int l;
1477                char c[sizeof (long int)];
1478              } u;
1479              u.l = 1;
1480              return u.c[sizeof (long int) - 1] == 1;
1481            ]])],
1482         [ac_cv_c_bigendian=no],
1483         [ac_cv_c_bigendian=yes],
1484         [# Try to guess by grepping values from an object file.
1485          AC_COMPILE_IFELSE(
1486            [AC_LANG_PROGRAM(
1487               [[short int ascii_mm[] =
1488                   { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1489                 short int ascii_ii[] =
1490                   { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1491                 int use_ascii (int i) {
1492                   return ascii_mm[i] + ascii_ii[i];
1493                 }
1494                 short int ebcdic_ii[] =
1495                   { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1496                 short int ebcdic_mm[] =
1497                   { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1498                 int use_ebcdic (int i) {
1499                   return ebcdic_mm[i] + ebcdic_ii[i];
1500                 }
1501                 extern int foo;
1502               ]],
1503               [[return use_ascii (foo) == use_ebcdic (foo);]])],
1504            [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1505               ac_cv_c_bigendian=yes
1506             fi
1507             if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1508               if test "$ac_cv_c_bigendian" = unknown; then
1509                 ac_cv_c_bigendian=no
1510               else
1511                 # finding both strings is unlikely to happen, but who knows?
1512                 ac_cv_c_bigendian=unknown
1513               fi
1514             fi])])
1515     fi])
1516  case $ac_cv_c_bigendian in #(
1517    yes)
1518      m4_default([$1],
1519        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1520    no)
1521      $2 ;; #(
1522    universal)
1523      $4 ;; #(
1524    *)
1525      m4_default([$3],
1526        [AC_MSG_ERROR([unknown endianness
1527  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1528  esac
1529 ])# AC_C_BIGENDIAN
1532 # AC_C_INLINE
1533 # -----------
1534 # Do nothing if the compiler accepts the inline keyword.
1535 # Otherwise define inline to __inline__ or __inline if one of those work,
1536 # otherwise define inline to be empty.
1538 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1539 # inline function, only builtin types.
1541 AN_IDENTIFIER([inline], [AC_C_INLINE])
1542 AC_DEFUN([AC_C_INLINE],
1543 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1544 [ac_cv_c_inline=no
1545 for ac_kw in inline __inline__ __inline; do
1546   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1547 [#ifndef __cplusplus
1548 typedef int foo_t;
1549 static $ac_kw foo_t static_foo () {return 0; }
1550 $ac_kw foo_t foo () {return 0; }
1551 #endif
1552 ])],
1553                     [ac_cv_c_inline=$ac_kw])
1554   test "$ac_cv_c_inline" != no && break
1555 done
1557 AH_VERBATIM([inline],
1558 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1559    calls it, or to nothing if 'inline' is not supported under any name.  */
1560 #ifndef __cplusplus
1561 #undef inline
1562 #endif])
1563 case $ac_cv_c_inline in
1564   inline | yes) ;;
1565   *)
1566     case $ac_cv_c_inline in
1567       no) ac_val=;;
1568       *) ac_val=$ac_cv_c_inline;;
1569     esac
1570     cat >>confdefs.h <<_ACEOF
1571 #ifndef __cplusplus
1572 #define inline $ac_val
1573 #endif
1574 _ACEOF
1575     ;;
1576 esac
1577 ])# AC_C_INLINE
1580 # AC_C_CONST
1581 # ----------
1582 AC_DEFUN([AC_C_CONST],
1583 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1584 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1585 [[/* FIXME: Include the comments suggested by Paul. */
1586 #ifndef __cplusplus
1587   /* Ultrix mips cc rejects this.  */
1588   typedef int charset[2];
1589   const charset cs;
1590   /* SunOS 4.1.1 cc rejects this.  */
1591   char const *const *pcpcc;
1592   char **ppc;
1593   /* NEC SVR4.0.2 mips cc rejects this.  */
1594   struct point {int x, y;};
1595   static struct point const zero = {0,0};
1596   /* AIX XL C 1.02.0.0 rejects this.
1597      It does not let you subtract one const X* pointer from another in
1598      an arm of an if-expression whose if-part is not a constant
1599      expression */
1600   const char *g = "string";
1601   pcpcc = &g + (g ? g-g : 0);
1602   /* HPUX 7.0 cc rejects these. */
1603   ++pcpcc;
1604   ppc = (char**) pcpcc;
1605   pcpcc = (char const *const *) ppc;
1606   { /* SCO 3.2v4 cc rejects this.  */
1607     char *t;
1608     char const *s = 0 ? (char *) 0 : (char const *) 0;
1610     *t++ = 0;
1611     if (s) return 0;
1612   }
1613   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1614     int x[] = {25, 17};
1615     const int *foo = &x[0];
1616     ++foo;
1617   }
1618   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1619     typedef const int *iptr;
1620     iptr p = 0;
1621     ++p;
1622   }
1623   { /* AIX XL C 1.02.0.0 rejects this saying
1624        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1625     struct s { int j; const int *ap[3]; };
1626     struct s *b; b->j = 5;
1627   }
1628   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1629     const int foo = 10;
1630     if (!foo) return 0;
1631   }
1632   return !cs[0] && !zero.x;
1633 #endif
1634 ]])],
1635                    [ac_cv_c_const=yes],
1636                    [ac_cv_c_const=no])])
1637 if test $ac_cv_c_const = no; then
1638   AC_DEFINE(const,,
1639             [Define to empty if `const' does not conform to ANSI C.])
1641 ])# AC_C_CONST
1644 # AC_C_RESTRICT
1645 # -------------
1646 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1647 # http://autoconf-archive.cryp.to/acx_restrict.html
1649 # Determine whether the C/C++ compiler supports the "restrict" keyword
1650 # introduced in ANSI C99, or an equivalent.  Define "restrict" to the alternate
1651 # spelling, if any; these are more likely to work in both C and C++ compilers of
1652 # the same family, and in the presence of varying compiler options.  If only
1653 # plain "restrict" works, do nothing.  Here are some variants:
1654 # - GCC supports both __restrict and __restrict__
1655 # - older DEC Alpha C compilers support only __restrict
1656 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1657 # Otherwise, define "restrict" to be empty.
1658 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1659 AC_DEFUN([AC_C_RESTRICT],
1660 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1661   [ac_cv_c_restrict=no
1662    # Try the official restrict keyword, then gcc's __restrict, and
1663    # the less common variants.
1664    for ac_kw in __restrict __restrict__ _Restrict restrict; do
1665      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1666       [[typedef int * int_ptr;
1667         int foo (int_ptr $ac_kw ip) {
1668         return ip[0];
1669        }]],
1670       [[int s[1];
1671         int * $ac_kw t = s;
1672         t[0] = 0;
1673         return foo(t)]])],
1674       [ac_cv_c_restrict=$ac_kw])
1675      test "$ac_cv_c_restrict" != no && break
1676    done
1677   ])
1678  case $ac_cv_c_restrict in
1679    restrict) ;;
1680    no) AC_DEFINE(restrict,,
1681         [Define to equivalent of C99 restrict keyword, or to nothing if this
1682         is not supported.  Do not define if restrict is supported directly.]) ;;
1683    *)  AC_DEFINE_UNQUOTED(restrict, $ac_cv_c_restrict) ;;
1684  esac
1685 ])# AC_C_RESTRICT
1688 # AC_C_VOLATILE
1689 # -------------
1690 # Note that, unlike const, #defining volatile to be the empty string can
1691 # actually turn a correct program into an incorrect one, since removing
1692 # uses of volatile actually grants the compiler permission to perform
1693 # optimizations that could break the user's code.  So, do not #define
1694 # volatile away unless it is really necessary to allow the user's code
1695 # to compile cleanly.  Benign compiler failures should be tolerated.
1696 AC_DEFUN([AC_C_VOLATILE],
1697 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1698 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1699 volatile int x;
1700 int * volatile y = (int *) 0;
1701 return !x && !y;])],
1702                    [ac_cv_c_volatile=yes],
1703                    [ac_cv_c_volatile=no])])
1704 if test $ac_cv_c_volatile = no; then
1705   AC_DEFINE(volatile,,
1706             [Define to empty if the keyword `volatile' does not work.
1707              Warning: valid code using `volatile' can become incorrect
1708              without.  Disable with care.])
1710 ])# AC_C_VOLATILE
1713 # AC_C_STRINGIZE
1714 # --------------
1715 # Checks if `#' can be used to glue strings together at the CPP level.
1716 # Defines HAVE_STRINGIZE if positive.
1717 AC_DEFUN([AC_C_STRINGIZE],
1718 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1719                 [ac_cv_c_stringize],
1720 [AC_EGREP_CPP([@%:@teststring],
1721               [@%:@define x(y) #y
1723 char *s = x(teststring);],
1724               [ac_cv_c_stringize=no],
1725               [ac_cv_c_stringize=yes])])
1726 if test $ac_cv_c_stringize = yes; then
1727   AC_DEFINE(HAVE_STRINGIZE, 1,
1728             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1730 ])# AC_C_STRINGIZE
1733 # AC_C_PROTOTYPES
1734 # ---------------
1735 # Check if the C compiler supports prototypes, included if it needs
1736 # options.
1737 AC_DEFUN([AC_C_PROTOTYPES],
1738 [AC_REQUIRE([AC_PROG_CC])dnl
1739 AC_MSG_CHECKING([for function prototypes])
1740 if test "$ac_cv_prog_cc_c89" != no; then
1741   AC_MSG_RESULT([yes])
1742   AC_DEFINE(PROTOTYPES, 1,
1743             [Define to 1 if the C compiler supports function prototypes.])
1744   AC_DEFINE(__PROTOTYPES, 1,
1745             [Define like PROTOTYPES; this can be used by system headers.])
1746 else
1747   AC_MSG_RESULT([no])
1749 ])# AC_C_PROTOTYPES
1752 # AC_C_FLEXIBLE_ARRAY_MEMBER
1753 # --------------------------
1754 # Check whether the C compiler supports flexible array members.
1755 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1757   AC_CACHE_CHECK([for flexible array members],
1758     ac_cv_c_flexmember,
1759     [AC_COMPILE_IFELSE(
1760        [AC_LANG_PROGRAM(
1761           [[#include <stdlib.h>
1762             #include <stdio.h>
1763             #include <stddef.h>
1764             struct s { int n; double d[]; };]],
1765           [[int m = getchar ();
1766             struct s *p = malloc (offsetof (struct s, d)
1767                                   + m * sizeof (double));
1768             p->d[0] = 0.0;
1769             return p->d != (double *) NULL;]])],
1770        [ac_cv_c_flexmember=yes],
1771        [ac_cv_c_flexmember=no])])
1772   if test $ac_cv_c_flexmember = yes; then
1773     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1774       [Define to nothing if C supports flexible array members, and to
1775        1 if it does not.  That way, with a declaration like `struct s
1776        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1777        can be used with pre-C99 compilers.
1778        When computing the size of such an object, don't use 'sizeof (struct s)'
1779        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
1780        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1781        MSVC and with C++ compilers.])
1782   else
1783     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1784   fi
1788 # AC_C_VARARRAYS
1789 # --------------
1790 # Check whether the C compiler supports variable-length arrays.
1791 AC_DEFUN([AC_C_VARARRAYS],
1793   AC_CACHE_CHECK([for variable-length arrays],
1794     ac_cv_c_vararrays,
1795     [AC_COMPILE_IFELSE(
1796        [AC_LANG_PROGRAM([],
1797           [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1798        [ac_cv_c_vararrays=yes],
1799        [ac_cv_c_vararrays=no])])
1800   if test $ac_cv_c_vararrays = yes; then
1801     AC_DEFINE([HAVE_C_VARARRAYS], 1,
1802       [Define to 1 if C supports variable-length arrays.])
1803   fi
1807 # AC_C_TYPEOF
1808 # -----------
1809 # Check if the C compiler supports GCC's typeof syntax.
1810 # The test case provokes incompatibilities in the Sun C compilers
1811 # (both Solaris 8 and Solaris 10).
1812 AC_DEFUN([AC_C_TYPEOF],
1814   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1815     [ac_cv_c_typeof=no
1816      for ac_kw in typeof __typeof__ no; do
1817        test $ac_kw = no && break
1818        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1819          [[
1820            int value;
1821            typedef struct {
1822                    char a [1
1823                            + ! (($ac_kw (value))
1824                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1825                                  ? ($ac_kw (value)) - 1
1826                                  : ~ (~ ($ac_kw (value)) 0
1827                                       << sizeof ($ac_kw (value)))))]; }
1828               ac__typeof_type_;
1829            return
1830              (! ((void) ((ac__typeof_type_ *) 0), 0));
1831          ]])],
1832          [ac_cv_c_typeof=$ac_kw])
1833        test $ac_cv_c_typeof != no && break
1834      done])
1835   if test $ac_cv_c_typeof != no; then
1836     AC_DEFINE([HAVE_TYPEOF], 1,
1837       [Define to 1 if typeof works with your compiler.])
1838     if test $ac_cv_c_typeof != typeof; then
1839       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1840         [Define to __typeof__ if your compiler spells it that way.])
1841     fi
1842   fi
1846 # AC_C_OPENMP
1847 # -----------
1848 # Check which options need to be passed to the C compiler to support OpenMP.
1849 # Set the OPENMP_CFLAGS variable to these options.
1850 # The options are necessary at compile time (so the #pragmas are understood)
1851 # and at link time (so the appropriate library is linked with).
1852 # This macro takes care to not produce redundant options if $CC $CFLAGS already
1853 # supports OpenMP. It also is careful to not pass options to compilers that
1854 # misinterpret them; for example, most compilers accept "-openmp" and create
1855 # an output file called 'penmp' rather than activating OpenMP support.
1856 AC_DEFUN([AC_C_OPENMP],
1858   AC_MSG_CHECKING([whether to use OpenMP])
1859   AC_ARG_ENABLE(openmp,
1860     [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])],
1861     [],
1862     [enable_openmp=yes])
1863   AC_MSG_RESULT([$enable_openmp])
1864   OPENMP_CFLAGS=
1865   if test "$enable_openmp" = yes; then
1866     AC_MSG_CHECKING([for $CC option to support OpenMP])
1867     AC_CACHE_VAL([ac_cv_prog_cc_openmp], [
1868       ac_cv_prog_cc_openmp=unsupported
1869       AC_LINK_IFELSE([
1870 #ifndef _OPENMP
1871  choke me
1872 #endif
1873 #include <omp.h>
1874 int main () { return omp_get_num_threads (); }
1875         ], [ac_cv_prog_cc_openmp="none needed"])
1876       if test "$ac_cv_prog_cc_openmp" = unsupported; then
1877         dnl Try these flags:
1878         dnl   GCC >= 4.2           -fopenmp
1879         dnl   SunPRO C             -xopenmp
1880         dnl   Intel C              -openmp
1881         dnl   SGI C, PGI C         -mp
1882         dnl   Tru64 Compaq C       -omp
1883         dnl   IBM C (AIX, Linux)   -qsmp=omp
1884         for brand in GCC SunPRO Intel SGI/PGI Compaq IBM; do
1885           case $brand in
1886             GCC)
1887               ac_conditional='defined __GNUC__'
1888               ac_option='-fopenmp' ;;
1889             SunPRO)
1890               ac_conditional='defined __SUNPRO_C || defined __SUNPRO_CC'
1891               ac_option='-xopenmp' ;;
1892             Intel)
1893               ac_conditional='defined __INTEL_COMPILER'
1894               ac_option='-openmp' ;;
1895             SGI/PGI)
1896               ac_conditional='defined __sgi || defined __PGI || defined __PGIC__'
1897               ac_option='-mp' ;;
1898             Compaq)
1899               ac_conditional='defined __DECC || defined __DECCXX'
1900               ac_option='-omp' ;;
1901             IBM)
1902               ac_conditional='defined __xlc__ || defined __xlC__'
1903               ac_option='-qsmp=omp' ;;
1904           esac
1905           if test $brand = GCC; then
1906             if test "$GCC" = yes; then
1907               ac_openmp_result=yes
1908             else
1909               ac_openmp_result=no
1910             fi
1911           else
1912             AC_EGREP_CPP([Brand], [
1913               #if $ac_conditional
1914                Brand
1915               #endif
1916               ], [ac_openmp_result=yes], [ac_openmp_result=no])
1917           fi
1918           if test $ac_openmp_result = yes; then
1919             ac_save_CFLAGS=$CFLAGS
1920             CFLAGS="$CFLAGS $ac_option"
1921             AC_LINK_IFELSE([
1922 #ifndef _OPENMP
1923  choke me
1924 #endif
1925 #include <omp.h>
1926 int main () { return omp_get_num_threads (); }
1927               ], [ac_cv_prog_cc_openmp=$ac_option])
1928             CFLAGS=$ac_save_CFLAGS
1929             break
1930           fi
1931         done
1932       fi
1933       ])
1934     AC_MSG_RESULT([$ac_cv_prog_cc_openmp])
1935     case $ac_cv_prog_cc_openmp in
1936       "none needed" | unsupported)
1937         OPENMP_CFLAGS= ;;
1938       *)
1939         OPENMP_CFLAGS=$ac_cv_prog_cc_openmp ;;
1940     esac
1941   fi
1942   AC_SUBST([OPENMP_CFLAGS])