AC_PROG_CC: clarify documentation, encourage -qlanglvl=extc1x
[autoconf.git] / lib / autoconf / c.m4
blobad40527021fe62f2580407417dcfc5876e1fd20d
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 enable ]m4_translit($1, [c], [C])[ features])
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 IBM XL C    -qlanglvl=extc1x (V12.1; does not pass C11 test)
1351 dnl IBM XL C    -qlanglvl=extc99
1352 dnl             (pre-V12.1; unused restrictive mode: -qlanglvl=stdc99)
1353 dnl HP cc       -AC99
1354 dnl Intel ICC   -std=c99, -c99 (deprecated)
1355 dnl IRIX        -c99
1356 dnl Solaris     -D_STDC_C99=
1357 dnl             cc's -xc99 option uses linker magic to define the external
1358 dnl             symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
1359 dnl             behavior for C library functions.  This is not wanted here,
1360 dnl             because it means that a single module compiled with -xc99
1361 dnl             alters C runtime behavior for the entire program, not for
1362 dnl             just the module.  Instead, define the (private) symbol
1363 dnl             _STDC_C99, which suppresses a bogus failure in <stdbool.h>.
1364 dnl             The resulting compiler passes the test case here, and that's
1365 dnl             good enough.  For more, please see the thread starting at:
1366 dnl            http://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
1367 dnl Tru64       -c99
1368 dnl with extended modes being tried first.
1369 [[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc1x -qlanglvl=extc99]], [$1], [$2])[]dnl
1370 ])# _AC_PROG_CC_C99
1373 # _AC_PROG_CC_C11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1374 # ----------------------------------------------------------------
1375 # If the C compiler is not in ISO C11 mode by default, try to add an
1376 # option to output variable CC to make it so.  This macro tries
1377 # various options that select ISO C11 on some system or another.  It
1378 # considers the compiler to be in ISO C11 mode if it handles _Alignas,
1379 # _Alignof, _Noreturn, _Static_assert, UTF-8 string literals,
1380 # duplicate typedefs, and anonymous structures and unions.
1381 AC_DEFUN([_AC_PROG_CC_C11],
1382 [_AC_C_STD_TRY([c11],
1383 [_AC_C_C99_TEST_HEADER[
1384 // Check _Alignas.
1385 char _Alignas (double) aligned_as_double;
1386 char _Alignas (0) no_special_alignment;
1387 extern char aligned_as_int;
1388 char _Alignas (0) _Alignas (int) aligned_as_int;
1390 // Check _Alignof.
1391 enum
1393   int_alignment = _Alignof (int),
1394   int_array_alignment = _Alignof (int[100]),
1395   char_alignment = _Alignof (char)
1397 _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
1399 // Check _Noreturn.
1400 int _Noreturn does_not_return (void) { for (;;) continue; }
1402 // Check _Static_assert.
1403 struct test_static_assert
1405   int x;
1406   _Static_assert (sizeof (int) <= sizeof (long int),
1407                   "_Static_assert does not work in struct");
1408   long int y;
1411 // Check UTF-8 literals.
1412 #define u8 syntax error!
1413 char const utf8_literal[] = u8"happens to be ASCII" "another string";
1415 // Check duplicate typedefs.
1416 typedef long *long_ptr;
1417 typedef long int *long_ptr;
1418 typedef long_ptr long_ptr;
1420 // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
1421 struct anonymous
1423   union {
1424     struct { int i; int j; };
1425     struct { int k; long int l; } w;
1426   };
1427   int m;
1428 } v1;
1430 [_AC_C_C99_TEST_BODY[
1431   v1.i = 2;
1432   v1.w.k = 5;
1433   _Static_assert (&v1.i == &v1.w.k, "Anonymous union alignment botch");
1435 dnl Try
1436 dnl GCC         -std=gnu11 (unused restrictive mode: -std=c11)
1437 dnl with extended modes being tried first.
1439 dnl Do not try -qlanglvl=extc1x, because IBM XL C V12.1 (the latest version as
1440 dnl of September 2012) does not pass the C11 test.  For now, try extc1x when
1441 dnl compiling the C99 test instead, since it enables _Static_assert and
1442 dnl _Noreturn, which is a win.  If -qlanglvl=extc11 or -qlanglvl=extc1x passes
1443 dnl the C11 test in some future version of IBM XL C, we'll add it here,
1444 dnl preferably extc11.
1445 [[-std=gnu11]], [$1], [$2])[]dnl
1446 ])# _AC_PROG_CC_C11
1449 # AC_PROG_CC_C89
1450 # --------------
1451 AC_DEFUN([AC_PROG_CC_C89],
1452 [ AC_REQUIRE([AC_PROG_CC])dnl
1453   m4_warn([obsolete], [$0 is obsolete; use AC_PROG_CC])
1456 # AC_PROG_CC_C99
1457 # --------------
1458 AC_DEFUN([AC_PROG_CC_C99],
1459 [ AC_REQUIRE([AC_PROG_CC])dnl
1460   m4_warn([obsolete], [$0 is obsolete; use AC_PROG_CC])
1463 # AC_PROG_CC_STDC
1464 # ---------------
1465 AC_DEFUN([AC_PROG_CC_STDC],
1466 [ AC_REQUIRE([AC_PROG_CC])dnl
1467   m4_warn([obsolete], [$0 is obsolete; use AC_PROG_CC])
1471 # AC_C_BACKSLASH_A
1472 # ----------------
1473 AC_DEFUN([AC_C_BACKSLASH_A],
1475   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1476    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1477      [[
1478 #if '\a' == 'a'
1479       syntax error;
1480 #endif
1481       char buf['\a' == 'a' ? -1 : 1];
1482       buf[0] = '\a';
1483       return buf[0] != "\a"[0];
1484      ]])],
1485      [ac_cv_c_backslash_a=yes],
1486      [ac_cv_c_backslash_a=no])])
1487   if test $ac_cv_c_backslash_a = yes; then
1488     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1489       [Define if backslash-a works in C strings.])
1490   fi
1494 # AC_C_CROSS
1495 # ----------
1496 # Has been merged into AC_PROG_CC.
1497 AU_DEFUN([AC_C_CROSS], [])
1500 # AC_C_CHAR_UNSIGNED
1501 # ------------------
1502 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1503 [AH_VERBATIM([__CHAR_UNSIGNED__],
1504 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1505 #ifndef __CHAR_UNSIGNED__
1506 # undef __CHAR_UNSIGNED__
1507 #endif])dnl
1508 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1509 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1510                                              [((char) -1) < 0])],
1511                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1512 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1513   AC_DEFINE(__CHAR_UNSIGNED__)
1515 ])# AC_C_CHAR_UNSIGNED
1518 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1519 #                 [ACTION-IF-UNIVERSAL])
1520 # -------------------------------------------------------------------------
1521 AC_DEFUN([AC_C_BIGENDIAN],
1522 [AH_VERBATIM([WORDS_BIGENDIAN],
1523 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1524    significant byte first (like Motorola and SPARC, unlike Intel). */
1525 #if defined AC_APPLE_UNIVERSAL_BUILD
1526 # if defined __BIG_ENDIAN__
1527 #  define WORDS_BIGENDIAN 1
1528 # endif
1529 #else
1530 # ifndef WORDS_BIGENDIAN
1531 #  undef WORDS_BIGENDIAN
1532 # endif
1533 #endif])dnl
1534  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1535    [ac_cv_c_bigendian=unknown
1536     # See if we're dealing with a universal compiler.
1537     AC_COMPILE_IFELSE(
1538          [AC_LANG_SOURCE(
1539             [[#ifndef __APPLE_CC__
1540                not a universal capable compiler
1541              #endif
1542              typedef int dummy;
1543             ]])],
1544          [
1545         # Check for potential -arch flags.  It is not universal unless
1546         # there are at least two -arch flags with different values.
1547         ac_arch=
1548         ac_prev=
1549         for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
1550          if test -n "$ac_prev"; then
1551            case $ac_word in
1552              i?86 | x86_64 | ppc | ppc64)
1553                if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
1554                  ac_arch=$ac_word
1555                else
1556                  ac_cv_c_bigendian=universal
1557                  break
1558                fi
1559                ;;
1560            esac
1561            ac_prev=
1562          elif test "x$ac_word" = "x-arch"; then
1563            ac_prev=arch
1564          fi
1565        done])
1566     if test $ac_cv_c_bigendian = unknown; then
1567       # See if sys/param.h defines the BYTE_ORDER macro.
1568       AC_COMPILE_IFELSE(
1569         [AC_LANG_PROGRAM(
1570            [[#include <sys/types.h>
1571              #include <sys/param.h>
1572            ]],
1573            [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1574                      && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1575                      && LITTLE_ENDIAN)
1576               bogus endian macros
1577              #endif
1578            ]])],
1579         [# It does; now see whether it defined to BIG_ENDIAN or not.
1580          AC_COMPILE_IFELSE(
1581            [AC_LANG_PROGRAM(
1582               [[#include <sys/types.h>
1583                 #include <sys/param.h>
1584               ]],
1585               [[#if BYTE_ORDER != BIG_ENDIAN
1586                  not big endian
1587                 #endif
1588               ]])],
1589            [ac_cv_c_bigendian=yes],
1590            [ac_cv_c_bigendian=no])])
1591     fi
1592     if test $ac_cv_c_bigendian = unknown; then
1593       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1594       AC_COMPILE_IFELSE(
1595         [AC_LANG_PROGRAM(
1596            [[#include <limits.h>
1597            ]],
1598            [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1599               bogus endian macros
1600              #endif
1601            ]])],
1602         [# It does; now see whether it defined to _BIG_ENDIAN or not.
1603          AC_COMPILE_IFELSE(
1604            [AC_LANG_PROGRAM(
1605               [[#include <limits.h>
1606               ]],
1607               [[#ifndef _BIG_ENDIAN
1608                  not big endian
1609                 #endif
1610               ]])],
1611            [ac_cv_c_bigendian=yes],
1612            [ac_cv_c_bigendian=no])])
1613     fi
1614     if test $ac_cv_c_bigendian = unknown; then
1615       # Compile a test program.
1616       AC_RUN_IFELSE(
1617         [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1618            [[
1619              /* Are we little or big endian?  From Harbison&Steele.  */
1620              union
1621              {
1622                long int l;
1623                char c[sizeof (long int)];
1624              } u;
1625              u.l = 1;
1626              return u.c[sizeof (long int) - 1] == 1;
1627            ]])],
1628         [ac_cv_c_bigendian=no],
1629         [ac_cv_c_bigendian=yes],
1630         [# Try to guess by grepping values from an object file.
1631          AC_COMPILE_IFELSE(
1632            [AC_LANG_PROGRAM(
1633               [[short int ascii_mm[] =
1634                   { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1635                 short int ascii_ii[] =
1636                   { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1637                 int use_ascii (int i) {
1638                   return ascii_mm[i] + ascii_ii[i];
1639                 }
1640                 short int ebcdic_ii[] =
1641                   { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1642                 short int ebcdic_mm[] =
1643                   { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1644                 int use_ebcdic (int i) {
1645                   return ebcdic_mm[i] + ebcdic_ii[i];
1646                 }
1647                 extern int foo;
1648               ]],
1649               [[return use_ascii (foo) == use_ebcdic (foo);]])],
1650            [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1651               ac_cv_c_bigendian=yes
1652             fi
1653             if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1654               if test "$ac_cv_c_bigendian" = unknown; then
1655                 ac_cv_c_bigendian=no
1656               else
1657                 # finding both strings is unlikely to happen, but who knows?
1658                 ac_cv_c_bigendian=unknown
1659               fi
1660             fi])])
1661     fi])
1662  case $ac_cv_c_bigendian in #(
1663    yes)
1664      m4_default([$1],
1665        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1666    no)
1667      $2 ;; #(
1668    universal)
1669 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
1670 dnl this is a necessity for proper config header operation.  Warn if
1671 dnl the user did not specify a config header but is relying on the
1672 dnl default behavior for universal builds.
1673      m4_default([$4],
1674        [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
1675          [AC_DIAGNOSE([obsolete],
1676            [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
1677         AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
1678           [Define if building universal (internal helper macro)])])
1679      ;; #(
1680    *)
1681      m4_default([$3],
1682        [AC_MSG_ERROR([unknown endianness
1683  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1684  esac
1685 ])# AC_C_BIGENDIAN
1688 # AC_C_INLINE
1689 # -----------
1690 # Do nothing if the compiler accepts the inline keyword.
1691 # Otherwise define inline to __inline__ or __inline if one of those work,
1692 # otherwise define inline to be empty.
1694 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1695 # inline function, only builtin types.
1697 AN_IDENTIFIER([inline], [AC_C_INLINE])
1698 AC_DEFUN([AC_C_INLINE],
1699 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1700 [ac_cv_c_inline=no
1701 for ac_kw in inline __inline__ __inline; do
1702   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1703 [#ifndef __cplusplus
1704 typedef int foo_t;
1705 static $ac_kw foo_t static_foo () {return 0; }
1706 $ac_kw foo_t foo () {return 0; }
1707 #endif
1708 ])],
1709                     [ac_cv_c_inline=$ac_kw])
1710   test "$ac_cv_c_inline" != no && break
1711 done
1713 AH_VERBATIM([inline],
1714 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1715    calls it, or to nothing if 'inline' is not supported under any name.  */
1716 #ifndef __cplusplus
1717 #undef inline
1718 #endif])
1719 case $ac_cv_c_inline in
1720   inline | yes) ;;
1721   *)
1722     case $ac_cv_c_inline in
1723       no) ac_val=;;
1724       *) ac_val=$ac_cv_c_inline;;
1725     esac
1726     cat >>confdefs.h <<_ACEOF
1727 #ifndef __cplusplus
1728 #define inline $ac_val
1729 #endif
1730 _ACEOF
1731     ;;
1732 esac
1733 ])# AC_C_INLINE
1736 # AC_C_CONST
1737 # ----------
1738 AC_DEFUN([AC_C_CONST],
1739 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1740 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1742 #ifndef __cplusplus
1743   /* Ultrix mips cc rejects this sort of thing.  */
1744   typedef int charset[2];
1745   const charset cs = { 0, 0 };
1746   /* SunOS 4.1.1 cc rejects this.  */
1747   char const *const *pcpcc;
1748   char **ppc;
1749   /* NEC SVR4.0.2 mips cc rejects this.  */
1750   struct point {int x, y;};
1751   static struct point const zero = {0,0};
1752   /* IBM XL C 1.02.0.0 rejects this.
1753      It does not let you subtract one const X* pointer from another in
1754      an arm of an if-expression whose if-part is not a constant
1755      expression */
1756   const char *g = "string";
1757   pcpcc = &g + (g ? g-g : 0);
1758   /* HPUX 7.0 cc rejects these. */
1759   ++pcpcc;
1760   ppc = (char**) pcpcc;
1761   pcpcc = (char const *const *) ppc;
1762   { /* SCO 3.2v4 cc rejects this sort of thing.  */
1763     char tx;
1764     char *t = &tx;
1765     char const *s = 0 ? (char *) 0 : (char const *) 0;
1767     *t++ = 0;
1768     if (s) return 0;
1769   }
1770   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1771     int x[] = {25, 17};
1772     const int *foo = &x[0];
1773     ++foo;
1774   }
1775   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1776     typedef const int *iptr;
1777     iptr p = 0;
1778     ++p;
1779   }
1780   { /* IBM XL C 1.02.0.0 rejects this sort of thing, saying
1781        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1782     struct s { int j; const int *ap[3]; } bx;
1783     struct s *b = &bx; b->j = 5;
1784   }
1785   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1786     const int foo = 10;
1787     if (!foo) return 0;
1788   }
1789   return !cs[0] && !zero.x;
1790 #endif
1791 ]])],
1792                    [ac_cv_c_const=yes],
1793                    [ac_cv_c_const=no])])
1794 if test $ac_cv_c_const = no; then
1795   AC_DEFINE(const,,
1796             [Define to empty if `const' does not conform to ANSI C.])
1798 ])# AC_C_CONST
1801 # AC_C_RESTRICT
1802 # -------------
1803 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1804 # http://autoconf-archive.cryp.to/acx_restrict.html
1806 # Determine whether the C/C++ compiler supports the "restrict" keyword
1807 # introduced in ANSI C99, or an equivalent.  Define "restrict" to the alternate
1808 # spelling, if any; these are more likely to work in both C and C++ compilers of
1809 # the same family, and in the presence of varying compiler options.  If only
1810 # plain "restrict" works, do nothing.  Here are some variants:
1811 # - GCC supports both __restrict and __restrict__
1812 # - older DEC Alpha C compilers support only __restrict
1813 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1814 # Otherwise, define "restrict" to be empty.
1815 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1816 AC_DEFUN([AC_C_RESTRICT],
1817 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1818   [ac_cv_c_restrict=no
1819    # The order here caters to the fact that C++ does not require restrict.
1820    for ac_kw in __restrict __restrict__ _Restrict restrict; do
1821      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1822       [[typedef int * int_ptr;
1823         int foo (int_ptr $ac_kw ip) {
1824         return ip[0];
1825        }]],
1826       [[int s[1];
1827         int * $ac_kw t = s;
1828         t[0] = 0;
1829         return foo(t)]])],
1830       [ac_cv_c_restrict=$ac_kw])
1831      test "$ac_cv_c_restrict" != no && break
1832    done
1833   ])
1834  AH_VERBATIM([restrict],
1835 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1836    nothing if this is not supported.  Do not define if restrict is
1837    supported directly.  */
1838 #undef restrict
1839 /* Work around a bug in Sun C++: it does not support _Restrict or
1840    __restrict__, even though the corresponding Sun C compiler ends up with
1841    "#define restrict _Restrict" or "#define restrict __restrict__" in the
1842    previous line.  Perhaps some future version of Sun C++ will work with
1843    restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
1844 #if defined __SUNPRO_CC && !defined __RESTRICT
1845 # define _Restrict
1846 # define __restrict__
1847 #endif])
1848  case $ac_cv_c_restrict in
1849    restrict) ;;
1850    no) AC_DEFINE([restrict], []) ;;
1851    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1852  esac
1853 ])# AC_C_RESTRICT
1856 # AC_C_VOLATILE
1857 # -------------
1858 # Note that, unlike const, #defining volatile to be the empty string can
1859 # actually turn a correct program into an incorrect one, since removing
1860 # uses of volatile actually grants the compiler permission to perform
1861 # optimizations that could break the user's code.  So, do not #define
1862 # volatile away unless it is really necessary to allow the user's code
1863 # to compile cleanly.  Benign compiler failures should be tolerated.
1864 AC_DEFUN([AC_C_VOLATILE],
1865 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1866 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1867 volatile int x;
1868 int * volatile y = (int *) 0;
1869 return !x && !y;])],
1870                    [ac_cv_c_volatile=yes],
1871                    [ac_cv_c_volatile=no])])
1872 if test $ac_cv_c_volatile = no; then
1873   AC_DEFINE(volatile,,
1874             [Define to empty if the keyword `volatile' does not work.
1875              Warning: valid code using `volatile' can become incorrect
1876              without.  Disable with care.])
1878 ])# AC_C_VOLATILE
1881 # AC_C_STRINGIZE
1882 # --------------
1883 # Checks if `#' can be used to glue strings together at the CPP level.
1884 # Defines HAVE_STRINGIZE if positive.
1885 AC_DEFUN([AC_C_STRINGIZE],
1886 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1887                 [ac_cv_c_stringize],
1888 [AC_EGREP_CPP([@%:@teststring],
1889               [@%:@define x(y) #y
1891 char *s = x(teststring);],
1892               [ac_cv_c_stringize=no],
1893               [ac_cv_c_stringize=yes])])
1894 if test $ac_cv_c_stringize = yes; then
1895   AC_DEFINE(HAVE_STRINGIZE, 1,
1896             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1898 ])# AC_C_STRINGIZE
1901 # AC_C_PROTOTYPES
1902 # ---------------
1903 # Check if the C compiler supports prototypes, included if it needs
1904 # options.
1905 AC_DEFUN([AC_C_PROTOTYPES],
1906 [AC_REQUIRE([AC_PROG_CC])dnl
1907 if test "$ac_prog_cc_stdc" != no; then
1908   AC_DEFINE(PROTOTYPES, 1,
1909             [Define to 1 if the C compiler supports function prototypes.])
1910   AC_DEFINE(__PROTOTYPES, 1,
1911             [Define like PROTOTYPES; this can be used by system headers.])
1913 ])# AC_C_PROTOTYPES
1916 # AC_C_FLEXIBLE_ARRAY_MEMBER
1917 # --------------------------
1918 # Check whether the C compiler supports flexible array members.
1919 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1921   AC_CACHE_CHECK([for flexible array members],
1922     ac_cv_c_flexmember,
1923     [AC_COMPILE_IFELSE(
1924        [AC_LANG_PROGRAM(
1925           [[#include <stdlib.h>
1926             #include <stdio.h>
1927             #include <stddef.h>
1928             struct s { int n; double d[]; };]],
1929           [[int m = getchar ();
1930             struct s *p = malloc (offsetof (struct s, d)
1931                                   + m * sizeof (double));
1932             p->d[0] = 0.0;
1933             return p->d != (double *) NULL;]])],
1934        [ac_cv_c_flexmember=yes],
1935        [ac_cv_c_flexmember=no])])
1936   if test $ac_cv_c_flexmember = yes; then
1937     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1938       [Define to nothing if C supports flexible array members, and to
1939        1 if it does not.  That way, with a declaration like `struct s
1940        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1941        can be used with pre-C99 compilers.
1942        When computing the size of such an object, don't use 'sizeof (struct s)'
1943        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
1944        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1945        MSVC and with C++ compilers.])
1946   else
1947     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1948   fi
1952 # AC_C_VARARRAYS
1953 # --------------
1954 # Check whether the C compiler supports variable-length arrays.
1955 AC_DEFUN([AC_C_VARARRAYS],
1957   AC_CACHE_CHECK([for variable-length arrays],
1958     ac_cv_c_vararrays,
1959     [AC_COMPILE_IFELSE(
1960        [AC_LANG_PROGRAM([],
1961           [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1962        [ac_cv_c_vararrays=yes],
1963        [ac_cv_c_vararrays=no])])
1964   if test $ac_cv_c_vararrays = yes; then
1965     AC_DEFINE([HAVE_C_VARARRAYS], 1,
1966       [Define to 1 if C supports variable-length arrays.])
1967   fi
1971 # AC_C_TYPEOF
1972 # -----------
1973 # Check if the C compiler supports GCC's typeof syntax.
1974 # The test case provokes incompatibilities in the Sun C compilers
1975 # (both Solaris 8 and Solaris 10).
1976 AC_DEFUN([AC_C_TYPEOF],
1978   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1979     [ac_cv_c_typeof=no
1980      for ac_kw in typeof __typeof__ no; do
1981        test $ac_kw = no && break
1982        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1983          [[
1984            int value;
1985            typedef struct {
1986                    char a [1
1987                            + ! (($ac_kw (value))
1988                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1989                                  ? ($ac_kw (value)) - 1
1990                                  : ~ (~ ($ac_kw (value)) 0
1991                                       << sizeof ($ac_kw (value)))))]; }
1992               ac__typeof_type_;
1993            return
1994              (! ((void) ((ac__typeof_type_ *) 0), 0));
1995          ]])],
1996          [ac_cv_c_typeof=$ac_kw])
1997        test $ac_cv_c_typeof != no && break
1998      done])
1999   if test $ac_cv_c_typeof != no; then
2000     AC_DEFINE([HAVE_TYPEOF], 1,
2001       [Define to 1 if typeof works with your compiler.])
2002     if test $ac_cv_c_typeof != typeof; then
2003       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
2004         [Define to __typeof__ if your compiler spells it that way.])
2005     fi
2006   fi
2010 # _AC_LANG_OPENMP
2011 # ---------------
2012 # Expands to some language dependent source code for testing the presence of
2013 # OpenMP.
2014 AC_DEFUN([_AC_LANG_OPENMP],
2015 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
2017 # _AC_LANG_OPENMP(C)
2018 # ------------------
2019 m4_define([_AC_LANG_OPENMP(C)],
2021 #ifndef _OPENMP
2022  choke me
2023 #endif
2024 #include <omp.h>
2025 int main () { return omp_get_num_threads (); }
2028 # _AC_LANG_OPENMP(C++)
2029 # --------------------
2030 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
2032 # _AC_LANG_OPENMP(Fortran 77)
2033 # ---------------------------
2034 m4_define([_AC_LANG_OPENMP(Fortran 77)],
2036       program main
2037       implicit none
2038 !$    integer tid
2039       tid = 42
2040       call omp_set_num_threads(2)
2041       end
2044 # _AC_LANG_OPENMP(Fortran)
2045 # ------------------------
2046 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
2048 # AC_OPENMP
2049 # ---------
2050 # Check which options need to be passed to the C compiler to support OpenMP.
2051 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
2052 # options.
2053 # The options are necessary at compile time (so the #pragmas are understood)
2054 # and at link time (so the appropriate library is linked with).
2055 # This macro takes care to not produce redundant options if $CC $CFLAGS already
2056 # supports OpenMP. It also is careful to not pass options to compilers that
2057 # misinterpret them; for example, most compilers accept "-openmp" and create
2058 # an output file called 'penmp' rather than activating OpenMP support.
2059 AC_DEFUN([AC_OPENMP],
2061   OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
2062   AC_ARG_ENABLE([openmp],
2063     [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
2064   if test "$enable_openmp" != no; then
2065     AC_CACHE_CHECK([for $[]_AC_CC[] option to support OpenMP],
2066       [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
2067       [AC_LINK_IFELSE([_AC_LANG_OPENMP],
2068          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
2069          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
2070           dnl Try these flags:
2071           dnl   GCC >= 4.2           -fopenmp
2072           dnl   SunPRO C             -xopenmp
2073           dnl   Intel C              -openmp
2074           dnl   SGI C, PGI C         -mp
2075           dnl   Tru64 Compaq C       -omp
2076           dnl   IBM XL C (AIX, Linux) -qsmp=omp
2077           dnl   Cray CCE             -homp
2078           dnl   NEC SX               -Popenmp
2079           dnl   Lahey Fortran (Linux)  --openmp
2080           dnl If in this loop a compiler is passed an option that it doesn't
2081           dnl understand or that it misinterprets, the AC_LINK_IFELSE test
2082           dnl will fail (since we know that it failed without the option),
2083           dnl therefore the loop will continue searching for an option, and
2084           dnl no output file called 'penmp' or 'mp' is created.
2085           for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
2086                            -Popenmp --openmp; do
2087             ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
2088             _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
2089             AC_LINK_IFELSE([_AC_LANG_OPENMP],
2090               [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
2091             _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
2092             if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
2093               break
2094             fi
2095           done])])
2096     case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
2097       "none needed" | unsupported)
2098         ;; #(
2099       *)
2100         OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
2101     esac
2102   fi
2103   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])