1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # As a special exception, the Free Software Foundation gives unlimited
22 # permission to copy, distribute and modify the configure scripts that
23 # are the output of Autoconf. You need not follow the terms of the GNU
24 # General Public License when using or distributing such scripts, even
25 # though portions of the text of Autoconf appear in them. The GNU
26 # General Public License (GPL) does govern all other use of the material
27 # that constitutes the Autoconf program.
29 # Certain portions of the Autoconf source text are designed to be copied
30 # (in certain cases, depending on the input) into the output of
31 # Autoconf. We call these the "data" portions. The rest of the Autoconf
32 # source text consists of comments plus executable code that decides which
33 # of the data portions to output in any given case. We call these
34 # comments and executable code the "non-data" portions. Autoconf never
35 # copies any of the non-data portions into its output.
37 # This special exception to the GPL applies to versions of Autoconf
38 # released by the Free Software Foundation. When you make and
39 # distribute a modified version of Autoconf, you may extend this special
40 # exception to the GPL to apply to your modified version as well, *unless*
41 # your modified version has the potential to copy into its output some
42 # of the text that was the non-data portion of the version that you started
43 # with. (In other words, unless your change moves or copies text from
44 # the non-data portions to the data portions.) If your modification has
45 # such potential, you must delete any notice of this special exception
46 # to the GPL from your modified version.
48 # Written by David MacKenzie, with help from
49 # Akim Demaille, Paul Eggert,
50 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
51 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
56 # 1. Language selection
57 # and routines to produce programs in a given language.
58 # 1a. C 1b. C++ 1c. Objective C
60 # 2. Producing programs in a given language.
61 # 2a. C 2b. C++ 2c. Objective C
63 # 3. Looking for a compiler
64 # And possibly the associated preprocessor.
65 # 3a. C 3b. C++ 3c. Objective C
67 # 4. Compilers' characteristics.
72 ## ----------------------- ##
73 ## 1. Language selection. ##
74 ## ----------------------- ##
76 # -------------------- #
77 # 1a. The C language. #
78 # -------------------- #
83 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
84 m4_define([AC_LANG(C)],
86 ac_cpp='$CPP $CPPFLAGS'
87 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
88 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
89 ac_compiler_gnu=$ac_cv_c_compiler_gnu
95 AU_DEFUN([AC_LANG_C], [AC_LANG(C)])
100 m4_define([_AC_LANG_ABBREV(C)], [c])
105 m4_define([_AC_LANG_PREFIX(C)], [C])
109 # ---------------------- #
110 # 1b. The C++ language. #
111 # ---------------------- #
116 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
117 m4_define([AC_LANG(C++)],
119 ac_cpp='$CXXCPP $CPPFLAGS'
120 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
121 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
122 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
128 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
131 # _AC_LANG_ABBREV(C++)
132 # --------------------
133 m4_define([_AC_LANG_ABBREV(C++)], [cxx])
136 # _AC_LANG_PREFIX(C++)
137 # --------------------
138 m4_define([_AC_LANG_PREFIX(C++)], [CXX])
142 # ------------------------------ #
143 # 1c. The Objective C language. #
144 # ------------------------------ #
147 # AC_LANG(Objective C)
148 # --------------------
149 m4_define([AC_LANG(Objective C)],
151 ac_cpp='$OBJCPP $CPPFLAGS'
152 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
153 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
154 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
160 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
163 # _AC_LANG_ABBREV(Objective C)
164 # ----------------------------
165 m4_define([_AC_LANG_ABBREV(Objective C)], [objc])
168 # _AC_LANG_PREFIX(Objective C)
169 # ----------------------------
170 m4_define([_AC_LANG_PREFIX(Objective C)], [OBJC])
174 ## ----------------------- ##
175 ## 2. Producing programs. ##
176 ## ----------------------- ##
183 # AC_LANG_SOURCE(C)(BODY)
184 # -----------------------
185 # We can't use '#line $LINENO "configure"' here, since
186 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
187 # rejects $LINENO greater than 32767, and some configure scripts
188 # are longer than 32767 lines.
189 m4_define([AC_LANG_SOURCE(C)],
192 cat confdefs.h >>conftest.$ac_ext
193 cat >>conftest.$ac_ext <<_ACEOF
194 /* end confdefs.h. */
198 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
199 # --------------------------------------
200 m4_define([AC_LANG_PROGRAM(C)],
202 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
203 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
207 dnl Do *not* indent the following line: there may be CPP directives.
208 dnl Don't move the `;' right after for the same reason.
215 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
216 # -----------------------------------
217 # Avoid conflicting decl of main.
218 m4_define([AC_LANG_CALL(C)],
220 m4_if([$2], [main], ,
221 [/* Override any GCC internal prototype to avoid an error.
222 Use char because int might match the return type of a GCC
223 builtin and then its argument prototype would still apply. */
227 char $2 ();])], [return $2 ();])])
230 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
231 # ----------------------------------
232 # Don't include <ctype.h> because on OSF/1 3.0 it includes
233 # <sys/types.h> which includes <sys/select.h> which contains a
234 # prototype for select. Similarly for bzero.
236 # This test used to merely assign f=$1 in main(), but that was
237 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
238 # presumably on the basis that there's no need to do that store if the
239 # program is about to exit. Conversely, the AIX linker optimizes an
240 # unused external declaration that initializes f=$1. So this test
241 # program has both an external initialization of f, and a use of f in
242 # main that affects the exit status.
244 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
246 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
247 For example, HP-UX 11i <limits.h> declares gettimeofday. */
248 #define $1 innocuous_$1
250 /* System header to define __stub macros and hopefully few prototypes,
251 which can conflict with char $1 (); below.
252 Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
253 <limits.h> exists even on freestanding compilers. */
263 /* Override any GCC internal prototype to avoid an error.
264 Use char because int might match the return type of a GCC
265 builtin and then its argument prototype would still apply. */
270 /* The GNU C library defines this for functions which it implements
271 to always fail with ENOSYS. Some functions are actually named
272 something starting with __ and the normal name is an alias. */
273 #if defined __stub_$1 || defined __stub___$1
276 ], [return $1 ();])])
279 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
280 # -------------------------------------------------
281 # Return a program that is valid if EXPRESSION is nonzero.
282 # EXPRESSION must be an integer constant expression.
283 # Be sure to use this array to avoid `unused' warnings, which are even
284 # errors with `-W error'.
285 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
286 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
287 test_array @<:@0@:>@ = 0
291 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
292 # -----------------------------------------
293 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
294 # But we include them only after the EXPRESSION has been evaluated.
295 m4_define([AC_LANG_INT_SAVE(C)],
297 static long int longval () { return $2; }
298 static unsigned long int ulongval () { return $2; }
299 @%:@include <stdio.h>
300 @%:@include <stdlib.h>],
302 FILE *f = fopen ("conftest.val", "w");
307 long int i = longval ();
310 fprintf (f, "%ld", i);
314 unsigned long int i = ulongval ();
317 fprintf (f, "%lu", i);
319 /* Do not output a trailing newline, as this causes \r\n confusion
320 on some platforms. */
321 return ferror (f) || fclose (f) != 0;
326 # ----------------- #
328 # ----------------- #
331 # AC_LANG_SOURCE(C++)(BODY)
332 # -------------------------
333 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(C++)])
336 # AC_LANG_PROGRAM(C++)([PROLOGUE], [BODY])
337 # ----------------------------------------
338 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(C++)])
341 # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
342 # -------------------------------------
343 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(C++)])
346 # AC_LANG_FUNC_LINK_TRY(C++)(FUNCTION)
347 # ------------------------------------
348 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(C++)])
351 # AC_LANG_BOOL_COMPILE_TRY(C++)(PROLOGUE, EXPRESSION)
352 # ---------------------------------------------------
353 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])
356 # AC_LANG_INT_SAVE(C++)(PROLOGUE, EXPRESSION)
357 # -------------------------------------------
358 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(C++)])
362 # ------------------------- #
363 # 2c. Objective C sources. #
364 # ------------------------- #
367 # AC_LANG_SOURCE(Objective C)(BODY)
368 # ---------------------------------
369 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(Objective C)])
372 # AC_LANG_PROGRAM(Objective C)([PROLOGUE], [BODY])
373 # ------------------------------------------------
374 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(Objective C)])
377 # AC_LANG_CALL(Objective C)(PROLOGUE, FUNCTION)
378 # ---------------------------------------------
379 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(Objective C)])
382 # AC_LANG_FUNC_LINK_TRY(Objective C)(FUNCTION)
383 # --------------------------------------------
384 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(Objective C)])
387 # AC_LANG_BOOL_COMPILE_TRY(Objective C)(PROLOGUE, EXPRESSION)
388 # -----------------------------------------------------------
389 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(Objective C)])
392 # AC_LANG_INT_SAVE(Objective C)(PROLOGUE, EXPRESSION)
393 # ---------------------------------------------------
394 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(Objective C)])
398 ## -------------------------------------------- ##
399 ## 3. Looking for Compilers and Preprocessors. ##
400 ## -------------------------------------------- ##
402 # -------------------- #
403 # 3a. The C compiler. #
404 # -------------------- #
407 # _AC_ARG_VAR_CPPFLAGS
408 # --------------------
409 # Document and register CPPFLAGS, which is used by
410 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP}.
411 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
412 [AC_ARG_VAR([CPPFLAGS],
413 [C/C++/Objective C preprocessor flags, e.g. -I<include dir>
414 if you have headers in a nonstandard directory <include dir>])])
417 # _AC_ARG_VAR_LDFLAGS
418 # -------------------
419 # Document and register LDFLAGS, which is used by
420 # AC_PROG_{CC, CXX, F77, FC, OBJC}.
421 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
422 [AC_ARG_VAR([LDFLAGS],
423 [linker flags, e.g. -L<lib dir> if you have libraries in a
424 nonstandard directory <lib dir>])])
429 # Document and register LIBS, which is used by
430 # AC_PROG_{CC, CXX, F77, FC, OBJS}.
431 AC_DEFUN([_AC_ARG_VAR_LIBS],
433 [libraries to pass to the linker, e.g. -l<library>])])
437 # -------------------
438 # Find the C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
439 AC_DEFUN([AC_LANG_PREPROC(C)],
440 [AC_REQUIRE([AC_PROG_CPP])])
443 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
444 # -----------------------------------------------
445 # Check if $ac_cpp is a working preprocessor that can flag absent
446 # includes either by the exit status or by warnings.
447 # This macro is for all languages, not only C.
448 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
450 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
452 # Use a header file that comes with gcc, so configuring glibc
453 # with a fresh cross-compiler works.
454 # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
455 # <limits.h> exists even on freestanding compilers.
456 # On the NeXT, cc -E runs the code through the compiler's parser,
457 # not just through cpp. "Syntax error" is here to catch this case.
458 _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@ifdef __STDC__
459 @%:@ include <limits.h>
461 @%:@ include <assert.h>
465 [# Broken: fails on valid input.
468 # OK, works on sane cases. Now check whether nonexistent headers
469 # can be detected and how.
470 _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
471 [# Broken: success on invalid input.
473 [# Passes both tests.
478 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
479 rm -f conftest.err conftest.$ac_ext
480 AS_IF([$ac_preproc_ok], [$1], [$2])])# _AC_PROG_PREPROC_WORKS_IFELSE
485 # Find a working C preprocessor.
486 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
487 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
488 AN_MAKEVAR([CPP], [AC_PROG_CPP])
489 AN_PROGRAM([cpp], [AC_PROG_CPP])
490 AC_DEFUN([AC_PROG_CPP],
491 [AC_REQUIRE([AC_PROG_CC])dnl
492 AC_ARG_VAR([CPP], [C preprocessor])dnl
493 _AC_ARG_VAR_CPPFLAGS()dnl
495 AC_MSG_CHECKING([how to run the C preprocessor])
496 # On Suns, sometimes $CPP names a directory.
497 if test -n "$CPP" && test -d "$CPP"; then
500 if test -z "$CPP"; then
501 AC_CACHE_VAL([ac_cv_prog_CPP],
503 # Double quotes because CPP needs to be expanded
504 for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
506 _AC_PROG_PREPROC_WORKS_IFELSE([break])
514 AC_MSG_RESULT([$CPP])
515 _AC_PROG_PREPROC_WORKS_IFELSE([],
516 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
523 # Treat warnings from the preprocessor as errors.
524 AC_DEFUN([AC_PROG_CPP_WERROR],
525 [AC_REQUIRE([AC_PROG_CPP])dnl
526 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
528 # AC_LANG_COMPILER(C)
529 # -------------------
530 # Find the C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
531 AC_DEFUN([AC_LANG_COMPILER(C)],
532 [AC_REQUIRE([AC_PROG_CC])])
537 # We used to name the cache variable this way.
538 AU_DEFUN([ac_cv_prog_gcc],
539 [ac_cv_c_compiler_gnu])
542 # AC_PROG_CC([COMPILER ...])
543 # --------------------------
544 # COMPILER ... is a space separated list of C compilers to search for.
545 # This just gives the user an opportunity to specify an alternative
546 # search list for the C compiler.
547 AN_MAKEVAR([CC], [AC_PROG_CC])
548 AN_PROGRAM([cc], [AC_PROG_CC])
549 AN_PROGRAM([gcc], [AC_PROG_CC])
550 AC_DEFUN([AC_PROG_CC],
552 AC_ARG_VAR([CC], [C compiler command])dnl
553 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
554 _AC_ARG_VAR_LDFLAGS()dnl
555 _AC_ARG_VAR_LIBS()dnl
556 _AC_ARG_VAR_CPPFLAGS()dnl
558 [AC_CHECK_TOOLS(CC, [$1])],
559 [AC_CHECK_TOOL(CC, gcc)
560 if test -z "$CC"; then
562 dnl AC_CHECK_TOOL(CC, cc)
563 dnl but without the check for a tool without the prefix.
564 dnl Until the check is removed from there, copy the code:
565 if test -n "$ac_tool_prefix"; then
566 AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
569 if test -z "$CC"; then
570 AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
572 if test -z "$CC"; then
573 AC_CHECK_TOOLS(CC, cl.exe)
577 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
579 # Provide some information about the compiler.
580 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
583 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
584 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
585 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
587 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
588 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
589 _AC_LANG_COMPILER_GNU
590 if test $ac_compiler_gnu = yes; then
603 # Check whether -g works, even if CFLAGS is set, in case the package
604 # plays around with CFLAGS (such as to build both debugging and normal
605 # versions of a library), tasteless as that idea is.
606 # Don't consider -g to work if it generates warnings when plain compiles don't.
607 m4_define([_AC_PROG_CC_G],
608 [ac_test_CFLAGS=${CFLAGS+set}
609 ac_save_CFLAGS=$CFLAGS
610 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
611 [ac_save_c_werror_flag=$ac_c_werror_flag
615 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
616 [ac_cv_prog_cc_g=yes],
618 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
620 [ac_c_werror_flag=$ac_save_c_werror_flag
622 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
623 [ac_cv_prog_cc_g=yes])])])
624 ac_c_werror_flag=$ac_save_c_werror_flag])
625 if test "$ac_test_CFLAGS" = set; then
626 CFLAGS=$ac_save_CFLAGS
627 elif test $ac_cv_prog_cc_g = yes; then
628 if test "$GCC" = yes; then
634 if test "$GCC" = yes; then
643 # AC_PROG_GCC_TRADITIONAL
644 # -----------------------
645 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
646 [AC_REQUIRE([AC_PROG_CC])dnl
647 if test $ac_cv_c_compiler_gnu = yes; then
648 AC_CACHE_CHECK(whether $CC needs -traditional,
649 ac_cv_prog_gcc_traditional,
650 [ ac_pattern="Autoconf.*'x'"
651 AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
653 ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
655 if test $ac_cv_prog_gcc_traditional = no; then
656 AC_EGREP_CPP($ac_pattern, [#include <termio.h>
658 ac_cv_prog_gcc_traditional=yes)
660 if test $ac_cv_prog_gcc_traditional = yes; then
661 CC="$CC -traditional"
664 ])# AC_PROG_GCC_TRADITIONAL
669 AC_DEFUN([AC_PROG_CC_C_O],
670 [AC_REQUIRE([AC_PROG_CC])dnl
671 if test "x$CC" != xcc; then
672 AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
674 AC_MSG_CHECKING([whether cc understands -c and -o together])
676 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
677 sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
678 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
679 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
680 # Make sure it works both with $CC and with simple cc.
681 # We do the test twice because some compilers refuse to overwrite an
682 # existing .o file with -o, though they will create one.
683 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
685 if _AC_DO_VAR(ac_try) &&
686 test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
688 eval ac_cv_prog_cc_${ac_cc}_c_o=yes
689 if test "x$CC" != xcc; then
690 # Test first that cc exists at all.
691 if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
692 ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
694 if _AC_DO_VAR(ac_try) &&
695 test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
700 # cc exists but doesn't like -o.
701 eval ac_cv_prog_cc_${ac_cc}_c_o=no
706 eval ac_cv_prog_cc_${ac_cc}_c_o=no
710 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
714 AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
715 [Define to 1 if your C compiler doesn't accept -c and -o together.])
721 # ---------------------- #
722 # 3b. The C++ compiler. #
723 # ---------------------- #
726 # AC_LANG_PREPROC(C++)
727 # ---------------------
728 # Find the C++ preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
729 AC_DEFUN([AC_LANG_PREPROC(C++)],
730 [AC_REQUIRE([AC_PROG_CXXCPP])])
735 # Find a working C++ preprocessor.
736 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
737 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
738 AC_DEFUN([AC_PROG_CXXCPP],
739 [AC_REQUIRE([AC_PROG_CXX])dnl
740 AC_ARG_VAR([CXXCPP], [C++ preprocessor])dnl
741 _AC_ARG_VAR_CPPFLAGS()dnl
743 AC_MSG_CHECKING([how to run the C++ preprocessor])
744 if test -z "$CXXCPP"; then
745 AC_CACHE_VAL(ac_cv_prog_CXXCPP,
747 # Double quotes because CXXCPP needs to be expanded
748 for CXXCPP in "$CXX -E" "/lib/cpp"
750 _AC_PROG_PREPROC_WORKS_IFELSE([break])
752 ac_cv_prog_CXXCPP=$CXXCPP
754 CXXCPP=$ac_cv_prog_CXXCPP
756 ac_cv_prog_CXXCPP=$CXXCPP
758 AC_MSG_RESULT([$CXXCPP])
759 _AC_PROG_PREPROC_WORKS_IFELSE([],
760 [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
766 # AC_LANG_COMPILER(C++)
767 # ---------------------
768 # Find the C++ compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
769 AC_DEFUN([AC_LANG_COMPILER(C++)],
770 [AC_REQUIRE([AC_PROG_CXX])])
775 # We used to name the cache variable this way.
776 AU_DEFUN([ac_cv_prog_gxx],
777 [ac_cv_cxx_compiler_gnu])
780 # AC_PROG_CXX([LIST-OF-COMPILERS])
781 # --------------------------------
782 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
783 # for (if not specified, a default list is used). This just gives the
784 # user an opportunity to specify an alternative search list for the C++
786 # aCC HP-UX C++ compiler much better than `CC', so test before.
787 # FCC Fujitsu C++ compiler
788 # KCC KAI C++ compiler
790 # xlC_r AIX C Set++ (with support for reentrant code)
792 AN_MAKEVAR([CXX], [AC_PROG_CXX])
793 AN_PROGRAM([CC], [AC_PROG_CXX])
794 AN_PROGRAM([c++], [AC_PROG_CXX])
795 AN_PROGRAM([g++], [AC_PROG_CXX])
796 AC_DEFUN([AC_PROG_CXX],
797 [AC_LANG_PUSH(C++)dnl
798 AC_ARG_VAR([CXX], [C++ compiler command])dnl
799 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
800 _AC_ARG_VAR_LDFLAGS()dnl
801 _AC_ARG_VAR_LIBS()dnl
802 _AC_ARG_VAR_CPPFLAGS()dnl
803 _AC_ARG_VAR_PRECIOUS([CCC])dnl
804 if test -z "$CXX"; then
805 if test -n "$CCC"; then
810 [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
814 # Provide some information about the compiler.
815 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
818 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
819 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
820 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
822 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
823 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
824 _AC_LANG_COMPILER_GNU
825 if test $ac_compiler_gnu = yes; then
837 # Check whether -g works, even if CXXFLAGS is set, in case the package
838 # plays around with CXXFLAGS (such as to build both debugging and
839 # normal versions of a library), tasteless as that idea is.
840 # Don't consider -g to work if it generates warnings when plain compiles don't.
841 m4_define([_AC_PROG_CXX_G],
842 [ac_test_CXXFLAGS=${CXXFLAGS+set}
843 ac_save_CXXFLAGS=$CXXFLAGS
844 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
845 [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
846 ac_cxx_werror_flag=yes
849 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
850 [ac_cv_prog_cxx_g=yes],
852 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
854 [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
856 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
857 [ac_cv_prog_cxx_g=yes])])])
858 ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
859 if test "$ac_test_CXXFLAGS" = set; then
860 CXXFLAGS=$ac_save_CXXFLAGS
861 elif test $ac_cv_prog_cxx_g = yes; then
862 if test "$GXX" = yes; then
868 if test "$GXX" = yes; then
879 # Test if the C++ compiler accepts the options `-c' and `-o'
880 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
881 AC_DEFUN([AC_PROG_CXX_C_O],
882 [AC_REQUIRE([AC_PROG_CXX])dnl
883 AC_LANG_PUSH([C++])dnl
884 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
885 [ac_cv_prog_cxx_c_o],
886 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
887 # We test twice because some compilers refuse to overwrite an existing
888 # `.o' file with `-o', although they will create one.
889 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
891 if _AC_DO_VAR(ac_try) &&
892 test -f conftest2.$ac_objext &&
893 _AC_DO_VAR(ac_try); then
894 ac_cv_prog_cxx_c_o=yes
896 ac_cv_prog_cxx_c_o=no
899 if test $ac_cv_prog_cxx_c_o = no; then
900 AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
901 [Define to 1 if your C++ compiler doesn't accept
902 -c and -o together.])
904 AC_LANG_POP([C++])dnl
909 # ------------------------------ #
910 # 3c. The Objective C compiler. #
911 # ------------------------------ #
914 # AC_LANG_PREPROC(Objective C)
915 # ----------------------------
916 # Find the Objective C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
917 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
918 [AC_REQUIRE([AC_PROG_OBJCPP])])
923 # Find a working Objective C preprocessor.
924 AC_DEFUN([AC_PROG_OBJCPP],
925 [AC_REQUIRE([AC_PROG_OBJC])dnl
926 AC_ARG_VAR([OBJCPP], [Objective C preprocessor])dnl
927 _AC_ARG_VAR_CPPFLAGS()dnl
928 AC_LANG_PUSH(Objective C)dnl
929 AC_MSG_CHECKING([how to run the Objective C preprocessor])
930 if test -z "$OBJCPP"; then
931 AC_CACHE_VAL(ac_cv_prog_OBJCPP,
933 # Double quotes because OBJCPP needs to be expanded
934 for OBJCPP in "$OBJC -E" "/lib/cpp"
936 _AC_PROG_PREPROC_WORKS_IFELSE([break])
938 ac_cv_prog_OBJCPP=$OBJCPP
940 OBJCPP=$ac_cv_prog_OBJCPP
942 ac_cv_prog_OBJCPP=$OBJCPP
944 AC_MSG_RESULT([$OBJCPP])
945 _AC_PROG_PREPROC_WORKS_IFELSE([],
946 [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
948 AC_LANG_POP(Objective C)dnl
952 # AC_LANG_COMPILER(Objective C)
953 # -----------------------------
954 # Find the Objective C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
955 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
956 [AC_REQUIRE([AC_PROG_OBJC])])
960 # AC_PROG_OBJC([LIST-OF-COMPILERS])
961 # ---------------------------------
962 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
963 # search for (if not specified, a default list is used). This just gives
964 # the user an opportunity to specify an alternative search list for the
965 # Objective C compiler.
966 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
967 # objc David Stes' POC. If you installed this, you likely want it.
968 # cc Native C compiler (for instance, Apple).
970 AN_MAKEVAR([OBJC], [AC_PROG_OBJC])
971 AN_PROGRAM([objcc], [AC_PROG_OBJC])
972 AN_PROGRAM([objc], [AC_PROG_OBJC])
973 AC_DEFUN([AC_PROG_OBJC],
974 [AC_LANG_PUSH(Objective C)dnl
975 AC_ARG_VAR([OBJC], [Objective C compiler command])dnl
976 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
977 _AC_ARG_VAR_LDFLAGS()dnl
978 _AC_ARG_VAR_LIBS()dnl
979 _AC_ARG_VAR_CPPFLAGS()dnl
980 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
982 [m4_default([$1], [gcc objcc objc cc CC])],
984 # Provide some information about the compiler.
985 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
988 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
989 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
990 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
992 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
993 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
994 _AC_LANG_COMPILER_GNU
995 if test $ac_compiler_gnu = yes; then
1001 AC_LANG_POP(Objective C)dnl
1007 # Check whether -g works, even if OBJCFLAGS is set, in case the package
1008 # plays around with OBJCFLAGS (such as to build both debugging and
1009 # normal versions of a library), tasteless as that idea is.
1010 # Don't consider -g to work if it generates warnings when plain compiles don't.
1011 m4_define([_AC_PROG_OBJC_G],
1012 [ac_test_OBJCFLAGS=${OBJCFLAGS+set}
1013 ac_save_OBJCFLAGS=$OBJCFLAGS
1014 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
1015 [ac_save_objc_werror_flag=$ac_objc_werror_flag
1016 ac_objc_werror_flag=yes
1017 ac_cv_prog_objc_g=no
1019 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1020 [ac_cv_prog_objc_g=yes],
1022 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1024 [ac_objc_werror_flag=$ac_save_objc_werror_flag
1026 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1027 [ac_cv_prog_objc_g=yes])])])
1028 ac_objc_werror_flag=$ac_save_objc_werror_flag])
1029 if test "$ac_test_OBJCFLAGS" = set; then
1030 OBJCFLAGS=$ac_save_OBJCFLAGS
1031 elif test $ac_cv_prog_objc_g = yes; then
1032 if test "$GOBJC" = yes; then
1038 if test "$GOBJC" = yes; then
1048 ## ------------------------------- ##
1049 ## 4. Compilers' characteristics. ##
1050 ## ------------------------------- ##
1052 # -------------------------------- #
1053 # 4a. C compiler characteristics. #
1054 # -------------------------------- #
1057 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1058 # ----------------------------------------------------------------
1059 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1060 # to add an option to output variable CC to make it so. This macro
1061 # tries various options that select ANSI C89 on some system or
1062 # another. It considers the compiler to be in ANSI C89 mode if it
1063 # handles function prototypes correctly.
1064 AC_DEFUN([_AC_PROG_CC_C89],
1065 [_AC_C_STD_TRY([c89],
1066 [[#include <stdarg.h>
1068 #include <sys/types.h>
1069 #include <sys/stat.h>
1070 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
1071 struct buf { int x; };
1072 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1073 static char *e (p, i)
1079 static char *f (char * (*g) (char **, int), char **p, ...)
1084 s = g (p, va_arg (v,int));
1089 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
1090 function prototypes and stuff, but not '\xHH' hex character constants.
1091 These don't provoke an error unfortunately, instead are silently treated
1092 as 'x'. The following induces an error, until -std is added to get
1093 proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
1094 array size at least. It's necessary to write '\x00'==0 to get something
1095 that's true only with -std. */
1096 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1098 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1099 inside strings and character constants. */
1101 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1103 int test (int i, double x);
1104 struct s1 {int (*f) (int a);};
1105 struct s2 {int (*f) (double a);};
1106 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1109 [[return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];]],
1110 dnl Don't try gcc -ansi; that turns off useful extensions and
1111 dnl breaks some systems' header files.
1112 dnl AIX circa 2003 -qlanglvl=extc89
1113 dnl old AIX -qlanglvl=ansi
1114 dnl Ultrix, OSF/1, Tru64 -std
1115 dnl HP-UX 10.20 and later -Ae
1116 dnl HP-UX older versions -Aa -D_HPUX_SOURCE
1117 dnl SVR4 -Xc -D__EXTENSIONS__
1118 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1119 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1123 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1124 # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1125 # --------------------------------------------------------------
1126 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1127 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
1128 # try again with each compiler option in the space-separated OPTION-LIST; if one
1129 # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
1130 # else ACTION-IF-UNAVAILABLE.
1131 AC_DEFUN([_AC_C_STD_TRY],
1132 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
1133 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1134 [ac_cv_prog_cc_$1=no
1136 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1139 CC="$ac_save_CC $ac_arg"
1140 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1141 test "x$ac_cv_prog_cc_$1" != "xno" && break
1143 rm -f conftest.$ac_ext
1146 case "x$ac_cv_prog_cc_$1" in
1148 AC_MSG_RESULT([none needed]) ;;
1150 AC_MSG_RESULT([unsupported]) ;;
1152 CC="$CC $ac_cv_prog_cc_$1"
1153 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1155 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1159 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1160 # ----------------------------------------------------------------
1161 # If the C compiler is not in ISO C99 mode by default, try to add an
1162 # option to output variable CC to make it so. This macro tries
1163 # various options that select ISO C99 on some system or another. It
1164 # considers the compiler to be in ISO C99 mode if it handles _Bool,
1165 # // comments, flexible array members, inline, long long int, mixed
1166 # code and declarations, named initialization of structs, restrict,
1167 # va_copy, varargs macros, variable declarations in for loops and
1168 # variable length arrays.
1169 AC_DEFUN([_AC_PROG_CC_C99],
1170 [_AC_C_STD_TRY([c99],
1171 [[#include <stdarg.h>
1172 #include <stdbool.h>
1177 // Check varargs macros. These examples are taken from C99 6.10.3.5.
1178 #define debug(...) fprintf (stderr, __VA_ARGS__)
1179 #define showlist(...) puts (#__VA_ARGS__)
1180 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1182 test_varargs_macros (void)
1187 debug ("X = %d\n", x);
1188 showlist (The first, second, and third items.);
1189 report (x>y, "x is %d but y is %d", x, y);
1192 // Check long long types.
1193 #define BIG64 18446744073709551615ull
1194 #define BIG32 4294967295ul
1195 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1197 your preprocessor is broken;
1201 your preprocessor is broken;
1203 static long long int bignum = -9223372036854775807LL;
1204 static unsigned long long int ubignum = BIG64;
1206 struct incomplete_array
1214 const wchar_t *name;
1218 typedef const char *ccp;
1221 test_restrict (ccp restrict text)
1223 // See if C++-style comments work.
1224 // Iterate through items via the restricted pointer.
1225 // Also check for declarations in for loops.
1226 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
1231 // Check varargs and va_copy.
1233 test_varargs (const char *format, ...)
1236 va_start (args, format);
1238 va_copy (args_copy, args);
1249 str = va_arg (args_copy, const char *);
1252 number = va_arg (args_copy, int);
1255 fnumber = va_arg (args_copy, double);
1267 _Bool success = false;
1270 if (test_restrict ("String literal") == 0)
1272 char *restrict newvar = "Another string";
1275 test_varargs ("s, d' f .", "string", 65, 34.234);
1276 test_varargs_macros ();
1278 // Check flexible array members.
1279 struct incomplete_array *ia =
1280 malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1282 for (int i = 0; i < ia->datasize; ++i)
1283 ia->data[i] = i * 1.234;
1285 // Check named initializers.
1286 struct named_init ni = {
1288 .name = L"Test wide string",
1289 .average = 543.34343,
1294 int dynamic_array[ni.number];
1295 dynamic_array[ni.number - 1] = 543;
1297 // work around unused variable warnings
1298 return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
1299 || dynamic_array[ni.number - 1] != 543);
1302 dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1303 dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
1306 dnl Solaris -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
1307 dnl as it incorrectly assumes C99 semantics for library functions)
1309 dnl with extended modes being tried first.
1310 [[-std=gnu99 -c99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
1316 AC_DEFUN([AC_PROG_CC_C89],
1317 [ AC_REQUIRE([AC_PROG_CC])dnl
1324 AC_DEFUN([AC_PROG_CC_C99],
1325 [ AC_REQUIRE([AC_PROG_CC])dnl
1332 AC_DEFUN([AC_PROG_CC_STDC],
1333 [ AC_REQUIRE([AC_PROG_CC])dnl
1334 AS_CASE([$ac_cv_prog_cc_stdc],
1335 [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
1336 [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1337 [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
1338 [ac_cv_prog_cc_stdc=no])])])dnl
1339 AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1340 AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1341 AS_CASE([$ac_cv_prog_cc_stdc],
1342 [no], [AC_MSG_RESULT([unsupported])],
1343 [''], [AC_MSG_RESULT([none needed])],
1344 [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
1350 AC_DEFUN([AC_C_BACKSLASH_A],
1352 AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1353 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1358 char buf['\a' == 'a' ? -1 : 1];
1360 return buf[0] != "\a"[0];
1362 [ac_cv_c_backslash_a=yes],
1363 [ac_cv_c_backslash_a=no])])
1364 if test $ac_cv_c_backslash_a = yes; then
1365 AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1366 [Define if backslash-a works in C strings.])
1373 # Has been merged into AC_PROG_CC.
1374 AU_DEFUN([AC_C_CROSS], [])
1377 # AC_C_CHAR_UNSIGNED
1378 # ------------------
1379 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1380 [AH_VERBATIM([__CHAR_UNSIGNED__],
1381 [/* Define to 1 if type `char' is unsigned and you are not using gcc. */
1382 #ifndef __CHAR_UNSIGNED__
1383 # undef __CHAR_UNSIGNED__
1385 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1386 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1387 [((char) -1) < 0])],
1388 ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1389 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1390 AC_DEFINE(__CHAR_UNSIGNED__)
1392 ])# AC_C_CHAR_UNSIGNED
1395 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1396 # [ACTION-IF-UNIVERSAL])
1397 # -------------------------------------------------------------------------
1398 AC_DEFUN([AC_C_BIGENDIAN],
1399 [AH_VERBATIM([WORDS_BIGENDIAN],
1400 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1401 significant byte first (like Motorola and SPARC, unlike Intel and VAX). */
1402 #if defined __BIG_ENDIAN__
1403 # define WORDS_BIGENDIAN 1
1404 #elif ! defined __LITTLE_ENDIAN__
1405 /* #undef WORDS_BIGENDIAN */
1407 AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1408 [ac_cv_c_bigendian=unknown
1409 m4_ifval(m4_ifdef([AH_HEADER], 1)[$4],
1410 [# See if __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined.
1413 [[#if ! (defined __BIG_ENDIAN__ || defined __LITTLE_ENDIAN__)
1418 [ac_cv_c_bigendian=universal])],
1419 [AC_DIAGNOSE([obsolete], [AC_C_BIGENDIAN suggests AC_CONFIG_HEADERS])])
1420 if test $ac_cv_c_bigendian = unknown; then
1421 # See if sys/param.h defines the BYTE_ORDER macro.
1424 [[#include <sys/types.h>
1425 #include <sys/param.h>
1427 [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1428 && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1433 [# It does; now see whether it defined to BIG_ENDIAN or not.
1436 [[#include <sys/types.h>
1437 #include <sys/param.h>
1439 [[#if BYTE_ORDER != BIG_ENDIAN
1443 [ac_cv_c_bigendian=yes],
1444 [ac_cv_c_bigendian=no])])
1446 if test $ac_cv_c_bigendian = unknown; then
1447 # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1450 [[#include <limits.h>
1452 [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1456 [# It does; now see whether it defined to _BIG_ENDIAN or not.
1459 [[#include <limits.h>
1461 [[#ifndef _BIG_ENDIAN
1465 [ac_cv_c_bigendian=yes],
1466 [ac_cv_c_bigendian=no])])
1468 if test $ac_cv_c_bigendian = unknown; then
1469 # Compile a test program.
1471 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1473 /* Are we little or big endian? From Harbison&Steele. */
1477 char c[sizeof (long int)];
1480 return u.c[sizeof (long int) - 1] == 1;
1482 [ac_cv_c_bigendian=no],
1483 [ac_cv_c_bigendian=yes],
1484 [# Try to guess by grepping values from an object file.
1487 [[short int ascii_mm[] =
1488 { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1489 short int ascii_ii[] =
1490 { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1491 int use_ascii (int i) {
1492 return ascii_mm[i] + ascii_ii[i];
1494 short int ebcdic_ii[] =
1495 { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1496 short int ebcdic_mm[] =
1497 { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1498 int use_ebcdic (int i) {
1499 return ebcdic_mm[i] + ebcdic_ii[i];
1503 [[return use_ascii (foo) == use_ebcdic (foo);]])],
1504 [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1505 ac_cv_c_bigendian=yes
1507 if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1508 if test "$ac_cv_c_bigendian" = unknown; then
1509 ac_cv_c_bigendian=no
1511 # finding both strings is unlikely to happen, but who knows?
1512 ac_cv_c_bigendian=unknown
1516 case $ac_cv_c_bigendian in #(
1519 [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1526 [AC_MSG_ERROR([unknown endianness
1527 presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1534 # Do nothing if the compiler accepts the inline keyword.
1535 # Otherwise define inline to __inline__ or __inline if one of those work,
1536 # otherwise define inline to be empty.
1538 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1539 # inline function, only builtin types.
1541 AN_IDENTIFIER([inline], [AC_C_INLINE])
1542 AC_DEFUN([AC_C_INLINE],
1543 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1545 for ac_kw in inline __inline__ __inline; do
1546 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1547 [#ifndef __cplusplus
1549 static $ac_kw foo_t static_foo () {return 0; }
1550 $ac_kw foo_t foo () {return 0; }
1553 [ac_cv_c_inline=$ac_kw])
1554 test "$ac_cv_c_inline" != no && break
1557 AH_VERBATIM([inline],
1558 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1559 calls it, or to nothing if 'inline' is not supported under any name. */
1563 case $ac_cv_c_inline in
1566 case $ac_cv_c_inline in
1568 *) ac_val=$ac_cv_c_inline;;
1570 cat >>confdefs.h <<_ACEOF
1572 #define inline $ac_val
1582 AC_DEFUN([AC_C_CONST],
1583 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1584 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1585 [[/* FIXME: Include the comments suggested by Paul. */
1587 /* Ultrix mips cc rejects this. */
1588 typedef int charset[2];
1590 /* SunOS 4.1.1 cc rejects this. */
1591 char const *const *pcpcc;
1593 /* NEC SVR4.0.2 mips cc rejects this. */
1594 struct point {int x, y;};
1595 static struct point const zero = {0,0};
1596 /* AIX XL C 1.02.0.0 rejects this.
1597 It does not let you subtract one const X* pointer from another in
1598 an arm of an if-expression whose if-part is not a constant
1600 const char *g = "string";
1601 pcpcc = &g + (g ? g-g : 0);
1602 /* HPUX 7.0 cc rejects these. */
1604 ppc = (char**) pcpcc;
1605 pcpcc = (char const *const *) ppc;
1606 { /* SCO 3.2v4 cc rejects this. */
1608 char const *s = 0 ? (char *) 0 : (char const *) 0;
1613 { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
1615 const int *foo = &x[0];
1618 { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1619 typedef const int *iptr;
1623 { /* AIX XL C 1.02.0.0 rejects this saying
1624 "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1625 struct s { int j; const int *ap[3]; };
1626 struct s *b; b->j = 5;
1628 { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1632 return !cs[0] && !zero.x;
1635 [ac_cv_c_const=yes],
1636 [ac_cv_c_const=no])])
1637 if test $ac_cv_c_const = no; then
1639 [Define to empty if `const' does not conform to ANSI C.])
1646 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1647 # http://autoconf-archive.cryp.to/acx_restrict.html
1649 # Determine whether the C/C++ compiler supports the "restrict" keyword
1650 # introduced in ANSI C99, or an equivalent. Define "restrict" to the alternate
1651 # spelling, if any; these are more likely to work in both C and C++ compilers of
1652 # the same family, and in the presence of varying compiler options. If only
1653 # plain "restrict" works, do nothing. Here are some variants:
1654 # - GCC supports both __restrict and __restrict__
1655 # - older DEC Alpha C compilers support only __restrict
1656 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1657 # Otherwise, define "restrict" to be empty.
1658 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1659 AC_DEFUN([AC_C_RESTRICT],
1660 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1661 [ac_cv_c_restrict=no
1662 # Try the official restrict keyword, then gcc's __restrict, and
1663 # the less common variants.
1664 for ac_kw in __restrict __restrict__ _Restrict restrict; do
1665 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1666 [[typedef int * int_ptr;
1667 int foo (int_ptr $ac_kw ip) {
1674 [ac_cv_c_restrict=$ac_kw])
1675 test "$ac_cv_c_restrict" != no && break
1678 case $ac_cv_c_restrict in
1680 no) AC_DEFINE(restrict,,
1681 [Define to equivalent of C99 restrict keyword, or to nothing if this
1682 is not supported. Do not define if restrict is supported directly.]) ;;
1683 *) AC_DEFINE_UNQUOTED(restrict, $ac_cv_c_restrict) ;;
1690 # Note that, unlike const, #defining volatile to be the empty string can
1691 # actually turn a correct program into an incorrect one, since removing
1692 # uses of volatile actually grants the compiler permission to perform
1693 # optimizations that could break the user's code. So, do not #define
1694 # volatile away unless it is really necessary to allow the user's code
1695 # to compile cleanly. Benign compiler failures should be tolerated.
1696 AC_DEFUN([AC_C_VOLATILE],
1697 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1698 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1700 int * volatile y = (int *) 0;
1701 return !x && !y;])],
1702 [ac_cv_c_volatile=yes],
1703 [ac_cv_c_volatile=no])])
1704 if test $ac_cv_c_volatile = no; then
1705 AC_DEFINE(volatile,,
1706 [Define to empty if the keyword `volatile' does not work.
1707 Warning: valid code using `volatile' can become incorrect
1708 without. Disable with care.])
1715 # Checks if `#' can be used to glue strings together at the CPP level.
1716 # Defines HAVE_STRINGIZE if positive.
1717 AC_DEFUN([AC_C_STRINGIZE],
1718 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1719 [ac_cv_c_stringize],
1720 [AC_EGREP_CPP([@%:@teststring],
1723 char *s = x(teststring);],
1724 [ac_cv_c_stringize=no],
1725 [ac_cv_c_stringize=yes])])
1726 if test $ac_cv_c_stringize = yes; then
1727 AC_DEFINE(HAVE_STRINGIZE, 1,
1728 [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1735 # Check if the C compiler supports prototypes, included if it needs
1737 AC_DEFUN([AC_C_PROTOTYPES],
1738 [AC_REQUIRE([AC_PROG_CC])dnl
1739 AC_MSG_CHECKING([for function prototypes])
1740 if test "$ac_cv_prog_cc_c89" != no; then
1741 AC_MSG_RESULT([yes])
1742 AC_DEFINE(PROTOTYPES, 1,
1743 [Define to 1 if the C compiler supports function prototypes.])
1744 AC_DEFINE(__PROTOTYPES, 1,
1745 [Define like PROTOTYPES; this can be used by system headers.])
1752 # AC_C_FLEXIBLE_ARRAY_MEMBER
1753 # --------------------------
1754 # Check whether the C compiler supports flexible array members.
1755 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1757 AC_CACHE_CHECK([for flexible array members],
1761 [[#include <stdlib.h>
1764 struct s { int n; double d[]; };]],
1765 [[int m = getchar ();
1766 struct s *p = malloc (offsetof (struct s, d)
1767 + m * sizeof (double));
1769 return p->d != (double *) NULL;]])],
1770 [ac_cv_c_flexmember=yes],
1771 [ac_cv_c_flexmember=no])])
1772 if test $ac_cv_c_flexmember = yes; then
1773 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1774 [Define to nothing if C supports flexible array members, and to
1775 1 if it does not. That way, with a declaration like `struct s
1776 { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1777 can be used with pre-C99 compilers.
1778 When computing the size of such an object, don't use 'sizeof (struct s)'
1779 as it overestimates the size. Use 'offsetof (struct s, d)' instead.
1780 Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1781 MSVC and with C++ compilers.])
1783 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1790 # Check whether the C compiler supports variable-length arrays.
1791 AC_DEFUN([AC_C_VARARRAYS],
1793 AC_CACHE_CHECK([for variable-length arrays],
1796 [AC_LANG_PROGRAM([],
1797 [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1798 [ac_cv_c_vararrays=yes],
1799 [ac_cv_c_vararrays=no])])
1800 if test $ac_cv_c_vararrays = yes; then
1801 AC_DEFINE([HAVE_C_VARARRAYS], 1,
1802 [Define to 1 if C supports variable-length arrays.])
1809 # Check if the C compiler supports GCC's typeof syntax.
1810 # The test case provokes incompatibilities in the Sun C compilers
1811 # (both Solaris 8 and Solaris 10).
1812 AC_DEFUN([AC_C_TYPEOF],
1814 AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1816 for ac_kw in typeof __typeof__ no; do
1817 test $ac_kw = no && break
1818 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1823 + ! (($ac_kw (value))
1824 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1825 ? ($ac_kw (value)) - 1
1826 : ~ (~ ($ac_kw (value)) 0
1827 << sizeof ($ac_kw (value)))))]; }
1830 (! ((void) ((ac__typeof_type_ *) 0), 0));
1832 [ac_cv_c_typeof=$ac_kw])
1833 test $ac_cv_c_typeof != no && break
1835 if test $ac_cv_c_typeof != no; then
1836 AC_DEFINE([HAVE_TYPEOF], 1,
1837 [Define to 1 if typeof works with your compiler.])
1838 if test $ac_cv_c_typeof != typeof; then
1839 AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1840 [Define to __typeof__ if your compiler spells it that way.])
1848 # Check which options need to be passed to the C compiler to support OpenMP.
1849 # Set the OPENMP_CFLAGS variable to these options.
1850 # The options are necessary at compile time (so the #pragmas are understood)
1851 # and at link time (so the appropriate library is linked with).
1852 # This macro takes care to not produce redundant options if $CC $CFLAGS already
1853 # supports OpenMP. It also is careful to not pass options to compilers that
1854 # misinterpret them; for example, most compilers accept "-openmp" and create
1855 # an output file called 'penmp' rather than activating OpenMP support.
1856 AC_DEFUN([AC_C_OPENMP],
1858 AC_MSG_CHECKING([whether to use OpenMP])
1859 AC_ARG_ENABLE(openmp,
1860 [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])],
1862 [enable_openmp=yes])
1863 AC_MSG_RESULT([$enable_openmp])
1865 if test "$enable_openmp" = yes; then
1866 AC_MSG_CHECKING([for $CC option to support OpenMP])
1867 AC_CACHE_VAL([ac_cv_prog_cc_openmp], [
1868 ac_cv_prog_cc_openmp=unsupported
1874 int main () { return omp_get_num_threads (); }
1875 ], [ac_cv_prog_cc_openmp="none needed"])
1876 if test "$ac_cv_prog_cc_openmp" = unsupported; then
1877 dnl Try these flags:
1878 dnl GCC >= 4.2 -fopenmp
1879 dnl SunPRO C -xopenmp
1881 dnl SGI C, PGI C -mp
1882 dnl Tru64 Compaq C -omp
1883 dnl IBM C (AIX, Linux) -qsmp=omp
1884 for brand in GCC SunPRO Intel SGI/PGI Compaq IBM; do
1887 ac_conditional='defined __GNUC__'
1888 ac_option='-fopenmp' ;;
1890 ac_conditional='defined __SUNPRO_C || defined __SUNPRO_CC'
1891 ac_option='-xopenmp' ;;
1893 ac_conditional='defined __INTEL_COMPILER'
1894 ac_option='-openmp' ;;
1896 ac_conditional='defined __sgi || defined __PGI || defined __PGIC__'
1899 ac_conditional='defined __DECC || defined __DECCXX'
1902 ac_conditional='defined __xlc__ || defined __xlC__'
1903 ac_option='-qsmp=omp' ;;
1905 if test $brand = GCC; then
1906 if test "$GCC" = yes; then
1907 ac_openmp_result=yes
1912 AC_EGREP_CPP([Brand], [
1916 ], [ac_openmp_result=yes], [ac_openmp_result=no])
1918 if test $ac_openmp_result = yes; then
1919 ac_save_CFLAGS=$CFLAGS
1920 CFLAGS="$CFLAGS $ac_option"
1926 int main () { return omp_get_num_threads (); }
1927 ], [ac_cv_prog_cc_openmp=$ac_option])
1928 CFLAGS=$ac_save_CFLAGS
1934 AC_MSG_RESULT([$ac_cv_prog_cc_openmp])
1935 case $ac_cv_prog_cc_openmp in
1936 "none needed" | unsupported)
1939 OPENMP_CFLAGS=$ac_cv_prog_cc_openmp ;;
1942 AC_SUBST([OPENMP_CFLAGS])