1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 # 2010 Free Software Foundation, Inc.
6 # This file is part of Autoconf. This program is free
7 # software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the
9 # Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # Under Section 7 of GPL version 3, you are granted additional
18 # permissions described in the Autoconf Configure Script Exception,
19 # version 3.0, as published by the Free Software Foundation.
21 # You should have received a copy of the GNU General Public License
22 # and a copy of the Autoconf Configure Script Exception along with
23 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
24 # respectively. If not, see <http://www.gnu.org/licenses/>.
26 # Written by David MacKenzie, with help from
27 # Akim Demaille, Paul Eggert,
28 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
29 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
34 # 1. Language selection
35 # 2. and routines to produce programs in a given language.
41 # 3. Looking for a compiler
42 # And possibly the associated preprocessor.
43 # 3a. C 3b. C++ 3c. Objective C 3d. Objective C++
45 # 4. Compilers' characteristics.
50 ## ----------------------- ##
51 ## 1a/2a. The C language. ##
52 ## ----------------------- ##
55 # ------------------------ #
56 # 1a. Language selection. #
57 # ------------------------ #
61 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
62 AC_LANG_DEFINE([C], [c], [C], [CC], [],
64 ac_cpp='$CPP $CPPFLAGS'
65 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
66 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
67 ac_compiler_gnu=$ac_cv_c_compiler_gnu
73 AU_DEFUN([AC_LANG_C], [AC_LANG(C)])
76 # ------------------------ #
77 # 2a. Producing programs. #
78 # ------------------------ #
81 # AC_LANG_CONFTEST(C)(BODY)
82 # -----------------------
83 # We can't use '#line $LINENO "configure"' here, since
84 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
85 # rejects $LINENO greater than 32767, and some configure scripts
86 # are longer than 32767 lines.
87 m4_define([AC_LANG_CONFTEST(C)],
88 [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
94 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
95 # --------------------------------------
96 m4_define([AC_LANG_PROGRAM(C)],
98 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
99 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
103 dnl Do *not* indent the following line: there may be CPP directives.
104 dnl Don't move the `;' right after for the same reason.
111 # _AC_LANG_IO_PROGRAM(C)
112 # ----------------------
113 # Produce source that performs I/O, necessary for proper
114 # cross-compiler detection.
115 m4_define([_AC_LANG_IO_PROGRAM(C)],
116 [AC_LANG_PROGRAM([@%:@include <stdio.h>],
117 [FILE *f = fopen ("conftest.out", "w");
118 return ferror (f) || fclose (f) != 0;
122 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
123 # -----------------------------------
124 # Avoid conflicting decl of main.
125 m4_define([AC_LANG_CALL(C)],
127 m4_if([$2], [main], ,
128 [/* Override any GCC internal prototype to avoid an error.
129 Use char because int might match the return type of a GCC
130 builtin and then its argument prototype would still apply. */
134 char $2 ();])], [return $2 ();])])
137 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
138 # ----------------------------------
139 # Don't include <ctype.h> because on OSF/1 3.0 it includes
140 # <sys/types.h> which includes <sys/select.h> which contains a
141 # prototype for select. Similarly for bzero.
143 # This test used to merely assign f=$1 in main(), but that was
144 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
145 # presumably on the basis that there's no need to do that store if the
146 # program is about to exit. Conversely, the AIX linker optimizes an
147 # unused external declaration that initializes f=$1. So this test
148 # program has both an external initialization of f, and a use of f in
149 # main that affects the exit status.
151 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
153 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
154 For example, HP-UX 11i <limits.h> declares gettimeofday. */
155 #define $1 innocuous_$1
157 /* System header to define __stub macros and hopefully few prototypes,
158 which can conflict with char $1 (); below.
159 Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
160 <limits.h> exists even on freestanding compilers. */
170 /* Override any GCC internal prototype to avoid an error.
171 Use char because int might match the return type of a GCC
172 builtin and then its argument prototype would still apply. */
177 /* The GNU C library defines this for functions which it implements
178 to always fail with ENOSYS. Some functions are actually named
179 something starting with __ and the normal name is an alias. */
180 #if defined __stub_$1 || defined __stub___$1
183 ], [return $1 ();])])
186 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
187 # -------------------------------------------------
188 # Return a program that is valid if EXPRESSION is nonzero.
189 # EXPRESSION must be an integer constant expression.
190 # Be sure to use this array to avoid `unused' warnings, which are even
191 # errors with `-W error'.
192 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
193 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
194 test_array @<:@0@:>@ = 0
198 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
199 # -----------------------------------------
200 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
201 # But we include them only after the EXPRESSION has been evaluated.
202 m4_define([AC_LANG_INT_SAVE(C)],
204 static long int longval () { return $2; }
205 static unsigned long int ulongval () { return $2; }
206 @%:@include <stdio.h>
207 @%:@include <stdlib.h>],
209 FILE *f = fopen ("conftest.val", "w");
214 long int i = longval ();
217 fprintf (f, "%ld", i);
221 unsigned long int i = ulongval ();
224 fprintf (f, "%lu", i);
226 /* Do not output a trailing newline, as this causes \r\n confusion
227 on some platforms. */
228 return ferror (f) || fclose (f) != 0;
233 ## ---------------------- ##
234 ## 1b. The C++ language. ##
235 ## ---------------------- ##
240 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
241 AC_LANG_DEFINE([C++], [cxx], [CXX], [CXX], [C],
243 ac_cpp='$CXXCPP $CPPFLAGS'
244 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
245 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
246 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
252 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
256 ## ------------------------------ ##
257 ## 1c. The Objective C language. ##
258 ## ------------------------------ ##
261 # AC_LANG(Objective C)
262 # --------------------
263 AC_LANG_DEFINE([Objective C], [objc], [OBJC], [OBJC], [C],
265 ac_cpp='$OBJCPP $CPPFLAGS'
266 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
267 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
268 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
274 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
278 ## -------------------------------- ##
279 ## 1d. The Objective C++ language. ##
280 ## -------------------------------- ##
283 # AC_LANG(Objective C++)
284 # ----------------------
285 AC_LANG_DEFINE([Objective C++], [objcxx], [OBJCXX], [OBJCXX], [C++],
287 ac_cpp='$OBJCXXCPP $CPPFLAGS'
288 ac_compile='$OBJCXX -c $OBJCXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
289 ac_link='$OBJCXX -o conftest$ac_exeext $OBJCXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
290 ac_compiler_gnu=$ac_cv_objcxx_compiler_gnu
295 ## -------------------------------------------- ##
296 ## 3. Looking for Compilers and Preprocessors. ##
297 ## -------------------------------------------- ##
299 # -------------------- #
300 # 3a. The C compiler. #
301 # -------------------- #
304 # _AC_ARG_VAR_CPPFLAGS
305 # --------------------
306 # Document and register CPPFLAGS, which is used by
307 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP, OBJCXX, OBJCXXCPP}.
308 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
309 [AC_ARG_VAR([CPPFLAGS],
310 [(Objective) C/C++ preprocessor flags, e.g. -I<include dir>
311 if you have headers in a nonstandard directory <include dir>])])
314 # _AC_ARG_VAR_LDFLAGS
315 # -------------------
316 # Document and register LDFLAGS, which is used by
317 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
318 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
319 [AC_ARG_VAR([LDFLAGS],
320 [linker flags, e.g. -L<lib dir> if you have libraries in a
321 nonstandard directory <lib dir>])])
326 # Document and register LIBS, which is used by
327 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
328 AC_DEFUN([_AC_ARG_VAR_LIBS],
330 [libraries to pass to the linker, e.g. -l<library>])])
334 # -------------------
335 # Find the C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
336 AC_DEFUN([AC_LANG_PREPROC(C)],
337 [AC_REQUIRE([AC_PROG_CPP])])
340 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
341 # -----------------------------------------------
342 # Check if $ac_cpp is a working preprocessor that can flag absent
343 # includes either by the exit status or by warnings.
344 # This macro is for all languages, not only C.
345 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
347 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
349 # Use a header file that comes with gcc, so configuring glibc
350 # with a fresh cross-compiler works.
351 # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
352 # <limits.h> exists even on freestanding compilers.
353 # On the NeXT, cc -E runs the code through the compiler's parser,
354 # not just through cpp. "Syntax error" is here to catch this case.
355 _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@ifdef __STDC__
356 @%:@ include <limits.h>
358 @%:@ include <assert.h>
362 [# Broken: fails on valid input.
365 # OK, works on sane cases. Now check whether nonexistent headers
366 # can be detected and how.
367 _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
368 [# Broken: success on invalid input.
370 [# Passes both tests.
375 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
376 rm -f conftest.err conftest.$ac_ext
377 AS_IF([$ac_preproc_ok], [$1], [$2])
378 ])# _AC_PROG_PREPROC_WORKS_IFELSE
383 # Find a working C preprocessor.
384 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
385 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
386 AN_MAKEVAR([CPP], [AC_PROG_CPP])
387 AN_PROGRAM([cpp], [AC_PROG_CPP])
388 AC_DEFUN([AC_PROG_CPP],
389 [AC_REQUIRE([AC_PROG_CC])dnl
390 AC_ARG_VAR([CPP], [C preprocessor])dnl
391 _AC_ARG_VAR_CPPFLAGS()dnl
393 AC_MSG_CHECKING([how to run the C preprocessor])
394 # On Suns, sometimes $CPP names a directory.
395 if test -n "$CPP" && test -d "$CPP"; then
398 if test -z "$CPP"; then
399 AC_CACHE_VAL([ac_cv_prog_CPP],
401 # Double quotes because CPP needs to be expanded
402 for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
404 _AC_PROG_PREPROC_WORKS_IFELSE([break])
412 AC_MSG_RESULT([$CPP])
413 _AC_PROG_PREPROC_WORKS_IFELSE([],
414 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
421 # Treat warnings from the preprocessor as errors.
422 AC_DEFUN([AC_PROG_CPP_WERROR],
423 [AC_REQUIRE([AC_PROG_CPP])dnl
424 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
426 # AC_LANG_COMPILER(C)
427 # -------------------
428 # Find the C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
429 AC_DEFUN([AC_LANG_COMPILER(C)],
430 [AC_REQUIRE([AC_PROG_CC])])
435 # We used to name the cache variable this way.
436 AU_DEFUN([ac_cv_prog_gcc],
437 [ac_cv_c_compiler_gnu])
440 # AC_PROG_CC([COMPILER ...])
441 # --------------------------
442 # COMPILER ... is a space separated list of C compilers to search for.
443 # This just gives the user an opportunity to specify an alternative
444 # search list for the C compiler.
445 AN_MAKEVAR([CC], [AC_PROG_CC])
446 AN_PROGRAM([cc], [AC_PROG_CC])
447 AN_PROGRAM([gcc], [AC_PROG_CC])
448 AC_DEFUN([AC_PROG_CC],
450 AC_ARG_VAR([CC], [C compiler command])dnl
451 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
452 _AC_ARG_VAR_LDFLAGS()dnl
453 _AC_ARG_VAR_LIBS()dnl
454 _AC_ARG_VAR_CPPFLAGS()dnl
456 [AC_CHECK_TOOLS(CC, [$1])],
457 [AC_CHECK_TOOL(CC, gcc)
458 if test -z "$CC"; then
460 dnl AC_CHECK_TOOL(CC, cc)
461 dnl but without the check for a tool without the prefix.
462 dnl Until the check is removed from there, copy the code:
463 if test -n "$ac_tool_prefix"; then
464 AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
467 if test -z "$CC"; then
468 AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
470 if test -z "$CC"; then
471 AC_CHECK_TOOLS(CC, cl.exe)
475 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
477 # Provide some information about the compiler.
478 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
481 for ac_option in --version -v -V -qversion; do
482 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
485 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
486 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
487 _AC_LANG_COMPILER_GNU
488 if test $ac_compiler_gnu = yes; then
501 # Check whether -g works, even if CFLAGS is set, in case the package
502 # plays around with CFLAGS (such as to build both debugging and normal
503 # versions of a library), tasteless as that idea is.
504 # Don't consider -g to work if it generates warnings when plain compiles don't.
505 m4_define([_AC_PROG_CC_G],
506 [ac_test_CFLAGS=${CFLAGS+set}
507 ac_save_CFLAGS=$CFLAGS
508 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
509 [ac_save_c_werror_flag=$ac_c_werror_flag
513 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
514 [ac_cv_prog_cc_g=yes],
516 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
518 [ac_c_werror_flag=$ac_save_c_werror_flag
520 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
521 [ac_cv_prog_cc_g=yes])])])
522 ac_c_werror_flag=$ac_save_c_werror_flag])
523 if test "$ac_test_CFLAGS" = set; then
524 CFLAGS=$ac_save_CFLAGS
525 elif test $ac_cv_prog_cc_g = yes; then
526 if test "$GCC" = yes; then
532 if test "$GCC" = yes; then
541 # AC_PROG_GCC_TRADITIONAL
542 # -----------------------
543 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
544 [AC_REQUIRE([AC_PROG_CC])dnl
545 if test $ac_cv_c_compiler_gnu = yes; then
546 AC_CACHE_CHECK(whether $CC needs -traditional,
547 ac_cv_prog_gcc_traditional,
548 [ ac_pattern="Autoconf.*'x'"
549 AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
551 ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
553 if test $ac_cv_prog_gcc_traditional = no; then
554 AC_EGREP_CPP($ac_pattern, [#include <termio.h>
556 ac_cv_prog_gcc_traditional=yes)
558 if test $ac_cv_prog_gcc_traditional = yes; then
559 CC="$CC -traditional"
562 ])# AC_PROG_GCC_TRADITIONAL
567 AC_DEFUN([AC_PROG_CC_C_O],
568 [AC_REQUIRE([AC_PROG_CC])dnl
569 if test "x$CC" != xcc; then
570 AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
572 AC_MSG_CHECKING([whether cc understands -c and -o together])
574 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
575 sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
576 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
577 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
578 # Make sure it works both with $CC and with simple cc.
579 # We do the test twice because some compilers refuse to overwrite an
580 # existing .o file with -o, though they will create one.
581 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
583 if _AC_DO_VAR(ac_try) &&
584 test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
586 eval ac_cv_prog_cc_${ac_cc}_c_o=yes
587 if test "x$CC" != xcc; then
588 # Test first that cc exists at all.
589 if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
590 ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
592 if _AC_DO_VAR(ac_try) &&
593 test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
598 # cc exists but doesn't like -o.
599 eval ac_cv_prog_cc_${ac_cc}_c_o=no
604 eval ac_cv_prog_cc_${ac_cc}_c_o=no
608 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
612 AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
613 [Define to 1 if your C compiler doesn't accept -c and -o together.])
619 # ---------------------- #
620 # 3b. The C++ compiler. #
621 # ---------------------- #
624 # AC_LANG_PREPROC(C++)
625 # ---------------------
626 # Find the C++ preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
627 AC_DEFUN([AC_LANG_PREPROC(C++)],
628 [AC_REQUIRE([AC_PROG_CXXCPP])])
633 # Find a working C++ preprocessor.
634 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
635 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
636 AC_DEFUN([AC_PROG_CXXCPP],
637 [AC_REQUIRE([AC_PROG_CXX])dnl
638 AC_ARG_VAR([CXXCPP], [C++ preprocessor])dnl
639 _AC_ARG_VAR_CPPFLAGS()dnl
641 AC_MSG_CHECKING([how to run the C++ preprocessor])
642 if test -z "$CXXCPP"; then
643 AC_CACHE_VAL(ac_cv_prog_CXXCPP,
645 # Double quotes because CXXCPP needs to be expanded
646 for CXXCPP in "$CXX -E" "/lib/cpp"
648 _AC_PROG_PREPROC_WORKS_IFELSE([break])
650 ac_cv_prog_CXXCPP=$CXXCPP
652 CXXCPP=$ac_cv_prog_CXXCPP
654 ac_cv_prog_CXXCPP=$CXXCPP
656 AC_MSG_RESULT([$CXXCPP])
657 _AC_PROG_PREPROC_WORKS_IFELSE([],
658 [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
664 # AC_LANG_COMPILER(C++)
665 # ---------------------
666 # Find the C++ compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
667 AC_DEFUN([AC_LANG_COMPILER(C++)],
668 [AC_REQUIRE([AC_PROG_CXX])])
673 # We used to name the cache variable this way.
674 AU_DEFUN([ac_cv_prog_gxx],
675 [ac_cv_cxx_compiler_gnu])
678 # AC_PROG_CXX([LIST-OF-COMPILERS])
679 # --------------------------------
680 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
681 # for (if not specified, a default list is used). This just gives the
682 # user an opportunity to specify an alternative search list for the C++
684 # aCC HP-UX C++ compiler much better than `CC', so test before.
685 # FCC Fujitsu C++ compiler
686 # KCC KAI C++ compiler
688 # xlC_r AIX C Set++ (with support for reentrant code)
690 AN_MAKEVAR([CXX], [AC_PROG_CXX])
691 AN_PROGRAM([CC], [AC_PROG_CXX])
692 AN_PROGRAM([c++], [AC_PROG_CXX])
693 AN_PROGRAM([g++], [AC_PROG_CXX])
694 AC_DEFUN([AC_PROG_CXX],
695 [AC_LANG_PUSH(C++)dnl
696 AC_ARG_VAR([CXX], [C++ compiler command])dnl
697 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
698 _AC_ARG_VAR_LDFLAGS()dnl
699 _AC_ARG_VAR_LIBS()dnl
700 _AC_ARG_VAR_CPPFLAGS()dnl
701 _AC_ARG_VAR_PRECIOUS([CCC])dnl
702 if test -z "$CXX"; then
703 if test -n "$CCC"; then
708 [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
712 # Provide some information about the compiler.
713 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
716 for ac_option in --version -v -V -qversion; do
717 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
720 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
721 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
722 _AC_LANG_COMPILER_GNU
723 if test $ac_compiler_gnu = yes; then
735 # Check whether -g works, even if CXXFLAGS is set, in case the package
736 # plays around with CXXFLAGS (such as to build both debugging and
737 # normal versions of a library), tasteless as that idea is.
738 # Don't consider -g to work if it generates warnings when plain compiles don't.
739 m4_define([_AC_PROG_CXX_G],
740 [ac_test_CXXFLAGS=${CXXFLAGS+set}
741 ac_save_CXXFLAGS=$CXXFLAGS
742 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
743 [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
744 ac_cxx_werror_flag=yes
747 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
748 [ac_cv_prog_cxx_g=yes],
750 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
752 [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
754 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
755 [ac_cv_prog_cxx_g=yes])])])
756 ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
757 if test "$ac_test_CXXFLAGS" = set; then
758 CXXFLAGS=$ac_save_CXXFLAGS
759 elif test $ac_cv_prog_cxx_g = yes; then
760 if test "$GXX" = yes; then
766 if test "$GXX" = yes; then
777 # Test if the C++ compiler accepts the options `-c' and `-o'
778 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
779 AC_DEFUN([AC_PROG_CXX_C_O],
780 [AC_REQUIRE([AC_PROG_CXX])dnl
781 AC_LANG_PUSH([C++])dnl
782 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
783 [ac_cv_prog_cxx_c_o],
784 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
785 # We test twice because some compilers refuse to overwrite an existing
786 # `.o' file with `-o', although they will create one.
787 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
789 if _AC_DO_VAR(ac_try) &&
790 test -f conftest2.$ac_objext &&
791 _AC_DO_VAR(ac_try); then
792 ac_cv_prog_cxx_c_o=yes
794 ac_cv_prog_cxx_c_o=no
797 if test $ac_cv_prog_cxx_c_o = no; then
798 AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
799 [Define to 1 if your C++ compiler doesn't accept
800 -c and -o together.])
802 AC_LANG_POP([C++])dnl
807 # ------------------------------ #
808 # 3c. The Objective C compiler. #
809 # ------------------------------ #
812 # AC_LANG_PREPROC(Objective C)
813 # ----------------------------
814 # Find the Objective C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
815 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
816 [AC_REQUIRE([AC_PROG_OBJCPP])])
821 # Find a working Objective C preprocessor.
822 AC_DEFUN([AC_PROG_OBJCPP],
823 [AC_REQUIRE([AC_PROG_OBJC])dnl
824 AC_ARG_VAR([OBJCPP], [Objective C preprocessor])dnl
825 _AC_ARG_VAR_CPPFLAGS()dnl
826 AC_LANG_PUSH(Objective C)dnl
827 AC_MSG_CHECKING([how to run the Objective C preprocessor])
828 if test -z "$OBJCPP"; then
829 AC_CACHE_VAL(ac_cv_prog_OBJCPP,
831 # Double quotes because OBJCPP needs to be expanded
832 for OBJCPP in "$OBJC -E" "/lib/cpp"
834 _AC_PROG_PREPROC_WORKS_IFELSE([break])
836 ac_cv_prog_OBJCPP=$OBJCPP
838 OBJCPP=$ac_cv_prog_OBJCPP
840 ac_cv_prog_OBJCPP=$OBJCPP
842 AC_MSG_RESULT([$OBJCPP])
843 _AC_PROG_PREPROC_WORKS_IFELSE([],
844 [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
846 AC_LANG_POP(Objective C)dnl
850 # AC_LANG_COMPILER(Objective C)
851 # -----------------------------
852 # Find the Objective C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
853 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
854 [AC_REQUIRE([AC_PROG_OBJC])])
858 # AC_PROG_OBJC([LIST-OF-COMPILERS])
859 # ---------------------------------
860 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
861 # search for (if not specified, a default list is used). This just gives
862 # the user an opportunity to specify an alternative search list for the
863 # Objective C compiler.
864 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
865 # objc David Stes' POC. If you installed this, you likely want it.
866 # cc Native C compiler (for instance, Apple).
868 AN_MAKEVAR([OBJC], [AC_PROG_OBJC])
869 AN_PROGRAM([objcc], [AC_PROG_OBJC])
870 AN_PROGRAM([objc], [AC_PROG_OBJC])
871 AC_DEFUN([AC_PROG_OBJC],
872 [AC_LANG_PUSH(Objective C)dnl
873 AC_ARG_VAR([OBJC], [Objective C compiler command])dnl
874 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
875 _AC_ARG_VAR_LDFLAGS()dnl
876 _AC_ARG_VAR_LIBS()dnl
877 _AC_ARG_VAR_CPPFLAGS()dnl
878 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
880 [m4_default([$1], [gcc objcc objc cc CC])],
882 # Provide some information about the compiler.
883 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
886 for ac_option in --version -v -V -qversion; do
887 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
890 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
891 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
892 _AC_LANG_COMPILER_GNU
893 if test $ac_compiler_gnu = yes; then
899 AC_LANG_POP(Objective C)dnl
905 # Check whether -g works, even if OBJCFLAGS is set, in case the package
906 # plays around with OBJCFLAGS (such as to build both debugging and
907 # normal versions of a library), tasteless as that idea is.
908 # Don't consider -g to work if it generates warnings when plain compiles don't.
909 m4_define([_AC_PROG_OBJC_G],
910 [ac_test_OBJCFLAGS=${OBJCFLAGS+set}
911 ac_save_OBJCFLAGS=$OBJCFLAGS
912 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
913 [ac_save_objc_werror_flag=$ac_objc_werror_flag
914 ac_objc_werror_flag=yes
917 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
918 [ac_cv_prog_objc_g=yes],
920 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
922 [ac_objc_werror_flag=$ac_save_objc_werror_flag
924 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
925 [ac_cv_prog_objc_g=yes])])])
926 ac_objc_werror_flag=$ac_save_objc_werror_flag])
927 if test "$ac_test_OBJCFLAGS" = set; then
928 OBJCFLAGS=$ac_save_OBJCFLAGS
929 elif test $ac_cv_prog_objc_g = yes; then
930 if test "$GOBJC" = yes; then
936 if test "$GOBJC" = yes; then
946 # -------------------------------- #
947 # 3d. The Objective C++ compiler. #
948 # -------------------------------- #
951 # AC_LANG_PREPROC(Objective C++)
952 # ------------------------------
953 # Find the Objective C++ preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
954 AC_DEFUN([AC_LANG_PREPROC(Objective C++)],
955 [AC_REQUIRE([AC_PROG_OBJCXXCPP])])
960 # Find a working Objective C++ preprocessor.
961 AC_DEFUN([AC_PROG_OBJCXXCPP],
962 [AC_REQUIRE([AC_PROG_OBJCXX])dnl
963 AC_ARG_VAR([OBJCXXCPP], [Objective C++ preprocessor])dnl
964 _AC_ARG_VAR_CPPFLAGS()dnl
965 AC_LANG_PUSH(Objective C++)dnl
966 AC_MSG_CHECKING([how to run the Objective C++ preprocessor])
967 if test -z "$OBJCXXCPP"; then
968 AC_CACHE_VAL(ac_cv_prog_OBJCXXCPP,
970 # Double quotes because OBJCXXCPP needs to be expanded
971 for OBJCXXCPP in "$OBJCXX -E" "/lib/cpp"
973 _AC_PROG_PREPROC_WORKS_IFELSE([break])
975 ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
977 OBJCXXCPP=$ac_cv_prog_OBJCXXCPP
979 ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
981 AC_MSG_RESULT([$OBJCXXCPP])
982 _AC_PROG_PREPROC_WORKS_IFELSE([],
983 [AC_MSG_FAILURE([Objective C++ preprocessor "$OBJCXXCPP" fails sanity check])])
984 AC_SUBST(OBJCXXCPP)dnl
985 AC_LANG_POP(Objective C++)dnl
986 ])# AC_PROG_OBJCXXCPP
989 # AC_LANG_COMPILER(Objective C++)
990 # -------------------------------
991 # Find the Objective C++ compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
992 AC_DEFUN([AC_LANG_COMPILER(Objective C++)],
993 [AC_REQUIRE([AC_PROG_OBJCXX])])
997 # AC_PROG_OBJCXX([LIST-OF-COMPILERS])
998 # ---------------------------------
999 # LIST-OF-COMPILERS is a space separated list of Objective C++ compilers to
1000 # search for (if not specified, a default list is used). This just gives
1001 # the user an opportunity to specify an alternative search list for the
1002 # Objective C++ compiler.
1003 # FIXME: this list is pure guesswork
1004 # objc++ StepStone Objective-C++ compiler (also "standard" name for OBJCXX)
1005 # objcxx David Stes' POC. If you installed this, you likely want it.
1006 # c++ Native C++ compiler (for instance, Apple).
1007 # CXX You never know.
1008 AN_MAKEVAR([OBJCXX], [AC_PROG_OBJCXX])
1009 AN_PROGRAM([objcxx], [AC_PROG_OBJCXX])
1010 AC_DEFUN([AC_PROG_OBJCXX],
1011 [AC_LANG_PUSH(Objective C++)dnl
1012 AC_ARG_VAR([OBJCXX], [Objective C++ compiler command])dnl
1013 AC_ARG_VAR([OBJCXXFLAGS], [Objective C++ compiler flags])dnl
1014 _AC_ARG_VAR_LDFLAGS()dnl
1015 _AC_ARG_VAR_LIBS()dnl
1016 _AC_ARG_VAR_CPPFLAGS()dnl
1017 _AC_ARG_VAR_PRECIOUS([OBJCXX])dnl
1018 AC_CHECK_TOOLS(OBJCXX,
1019 [m4_default([$1], [g++ objc++ objcxx c++ CXX])],
1021 # Provide some information about the compiler.
1022 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
1025 for ac_option in --version -v -V -qversion; do
1026 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
1029 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
1030 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
1031 _AC_LANG_COMPILER_GNU
1032 if test $ac_compiler_gnu = yes; then
1038 AC_LANG_POP(Objective C++)dnl
1044 # Check whether -g works, even if OBJCFLAGS is set, in case the package
1045 # plays around with OBJCFLAGS (such as to build both debugging and
1046 # normal versions of a library), tasteless as that idea is.
1047 # Don't consider -g to work if it generates warnings when plain compiles don't.
1048 m4_define([_AC_PROG_OBJCXX_G],
1049 [ac_test_OBJCXXFLAGS=${OBJCXXFLAGS+set}
1050 ac_save_OBJCXXFLAGS=$OBJCXXFLAGS
1051 AC_CACHE_CHECK(whether $OBJCXX accepts -g, ac_cv_prog_objcxx_g,
1052 [ac_save_objcxx_werror_flag=$ac_objcxx_werror_flag
1053 ac_objcxx_werror_flag=yes
1054 ac_cv_prog_objcxx_g=no
1056 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1057 [ac_cv_prog_objcxx_g=yes],
1059 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1061 [ac_objcxx_werror_flag=$ac_save_objcxx_werror_flag
1063 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1064 [ac_cv_prog_objcxx_g=yes])])])
1065 ac_objcxx_werror_flag=$ac_save_objcx_werror_flag])
1066 if test "$ac_test_OBJCXXFLAGS" = set; then
1067 OBJCXXFLAGS=$ac_save_OBJCXXFLAGS
1068 elif test $ac_cv_prog_objcxx_g = yes; then
1069 if test "$GOBJCXX" = yes; then
1070 OBJCXXFLAGS="-g -O2"
1075 if test "$GOBJCXX" = yes; then
1081 ])# _AC_PROG_OBJCXX_G
1085 ## ------------------------------- ##
1086 ## 4. Compilers' characteristics. ##
1087 ## ------------------------------- ##
1089 # -------------------------------- #
1090 # 4a. C compiler characteristics. #
1091 # -------------------------------- #
1094 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1095 # ----------------------------------------------------------------
1096 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1097 # to add an option to output variable CC to make it so. This macro
1098 # tries various options that select ANSI C89 on some system or
1099 # another. It considers the compiler to be in ANSI C89 mode if it
1100 # handles function prototypes correctly.
1101 AC_DEFUN([_AC_PROG_CC_C89],
1102 [_AC_C_STD_TRY([c89],
1103 [[#include <stdarg.h>
1105 #include <sys/types.h>
1106 #include <sys/stat.h>
1107 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
1108 struct buf { int x; };
1109 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1110 static char *e (p, i)
1116 static char *f (char * (*g) (char **, int), char **p, ...)
1121 s = g (p, va_arg (v,int));
1126 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
1127 function prototypes and stuff, but not '\xHH' hex character constants.
1128 These don't provoke an error unfortunately, instead are silently treated
1129 as 'x'. The following induces an error, until -std is added to get
1130 proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
1131 array size at least. It's necessary to write '\x00'==0 to get something
1132 that's true only with -std. */
1133 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1135 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1136 inside strings and character constants. */
1138 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1140 int test (int i, double x);
1141 struct s1 {int (*f) (int a);};
1142 struct s2 {int (*f) (double a);};
1143 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1146 [[return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];]],
1147 dnl Don't try gcc -ansi; that turns off useful extensions and
1148 dnl breaks some systems' header files.
1149 dnl AIX circa 2003 -qlanglvl=extc89
1150 dnl old AIX -qlanglvl=ansi
1151 dnl Ultrix, OSF/1, Tru64 -std
1152 dnl HP-UX 10.20 and later -Ae
1153 dnl HP-UX older versions -Aa -D_HPUX_SOURCE
1154 dnl SVR4 -Xc -D__EXTENSIONS__
1155 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1156 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1160 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1161 # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1162 # --------------------------------------------------------------
1163 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1164 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
1165 # try again with each compiler option in the space-separated OPTION-LIST; if one
1166 # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
1167 # else ACTION-IF-UNAVAILABLE.
1168 AC_DEFUN([_AC_C_STD_TRY],
1169 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
1170 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1171 [ac_cv_prog_cc_$1=no
1173 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1176 CC="$ac_save_CC $ac_arg"
1177 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1178 test "x$ac_cv_prog_cc_$1" != "xno" && break
1180 rm -f conftest.$ac_ext
1183 case "x$ac_cv_prog_cc_$1" in
1185 AC_MSG_RESULT([none needed]) ;;
1187 AC_MSG_RESULT([unsupported]) ;;
1189 CC="$CC $ac_cv_prog_cc_$1"
1190 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1192 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1196 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1197 # ----------------------------------------------------------------
1198 # If the C compiler is not in ISO C99 mode by default, try to add an
1199 # option to output variable CC to make it so. This macro tries
1200 # various options that select ISO C99 on some system or another. It
1201 # considers the compiler to be in ISO C99 mode if it handles _Bool,
1202 # // comments, flexible array members, inline, long long int, mixed
1203 # code and declarations, named initialization of structs, restrict,
1204 # va_copy, varargs macros, variable declarations in for loops and
1205 # variable length arrays.
1206 AC_DEFUN([_AC_PROG_CC_C99],
1207 [_AC_C_STD_TRY([c99],
1208 [[#include <stdarg.h>
1209 #include <stdbool.h>
1214 // Check varargs macros. These examples are taken from C99 6.10.3.5.
1215 #define debug(...) fprintf (stderr, __VA_ARGS__)
1216 #define showlist(...) puts (#__VA_ARGS__)
1217 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1219 test_varargs_macros (void)
1224 debug ("X = %d\n", x);
1225 showlist (The first, second, and third items.);
1226 report (x>y, "x is %d but y is %d", x, y);
1229 // Check long long types.
1230 #define BIG64 18446744073709551615ull
1231 #define BIG32 4294967295ul
1232 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1234 your preprocessor is broken;
1238 your preprocessor is broken;
1240 static long long int bignum = -9223372036854775807LL;
1241 static unsigned long long int ubignum = BIG64;
1243 struct incomplete_array
1251 const wchar_t *name;
1255 typedef const char *ccp;
1258 test_restrict (ccp restrict text)
1260 // See if C++-style comments work.
1261 // Iterate through items via the restricted pointer.
1262 // Also check for declarations in for loops.
1263 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
1268 // Check varargs and va_copy.
1270 test_varargs (const char *format, ...)
1273 va_start (args, format);
1275 va_copy (args_copy, args);
1286 str = va_arg (args_copy, const char *);
1289 number = va_arg (args_copy, int);
1292 fnumber = va_arg (args_copy, double);
1304 _Bool success = false;
1307 if (test_restrict ("String literal") == 0)
1309 char *restrict newvar = "Another string";
1312 test_varargs ("s, d' f .", "string", 65, 34.234);
1313 test_varargs_macros ();
1315 // Check flexible array members.
1316 struct incomplete_array *ia =
1317 malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1319 for (int i = 0; i < ia->datasize; ++i)
1320 ia->data[i] = i * 1.234;
1322 // Check named initializers.
1323 struct named_init ni = {
1325 .name = L"Test wide string",
1326 .average = 543.34343,
1331 int dynamic_array[ni.number];
1332 dynamic_array[ni.number - 1] = 543;
1334 // work around unused variable warnings
1335 return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
1336 || dynamic_array[ni.number - 1] != 543);
1339 dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1340 dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
1342 dnl Intel ICC -std=c99, -c99 (deprecated)
1344 dnl Solaris -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
1345 dnl as it incorrectly assumes C99 semantics for library functions)
1347 dnl with extended modes being tried first.
1348 [[-std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
1354 AC_DEFUN([AC_PROG_CC_C89],
1355 [ AC_REQUIRE([AC_PROG_CC])dnl
1362 AC_DEFUN([AC_PROG_CC_C99],
1363 [ AC_REQUIRE([AC_PROG_CC])dnl
1370 AC_DEFUN([AC_PROG_CC_STDC],
1371 [ AC_REQUIRE([AC_PROG_CC])dnl
1372 AS_CASE([$ac_cv_prog_cc_stdc],
1373 [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
1374 [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1375 [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
1376 [ac_cv_prog_cc_stdc=no])])])
1377 AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1378 AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1379 AS_CASE([$ac_cv_prog_cc_stdc],
1380 [no], [AC_MSG_RESULT([unsupported])],
1381 [''], [AC_MSG_RESULT([none needed])],
1382 [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
1388 AC_DEFUN([AC_C_BACKSLASH_A],
1390 AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1391 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1396 char buf['\a' == 'a' ? -1 : 1];
1398 return buf[0] != "\a"[0];
1400 [ac_cv_c_backslash_a=yes],
1401 [ac_cv_c_backslash_a=no])])
1402 if test $ac_cv_c_backslash_a = yes; then
1403 AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1404 [Define if backslash-a works in C strings.])
1411 # Has been merged into AC_PROG_CC.
1412 AU_DEFUN([AC_C_CROSS], [])
1415 # AC_C_CHAR_UNSIGNED
1416 # ------------------
1417 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1418 [AH_VERBATIM([__CHAR_UNSIGNED__],
1419 [/* Define to 1 if type `char' is unsigned and you are not using gcc. */
1420 #ifndef __CHAR_UNSIGNED__
1421 # undef __CHAR_UNSIGNED__
1423 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1424 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1425 [((char) -1) < 0])],
1426 ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1427 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1428 AC_DEFINE(__CHAR_UNSIGNED__)
1430 ])# AC_C_CHAR_UNSIGNED
1433 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1434 # [ACTION-IF-UNIVERSAL])
1435 # -------------------------------------------------------------------------
1436 AC_DEFUN([AC_C_BIGENDIAN],
1437 [AH_VERBATIM([WORDS_BIGENDIAN],
1438 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1439 significant byte first (like Motorola and SPARC, unlike Intel). */
1440 #if defined AC_APPLE_UNIVERSAL_BUILD
1441 # if defined __BIG_ENDIAN__
1442 # define WORDS_BIGENDIAN 1
1445 # ifndef WORDS_BIGENDIAN
1446 # undef WORDS_BIGENDIAN
1449 AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1450 [ac_cv_c_bigendian=unknown
1451 # See if we're dealing with a universal compiler.
1454 [[#ifndef __APPLE_CC__
1455 not a universal capable compiler
1460 # Check for potential -arch flags. It is not universal unless
1461 # there are at least two -arch flags with different values.
1464 for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
1465 if test -n "$ac_prev"; then
1467 i?86 | x86_64 | ppc | ppc64)
1468 if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
1471 ac_cv_c_bigendian=universal
1477 elif test "x$ac_word" = "x-arch"; then
1481 if test $ac_cv_c_bigendian = unknown; then
1482 # See if sys/param.h defines the BYTE_ORDER macro.
1485 [[#include <sys/types.h>
1486 #include <sys/param.h>
1488 [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1489 && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1494 [# It does; now see whether it defined to BIG_ENDIAN or not.
1497 [[#include <sys/types.h>
1498 #include <sys/param.h>
1500 [[#if BYTE_ORDER != BIG_ENDIAN
1504 [ac_cv_c_bigendian=yes],
1505 [ac_cv_c_bigendian=no])])
1507 if test $ac_cv_c_bigendian = unknown; then
1508 # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1511 [[#include <limits.h>
1513 [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1517 [# It does; now see whether it defined to _BIG_ENDIAN or not.
1520 [[#include <limits.h>
1522 [[#ifndef _BIG_ENDIAN
1526 [ac_cv_c_bigendian=yes],
1527 [ac_cv_c_bigendian=no])])
1529 if test $ac_cv_c_bigendian = unknown; then
1530 # Compile a test program.
1532 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1534 /* Are we little or big endian? From Harbison&Steele. */
1538 char c[sizeof (long int)];
1541 return u.c[sizeof (long int) - 1] == 1;
1543 [ac_cv_c_bigendian=no],
1544 [ac_cv_c_bigendian=yes],
1545 [# Try to guess by grepping values from an object file.
1548 [[short int ascii_mm[] =
1549 { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1550 short int ascii_ii[] =
1551 { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1552 int use_ascii (int i) {
1553 return ascii_mm[i] + ascii_ii[i];
1555 short int ebcdic_ii[] =
1556 { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1557 short int ebcdic_mm[] =
1558 { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1559 int use_ebcdic (int i) {
1560 return ebcdic_mm[i] + ebcdic_ii[i];
1564 [[return use_ascii (foo) == use_ebcdic (foo);]])],
1565 [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1566 ac_cv_c_bigendian=yes
1568 if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1569 if test "$ac_cv_c_bigendian" = unknown; then
1570 ac_cv_c_bigendian=no
1572 # finding both strings is unlikely to happen, but who knows?
1573 ac_cv_c_bigendian=unknown
1577 case $ac_cv_c_bigendian in #(
1580 [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1584 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
1585 dnl this is a necessity for proper config header operation. Warn if
1586 dnl the user did not specify a config header but is relying on the
1587 dnl default behavior for universal builds.
1589 [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
1590 [AC_DIAGNOSE([obsolete],
1591 [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
1592 AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
1593 [Define if building universal (internal helper macro)])])
1597 [AC_MSG_ERROR([unknown endianness
1598 presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1605 # Do nothing if the compiler accepts the inline keyword.
1606 # Otherwise define inline to __inline__ or __inline if one of those work,
1607 # otherwise define inline to be empty.
1609 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1610 # inline function, only builtin types.
1612 AN_IDENTIFIER([inline], [AC_C_INLINE])
1613 AC_DEFUN([AC_C_INLINE],
1614 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1616 for ac_kw in inline __inline__ __inline; do
1617 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1618 [#ifndef __cplusplus
1620 static $ac_kw foo_t static_foo () {return 0; }
1621 $ac_kw foo_t foo () {return 0; }
1624 [ac_cv_c_inline=$ac_kw])
1625 test "$ac_cv_c_inline" != no && break
1628 AH_VERBATIM([inline],
1629 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1630 calls it, or to nothing if 'inline' is not supported under any name. */
1634 case $ac_cv_c_inline in
1637 case $ac_cv_c_inline in
1639 *) ac_val=$ac_cv_c_inline;;
1641 cat >>confdefs.h <<_ACEOF
1643 #define inline $ac_val
1653 AC_DEFUN([AC_C_CONST],
1654 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1655 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1656 [[/* FIXME: Include the comments suggested by Paul. */
1658 /* Ultrix mips cc rejects this. */
1659 typedef int charset[2];
1661 /* SunOS 4.1.1 cc rejects this. */
1662 char const *const *pcpcc;
1664 /* NEC SVR4.0.2 mips cc rejects this. */
1665 struct point {int x, y;};
1666 static struct point const zero = {0,0};
1667 /* AIX XL C 1.02.0.0 rejects this.
1668 It does not let you subtract one const X* pointer from another in
1669 an arm of an if-expression whose if-part is not a constant
1671 const char *g = "string";
1672 pcpcc = &g + (g ? g-g : 0);
1673 /* HPUX 7.0 cc rejects these. */
1675 ppc = (char**) pcpcc;
1676 pcpcc = (char const *const *) ppc;
1677 { /* SCO 3.2v4 cc rejects this. */
1679 char const *s = 0 ? (char *) 0 : (char const *) 0;
1684 { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
1686 const int *foo = &x[0];
1689 { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1690 typedef const int *iptr;
1694 { /* AIX XL C 1.02.0.0 rejects this saying
1695 "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1696 struct s { int j; const int *ap[3]; };
1697 struct s *b; b->j = 5;
1699 { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1703 return !cs[0] && !zero.x;
1706 [ac_cv_c_const=yes],
1707 [ac_cv_c_const=no])])
1708 if test $ac_cv_c_const = no; then
1710 [Define to empty if `const' does not conform to ANSI C.])
1717 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1718 # http://autoconf-archive.cryp.to/acx_restrict.html
1720 # Determine whether the C/C++ compiler supports the "restrict" keyword
1721 # introduced in ANSI C99, or an equivalent. Define "restrict" to the alternate
1722 # spelling, if any; these are more likely to work in both C and C++ compilers of
1723 # the same family, and in the presence of varying compiler options. If only
1724 # plain "restrict" works, do nothing. Here are some variants:
1725 # - GCC supports both __restrict and __restrict__
1726 # - older DEC Alpha C compilers support only __restrict
1727 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1728 # Otherwise, define "restrict" to be empty.
1729 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1730 AC_DEFUN([AC_C_RESTRICT],
1731 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1732 [ac_cv_c_restrict=no
1733 # The order here caters to the fact that C++ does not require restrict.
1734 for ac_kw in __restrict __restrict__ _Restrict restrict; do
1735 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1736 [[typedef int * int_ptr;
1737 int foo (int_ptr $ac_kw ip) {
1744 [ac_cv_c_restrict=$ac_kw])
1745 test "$ac_cv_c_restrict" != no && break
1748 AH_VERBATIM([restrict],
1749 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1750 nothing if this is not supported. Do not define if restrict is
1751 supported directly. */
1753 /* Work around a bug in Sun C++: it does not support _Restrict or
1754 __restrict__, even though the corresponding Sun C compiler ends up with
1755 "#define restrict _Restrict" or "#define restrict __restrict__" in the
1756 previous line. Perhaps some future version of Sun C++ will work with
1757 restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
1758 #if defined __SUNPRO_CC && !defined __RESTRICT
1760 # define __restrict__
1762 case $ac_cv_c_restrict in
1764 no) AC_DEFINE([restrict], []) ;;
1765 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1772 # Note that, unlike const, #defining volatile to be the empty string can
1773 # actually turn a correct program into an incorrect one, since removing
1774 # uses of volatile actually grants the compiler permission to perform
1775 # optimizations that could break the user's code. So, do not #define
1776 # volatile away unless it is really necessary to allow the user's code
1777 # to compile cleanly. Benign compiler failures should be tolerated.
1778 AC_DEFUN([AC_C_VOLATILE],
1779 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1780 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1782 int * volatile y = (int *) 0;
1783 return !x && !y;])],
1784 [ac_cv_c_volatile=yes],
1785 [ac_cv_c_volatile=no])])
1786 if test $ac_cv_c_volatile = no; then
1787 AC_DEFINE(volatile,,
1788 [Define to empty if the keyword `volatile' does not work.
1789 Warning: valid code using `volatile' can become incorrect
1790 without. Disable with care.])
1797 # Checks if `#' can be used to glue strings together at the CPP level.
1798 # Defines HAVE_STRINGIZE if positive.
1799 AC_DEFUN([AC_C_STRINGIZE],
1800 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1801 [ac_cv_c_stringize],
1802 [AC_EGREP_CPP([@%:@teststring],
1805 char *s = x(teststring);],
1806 [ac_cv_c_stringize=no],
1807 [ac_cv_c_stringize=yes])])
1808 if test $ac_cv_c_stringize = yes; then
1809 AC_DEFINE(HAVE_STRINGIZE, 1,
1810 [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1817 # Check if the C compiler supports prototypes, included if it needs
1819 AC_DEFUN([AC_C_PROTOTYPES],
1820 [AC_REQUIRE([AC_PROG_CC])dnl
1821 AC_MSG_CHECKING([for function prototypes])
1822 if test "$ac_cv_prog_cc_c89" != no; then
1823 AC_MSG_RESULT([yes])
1824 AC_DEFINE(PROTOTYPES, 1,
1825 [Define to 1 if the C compiler supports function prototypes.])
1826 AC_DEFINE(__PROTOTYPES, 1,
1827 [Define like PROTOTYPES; this can be used by system headers.])
1834 # AC_C_FLEXIBLE_ARRAY_MEMBER
1835 # --------------------------
1836 # Check whether the C compiler supports flexible array members.
1837 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1839 AC_CACHE_CHECK([for flexible array members],
1843 [[#include <stdlib.h>
1846 struct s { int n; double d[]; };]],
1847 [[int m = getchar ();
1848 struct s *p = malloc (offsetof (struct s, d)
1849 + m * sizeof (double));
1851 return p->d != (double *) NULL;]])],
1852 [ac_cv_c_flexmember=yes],
1853 [ac_cv_c_flexmember=no])])
1854 if test $ac_cv_c_flexmember = yes; then
1855 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1856 [Define to nothing if C supports flexible array members, and to
1857 1 if it does not. That way, with a declaration like `struct s
1858 { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1859 can be used with pre-C99 compilers.
1860 When computing the size of such an object, don't use 'sizeof (struct s)'
1861 as it overestimates the size. Use 'offsetof (struct s, d)' instead.
1862 Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1863 MSVC and with C++ compilers.])
1865 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1872 # Check whether the C compiler supports variable-length arrays.
1873 AC_DEFUN([AC_C_VARARRAYS],
1875 AC_CACHE_CHECK([for variable-length arrays],
1878 [AC_LANG_PROGRAM([],
1879 [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1880 [ac_cv_c_vararrays=yes],
1881 [ac_cv_c_vararrays=no])])
1882 if test $ac_cv_c_vararrays = yes; then
1883 AC_DEFINE([HAVE_C_VARARRAYS], 1,
1884 [Define to 1 if C supports variable-length arrays.])
1891 # Check if the C compiler supports GCC's typeof syntax.
1892 # The test case provokes incompatibilities in the Sun C compilers
1893 # (both Solaris 8 and Solaris 10).
1894 AC_DEFUN([AC_C_TYPEOF],
1896 AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1898 for ac_kw in typeof __typeof__ no; do
1899 test $ac_kw = no && break
1900 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1905 + ! (($ac_kw (value))
1906 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1907 ? ($ac_kw (value)) - 1
1908 : ~ (~ ($ac_kw (value)) 0
1909 << sizeof ($ac_kw (value)))))]; }
1912 (! ((void) ((ac__typeof_type_ *) 0), 0));
1914 [ac_cv_c_typeof=$ac_kw])
1915 test $ac_cv_c_typeof != no && break
1917 if test $ac_cv_c_typeof != no; then
1918 AC_DEFINE([HAVE_TYPEOF], 1,
1919 [Define to 1 if typeof works with your compiler.])
1920 if test $ac_cv_c_typeof != typeof; then
1921 AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1922 [Define to __typeof__ if your compiler spells it that way.])
1930 # Expands to some language dependent source code for testing the presence of
1932 AC_DEFUN([_AC_LANG_OPENMP],
1933 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
1935 # _AC_LANG_OPENMP(C)
1936 # ------------------
1937 m4_define([_AC_LANG_OPENMP(C)],
1943 int main () { return omp_get_num_threads (); }
1946 # _AC_LANG_OPENMP(C++)
1947 # --------------------
1948 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
1950 # _AC_LANG_OPENMP(Fortran 77)
1951 # ---------------------------
1952 m4_define([_AC_LANG_OPENMP(Fortran 77)],
1953 [AC_LANG_FUNC_LINK_TRY([omp_get_num_threads])])
1955 # _AC_LANG_OPENMP(Fortran)
1956 # ---------------------------
1957 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
1961 # Check which options need to be passed to the C compiler to support OpenMP.
1962 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
1964 # The options are necessary at compile time (so the #pragmas are understood)
1965 # and at link time (so the appropriate library is linked with).
1966 # This macro takes care to not produce redundant options if $CC $CFLAGS already
1967 # supports OpenMP. It also is careful to not pass options to compilers that
1968 # misinterpret them; for example, most compilers accept "-openmp" and create
1969 # an output file called 'penmp' rather than activating OpenMP support.
1970 AC_DEFUN([AC_OPENMP],
1972 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
1973 AC_ARG_ENABLE([openmp],
1974 [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
1975 if test "$enable_openmp" != no; then
1976 AC_CACHE_CHECK([for $[]_AC_CC[] option to support OpenMP],
1977 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
1978 [AC_LINK_IFELSE([_AC_LANG_OPENMP],
1979 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
1980 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
1981 dnl Try these flags:
1982 dnl GCC >= 4.2 -fopenmp
1983 dnl SunPRO C -xopenmp
1985 dnl SGI C, PGI C -mp
1986 dnl Tru64 Compaq C -omp
1987 dnl IBM C (AIX, Linux) -qsmp=omp
1988 dnl If in this loop a compiler is passed an option that it doesn't
1989 dnl understand or that it misinterprets, the AC_LINK_IFELSE test
1990 dnl will fail (since we know that it failed without the option),
1991 dnl therefore the loop will continue searching for an option, and
1992 dnl no output file called 'penmp' or 'mp' is created.
1993 for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
1994 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
1995 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
1996 AC_LINK_IFELSE([_AC_LANG_OPENMP],
1997 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
1998 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
1999 if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
2003 case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
2004 "none needed" | unsupported)
2007 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
2010 AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])