1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free
4 # Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
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)
1305 dnl Intel ICC -std=c99, -c99 (deprecated)
1307 dnl Solaris -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
1308 dnl as it incorrectly assumes C99 semantics for library functions)
1310 dnl with extended modes being tried first.
1311 [[-std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
1317 AC_DEFUN([AC_PROG_CC_C89],
1318 [ AC_REQUIRE([AC_PROG_CC])dnl
1325 AC_DEFUN([AC_PROG_CC_C99],
1326 [ AC_REQUIRE([AC_PROG_CC])dnl
1333 AC_DEFUN([AC_PROG_CC_STDC],
1334 [ AC_REQUIRE([AC_PROG_CC])dnl
1335 AS_CASE([$ac_cv_prog_cc_stdc],
1336 [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
1337 [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1338 [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
1339 [ac_cv_prog_cc_stdc=no])])])dnl
1340 AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1341 AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1342 AS_CASE([$ac_cv_prog_cc_stdc],
1343 [no], [AC_MSG_RESULT([unsupported])],
1344 [''], [AC_MSG_RESULT([none needed])],
1345 [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
1351 AC_DEFUN([AC_C_BACKSLASH_A],
1353 AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1354 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1359 char buf['\a' == 'a' ? -1 : 1];
1361 return buf[0] != "\a"[0];
1363 [ac_cv_c_backslash_a=yes],
1364 [ac_cv_c_backslash_a=no])])
1365 if test $ac_cv_c_backslash_a = yes; then
1366 AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1367 [Define if backslash-a works in C strings.])
1374 # Has been merged into AC_PROG_CC.
1375 AU_DEFUN([AC_C_CROSS], [])
1378 # AC_C_CHAR_UNSIGNED
1379 # ------------------
1380 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1381 [AH_VERBATIM([__CHAR_UNSIGNED__],
1382 [/* Define to 1 if type `char' is unsigned and you are not using gcc. */
1383 #ifndef __CHAR_UNSIGNED__
1384 # undef __CHAR_UNSIGNED__
1386 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1387 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1388 [((char) -1) < 0])],
1389 ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1390 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1391 AC_DEFINE(__CHAR_UNSIGNED__)
1393 ])# AC_C_CHAR_UNSIGNED
1396 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1397 # [ACTION-IF-UNIVERSAL])
1398 # -------------------------------------------------------------------------
1399 AC_DEFUN([AC_C_BIGENDIAN],
1400 [AH_VERBATIM([WORDS_BIGENDIAN],
1401 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1402 significant byte first (like Motorola and SPARC, unlike Intel). */
1403 #if defined AC_APPLE_UNIVERSAL_BUILD
1404 # if defined __BIG_ENDIAN__
1405 # define WORDS_BIGENDIAN 1
1408 # ifndef WORDS_BIGENDIAN
1409 # undef WORDS_BIGENDIAN
1412 AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1413 [ac_cv_c_bigendian=unknown
1414 # See if we're dealing with a universal compiler.
1417 [[#ifndef __APPLE_CC__
1418 not a universal capable compiler
1423 # Check for potential -arch flags. It is not universal unless
1424 # there are some -arch flags. Note that *ppc* also matches
1425 # ppc64. This check is also rather less than ideal.
1426 case "${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}" in #(
1427 *-arch*ppc*|*-arch*i386*|*-arch*x86_64*) ac_cv_c_bigendian=universal;;
1429 if test $ac_cv_c_bigendian = unknown; then
1430 # See if sys/param.h defines the BYTE_ORDER macro.
1433 [[#include <sys/types.h>
1434 #include <sys/param.h>
1436 [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1437 && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1442 [# It does; now see whether it defined to BIG_ENDIAN or not.
1445 [[#include <sys/types.h>
1446 #include <sys/param.h>
1448 [[#if BYTE_ORDER != BIG_ENDIAN
1452 [ac_cv_c_bigendian=yes],
1453 [ac_cv_c_bigendian=no])])
1455 if test $ac_cv_c_bigendian = unknown; then
1456 # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1459 [[#include <limits.h>
1461 [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1465 [# It does; now see whether it defined to _BIG_ENDIAN or not.
1468 [[#include <limits.h>
1470 [[#ifndef _BIG_ENDIAN
1474 [ac_cv_c_bigendian=yes],
1475 [ac_cv_c_bigendian=no])])
1477 if test $ac_cv_c_bigendian = unknown; then
1478 # Compile a test program.
1480 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1482 /* Are we little or big endian? From Harbison&Steele. */
1486 char c[sizeof (long int)];
1489 return u.c[sizeof (long int) - 1] == 1;
1491 [ac_cv_c_bigendian=no],
1492 [ac_cv_c_bigendian=yes],
1493 [# Try to guess by grepping values from an object file.
1496 [[short int ascii_mm[] =
1497 { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1498 short int ascii_ii[] =
1499 { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1500 int use_ascii (int i) {
1501 return ascii_mm[i] + ascii_ii[i];
1503 short int ebcdic_ii[] =
1504 { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1505 short int ebcdic_mm[] =
1506 { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1507 int use_ebcdic (int i) {
1508 return ebcdic_mm[i] + ebcdic_ii[i];
1512 [[return use_ascii (foo) == use_ebcdic (foo);]])],
1513 [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1514 ac_cv_c_bigendian=yes
1516 if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1517 if test "$ac_cv_c_bigendian" = unknown; then
1518 ac_cv_c_bigendian=no
1520 # finding both strings is unlikely to happen, but who knows?
1521 ac_cv_c_bigendian=unknown
1525 case $ac_cv_c_bigendian in #(
1528 [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1532 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
1533 dnl this is a necessity for proper config header operation. Warn if
1534 dnl the user did not specify a config header but is relying on the
1535 dnl default behavior for universal builds.
1537 [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
1538 [AC_DIAGNOSE([obsolete],
1539 [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
1540 AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
1541 [Define if building universal (internal helper macro)])])
1545 [AC_MSG_ERROR([unknown endianness
1546 presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1553 # Do nothing if the compiler accepts the inline keyword.
1554 # Otherwise define inline to __inline__ or __inline if one of those work,
1555 # otherwise define inline to be empty.
1557 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1558 # inline function, only builtin types.
1560 AN_IDENTIFIER([inline], [AC_C_INLINE])
1561 AC_DEFUN([AC_C_INLINE],
1562 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1564 for ac_kw in inline __inline__ __inline; do
1565 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1566 [#ifndef __cplusplus
1568 static $ac_kw foo_t static_foo () {return 0; }
1569 $ac_kw foo_t foo () {return 0; }
1572 [ac_cv_c_inline=$ac_kw])
1573 test "$ac_cv_c_inline" != no && break
1576 AH_VERBATIM([inline],
1577 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1578 calls it, or to nothing if 'inline' is not supported under any name. */
1582 case $ac_cv_c_inline in
1585 case $ac_cv_c_inline in
1587 *) ac_val=$ac_cv_c_inline;;
1589 cat >>confdefs.h <<_ACEOF
1591 #define inline $ac_val
1601 AC_DEFUN([AC_C_CONST],
1602 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1603 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1604 [[/* FIXME: Include the comments suggested by Paul. */
1606 /* Ultrix mips cc rejects this. */
1607 typedef int charset[2];
1609 /* SunOS 4.1.1 cc rejects this. */
1610 char const *const *pcpcc;
1612 /* NEC SVR4.0.2 mips cc rejects this. */
1613 struct point {int x, y;};
1614 static struct point const zero = {0,0};
1615 /* AIX XL C 1.02.0.0 rejects this.
1616 It does not let you subtract one const X* pointer from another in
1617 an arm of an if-expression whose if-part is not a constant
1619 const char *g = "string";
1620 pcpcc = &g + (g ? g-g : 0);
1621 /* HPUX 7.0 cc rejects these. */
1623 ppc = (char**) pcpcc;
1624 pcpcc = (char const *const *) ppc;
1625 { /* SCO 3.2v4 cc rejects this. */
1627 char const *s = 0 ? (char *) 0 : (char const *) 0;
1632 { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
1634 const int *foo = &x[0];
1637 { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1638 typedef const int *iptr;
1642 { /* AIX XL C 1.02.0.0 rejects this saying
1643 "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1644 struct s { int j; const int *ap[3]; };
1645 struct s *b; b->j = 5;
1647 { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1651 return !cs[0] && !zero.x;
1654 [ac_cv_c_const=yes],
1655 [ac_cv_c_const=no])])
1656 if test $ac_cv_c_const = no; then
1658 [Define to empty if `const' does not conform to ANSI C.])
1665 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1666 # http://autoconf-archive.cryp.to/acx_restrict.html
1668 # Determine whether the C/C++ compiler supports the "restrict" keyword
1669 # introduced in ANSI C99, or an equivalent. Define "restrict" to the alternate
1670 # spelling, if any; these are more likely to work in both C and C++ compilers of
1671 # the same family, and in the presence of varying compiler options. If only
1672 # plain "restrict" works, do nothing. Here are some variants:
1673 # - GCC supports both __restrict and __restrict__
1674 # - older DEC Alpha C compilers support only __restrict
1675 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1676 # Otherwise, define "restrict" to be empty.
1677 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1678 AC_DEFUN([AC_C_RESTRICT],
1679 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1680 [ac_cv_c_restrict=no
1681 # The order here caters to the fact that C++ does not require restrict.
1682 for ac_kw in __restrict __restrict__ _Restrict restrict; do
1683 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1684 [[typedef int * int_ptr;
1685 int foo (int_ptr $ac_kw ip) {
1692 [ac_cv_c_restrict=$ac_kw])
1693 test "$ac_cv_c_restrict" != no && break
1696 AH_VERBATIM([restrict],
1697 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1698 nothing if this is not supported. Do not define if restrict is
1699 supported directly. */
1701 /* Work around a bug in Sun C++: it does not support _Restrict, even
1702 though the corresponding Sun C compiler does, which causes
1703 "#define restrict _Restrict" in the previous line. Perhaps some future
1704 version of Sun C++ will work with _Restrict; if so, it'll probably
1705 define __RESTRICT, just as Sun C does. */
1706 #if defined __SUNPRO_CC && !defined __RESTRICT
1709 case $ac_cv_c_restrict in
1711 no) AC_DEFINE([restrict], []) ;;
1712 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1719 # Note that, unlike const, #defining volatile to be the empty string can
1720 # actually turn a correct program into an incorrect one, since removing
1721 # uses of volatile actually grants the compiler permission to perform
1722 # optimizations that could break the user's code. So, do not #define
1723 # volatile away unless it is really necessary to allow the user's code
1724 # to compile cleanly. Benign compiler failures should be tolerated.
1725 AC_DEFUN([AC_C_VOLATILE],
1726 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1727 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1729 int * volatile y = (int *) 0;
1730 return !x && !y;])],
1731 [ac_cv_c_volatile=yes],
1732 [ac_cv_c_volatile=no])])
1733 if test $ac_cv_c_volatile = no; then
1734 AC_DEFINE(volatile,,
1735 [Define to empty if the keyword `volatile' does not work.
1736 Warning: valid code using `volatile' can become incorrect
1737 without. Disable with care.])
1744 # Checks if `#' can be used to glue strings together at the CPP level.
1745 # Defines HAVE_STRINGIZE if positive.
1746 AC_DEFUN([AC_C_STRINGIZE],
1747 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1748 [ac_cv_c_stringize],
1749 [AC_EGREP_CPP([@%:@teststring],
1752 char *s = x(teststring);],
1753 [ac_cv_c_stringize=no],
1754 [ac_cv_c_stringize=yes])])
1755 if test $ac_cv_c_stringize = yes; then
1756 AC_DEFINE(HAVE_STRINGIZE, 1,
1757 [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1764 # Check if the C compiler supports prototypes, included if it needs
1766 AC_DEFUN([AC_C_PROTOTYPES],
1767 [AC_REQUIRE([AC_PROG_CC])dnl
1768 AC_MSG_CHECKING([for function prototypes])
1769 if test "$ac_cv_prog_cc_c89" != no; then
1770 AC_MSG_RESULT([yes])
1771 AC_DEFINE(PROTOTYPES, 1,
1772 [Define to 1 if the C compiler supports function prototypes.])
1773 AC_DEFINE(__PROTOTYPES, 1,
1774 [Define like PROTOTYPES; this can be used by system headers.])
1781 # AC_C_FLEXIBLE_ARRAY_MEMBER
1782 # --------------------------
1783 # Check whether the C compiler supports flexible array members.
1784 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1786 AC_CACHE_CHECK([for flexible array members],
1790 [[#include <stdlib.h>
1793 struct s { int n; double d[]; };]],
1794 [[int m = getchar ();
1795 struct s *p = malloc (offsetof (struct s, d)
1796 + m * sizeof (double));
1798 return p->d != (double *) NULL;]])],
1799 [ac_cv_c_flexmember=yes],
1800 [ac_cv_c_flexmember=no])])
1801 if test $ac_cv_c_flexmember = yes; then
1802 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1803 [Define to nothing if C supports flexible array members, and to
1804 1 if it does not. That way, with a declaration like `struct s
1805 { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1806 can be used with pre-C99 compilers.
1807 When computing the size of such an object, don't use 'sizeof (struct s)'
1808 as it overestimates the size. Use 'offsetof (struct s, d)' instead.
1809 Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1810 MSVC and with C++ compilers.])
1812 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1819 # Check whether the C compiler supports variable-length arrays.
1820 AC_DEFUN([AC_C_VARARRAYS],
1822 AC_CACHE_CHECK([for variable-length arrays],
1825 [AC_LANG_PROGRAM([],
1826 [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1827 [ac_cv_c_vararrays=yes],
1828 [ac_cv_c_vararrays=no])])
1829 if test $ac_cv_c_vararrays = yes; then
1830 AC_DEFINE([HAVE_C_VARARRAYS], 1,
1831 [Define to 1 if C supports variable-length arrays.])
1838 # Check if the C compiler supports GCC's typeof syntax.
1839 # The test case provokes incompatibilities in the Sun C compilers
1840 # (both Solaris 8 and Solaris 10).
1841 AC_DEFUN([AC_C_TYPEOF],
1843 AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1845 for ac_kw in typeof __typeof__ no; do
1846 test $ac_kw = no && break
1847 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1852 + ! (($ac_kw (value))
1853 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1854 ? ($ac_kw (value)) - 1
1855 : ~ (~ ($ac_kw (value)) 0
1856 << sizeof ($ac_kw (value)))))]; }
1859 (! ((void) ((ac__typeof_type_ *) 0), 0));
1861 [ac_cv_c_typeof=$ac_kw])
1862 test $ac_cv_c_typeof != no && break
1864 if test $ac_cv_c_typeof != no; then
1865 AC_DEFINE([HAVE_TYPEOF], 1,
1866 [Define to 1 if typeof works with your compiler.])
1867 if test $ac_cv_c_typeof != typeof; then
1868 AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1869 [Define to __typeof__ if your compiler spells it that way.])
1877 # Expands to some language dependent source code for testing the presence of
1879 AC_DEFUN([_AC_LANG_OPENMP],
1880 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
1882 # _AC_LANG_OPENMP(C)
1883 # ------------------
1884 m4_define([_AC_LANG_OPENMP(C)],
1890 int main () { return omp_get_num_threads (); }
1893 # _AC_LANG_OPENMP(C++)
1894 # --------------------
1895 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
1897 # _AC_LANG_OPENMP(Fortran 77)
1898 # ---------------------------
1899 m4_define([_AC_LANG_OPENMP(Fortran 77)],
1900 [AC_LANG_FUNC_LINK_TRY([omp_get_num_threads])])
1902 # _AC_LANG_OPENMP(Fortran)
1903 # ---------------------------
1904 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
1908 # Check which options need to be passed to the C compiler to support OpenMP.
1909 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
1911 # The options are necessary at compile time (so the #pragmas are understood)
1912 # and at link time (so the appropriate library is linked with).
1913 # This macro takes care to not produce redundant options if $CC $CFLAGS already
1914 # supports OpenMP. It also is careful to not pass options to compilers that
1915 # misinterpret them; for example, most compilers accept "-openmp" and create
1916 # an output file called 'penmp' rather than activating OpenMP support.
1917 AC_DEFUN([AC_OPENMP],
1919 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
1920 AC_ARG_ENABLE([openmp],
1921 [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
1922 if test "$enable_openmp" != no; then
1923 AC_CACHE_CHECK([for $CC option to support OpenMP],
1924 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
1925 [AC_LINK_IFELSE([_AC_LANG_OPENMP],
1926 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
1927 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
1928 dnl Try these flags:
1929 dnl GCC >= 4.2 -fopenmp
1930 dnl SunPRO C -xopenmp
1932 dnl SGI C, PGI C -mp
1933 dnl Tru64 Compaq C -omp
1934 dnl IBM C (AIX, Linux) -qsmp=omp
1935 dnl If in this loop a compiler is passed an option that it doesn't
1936 dnl understand or that it misinterprets, the AC_LINK_IFELSE test
1937 dnl will fail (since we know that it failed without the option),
1938 dnl therefore the loop will continue searching for an option, and
1939 dnl no output file called 'penmp' or 'mp' is created.
1940 for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
1941 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
1942 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
1943 AC_LINK_IFELSE([_AC_LANG_OPENMP],
1944 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
1945 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
1946 if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
1950 case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
1951 "none needed" | unsupported)
1954 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
1957 AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])