AC_PROG_CC_STDC: fold into AC_PROG_CC, removing C11 macro
[autoconf.git] / lib / autoconf / c.m4
blob614d9b7772b4b39b2c1516d38d57b59a779ef893
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001-2012 Free Software Foundation, Inc.
5 # This file is part of Autoconf.  This program is free
6 # software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 3 of the License, or
9 # (at your option) 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 # Under Section 7 of GPL version 3, you are granted additional
17 # permissions described in the Autoconf Configure Script Exception,
18 # version 3.0, as published by the Free Software Foundation.
20 # You should have received a copy of the GNU General Public License
21 # and a copy of the Autoconf Configure Script Exception along with
22 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
23 # respectively.  If not, see <http://www.gnu.org/licenses/>.
25 # Written by David MacKenzie, with help from
26 # Akim Demaille, Paul Eggert,
27 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
28 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
31 # Table of Contents:
33 # 1. Language selection
34 # 2. and routines to produce programs in a given language.
35 #      1a. C   2a. C
36 #      1b. C++
37 #      1c. Objective C
38 #      1d. Objective C++
40 # 3. Looking for a compiler
41 #    And possibly the associated preprocessor.
42 #      3a. C   3b. C++   3c. Objective C   3d. Objective C++
44 # 4. Compilers' characteristics.
45 #      4a. C
49 ## ----------------------- ##
50 ## 1a/2a. The C language.  ##
51 ## ----------------------- ##
54 # ------------------------ #
55 # 1a. Language selection.  #
56 # ------------------------ #
58 # AC_LANG(C)
59 # ----------
60 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
61 AC_LANG_DEFINE([C], [c], [C], [CC], [],
62 [ac_ext=c
63 ac_cpp='$CPP $CPPFLAGS'
64 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
65 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
66 ac_compiler_gnu=$ac_cv_c_compiler_gnu
70 # AC_LANG_C
71 # ---------
72 AU_DEFUN([AC_LANG_C], [AC_LANG(C)])
75 # ------------------------ #
76 # 2a. Producing programs.  #
77 # ------------------------ #
80 # AC_LANG_CONFTEST(C)(BODY)
81 # -------------------------
82 # We can't use '#line $LINENO "configure"' here, since
83 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
84 # rejects $LINENO greater than 32767, and some configure scripts
85 # are longer than 32767 lines.
86 m4_define([AC_LANG_CONFTEST(C)],
87 [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
88 /* end confdefs.h.  */
90 _ACEOF])
93 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
94 # --------------------------------------
95 m4_define([AC_LANG_PROGRAM(C)],
96 [$1
97 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
98 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
99 int
100 main ()
102 dnl Do *not* indent the following line: there may be CPP directives.
103 dnl Don't move the `;' right after for the same reason.
105   ;
106   return 0;
110 # _AC_LANG_IO_PROGRAM(C)
111 # ----------------------
112 # Produce source that performs I/O, necessary for proper
113 # cross-compiler detection.
114 m4_define([_AC_LANG_IO_PROGRAM(C)],
115 [AC_LANG_PROGRAM([@%:@include <stdio.h>],
116 [FILE *f = fopen ("conftest.out", "w");
117  return ferror (f) || fclose (f) != 0;
118 ])])
121 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
122 # -----------------------------------
123 # Avoid conflicting decl of main.
124 m4_define([AC_LANG_CALL(C)],
125 [AC_LANG_PROGRAM([$1
126 m4_if([$2], [main], ,
127 [/* Override any GCC internal prototype to avoid an error.
128    Use char because int might match the return type of a GCC
129    builtin and then its argument prototype would still apply.  */
130 #ifdef __cplusplus
131 extern "C"
132 #endif
133 char $2 ();])], [return $2 ();])])
136 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
137 # ----------------------------------
138 # Don't include <ctype.h> because on OSF/1 3.0 it includes
139 # <sys/types.h> which includes <sys/select.h> which contains a
140 # prototype for select.  Similarly for bzero.
142 # This test used to merely assign f=$1 in main(), but that was
143 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
144 # presumably on the basis that there's no need to do that store if the
145 # program is about to exit.  Conversely, the AIX linker optimizes an
146 # unused external declaration that initializes f=$1.  So this test
147 # program has both an external initialization of f, and a use of f in
148 # main that affects the exit status.
150 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
151 [AC_LANG_PROGRAM(
152 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
153    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
154 #define $1 innocuous_$1
156 /* System header to define __stub macros and hopefully few prototypes,
157    which can conflict with char $1 (); below.  */
159 #include <limits.h>
160 #undef $1
162 /* Override any GCC internal prototype to avoid an error.
163    Use char because int might match the return type of a GCC
164    builtin and then its argument prototype would still apply.  */
165 #ifdef __cplusplus
166 extern "C"
167 #endif
168 char $1 ();
169 /* The GNU C library defines this for functions which it implements
170     to always fail with ENOSYS.  Some functions are actually named
171     something starting with __ and the normal name is an alias.  */
172 #if defined __stub_$1 || defined __stub___$1
173 choke me
174 #endif
175 ], [return $1 ();])])
178 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
179 # -------------------------------------------------
180 # Return a program that is valid if EXPRESSION is nonzero.
181 # EXPRESSION must be an integer constant expression.
182 # Be sure to use this array to avoid `unused' warnings, which are even
183 # errors with `-W error'.
184 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
185 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
186 test_array @<:@0@:>@ = 0;
187 return test_array @<:@0@:>@;
188 ])])
191 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
192 # -----------------------------------------
193 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
194 # But we include them only after the EXPRESSION has been evaluated.
195 m4_define([AC_LANG_INT_SAVE(C)],
196 [AC_LANG_PROGRAM([$1
197 static long int longval () { return $2; }
198 static unsigned long int ulongval () { return $2; }
199 @%:@include <stdio.h>
200 @%:@include <stdlib.h>],
202   FILE *f = fopen ("conftest.val", "w");
203   if (! f)
204     return 1;
205   if (($2) < 0)
206     {
207       long int i = longval ();
208       if (i != ($2))
209         return 1;
210       fprintf (f, "%ld", i);
211     }
212   else
213     {
214       unsigned long int i = ulongval ();
215       if (i != ($2))
216         return 1;
217       fprintf (f, "%lu", i);
218     }
219   /* Do not output a trailing newline, as this causes \r\n confusion
220      on some platforms.  */
221   return ferror (f) || fclose (f) != 0;
222 ])])
226 ## ---------------------- ##
227 ## 1b. The C++ language.  ##
228 ## ---------------------- ##
231 # AC_LANG(C++)
232 # ------------
233 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
234 AC_LANG_DEFINE([C++], [cxx], [CXX], [CXX], [C],
235 [ac_ext=cpp
236 ac_cpp='$CXXCPP $CPPFLAGS'
237 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
238 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
239 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
243 # AC_LANG_CPLUSPLUS
244 # -----------------
245 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
249 ## ------------------------------ ##
250 ## 1c. The Objective C language.  ##
251 ## ------------------------------ ##
254 # AC_LANG(Objective C)
255 # --------------------
256 AC_LANG_DEFINE([Objective C], [objc], [OBJC], [OBJC], [C],
257 [ac_ext=m
258 ac_cpp='$OBJCPP $CPPFLAGS'
259 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
260 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
261 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
265 # AC_LANG_OBJC
266 # ------------
267 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
271 ## -------------------------------- ##
272 ## 1d. The Objective C++ language.  ##
273 ## -------------------------------- ##
276 # AC_LANG(Objective C++)
277 # ----------------------
278 AC_LANG_DEFINE([Objective C++], [objcxx], [OBJCXX], [OBJCXX], [C++],
279 [ac_ext=mm
280 ac_cpp='$OBJCXXCPP $CPPFLAGS'
281 ac_compile='$OBJCXX -c $OBJCXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
282 ac_link='$OBJCXX -o conftest$ac_exeext $OBJCXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
283 ac_compiler_gnu=$ac_cv_objcxx_compiler_gnu
288 ## -------------------------------------------- ##
289 ## 3. Looking for Compilers and Preprocessors.  ##
290 ## -------------------------------------------- ##
292 # -------------------- #
293 # 3a. The C compiler.  #
294 # -------------------- #
297 # _AC_ARG_VAR_CPPFLAGS
298 # --------------------
299 # Document and register CPPFLAGS, which is used by
300 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP, OBJCXX, OBJCXXCPP}.
301 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
302 [AC_ARG_VAR([CPPFLAGS],
303             [(Objective) C/C++ preprocessor flags, e.g. -I<include dir>
304              if you have headers in a nonstandard directory <include dir>])])
307 # _AC_ARG_VAR_LDFLAGS
308 # -------------------
309 # Document and register LDFLAGS, which is used by
310 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
311 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
312 [AC_ARG_VAR([LDFLAGS],
313             [linker flags, e.g. -L<lib dir> if you have libraries in a
314              nonstandard directory <lib dir>])])
317 # _AC_ARG_VAR_LIBS
318 # ----------------
319 # Document and register LIBS, which is used by
320 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
321 AC_DEFUN([_AC_ARG_VAR_LIBS],
322 [AC_ARG_VAR([LIBS],
323             [libraries to pass to the linker, e.g. -l<library>])])
326 # AC_LANG_PREPROC(C)
327 # ------------------
328 # Find the C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
329 AC_DEFUN([AC_LANG_PREPROC(C)],
330 [AC_REQUIRE([AC_PROG_CPP])])
333 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
334 # -----------------------------------------------
335 # Check if $ac_cpp is a working preprocessor that can flag absent
336 # includes either by the exit status or by warnings.
337 # This macro is for all languages, not only C.
338 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
339 [ac_preproc_ok=false
340 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
342   # Use a header file that comes with gcc, so configuring glibc
343   # with a fresh cross-compiler works.
344   # On the NeXT, cc -E runs the code through the compiler's parser,
345   # not just through cpp. "Syntax error" is here to catch this case.
346   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <limits.h>
347                      Syntax error]])],
348                      [],
349                      [# Broken: fails on valid input.
350 continue])
352   # OK, works on sane cases.  Now check whether nonexistent headers
353   # can be detected and how.
354   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
355                      [# Broken: success on invalid input.
356 continue],
357                      [# Passes both tests.
358 ac_preproc_ok=:
359 break])
361 done
362 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
363 rm -f conftest.i conftest.err conftest.$ac_ext
364 AS_IF([$ac_preproc_ok], [$1], [$2])
365 ])# _AC_PROG_PREPROC_WORKS_IFELSE
368 # AC_PROG_CPP
369 # -----------
370 # Find a working C preprocessor.
371 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
372 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
373 AN_MAKEVAR([CPP], [AC_PROG_CPP])
374 AN_PROGRAM([cpp], [AC_PROG_CPP])
375 AC_DEFUN([AC_PROG_CPP],
376 [AC_REQUIRE([AC_PROG_CC])dnl
377 AC_ARG_VAR([CPP],      [C preprocessor])dnl
378 _AC_ARG_VAR_CPPFLAGS()dnl
379 AC_LANG_PUSH(C)dnl
380 AC_MSG_CHECKING([how to run the C preprocessor])
381 # On Suns, sometimes $CPP names a directory.
382 if test -n "$CPP" && test -d "$CPP"; then
383   CPP=
385 if test -z "$CPP"; then
386   AC_CACHE_VAL([ac_cv_prog_CPP],
387   [dnl
388     # Double quotes because CPP needs to be expanded
389     for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
390     do
391       _AC_PROG_PREPROC_WORKS_IFELSE([break])
392     done
393     ac_cv_prog_CPP=$CPP
394   ])dnl
395   CPP=$ac_cv_prog_CPP
396 else
397   ac_cv_prog_CPP=$CPP
399 AC_MSG_RESULT([$CPP])
400 _AC_PROG_PREPROC_WORKS_IFELSE([],
401                 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
402 AC_SUBST(CPP)dnl
403 AC_LANG_POP(C)dnl
404 ])# AC_PROG_CPP
406 # AC_PROG_CPP_WERROR
407 # ------------------
408 # Treat warnings from the preprocessor as errors.
409 AC_DEFUN([AC_PROG_CPP_WERROR],
410 [AC_REQUIRE([AC_PROG_CPP])dnl
411 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
413 # AC_LANG_COMPILER(C)
414 # -------------------
415 # Find the C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
416 AC_DEFUN([AC_LANG_COMPILER(C)],
417 [AC_REQUIRE([AC_PROG_CC])])
420 # ac_cv_prog_gcc
421 # --------------
422 # We used to name the cache variable this way.
423 AU_DEFUN([ac_cv_prog_gcc],
424 [ac_cv_c_compiler_gnu])
427 # AC_PROG_CC([COMPILER ...])
428 # --------------------------
429 # COMPILER ... is a space separated list of C compilers to search for.
430 # This just gives the user an opportunity to specify an alternative
431 # search list for the C compiler.
432 AN_MAKEVAR([CC],  [AC_PROG_CC])
433 AN_PROGRAM([cc],  [AC_PROG_CC])
434 AN_PROGRAM([gcc], [AC_PROG_CC])
435 AC_DEFUN([AC_PROG_CC],
436 [AC_LANG_PUSH(C)dnl
437 AC_ARG_VAR([CC],     [C compiler command])dnl
438 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
439 _AC_ARG_VAR_LDFLAGS()dnl
440 _AC_ARG_VAR_LIBS()dnl
441 _AC_ARG_VAR_CPPFLAGS()dnl
442 m4_ifval([$1],
443       [AC_CHECK_TOOLS(CC, [$1])],
444 [AC_CHECK_TOOL(CC, gcc)
445 if test -z "$CC"; then
446   dnl Here we want:
447   dnl   AC_CHECK_TOOL(CC, cc)
448   dnl but without the check for a tool without the prefix.
449   dnl Until the check is removed from there, copy the code:
450   if test -n "$ac_tool_prefix"; then
451     AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
452   fi
454 if test -z "$CC"; then
455   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
457 if test -z "$CC"; then
458   AC_CHECK_TOOLS(CC, cl.exe)
462 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
464 # Provide some information about the compiler.
465 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
466 set X $ac_compile
467 ac_compiler=$[2]
468 for ac_option in --version -v -V -qversion; do
469   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
470 done
472 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
473 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
474 _AC_LANG_COMPILER_GNU
475 if test $ac_compiler_gnu = yes; then
476   GCC=yes
477 else
478   GCC=
480 _AC_PROG_CC_G
482 dnl Set ac_prog_cc_stdc to the supported C version.
483 dnl Also set the documented variable ac_cv_prog_cc_stdc;
484 dnl its name was chosen when it was cached, but it is no longer cached.
485 _AC_PROG_CC_C11([ac_prog_cc_stdc=c11
486                  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11],
487   [_AC_PROG_CC_C99([ac_prog_cc_stdc=c99
488                     ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
489      [_AC_PROG_CC_C89([ac_prog_cc_stdc=c89
490                        ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
491                       [ac_prog_cc_stdc=no
492                        ac_cv_prog_cc_stdc=no])])])
494 AC_LANG_POP(C)dnl
495 ])# AC_PROG_CC
498 # _AC_PROG_CC_G
499 # -------------
500 # Check whether -g works, even if CFLAGS is set, in case the package
501 # plays around with CFLAGS (such as to build both debugging and normal
502 # versions of a library), tasteless as that idea is.
503 # Don't consider -g to work if it generates warnings when plain compiles don't.
504 m4_define([_AC_PROG_CC_G],
505 [ac_test_CFLAGS=${CFLAGS+set}
506 ac_save_CFLAGS=$CFLAGS
507 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
508   [ac_save_c_werror_flag=$ac_c_werror_flag
509    ac_c_werror_flag=yes
510    ac_cv_prog_cc_g=no
511    CFLAGS="-g"
512    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
513      [ac_cv_prog_cc_g=yes],
514      [CFLAGS=""
515       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
516         [],
517         [ac_c_werror_flag=$ac_save_c_werror_flag
518          CFLAGS="-g"
519          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
520            [ac_cv_prog_cc_g=yes])])])
521    ac_c_werror_flag=$ac_save_c_werror_flag])
522 if test "$ac_test_CFLAGS" = set; then
523   CFLAGS=$ac_save_CFLAGS
524 elif test $ac_cv_prog_cc_g = yes; then
525   if test "$GCC" = yes; then
526     CFLAGS="-g -O2"
527   else
528     CFLAGS="-g"
529   fi
530 else
531   if test "$GCC" = yes; then
532     CFLAGS="-O2"
533   else
534     CFLAGS=
535   fi
536 fi[]dnl
537 ])# _AC_PROG_CC_G
540 # AC_PROG_GCC_TRADITIONAL
541 # -----------------------
542 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
543 [AC_REQUIRE([AC_PROG_CC])dnl
544 if test $ac_cv_c_compiler_gnu = yes; then
545     AC_CACHE_CHECK(whether $CC needs -traditional,
546       ac_cv_prog_gcc_traditional,
547 [  ac_pattern="Autoconf.*'x'"
548   AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
549 Autoconf TIOCGETP],
550   ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
552   if test $ac_cv_prog_gcc_traditional = no; then
553     AC_EGREP_CPP($ac_pattern, [#include <termio.h>
554 Autoconf TCGETA],
555     ac_cv_prog_gcc_traditional=yes)
556   fi])
557   if test $ac_cv_prog_gcc_traditional = yes; then
558     CC="$CC -traditional"
559   fi
561 ])# AC_PROG_GCC_TRADITIONAL
564 # AC_PROG_CC_C_O
565 # --------------
566 AC_DEFUN([AC_PROG_CC_C_O],
567 [AC_REQUIRE([AC_PROG_CC])dnl
568 if test "x$CC" != xcc; then
569   AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
570 else
571   AC_MSG_CHECKING([whether cc understands -c and -o together])
573 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
574                       sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
575 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
576 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
577 # Make sure it works both with $CC and with simple cc.
578 # We do the test twice because some compilers refuse to overwrite an
579 # existing .o file with -o, though they will create one.
580 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
581 rm -f conftest2.*
582 if _AC_DO_VAR(ac_try) &&
583    test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
584 then
585   eval ac_cv_prog_cc_${ac_cc}_c_o=yes
586   if test "x$CC" != xcc; then
587     # Test first that cc exists at all.
588     if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
589       ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
590       rm -f conftest2.*
591       if _AC_DO_VAR(ac_try) &&
592          test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
593       then
594         # cc works too.
595         :
596       else
597         # cc exists but doesn't like -o.
598         eval ac_cv_prog_cc_${ac_cc}_c_o=no
599       fi
600     fi
601   fi
602 else
603   eval ac_cv_prog_cc_${ac_cc}_c_o=no
605 rm -f core conftest*
606 ])dnl
607 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
608   AC_MSG_RESULT([yes])
609 else
610   AC_MSG_RESULT([no])
611   AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
612            [Define to 1 if your C compiler doesn't accept -c and -o together.])
614 ])# AC_PROG_CC_C_O
618 # ---------------------- #
619 # 3b. The C++ compiler.  #
620 # ---------------------- #
623 # AC_LANG_PREPROC(C++)
624 # --------------------
625 # Find the C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
626 AC_DEFUN([AC_LANG_PREPROC(C++)],
627 [AC_REQUIRE([AC_PROG_CXXCPP])])
630 # AC_PROG_CXXCPP
631 # --------------
632 # Find a working C++ preprocessor.
633 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
634 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
635 AC_DEFUN([AC_PROG_CXXCPP],
636 [AC_REQUIRE([AC_PROG_CXX])dnl
637 AC_ARG_VAR([CXXCPP],   [C++ preprocessor])dnl
638 _AC_ARG_VAR_CPPFLAGS()dnl
639 AC_LANG_PUSH(C++)dnl
640 AC_MSG_CHECKING([how to run the C++ preprocessor])
641 if test -z "$CXXCPP"; then
642   AC_CACHE_VAL(ac_cv_prog_CXXCPP,
643   [dnl
644     # Double quotes because CXXCPP needs to be expanded
645     for CXXCPP in "$CXX -E" "/lib/cpp"
646     do
647       _AC_PROG_PREPROC_WORKS_IFELSE([break])
648     done
649     ac_cv_prog_CXXCPP=$CXXCPP
650   ])dnl
651   CXXCPP=$ac_cv_prog_CXXCPP
652 else
653   ac_cv_prog_CXXCPP=$CXXCPP
655 AC_MSG_RESULT([$CXXCPP])
656 _AC_PROG_PREPROC_WORKS_IFELSE([],
657           [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
658 AC_SUBST(CXXCPP)dnl
659 AC_LANG_POP(C++)dnl
660 ])# AC_PROG_CXXCPP
663 # AC_LANG_COMPILER(C++)
664 # ---------------------
665 # Find the C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
666 AC_DEFUN([AC_LANG_COMPILER(C++)],
667 [AC_REQUIRE([AC_PROG_CXX])])
670 # ac_cv_prog_gxx
671 # --------------
672 # We used to name the cache variable this way.
673 AU_DEFUN([ac_cv_prog_gxx],
674 [ac_cv_cxx_compiler_gnu])
677 # AC_PROG_CXX([LIST-OF-COMPILERS])
678 # --------------------------------
679 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
680 # for (if not specified, a default list is used).  This just gives the
681 # user an opportunity to specify an alternative search list for the C++
682 # compiler.
683 # aCC   HP-UX C++ compiler much better than `CC', so test before.
684 # FCC   Fujitsu C++ compiler
685 # KCC   KAI C++ compiler
686 # RCC   Rational C++
687 # xlC_r AIX C Set++ (with support for reentrant code)
688 # xlC   AIX C Set++
689 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
690 AN_PROGRAM([CC],   [AC_PROG_CXX])
691 AN_PROGRAM([c++],  [AC_PROG_CXX])
692 AN_PROGRAM([g++],  [AC_PROG_CXX])
693 AC_DEFUN([AC_PROG_CXX],
694 [AC_LANG_PUSH(C++)dnl
695 AC_ARG_VAR([CXX],      [C++ compiler command])dnl
696 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
697 _AC_ARG_VAR_LDFLAGS()dnl
698 _AC_ARG_VAR_LIBS()dnl
699 _AC_ARG_VAR_CPPFLAGS()dnl
700 _AC_ARG_VAR_PRECIOUS([CCC])dnl
701 if test -z "$CXX"; then
702   if test -n "$CCC"; then
703     CXX=$CCC
704   else
705     AC_CHECK_TOOLS(CXX,
706                    [m4_default([$1],
707                                [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
708                    g++)
709   fi
711 # Provide some information about the compiler.
712 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
713 set X $ac_compile
714 ac_compiler=$[2]
715 for ac_option in --version -v -V -qversion; do
716   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
717 done
719 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
720 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
721 _AC_LANG_COMPILER_GNU
722 if test $ac_compiler_gnu = yes; then
723   GXX=yes
724 else
725   GXX=
727 _AC_PROG_CXX_G
728 AC_LANG_POP(C++)dnl
729 ])# AC_PROG_CXX
732 # _AC_PROG_CXX_G
733 # --------------
734 # Check whether -g works, even if CXXFLAGS is set, in case the package
735 # plays around with CXXFLAGS (such as to build both debugging and
736 # normal versions of a library), tasteless as that idea is.
737 # Don't consider -g to work if it generates warnings when plain compiles don't.
738 m4_define([_AC_PROG_CXX_G],
739 [ac_test_CXXFLAGS=${CXXFLAGS+set}
740 ac_save_CXXFLAGS=$CXXFLAGS
741 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
742   [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
743    ac_cxx_werror_flag=yes
744    ac_cv_prog_cxx_g=no
745    CXXFLAGS="-g"
746    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
747      [ac_cv_prog_cxx_g=yes],
748      [CXXFLAGS=""
749       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
750         [],
751         [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
752          CXXFLAGS="-g"
753          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
754            [ac_cv_prog_cxx_g=yes])])])
755    ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
756 if test "$ac_test_CXXFLAGS" = set; then
757   CXXFLAGS=$ac_save_CXXFLAGS
758 elif test $ac_cv_prog_cxx_g = yes; then
759   if test "$GXX" = yes; then
760     CXXFLAGS="-g -O2"
761   else
762     CXXFLAGS="-g"
763   fi
764 else
765   if test "$GXX" = yes; then
766     CXXFLAGS="-O2"
767   else
768     CXXFLAGS=
769   fi
770 fi[]dnl
771 ])# _AC_PROG_CXX_G
774 # AC_PROG_CXX_C_O
775 # ---------------
776 # Test if the C++ compiler accepts the options `-c' and `-o'
777 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
778 AC_DEFUN([AC_PROG_CXX_C_O],
779 [AC_REQUIRE([AC_PROG_CXX])dnl
780 AC_LANG_PUSH([C++])dnl
781 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
782                [ac_cv_prog_cxx_c_o],
783 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
784 # We test twice because some compilers refuse to overwrite an existing
785 # `.o' file with `-o', although they will create one.
786 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
787 rm -f conftest2.*
788 if _AC_DO_VAR(ac_try) &&
789      test -f conftest2.$ac_objext &&
790      _AC_DO_VAR(ac_try); then
791   ac_cv_prog_cxx_c_o=yes
792 else
793   ac_cv_prog_cxx_c_o=no
795 rm -f conftest*])
796 if test $ac_cv_prog_cxx_c_o = no; then
797   AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
798             [Define to 1 if your C++ compiler doesn't accept
799              -c and -o together.])
801 AC_LANG_POP([C++])dnl
802 ])# AC_PROG_CXX_C_O
806 # ------------------------------ #
807 # 3c. The Objective C compiler.  #
808 # ------------------------------ #
811 # AC_LANG_PREPROC(Objective C)
812 # ----------------------------
813 # Find the Objective C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
814 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
815 [AC_REQUIRE([AC_PROG_OBJCPP])])
818 # AC_PROG_OBJCPP
819 # --------------
820 # Find a working Objective C preprocessor.
821 AC_DEFUN([AC_PROG_OBJCPP],
822 [AC_REQUIRE([AC_PROG_OBJC])dnl
823 AC_ARG_VAR([OBJCPP],   [Objective C preprocessor])dnl
824 _AC_ARG_VAR_CPPFLAGS()dnl
825 AC_LANG_PUSH(Objective C)dnl
826 AC_MSG_CHECKING([how to run the Objective C preprocessor])
827 if test -z "$OBJCPP"; then
828   AC_CACHE_VAL(ac_cv_prog_OBJCPP,
829   [dnl
830     # Double quotes because OBJCPP needs to be expanded
831     for OBJCPP in "$OBJC -E" "/lib/cpp"
832     do
833       _AC_PROG_PREPROC_WORKS_IFELSE([break])
834     done
835     ac_cv_prog_OBJCPP=$OBJCPP
836   ])dnl
837   OBJCPP=$ac_cv_prog_OBJCPP
838 else
839   ac_cv_prog_OBJCPP=$OBJCPP
841 AC_MSG_RESULT([$OBJCPP])
842 _AC_PROG_PREPROC_WORKS_IFELSE([],
843           [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
844 AC_SUBST(OBJCPP)dnl
845 AC_LANG_POP(Objective C)dnl
846 ])# AC_PROG_OBJCPP
849 # AC_LANG_COMPILER(Objective C)
850 # -----------------------------
851 # Find the Objective C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
852 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
853 [AC_REQUIRE([AC_PROG_OBJC])])
857 # AC_PROG_OBJC([LIST-OF-COMPILERS])
858 # ---------------------------------
859 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
860 # search for (if not specified, a default list is used).  This just gives
861 # the user an opportunity to specify an alternative search list for the
862 # Objective C compiler.
863 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
864 # objc  David Stes' POC.  If you installed this, you likely want it.
865 # cc    Native C compiler (for instance, Apple).
866 # CC    You never know.
867 AN_MAKEVAR([OBJC],  [AC_PROG_OBJC])
868 AN_PROGRAM([objcc],  [AC_PROG_OBJC])
869 AN_PROGRAM([objc],  [AC_PROG_OBJC])
870 AC_DEFUN([AC_PROG_OBJC],
871 [AC_LANG_PUSH(Objective C)dnl
872 AC_ARG_VAR([OBJC],      [Objective C compiler command])dnl
873 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
874 _AC_ARG_VAR_LDFLAGS()dnl
875 _AC_ARG_VAR_LIBS()dnl
876 _AC_ARG_VAR_CPPFLAGS()dnl
877 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
878 AC_CHECK_TOOLS(OBJC,
879                [m4_default([$1], [gcc objcc objc cc CC])],
880                gcc)
881 # Provide some information about the compiler.
882 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
883 set X $ac_compile
884 ac_compiler=$[2]
885 for ac_option in --version -v -V -qversion; do
886   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
887 done
889 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
890 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
891 _AC_LANG_COMPILER_GNU
892 if test $ac_compiler_gnu = yes; then
893   GOBJC=yes
894 else
895   GOBJC=
897 _AC_PROG_OBJC_G
898 AC_LANG_POP(Objective C)dnl
899 ])# AC_PROG_OBJC
902 # _AC_PROG_OBJC_G
903 # ---------------
904 # Check whether -g works, even if OBJCFLAGS is set, in case the package
905 # plays around with OBJCFLAGS (such as to build both debugging and
906 # normal versions of a library), tasteless as that idea is.
907 # Don't consider -g to work if it generates warnings when plain compiles don't.
908 m4_define([_AC_PROG_OBJC_G],
909 [ac_test_OBJCFLAGS=${OBJCFLAGS+set}
910 ac_save_OBJCFLAGS=$OBJCFLAGS
911 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
912   [ac_save_objc_werror_flag=$ac_objc_werror_flag
913    ac_objc_werror_flag=yes
914    ac_cv_prog_objc_g=no
915    OBJCFLAGS="-g"
916    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
917      [ac_cv_prog_objc_g=yes],
918      [OBJCFLAGS=""
919       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
920         [],
921         [ac_objc_werror_flag=$ac_save_objc_werror_flag
922          OBJCFLAGS="-g"
923          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
924            [ac_cv_prog_objc_g=yes])])])
925    ac_objc_werror_flag=$ac_save_objc_werror_flag])
926 if test "$ac_test_OBJCFLAGS" = set; then
927   OBJCFLAGS=$ac_save_OBJCFLAGS
928 elif test $ac_cv_prog_objc_g = yes; then
929   if test "$GOBJC" = yes; then
930     OBJCFLAGS="-g -O2"
931   else
932     OBJCFLAGS="-g"
933   fi
934 else
935   if test "$GOBJC" = yes; then
936     OBJCFLAGS="-O2"
937   else
938     OBJCFLAGS=
939   fi
940 fi[]dnl
941 ])# _AC_PROG_OBJC_G
945 # -------------------------------- #
946 # 3d. The Objective C++ compiler.  #
947 # -------------------------------- #
950 # AC_LANG_PREPROC(Objective C++)
951 # ------------------------------
952 # Find the Objective C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
953 AC_DEFUN([AC_LANG_PREPROC(Objective C++)],
954 [AC_REQUIRE([AC_PROG_OBJCXXCPP])])
957 # AC_PROG_OBJCXXCPP
958 # -----------------
959 # Find a working Objective C++ preprocessor.
960 AC_DEFUN([AC_PROG_OBJCXXCPP],
961 [AC_REQUIRE([AC_PROG_OBJCXX])dnl
962 AC_ARG_VAR([OBJCXXCPP],   [Objective C++ preprocessor])dnl
963 _AC_ARG_VAR_CPPFLAGS()dnl
964 AC_LANG_PUSH(Objective C++)dnl
965 AC_MSG_CHECKING([how to run the Objective C++ preprocessor])
966 if test -z "$OBJCXXCPP"; then
967   AC_CACHE_VAL(ac_cv_prog_OBJCXXCPP,
968   [dnl
969     # Double quotes because OBJCXXCPP needs to be expanded
970     for OBJCXXCPP in "$OBJCXX -E" "/lib/cpp"
971     do
972       _AC_PROG_PREPROC_WORKS_IFELSE([break])
973     done
974     ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
975   ])dnl
976   OBJCXXCPP=$ac_cv_prog_OBJCXXCPP
977 else
978   ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
980 AC_MSG_RESULT([$OBJCXXCPP])
981 _AC_PROG_PREPROC_WORKS_IFELSE([],
982           [AC_MSG_FAILURE([Objective C++ preprocessor "$OBJCXXCPP" fails sanity check])])
983 AC_SUBST(OBJCXXCPP)dnl
984 AC_LANG_POP(Objective C++)dnl
985 ])# AC_PROG_OBJCXXCPP
988 # AC_LANG_COMPILER(Objective C++)
989 # -------------------------------
990 # Find the Objective C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
991 AC_DEFUN([AC_LANG_COMPILER(Objective C++)],
992 [AC_REQUIRE([AC_PROG_OBJCXX])])
996 # AC_PROG_OBJCXX([LIST-OF-COMPILERS])
997 # -----------------------------------
998 # LIST-OF-COMPILERS is a space separated list of Objective C++ compilers to
999 # search for (if not specified, a default list is used).  This just gives
1000 # the user an opportunity to specify an alternative search list for the
1001 # Objective C++ compiler.
1002 # FIXME: this list is pure guesswork
1003 # objc++ StepStone Objective-C++ compiler (also "standard" name for OBJCXX)
1004 # objcxx David Stes' POC.  If you installed this, you likely want it.
1005 # c++    Native C++ compiler (for instance, Apple).
1006 # CXX    You never know.
1007 AN_MAKEVAR([OBJCXX],  [AC_PROG_OBJCXX])
1008 AN_PROGRAM([objcxx],  [AC_PROG_OBJCXX])
1009 AC_DEFUN([AC_PROG_OBJCXX],
1010 [AC_LANG_PUSH(Objective C++)dnl
1011 AC_ARG_VAR([OBJCXX],      [Objective C++ compiler command])dnl
1012 AC_ARG_VAR([OBJCXXFLAGS], [Objective C++ compiler flags])dnl
1013 _AC_ARG_VAR_LDFLAGS()dnl
1014 _AC_ARG_VAR_LIBS()dnl
1015 _AC_ARG_VAR_CPPFLAGS()dnl
1016 _AC_ARG_VAR_PRECIOUS([OBJCXX])dnl
1017 AC_CHECK_TOOLS(OBJCXX,
1018                [m4_default([$1], [g++ objc++ objcxx c++ CXX])],
1019                g++)
1020 # Provide some information about the compiler.
1021 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
1022 set X $ac_compile
1023 ac_compiler=$[2]
1024 for ac_option in --version -v -V -qversion; do
1025   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
1026 done
1028 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
1029 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
1030 _AC_LANG_COMPILER_GNU
1031 if test $ac_compiler_gnu = yes; then
1032   GOBJCXX=yes
1033 else
1034   GOBJCXX=
1036 _AC_PROG_OBJCXX_G
1037 AC_LANG_POP(Objective C++)dnl
1038 ])# AC_PROG_OBJCXX
1041 # _AC_PROG_OBJCXX_G
1042 # -----------------
1043 # Check whether -g works, even if OBJCFLAGS is set, in case the package
1044 # plays around with OBJCFLAGS (such as to build both debugging and
1045 # normal versions of a library), tasteless as that idea is.
1046 # Don't consider -g to work if it generates warnings when plain compiles don't.
1047 m4_define([_AC_PROG_OBJCXX_G],
1048 [ac_test_OBJCXXFLAGS=${OBJCXXFLAGS+set}
1049 ac_save_OBJCXXFLAGS=$OBJCXXFLAGS
1050 AC_CACHE_CHECK(whether $OBJCXX accepts -g, ac_cv_prog_objcxx_g,
1051   [ac_save_objcxx_werror_flag=$ac_objcxx_werror_flag
1052    ac_objcxx_werror_flag=yes
1053    ac_cv_prog_objcxx_g=no
1054    OBJCXXFLAGS="-g"
1055    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1056      [ac_cv_prog_objcxx_g=yes],
1057      [OBJCXXFLAGS=""
1058       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1059         [],
1060         [ac_objcxx_werror_flag=$ac_save_objcxx_werror_flag
1061          OBJCXXFLAGS="-g"
1062          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1063            [ac_cv_prog_objcxx_g=yes])])])
1064    ac_objcxx_werror_flag=$ac_save_objcx_werror_flag])
1065 if test "$ac_test_OBJCXXFLAGS" = set; then
1066   OBJCXXFLAGS=$ac_save_OBJCXXFLAGS
1067 elif test $ac_cv_prog_objcxx_g = yes; then
1068   if test "$GOBJCXX" = yes; then
1069     OBJCXXFLAGS="-g -O2"
1070   else
1071     OBJCXXFLAGS="-g"
1072   fi
1073 else
1074   if test "$GOBJCXX" = yes; then
1075     OBJCXXFLAGS="-O2"
1076   else
1077     OBJCXXFLAGS=
1078   fi
1079 fi[]dnl
1080 ])# _AC_PROG_OBJCXX_G
1084 ## ------------------------------- ##
1085 ## 4. Compilers' characteristics.  ##
1086 ## ------------------------------- ##
1088 # -------------------------------- #
1089 # 4a. C compiler characteristics.  #
1090 # -------------------------------- #
1093 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1094 # ----------------------------------------------------------------
1095 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1096 # to add an option to output variable CC to make it so.  This macro
1097 # tries various options that select ANSI C89 on some system or
1098 # another.  It considers the compiler to be in ANSI C89 mode if it
1099 # handles function prototypes correctly.
1100 AC_DEFUN([_AC_PROG_CC_C89],
1101 [_AC_C_STD_TRY([c89],
1102 [[#include <stdarg.h>
1103 #include <stdio.h>
1104 struct stat;
1105 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
1106 struct buf { int x; };
1107 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1108 static char *e (p, i)
1109      char **p;
1110      int i;
1112   return p[i];
1114 static char *f (char * (*g) (char **, int), char **p, ...)
1116   char *s;
1117   va_list v;
1118   va_start (v,p);
1119   s = g (p, va_arg (v,int));
1120   va_end (v);
1121   return s;
1124 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
1125    function prototypes and stuff, but not '\xHH' hex character constants.
1126    These don't provoke an error unfortunately, instead are silently treated
1127    as 'x'.  The following induces an error, until -std is added to get
1128    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
1129    array size at least.  It's necessary to write '\x00'==0 to get something
1130    that's true only with -std.  */
1131 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1133 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1134    inside strings and character constants.  */
1135 #define FOO(x) 'x'
1136 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1138 int test (int i, double x);
1139 struct s1 {int (*f) (int a);};
1140 struct s2 {int (*f) (double a);};
1141 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1142 int argc;
1143 char **argv;]],
1144 [[return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];]],
1145 dnl Don't try gcc -ansi; that turns off useful extensions and
1146 dnl breaks some systems' header files.
1147 dnl AIX circa 2003      -qlanglvl=extc89
1148 dnl old AIX             -qlanglvl=ansi
1149 dnl Ultrix, OSF/1, Tru64        -std
1150 dnl HP-UX 10.20 and later       -Ae
1151 dnl HP-UX older versions        -Aa -D_HPUX_SOURCE
1152 dnl SVR4                        -Xc -D__EXTENSIONS__
1153 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1154         -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1155 ])# _AC_PROG_CC_C89
1158 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1159 #               ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1160 # --------------------------------------------------------------
1161 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1162 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
1163 # try again with each compiler option in the space-separated OPTION-LIST; if one
1164 # helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
1165 # else ACTION-IF-UNAVAILABLE.
1166 AC_DEFUN([_AC_C_STD_TRY],
1167 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
1168 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1169 [ac_cv_prog_cc_$1=no
1170 ac_save_CC=$CC
1171 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1172 for ac_arg in '' $4
1174   CC="$ac_save_CC $ac_arg"
1175   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1176   test "x$ac_cv_prog_cc_$1" != "xno" && break
1177 done
1178 rm -f conftest.$ac_ext
1179 CC=$ac_save_CC
1180 ])# AC_CACHE_VAL
1181 ac_prog_cc_stdc_options=
1182 case "x$ac_cv_prog_cc_$1" in
1183   x)
1184     AC_MSG_RESULT([none needed]) ;;
1185   xno)
1186     AC_MSG_RESULT([unsupported]) ;;
1187   *)
1188     ac_prog_cc_stdc_options=" $ac_cv_prog_cc_$1"
1189     CC=$CC$ac_prog_cc_stdc_options
1190     AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1191 esac
1192 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1193 ])# _AC_C_STD_TRY
1195 # _AC_C_C99_TEST_HEADER
1196 # ---------------------
1197 # A C header suitable for testing for C99.
1198 AC_DEFUN([_AC_C_C99_TEST_HEADER],
1199 [[#include <stdarg.h>
1200 #include <stdbool.h>
1201 #include <stdlib.h>
1202 #include <wchar.h>
1203 #include <stdio.h>
1205 // Check varargs macros.  These examples are taken from C99 6.10.3.5.
1206 #define debug(...) fprintf (stderr, __VA_ARGS__)
1207 #define showlist(...) puts (#__VA_ARGS__)
1208 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1209 static void
1210 test_varargs_macros (void)
1212   int x = 1234;
1213   int y = 5678;
1214   debug ("Flag");
1215   debug ("X = %d\n", x);
1216   showlist (The first, second, and third items.);
1217   report (x>y, "x is %d but y is %d", x, y);
1220 // Check long long types.
1221 #define BIG64 18446744073709551615ull
1222 #define BIG32 4294967295ul
1223 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1224 #if !BIG_OK
1225   your preprocessor is broken;
1226 #endif
1227 #if BIG_OK
1228 #else
1229   your preprocessor is broken;
1230 #endif
1231 static long long int bignum = -9223372036854775807LL;
1232 static unsigned long long int ubignum = BIG64;
1234 struct incomplete_array
1236   int datasize;
1237   double data[];
1240 struct named_init {
1241   int number;
1242   const wchar_t *name;
1243   double average;
1246 typedef const char *ccp;
1248 static inline int
1249 test_restrict (ccp restrict text)
1251   // See if C++-style comments work.
1252   // Iterate through items via the restricted pointer.
1253   // Also check for declarations in for loops.
1254   for (unsigned int i = 0; *(text+i) != '\0'; ++i)
1255     continue;
1256   return 0;
1259 // Check varargs and va_copy.
1260 static void
1261 test_varargs (const char *format, ...)
1263   va_list args;
1264   va_start (args, format);
1265   va_list args_copy;
1266   va_copy (args_copy, args);
1268   const char *str;
1269   int number;
1270   float fnumber;
1272   while (*format)
1273     {
1274       switch (*format++)
1275         {
1276         case 's': // string
1277           str = va_arg (args_copy, const char *);
1278           break;
1279         case 'd': // int
1280           number = va_arg (args_copy, int);
1281           break;
1282         case 'f': // float
1283           fnumber = va_arg (args_copy, double);
1284           break;
1285         default:
1286           break;
1287         }
1288     }
1289   va_end (args_copy);
1290   va_end (args);
1291 }]])# _AC_C_C99_TEST_HEADER
1293 # _AC_C_C99_TEST_BODY
1294 # -------------------
1295 # A C body suitable for testing for C99, assuming the corresponding header.
1296 AC_DEFUN([_AC_C_C99_TEST_BODY],
1298   // Check bool.
1299   _Bool success = false;
1301   // Check restrict.
1302   if (test_restrict ("String literal") == 0)
1303     success = true;
1304   char *restrict newvar = "Another string";
1306   // Check varargs.
1307   test_varargs ("s, d' f .", "string", 65, 34.234);
1308   test_varargs_macros ();
1310   // Check flexible array members.
1311   struct incomplete_array *ia =
1312     malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1313   ia->datasize = 10;
1314   for (int i = 0; i < ia->datasize; ++i)
1315     ia->data[i] = i * 1.234;
1317   // Check named initializers.
1318   struct named_init ni = {
1319     .number = 34,
1320     .name = L"Test wide string",
1321     .average = 543.34343,
1322   };
1324   ni.number = 58;
1326   int dynamic_array[ni.number];
1327   dynamic_array[ni.number - 1] = 543;
1329   // work around unused variable warnings
1330   return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
1331           || dynamic_array[ni.number - 1] != 543);
1334 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1335 # ----------------------------------------------------------------
1336 # If the C compiler is not in ISO C99 mode by default, try to add an
1337 # option to output variable CC to make it so.  This macro tries
1338 # various options that select ISO C99 on some system or another.  It
1339 # considers the compiler to be in ISO C99 mode if it handles _Bool,
1340 # // comments, flexible array members, inline, long long int, mixed
1341 # code and declarations, named initialization of structs, restrict,
1342 # va_copy, varargs macros, variable declarations in for loops and
1343 # variable length arrays.
1344 AC_DEFUN([_AC_PROG_CC_C99],
1345 [_AC_C_STD_TRY([c99],
1346 [_AC_C_C99_TEST_HEADER],
1347 [_AC_C_C99_TEST_BODY],
1348 dnl Try
1349 dnl GCC         -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1350 dnl AIX         -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
1351 dnl HP cc       -AC99
1352 dnl Intel ICC   -std=c99, -c99 (deprecated)
1353 dnl IRIX        -c99
1354 dnl Solaris     -D_STDC_C99=
1355 dnl             cc's -xc99 option uses linker magic to define the external
1356 dnl             symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
1357 dnl             behavior for C library functions.  This is not wanted here,
1358 dnl             because it means that a single module compiled with -xc99
1359 dnl             alters C runtime behavior for the entire program, not for
1360 dnl             just the module.  Instead, define the (private) symbol
1361 dnl             _STDC_C99, which suppresses a bogus failure in <stdbool.h>.
1362 dnl             The resulting compiler passes the test case here, and that's
1363 dnl             good enough.  For more, please see the thread starting at:
1364 dnl            http://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
1365 dnl Tru64       -c99
1366 dnl with extended modes being tried first.
1367 [[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc99]], [$1], [$2])[]dnl
1368 ])# _AC_PROG_CC_C99
1371 # _AC_PROG_CC_C11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1372 # ----------------------------------------------------------------
1373 # If the C compiler is not in ISO C11 mode by default, try to add an
1374 # option to output variable CC to make it so.  This macro tries
1375 # various options that select ISO C11 on some system or another.  It
1376 # considers the compiler to be in ISO C11 mode if it handles _Alignas,
1377 # _Alignof, _Noreturn, _Static_assert, UTF-8 string literals,
1378 # duplicate typedefs, and anonymous structures and unions.
1379 AC_DEFUN([_AC_PROG_CC_C11],
1380 [_AC_C_STD_TRY([c11],
1381 [_AC_C_C99_TEST_HEADER[
1382 // Check _Alignas.
1383 char _Alignas (double) aligned_as_double;
1384 char _Alignas (0) no_special_alignment;
1385 extern char aligned_as_int;
1386 char _Alignas (0) _Alignas (int) aligned_as_int;
1388 // Check _Alignof.
1389 enum
1391   int_alignment = _Alignof (int),
1392   int_array_alignment = _Alignof (int[100]),
1393   char_alignment = _Alignof (char)
1395 _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
1397 // Check _Noreturn.
1398 int _Noreturn does_not_return (void) { for (;;) continue; }
1400 // Check _Static_assert.
1401 struct test_static_assert
1403   int x;
1404   _Static_assert (sizeof (int) <= sizeof (long int),
1405                   "_Static_assert does not work in struct");
1406   long int y;
1409 // Check UTF-8 literals.
1410 #define u8 syntax error!
1411 char const utf8_literal[] = u8"happens to be ASCII" "another string";
1413 // Check duplicate typedefs.
1414 typedef long *long_ptr;
1415 typedef long int *long_ptr;
1416 typedef long_ptr long_ptr;
1418 // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
1419 struct anonymous
1421   union {
1422     struct { int i; int j; };
1423     struct { int k; long int l; } w;
1424   };
1425   int m;
1426 } v1;
1428 [_AC_C_C99_TEST_BODY[
1429   v1.i = 2;
1430   v1.w.k = 5;
1431   _Static_assert (&v1.i == &v1.w.k, "Anonymous union alignment botch");
1433 dnl Try
1434 dnl GCC         -std=gnu11 (unused restrictive mode: -std=c11)
1435 dnl with extended modes being tried first.
1436 [[-std=gnu11]], [$1], [$2])[]dnl
1437 ])# _AC_PROG_CC_C11
1440 # _AC_PROG_CC_FORCE_VERSION(LOWER-VERSION, UPPER-VERSION)
1441 # -------------------------------------------------------
1442 # Require a compiler for a particular version of C, either C89 or C99.
1443 # LOWER-VERSION uses lower-case c, UPPER-VERSION uses upper-case.
1444 AC_DEFUN([_AC_PROG_CC_FORCE_VERSION],
1445 [ AC_REQUIRE([AC_PROG_CC])dnl
1446   if test $ac_prog_cc_stdc != $1; then
1447     ac_save_std_CC=$CC
1448     if test -n "$ac_prog_cc_stdc_options"; then
1449       CC=`expr "X$CC" : 'X\(.*\)'"$ac_prog_cc_stdc_options"
1450         ``expr "X$CC" : ".*$ac_prog_cc_stdc_options"'\(.*\)'
1451         `
1452     fi
1453     _AC_PROG_CC_$2(
1454        [ac_prog_cc_stdc=$1
1455         ac_cv_prog_cc_stdc=$ac_cv_prog_cc_$1],
1456        [CC=$ac_save_std_CC
1457         AC_MSG_WARN([$2 compiler not available; falling back on $CC])])
1458   fi
1461 # AC_PROG_CC_C89
1462 # --------------
1463 AC_DEFUN([AC_PROG_CC_C89], [_AC_PROG_CC_FORCE_VERSION([c89], [C89])])
1465 # AC_PROG_CC_C99
1466 # --------------
1467 AC_DEFUN([AC_PROG_CC_C99], [_AC_PROG_CC_FORCE_VERSION([c99], [C99])])
1469 # There is no AC_PROG_CC_C11, as we have not identified a need for it.
1470 # Applications should use AC_PROG_CC instead.
1473 # AC_PROG_CC_STDC
1474 # ---------------
1475 # This has been folded into AC_PROG_CC.
1476 AU_ALIAS([AC_PROG_CC_STDC], [AC_PROG_CC])
1479 # AC_C_BACKSLASH_A
1480 # ----------------
1481 AC_DEFUN([AC_C_BACKSLASH_A],
1483   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1484    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1485      [[
1486 #if '\a' == 'a'
1487       syntax error;
1488 #endif
1489       char buf['\a' == 'a' ? -1 : 1];
1490       buf[0] = '\a';
1491       return buf[0] != "\a"[0];
1492      ]])],
1493      [ac_cv_c_backslash_a=yes],
1494      [ac_cv_c_backslash_a=no])])
1495   if test $ac_cv_c_backslash_a = yes; then
1496     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1497       [Define if backslash-a works in C strings.])
1498   fi
1502 # AC_C_CROSS
1503 # ----------
1504 # Has been merged into AC_PROG_CC.
1505 AU_DEFUN([AC_C_CROSS], [])
1508 # AC_C_CHAR_UNSIGNED
1509 # ------------------
1510 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1511 [AH_VERBATIM([__CHAR_UNSIGNED__],
1512 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1513 #ifndef __CHAR_UNSIGNED__
1514 # undef __CHAR_UNSIGNED__
1515 #endif])dnl
1516 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1517 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1518                                              [((char) -1) < 0])],
1519                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1520 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1521   AC_DEFINE(__CHAR_UNSIGNED__)
1523 ])# AC_C_CHAR_UNSIGNED
1526 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1527 #                 [ACTION-IF-UNIVERSAL])
1528 # -------------------------------------------------------------------------
1529 AC_DEFUN([AC_C_BIGENDIAN],
1530 [AH_VERBATIM([WORDS_BIGENDIAN],
1531 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1532    significant byte first (like Motorola and SPARC, unlike Intel). */
1533 #if defined AC_APPLE_UNIVERSAL_BUILD
1534 # if defined __BIG_ENDIAN__
1535 #  define WORDS_BIGENDIAN 1
1536 # endif
1537 #else
1538 # ifndef WORDS_BIGENDIAN
1539 #  undef WORDS_BIGENDIAN
1540 # endif
1541 #endif])dnl
1542  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1543    [ac_cv_c_bigendian=unknown
1544     # See if we're dealing with a universal compiler.
1545     AC_COMPILE_IFELSE(
1546          [AC_LANG_SOURCE(
1547             [[#ifndef __APPLE_CC__
1548                not a universal capable compiler
1549              #endif
1550              typedef int dummy;
1551             ]])],
1552          [
1553         # Check for potential -arch flags.  It is not universal unless
1554         # there are at least two -arch flags with different values.
1555         ac_arch=
1556         ac_prev=
1557         for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
1558          if test -n "$ac_prev"; then
1559            case $ac_word in
1560              i?86 | x86_64 | ppc | ppc64)
1561                if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
1562                  ac_arch=$ac_word
1563                else
1564                  ac_cv_c_bigendian=universal
1565                  break
1566                fi
1567                ;;
1568            esac
1569            ac_prev=
1570          elif test "x$ac_word" = "x-arch"; then
1571            ac_prev=arch
1572          fi
1573        done])
1574     if test $ac_cv_c_bigendian = unknown; then
1575       # See if sys/param.h defines the BYTE_ORDER macro.
1576       AC_COMPILE_IFELSE(
1577         [AC_LANG_PROGRAM(
1578            [[#include <sys/types.h>
1579              #include <sys/param.h>
1580            ]],
1581            [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1582                      && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1583                      && LITTLE_ENDIAN)
1584               bogus endian macros
1585              #endif
1586            ]])],
1587         [# It does; now see whether it defined to BIG_ENDIAN or not.
1588          AC_COMPILE_IFELSE(
1589            [AC_LANG_PROGRAM(
1590               [[#include <sys/types.h>
1591                 #include <sys/param.h>
1592               ]],
1593               [[#if BYTE_ORDER != BIG_ENDIAN
1594                  not big endian
1595                 #endif
1596               ]])],
1597            [ac_cv_c_bigendian=yes],
1598            [ac_cv_c_bigendian=no])])
1599     fi
1600     if test $ac_cv_c_bigendian = unknown; then
1601       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1602       AC_COMPILE_IFELSE(
1603         [AC_LANG_PROGRAM(
1604            [[#include <limits.h>
1605            ]],
1606            [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1607               bogus endian macros
1608              #endif
1609            ]])],
1610         [# It does; now see whether it defined to _BIG_ENDIAN or not.
1611          AC_COMPILE_IFELSE(
1612            [AC_LANG_PROGRAM(
1613               [[#include <limits.h>
1614               ]],
1615               [[#ifndef _BIG_ENDIAN
1616                  not big endian
1617                 #endif
1618               ]])],
1619            [ac_cv_c_bigendian=yes],
1620            [ac_cv_c_bigendian=no])])
1621     fi
1622     if test $ac_cv_c_bigendian = unknown; then
1623       # Compile a test program.
1624       AC_RUN_IFELSE(
1625         [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1626            [[
1627              /* Are we little or big endian?  From Harbison&Steele.  */
1628              union
1629              {
1630                long int l;
1631                char c[sizeof (long int)];
1632              } u;
1633              u.l = 1;
1634              return u.c[sizeof (long int) - 1] == 1;
1635            ]])],
1636         [ac_cv_c_bigendian=no],
1637         [ac_cv_c_bigendian=yes],
1638         [# Try to guess by grepping values from an object file.
1639          AC_COMPILE_IFELSE(
1640            [AC_LANG_PROGRAM(
1641               [[short int ascii_mm[] =
1642                   { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1643                 short int ascii_ii[] =
1644                   { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1645                 int use_ascii (int i) {
1646                   return ascii_mm[i] + ascii_ii[i];
1647                 }
1648                 short int ebcdic_ii[] =
1649                   { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1650                 short int ebcdic_mm[] =
1651                   { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1652                 int use_ebcdic (int i) {
1653                   return ebcdic_mm[i] + ebcdic_ii[i];
1654                 }
1655                 extern int foo;
1656               ]],
1657               [[return use_ascii (foo) == use_ebcdic (foo);]])],
1658            [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1659               ac_cv_c_bigendian=yes
1660             fi
1661             if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1662               if test "$ac_cv_c_bigendian" = unknown; then
1663                 ac_cv_c_bigendian=no
1664               else
1665                 # finding both strings is unlikely to happen, but who knows?
1666                 ac_cv_c_bigendian=unknown
1667               fi
1668             fi])])
1669     fi])
1670  case $ac_cv_c_bigendian in #(
1671    yes)
1672      m4_default([$1],
1673        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1674    no)
1675      $2 ;; #(
1676    universal)
1677 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
1678 dnl this is a necessity for proper config header operation.  Warn if
1679 dnl the user did not specify a config header but is relying on the
1680 dnl default behavior for universal builds.
1681      m4_default([$4],
1682        [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
1683          [AC_DIAGNOSE([obsolete],
1684            [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
1685         AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
1686           [Define if building universal (internal helper macro)])])
1687      ;; #(
1688    *)
1689      m4_default([$3],
1690        [AC_MSG_ERROR([unknown endianness
1691  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1692  esac
1693 ])# AC_C_BIGENDIAN
1696 # AC_C_INLINE
1697 # -----------
1698 # Do nothing if the compiler accepts the inline keyword.
1699 # Otherwise define inline to __inline__ or __inline if one of those work,
1700 # otherwise define inline to be empty.
1702 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1703 # inline function, only builtin types.
1705 AN_IDENTIFIER([inline], [AC_C_INLINE])
1706 AC_DEFUN([AC_C_INLINE],
1707 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1708 [ac_cv_c_inline=no
1709 for ac_kw in inline __inline__ __inline; do
1710   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1711 [#ifndef __cplusplus
1712 typedef int foo_t;
1713 static $ac_kw foo_t static_foo () {return 0; }
1714 $ac_kw foo_t foo () {return 0; }
1715 #endif
1716 ])],
1717                     [ac_cv_c_inline=$ac_kw])
1718   test "$ac_cv_c_inline" != no && break
1719 done
1721 AH_VERBATIM([inline],
1722 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1723    calls it, or to nothing if 'inline' is not supported under any name.  */
1724 #ifndef __cplusplus
1725 #undef inline
1726 #endif])
1727 case $ac_cv_c_inline in
1728   inline | yes) ;;
1729   *)
1730     case $ac_cv_c_inline in
1731       no) ac_val=;;
1732       *) ac_val=$ac_cv_c_inline;;
1733     esac
1734     cat >>confdefs.h <<_ACEOF
1735 #ifndef __cplusplus
1736 #define inline $ac_val
1737 #endif
1738 _ACEOF
1739     ;;
1740 esac
1741 ])# AC_C_INLINE
1744 # AC_C_CONST
1745 # ----------
1746 AC_DEFUN([AC_C_CONST],
1747 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1748 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1750 #ifndef __cplusplus
1751   /* Ultrix mips cc rejects this sort of thing.  */
1752   typedef int charset[2];
1753   const charset cs = { 0, 0 };
1754   /* SunOS 4.1.1 cc rejects this.  */
1755   char const *const *pcpcc;
1756   char **ppc;
1757   /* NEC SVR4.0.2 mips cc rejects this.  */
1758   struct point {int x, y;};
1759   static struct point const zero = {0,0};
1760   /* AIX XL C 1.02.0.0 rejects this.
1761      It does not let you subtract one const X* pointer from another in
1762      an arm of an if-expression whose if-part is not a constant
1763      expression */
1764   const char *g = "string";
1765   pcpcc = &g + (g ? g-g : 0);
1766   /* HPUX 7.0 cc rejects these. */
1767   ++pcpcc;
1768   ppc = (char**) pcpcc;
1769   pcpcc = (char const *const *) ppc;
1770   { /* SCO 3.2v4 cc rejects this sort of thing.  */
1771     char tx;
1772     char *t = &tx;
1773     char const *s = 0 ? (char *) 0 : (char const *) 0;
1775     *t++ = 0;
1776     if (s) return 0;
1777   }
1778   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1779     int x[] = {25, 17};
1780     const int *foo = &x[0];
1781     ++foo;
1782   }
1783   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1784     typedef const int *iptr;
1785     iptr p = 0;
1786     ++p;
1787   }
1788   { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying
1789        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1790     struct s { int j; const int *ap[3]; } bx;
1791     struct s *b = &bx; b->j = 5;
1792   }
1793   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1794     const int foo = 10;
1795     if (!foo) return 0;
1796   }
1797   return !cs[0] && !zero.x;
1798 #endif
1799 ]])],
1800                    [ac_cv_c_const=yes],
1801                    [ac_cv_c_const=no])])
1802 if test $ac_cv_c_const = no; then
1803   AC_DEFINE(const,,
1804             [Define to empty if `const' does not conform to ANSI C.])
1806 ])# AC_C_CONST
1809 # AC_C_RESTRICT
1810 # -------------
1811 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1812 # http://autoconf-archive.cryp.to/acx_restrict.html
1814 # Determine whether the C/C++ compiler supports the "restrict" keyword
1815 # introduced in ANSI C99, or an equivalent.  Define "restrict" to the alternate
1816 # spelling, if any; these are more likely to work in both C and C++ compilers of
1817 # the same family, and in the presence of varying compiler options.  If only
1818 # plain "restrict" works, do nothing.  Here are some variants:
1819 # - GCC supports both __restrict and __restrict__
1820 # - older DEC Alpha C compilers support only __restrict
1821 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1822 # Otherwise, define "restrict" to be empty.
1823 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1824 AC_DEFUN([AC_C_RESTRICT],
1825 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1826   [ac_cv_c_restrict=no
1827    # The order here caters to the fact that C++ does not require restrict.
1828    for ac_kw in __restrict __restrict__ _Restrict restrict; do
1829      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1830       [[typedef int * int_ptr;
1831         int foo (int_ptr $ac_kw ip) {
1832         return ip[0];
1833        }]],
1834       [[int s[1];
1835         int * $ac_kw t = s;
1836         t[0] = 0;
1837         return foo(t)]])],
1838       [ac_cv_c_restrict=$ac_kw])
1839      test "$ac_cv_c_restrict" != no && break
1840    done
1841   ])
1842  AH_VERBATIM([restrict],
1843 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1844    nothing if this is not supported.  Do not define if restrict is
1845    supported directly.  */
1846 #undef restrict
1847 /* Work around a bug in Sun C++: it does not support _Restrict or
1848    __restrict__, even though the corresponding Sun C compiler ends up with
1849    "#define restrict _Restrict" or "#define restrict __restrict__" in the
1850    previous line.  Perhaps some future version of Sun C++ will work with
1851    restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
1852 #if defined __SUNPRO_CC && !defined __RESTRICT
1853 # define _Restrict
1854 # define __restrict__
1855 #endif])
1856  case $ac_cv_c_restrict in
1857    restrict) ;;
1858    no) AC_DEFINE([restrict], []) ;;
1859    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1860  esac
1861 ])# AC_C_RESTRICT
1864 # AC_C_VOLATILE
1865 # -------------
1866 # Note that, unlike const, #defining volatile to be the empty string can
1867 # actually turn a correct program into an incorrect one, since removing
1868 # uses of volatile actually grants the compiler permission to perform
1869 # optimizations that could break the user's code.  So, do not #define
1870 # volatile away unless it is really necessary to allow the user's code
1871 # to compile cleanly.  Benign compiler failures should be tolerated.
1872 AC_DEFUN([AC_C_VOLATILE],
1873 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1874 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1875 volatile int x;
1876 int * volatile y = (int *) 0;
1877 return !x && !y;])],
1878                    [ac_cv_c_volatile=yes],
1879                    [ac_cv_c_volatile=no])])
1880 if test $ac_cv_c_volatile = no; then
1881   AC_DEFINE(volatile,,
1882             [Define to empty if the keyword `volatile' does not work.
1883              Warning: valid code using `volatile' can become incorrect
1884              without.  Disable with care.])
1886 ])# AC_C_VOLATILE
1889 # AC_C_STRINGIZE
1890 # --------------
1891 # Checks if `#' can be used to glue strings together at the CPP level.
1892 # Defines HAVE_STRINGIZE if positive.
1893 AC_DEFUN([AC_C_STRINGIZE],
1894 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1895                 [ac_cv_c_stringize],
1896 [AC_EGREP_CPP([@%:@teststring],
1897               [@%:@define x(y) #y
1899 char *s = x(teststring);],
1900               [ac_cv_c_stringize=no],
1901               [ac_cv_c_stringize=yes])])
1902 if test $ac_cv_c_stringize = yes; then
1903   AC_DEFINE(HAVE_STRINGIZE, 1,
1904             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1906 ])# AC_C_STRINGIZE
1909 # AC_C_PROTOTYPES
1910 # ---------------
1911 # Check if the C compiler supports prototypes, included if it needs
1912 # options.
1913 AC_DEFUN([AC_C_PROTOTYPES],
1914 [AC_REQUIRE([AC_PROG_CC])dnl
1915 if test "$ac_prog_cc_stdc" != no; then
1916   AC_DEFINE(PROTOTYPES, 1,
1917             [Define to 1 if the C compiler supports function prototypes.])
1918   AC_DEFINE(__PROTOTYPES, 1,
1919             [Define like PROTOTYPES; this can be used by system headers.])
1921 ])# AC_C_PROTOTYPES
1924 # AC_C_FLEXIBLE_ARRAY_MEMBER
1925 # --------------------------
1926 # Check whether the C compiler supports flexible array members.
1927 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1929   AC_CACHE_CHECK([for flexible array members],
1930     ac_cv_c_flexmember,
1931     [AC_COMPILE_IFELSE(
1932        [AC_LANG_PROGRAM(
1933           [[#include <stdlib.h>
1934             #include <stdio.h>
1935             #include <stddef.h>
1936             struct s { int n; double d[]; };]],
1937           [[int m = getchar ();
1938             struct s *p = malloc (offsetof (struct s, d)
1939                                   + m * sizeof (double));
1940             p->d[0] = 0.0;
1941             return p->d != (double *) NULL;]])],
1942        [ac_cv_c_flexmember=yes],
1943        [ac_cv_c_flexmember=no])])
1944   if test $ac_cv_c_flexmember = yes; then
1945     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1946       [Define to nothing if C supports flexible array members, and to
1947        1 if it does not.  That way, with a declaration like `struct s
1948        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1949        can be used with pre-C99 compilers.
1950        When computing the size of such an object, don't use 'sizeof (struct s)'
1951        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
1952        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1953        MSVC and with C++ compilers.])
1954   else
1955     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1956   fi
1960 # AC_C_VARARRAYS
1961 # --------------
1962 # Check whether the C compiler supports variable-length arrays.
1963 AC_DEFUN([AC_C_VARARRAYS],
1965   AC_CACHE_CHECK([for variable-length arrays],
1966     ac_cv_c_vararrays,
1967     [AC_COMPILE_IFELSE(
1968        [AC_LANG_PROGRAM([],
1969           [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1970        [ac_cv_c_vararrays=yes],
1971        [ac_cv_c_vararrays=no])])
1972   if test $ac_cv_c_vararrays = yes; then
1973     AC_DEFINE([HAVE_C_VARARRAYS], 1,
1974       [Define to 1 if C supports variable-length arrays.])
1975   fi
1979 # AC_C_TYPEOF
1980 # -----------
1981 # Check if the C compiler supports GCC's typeof syntax.
1982 # The test case provokes incompatibilities in the Sun C compilers
1983 # (both Solaris 8 and Solaris 10).
1984 AC_DEFUN([AC_C_TYPEOF],
1986   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1987     [ac_cv_c_typeof=no
1988      for ac_kw in typeof __typeof__ no; do
1989        test $ac_kw = no && break
1990        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1991          [[
1992            int value;
1993            typedef struct {
1994                    char a [1
1995                            + ! (($ac_kw (value))
1996                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1997                                  ? ($ac_kw (value)) - 1
1998                                  : ~ (~ ($ac_kw (value)) 0
1999                                       << sizeof ($ac_kw (value)))))]; }
2000               ac__typeof_type_;
2001            return
2002              (! ((void) ((ac__typeof_type_ *) 0), 0));
2003          ]])],
2004          [ac_cv_c_typeof=$ac_kw])
2005        test $ac_cv_c_typeof != no && break
2006      done])
2007   if test $ac_cv_c_typeof != no; then
2008     AC_DEFINE([HAVE_TYPEOF], 1,
2009       [Define to 1 if typeof works with your compiler.])
2010     if test $ac_cv_c_typeof != typeof; then
2011       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
2012         [Define to __typeof__ if your compiler spells it that way.])
2013     fi
2014   fi
2018 # _AC_LANG_OPENMP
2019 # ---------------
2020 # Expands to some language dependent source code for testing the presence of
2021 # OpenMP.
2022 AC_DEFUN([_AC_LANG_OPENMP],
2023 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
2025 # _AC_LANG_OPENMP(C)
2026 # ------------------
2027 m4_define([_AC_LANG_OPENMP(C)],
2029 #ifndef _OPENMP
2030  choke me
2031 #endif
2032 #include <omp.h>
2033 int main () { return omp_get_num_threads (); }
2036 # _AC_LANG_OPENMP(C++)
2037 # --------------------
2038 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
2040 # _AC_LANG_OPENMP(Fortran 77)
2041 # ---------------------------
2042 m4_define([_AC_LANG_OPENMP(Fortran 77)],
2044       program main
2045       implicit none
2046 !$    integer tid
2047       tid = 42
2048       call omp_set_num_threads(2)
2049       end
2052 # _AC_LANG_OPENMP(Fortran)
2053 # ------------------------
2054 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
2056 # AC_OPENMP
2057 # ---------
2058 # Check which options need to be passed to the C compiler to support OpenMP.
2059 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
2060 # options.
2061 # The options are necessary at compile time (so the #pragmas are understood)
2062 # and at link time (so the appropriate library is linked with).
2063 # This macro takes care to not produce redundant options if $CC $CFLAGS already
2064 # supports OpenMP. It also is careful to not pass options to compilers that
2065 # misinterpret them; for example, most compilers accept "-openmp" and create
2066 # an output file called 'penmp' rather than activating OpenMP support.
2067 AC_DEFUN([AC_OPENMP],
2069   OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
2070   AC_ARG_ENABLE([openmp],
2071     [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
2072   if test "$enable_openmp" != no; then
2073     AC_CACHE_CHECK([for $[]_AC_CC[] option to support OpenMP],
2074       [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
2075       [AC_LINK_IFELSE([_AC_LANG_OPENMP],
2076          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
2077          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
2078           dnl Try these flags:
2079           dnl   GCC >= 4.2           -fopenmp
2080           dnl   SunPRO C             -xopenmp
2081           dnl   Intel C              -openmp
2082           dnl   SGI C, PGI C         -mp
2083           dnl   Tru64 Compaq C       -omp
2084           dnl   IBM C (AIX, Linux)   -qsmp=omp
2085           dnl   Cray CCE             -homp
2086           dnl   NEC SX               -Popenmp
2087           dnl   Lahey Fortran (Linux)  --openmp
2088           dnl If in this loop a compiler is passed an option that it doesn't
2089           dnl understand or that it misinterprets, the AC_LINK_IFELSE test
2090           dnl will fail (since we know that it failed without the option),
2091           dnl therefore the loop will continue searching for an option, and
2092           dnl no output file called 'penmp' or 'mp' is created.
2093           for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
2094                            -Popenmp --openmp; do
2095             ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
2096             _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
2097             AC_LINK_IFELSE([_AC_LANG_OPENMP],
2098               [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
2099             _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
2100             if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
2101               break
2102             fi
2103           done])])
2104     case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
2105       "none needed" | unsupported)
2106         ;; #(
2107       *)
2108         OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
2109     esac
2110   fi
2111   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])