1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001-2012 Free Software Foundation, Inc.
5 # This file is part of Autoconf. This program is free
6 # software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # Under Section 7 of GPL version 3, you are granted additional
17 # permissions described in the Autoconf Configure Script Exception,
18 # version 3.0, as published by the Free Software Foundation.
20 # You should have received a copy of the GNU General Public License
21 # and a copy of the Autoconf Configure Script Exception along with
22 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
23 # respectively. If not, see <http://www.gnu.org/licenses/>.
25 # Written by David MacKenzie, with help from
26 # Akim Demaille, Paul Eggert,
27 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
28 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
33 # 1. Language selection
34 # 2. and routines to produce programs in a given language.
40 # 3. Looking for a compiler
41 # And possibly the associated preprocessor.
42 # 3a. C 3b. C++ 3c. Objective C 3d. Objective C++
44 # 4. Compilers' characteristics.
49 ## ----------------------- ##
50 ## 1a/2a. The C language. ##
51 ## ----------------------- ##
54 # ------------------------ #
55 # 1a. Language selection. #
56 # ------------------------ #
60 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
61 AC_LANG_DEFINE([C], [c], [C], [CC], [],
63 ac_cpp='$CPP $CPPFLAGS'
64 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
65 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
66 ac_compiler_gnu=$ac_cv_c_compiler_gnu
72 AU_DEFUN([AC_LANG_C], [AC_LANG(C)])
75 # ------------------------ #
76 # 2a. Producing programs. #
77 # ------------------------ #
80 # AC_LANG_CONFTEST(C)(BODY)
81 # -------------------------
82 # We can't use '#line $LINENO "configure"' here, since
83 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
84 # rejects $LINENO greater than 32767, and some configure scripts
85 # are longer than 32767 lines.
86 m4_define([AC_LANG_CONFTEST(C)],
87 [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
93 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
94 # --------------------------------------
95 m4_define([AC_LANG_PROGRAM(C)],
97 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
98 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
102 dnl Do *not* indent the following line: there may be CPP directives.
103 dnl Don't move the `;' right after for the same reason.
110 # _AC_LANG_IO_PROGRAM(C)
111 # ----------------------
112 # Produce source that performs I/O, necessary for proper
113 # cross-compiler detection.
114 m4_define([_AC_LANG_IO_PROGRAM(C)],
115 [AC_LANG_PROGRAM([@%:@include <stdio.h>],
116 [FILE *f = fopen ("conftest.out", "w");
117 return ferror (f) || fclose (f) != 0;
121 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
122 # -----------------------------------
123 # Avoid conflicting decl of main.
124 m4_define([AC_LANG_CALL(C)],
126 m4_if([$2], [main], ,
127 [/* Override any GCC internal prototype to avoid an error.
128 Use char because int might match the return type of a GCC
129 builtin and then its argument prototype would still apply. */
133 char $2 ();])], [return $2 ();])])
136 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
137 # ----------------------------------
138 # Don't include <ctype.h> because on OSF/1 3.0 it includes
139 # <sys/types.h> which includes <sys/select.h> which contains a
140 # prototype for select. Similarly for bzero.
142 # This test used to merely assign f=$1 in main(), but that was
143 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
144 # presumably on the basis that there's no need to do that store if the
145 # program is about to exit. Conversely, the AIX linker optimizes an
146 # unused external declaration that initializes f=$1. So this test
147 # program has both an external initialization of f, and a use of f in
148 # main that affects the exit status.
150 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
152 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
153 For example, HP-UX 11i <limits.h> declares gettimeofday. */
154 #define $1 innocuous_$1
156 /* System header to define __stub macros and hopefully few prototypes,
157 which can conflict with char $1 (); below. */
162 /* Override any GCC internal prototype to avoid an error.
163 Use char because int might match the return type of a GCC
164 builtin and then its argument prototype would still apply. */
169 /* The GNU C library defines this for functions which it implements
170 to always fail with ENOSYS. Some functions are actually named
171 something starting with __ and the normal name is an alias. */
172 #if defined __stub_$1 || defined __stub___$1
175 ], [return $1 ();])])
178 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
179 # -------------------------------------------------
180 # Return a program that is valid if EXPRESSION is nonzero.
181 # EXPRESSION must be an integer constant expression.
182 # Be sure to use this array to avoid `unused' warnings, which are even
183 # errors with `-W error'.
184 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
185 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
186 test_array @<:@0@:>@ = 0;
187 return test_array @<:@0@:>@;
191 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
192 # -----------------------------------------
193 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
194 # But we include them only after the EXPRESSION has been evaluated.
195 m4_define([AC_LANG_INT_SAVE(C)],
197 static long int longval () { return $2; }
198 static unsigned long int ulongval () { return $2; }
199 @%:@include <stdio.h>
200 @%:@include <stdlib.h>],
202 FILE *f = fopen ("conftest.val", "w");
207 long int i = longval ();
210 fprintf (f, "%ld", i);
214 unsigned long int i = ulongval ();
217 fprintf (f, "%lu", i);
219 /* Do not output a trailing newline, as this causes \r\n confusion
220 on some platforms. */
221 return ferror (f) || fclose (f) != 0;
226 ## ---------------------- ##
227 ## 1b. The C++ language. ##
228 ## ---------------------- ##
233 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
234 AC_LANG_DEFINE([C++], [cxx], [CXX], [CXX], [C],
236 ac_cpp='$CXXCPP $CPPFLAGS'
237 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
238 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
239 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
245 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
249 ## ------------------------------ ##
250 ## 1c. The Objective C language. ##
251 ## ------------------------------ ##
254 # AC_LANG(Objective C)
255 # --------------------
256 AC_LANG_DEFINE([Objective C], [objc], [OBJC], [OBJC], [C],
258 ac_cpp='$OBJCPP $CPPFLAGS'
259 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
260 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
261 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
267 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
271 ## -------------------------------- ##
272 ## 1d. The Objective C++ language. ##
273 ## -------------------------------- ##
276 # AC_LANG(Objective C++)
277 # ----------------------
278 AC_LANG_DEFINE([Objective C++], [objcxx], [OBJCXX], [OBJCXX], [C++],
280 ac_cpp='$OBJCXXCPP $CPPFLAGS'
281 ac_compile='$OBJCXX -c $OBJCXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
282 ac_link='$OBJCXX -o conftest$ac_exeext $OBJCXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
283 ac_compiler_gnu=$ac_cv_objcxx_compiler_gnu
288 ## -------------------------------------------- ##
289 ## 3. Looking for Compilers and Preprocessors. ##
290 ## -------------------------------------------- ##
292 # -------------------- #
293 # 3a. The C compiler. #
294 # -------------------- #
297 # _AC_ARG_VAR_CPPFLAGS
298 # --------------------
299 # Document and register CPPFLAGS, which is used by
300 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP, OBJCXX, OBJCXXCPP}.
301 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
302 [AC_ARG_VAR([CPPFLAGS],
303 [(Objective) C/C++ preprocessor flags, e.g. -I<include dir>
304 if you have headers in a nonstandard directory <include dir>])])
307 # _AC_ARG_VAR_LDFLAGS
308 # -------------------
309 # Document and register LDFLAGS, which is used by
310 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
311 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
312 [AC_ARG_VAR([LDFLAGS],
313 [linker flags, e.g. -L<lib dir> if you have libraries in a
314 nonstandard directory <lib dir>])])
319 # Document and register LIBS, which is used by
320 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
321 AC_DEFUN([_AC_ARG_VAR_LIBS],
323 [libraries to pass to the linker, e.g. -l<library>])])
328 # Find the C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
329 AC_DEFUN([AC_LANG_PREPROC(C)],
330 [AC_REQUIRE([AC_PROG_CPP])])
333 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
334 # -----------------------------------------------
335 # Check if $ac_cpp is a working preprocessor that can flag absent
336 # includes either by the exit status or by warnings.
337 # This macro is for all languages, not only C.
338 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
340 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
342 # Use a header file that comes with gcc, so configuring glibc
343 # with a fresh cross-compiler works.
344 # On the NeXT, cc -E runs the code through the compiler's parser,
345 # not just through cpp. "Syntax error" is here to catch this case.
346 _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <limits.h>
349 [# Broken: fails on valid input.
352 # OK, works on sane cases. Now check whether nonexistent headers
353 # can be detected and how.
354 _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
355 [# Broken: success on invalid input.
357 [# Passes both tests.
362 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
363 rm -f conftest.i conftest.err conftest.$ac_ext
364 AS_IF([$ac_preproc_ok], [$1], [$2])
365 ])# _AC_PROG_PREPROC_WORKS_IFELSE
370 # Find a working C preprocessor.
371 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
372 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
373 AN_MAKEVAR([CPP], [AC_PROG_CPP])
374 AN_PROGRAM([cpp], [AC_PROG_CPP])
375 AC_DEFUN([AC_PROG_CPP],
376 [AC_REQUIRE([AC_PROG_CC])dnl
377 AC_ARG_VAR([CPP], [C preprocessor])dnl
378 _AC_ARG_VAR_CPPFLAGS()dnl
380 AC_MSG_CHECKING([how to run the C preprocessor])
381 # On Suns, sometimes $CPP names a directory.
382 if test -n "$CPP" && test -d "$CPP"; then
385 if test -z "$CPP"; then
386 AC_CACHE_VAL([ac_cv_prog_CPP],
388 # Double quotes because CPP needs to be expanded
389 for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
391 _AC_PROG_PREPROC_WORKS_IFELSE([break])
399 AC_MSG_RESULT([$CPP])
400 _AC_PROG_PREPROC_WORKS_IFELSE([],
401 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
408 # Treat warnings from the preprocessor as errors.
409 AC_DEFUN([AC_PROG_CPP_WERROR],
410 [AC_REQUIRE([AC_PROG_CPP])dnl
411 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
413 # AC_LANG_COMPILER(C)
414 # -------------------
415 # Find the C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
416 AC_DEFUN([AC_LANG_COMPILER(C)],
417 [AC_REQUIRE([AC_PROG_CC])])
422 # We used to name the cache variable this way.
423 AU_DEFUN([ac_cv_prog_gcc],
424 [ac_cv_c_compiler_gnu])
427 # AC_PROG_CC([COMPILER ...])
428 # --------------------------
429 # COMPILER ... is a space separated list of C compilers to search for.
430 # This just gives the user an opportunity to specify an alternative
431 # search list for the C compiler.
432 AN_MAKEVAR([CC], [AC_PROG_CC])
433 AN_PROGRAM([cc], [AC_PROG_CC])
434 AN_PROGRAM([gcc], [AC_PROG_CC])
435 AC_DEFUN([AC_PROG_CC],
437 AC_ARG_VAR([CC], [C compiler command])dnl
438 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
439 _AC_ARG_VAR_LDFLAGS()dnl
440 _AC_ARG_VAR_LIBS()dnl
441 _AC_ARG_VAR_CPPFLAGS()dnl
443 [AC_CHECK_TOOLS(CC, [$1])],
444 [AC_CHECK_TOOL(CC, gcc)
445 if test -z "$CC"; then
447 dnl AC_CHECK_TOOL(CC, cc)
448 dnl but without the check for a tool without the prefix.
449 dnl Until the check is removed from there, copy the code:
450 if test -n "$ac_tool_prefix"; then
451 AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
454 if test -z "$CC"; then
455 AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
457 if test -z "$CC"; then
458 AC_CHECK_TOOLS(CC, cl.exe)
462 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
464 # Provide some information about the compiler.
465 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
468 for ac_option in --version -v -V -qversion; do
469 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
472 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
473 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
474 _AC_LANG_COMPILER_GNU
475 if test $ac_compiler_gnu = yes; then
482 dnl Set ac_prog_cc_stdc to the supported C version.
483 dnl Also set the documented variable ac_cv_prog_cc_stdc;
484 dnl its name was chosen when it was cached, but it is no longer cached.
485 _AC_PROG_CC_C11([ac_prog_cc_stdc=c11
486 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11],
487 [_AC_PROG_CC_C99([ac_prog_cc_stdc=c99
488 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
489 [_AC_PROG_CC_C89([ac_prog_cc_stdc=c89
490 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
492 ac_cv_prog_cc_stdc=no])])])
500 # Check whether -g works, even if CFLAGS is set, in case the package
501 # plays around with CFLAGS (such as to build both debugging and normal
502 # versions of a library), tasteless as that idea is.
503 # Don't consider -g to work if it generates warnings when plain compiles don't.
504 m4_define([_AC_PROG_CC_G],
505 [ac_test_CFLAGS=${CFLAGS+set}
506 ac_save_CFLAGS=$CFLAGS
507 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
508 [ac_save_c_werror_flag=$ac_c_werror_flag
512 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
513 [ac_cv_prog_cc_g=yes],
515 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
517 [ac_c_werror_flag=$ac_save_c_werror_flag
519 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
520 [ac_cv_prog_cc_g=yes])])])
521 ac_c_werror_flag=$ac_save_c_werror_flag])
522 if test "$ac_test_CFLAGS" = set; then
523 CFLAGS=$ac_save_CFLAGS
524 elif test $ac_cv_prog_cc_g = yes; then
525 if test "$GCC" = yes; then
531 if test "$GCC" = yes; then
540 # AC_PROG_GCC_TRADITIONAL
541 # -----------------------
542 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
543 [AC_REQUIRE([AC_PROG_CC])dnl
544 if test $ac_cv_c_compiler_gnu = yes; then
545 AC_CACHE_CHECK(whether $CC needs -traditional,
546 ac_cv_prog_gcc_traditional,
547 [ ac_pattern="Autoconf.*'x'"
548 AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
550 ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
552 if test $ac_cv_prog_gcc_traditional = no; then
553 AC_EGREP_CPP($ac_pattern, [#include <termio.h>
555 ac_cv_prog_gcc_traditional=yes)
557 if test $ac_cv_prog_gcc_traditional = yes; then
558 CC="$CC -traditional"
561 ])# AC_PROG_GCC_TRADITIONAL
566 AC_DEFUN([AC_PROG_CC_C_O],
567 [AC_REQUIRE([AC_PROG_CC])dnl
568 if test "x$CC" != xcc; then
569 AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
571 AC_MSG_CHECKING([whether cc understands -c and -o together])
573 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
574 sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
575 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
576 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
577 # Make sure it works both with $CC and with simple cc.
578 # We do the test twice because some compilers refuse to overwrite an
579 # existing .o file with -o, though they will create one.
580 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
582 if _AC_DO_VAR(ac_try) &&
583 test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
585 eval ac_cv_prog_cc_${ac_cc}_c_o=yes
586 if test "x$CC" != xcc; then
587 # Test first that cc exists at all.
588 if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
589 ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
591 if _AC_DO_VAR(ac_try) &&
592 test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
597 # cc exists but doesn't like -o.
598 eval ac_cv_prog_cc_${ac_cc}_c_o=no
603 eval ac_cv_prog_cc_${ac_cc}_c_o=no
607 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
611 AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
612 [Define to 1 if your C compiler doesn't accept -c and -o together.])
618 # ---------------------- #
619 # 3b. The C++ compiler. #
620 # ---------------------- #
623 # AC_LANG_PREPROC(C++)
624 # --------------------
625 # Find the C++ preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
626 AC_DEFUN([AC_LANG_PREPROC(C++)],
627 [AC_REQUIRE([AC_PROG_CXXCPP])])
632 # Find a working C++ preprocessor.
633 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
634 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
635 AC_DEFUN([AC_PROG_CXXCPP],
636 [AC_REQUIRE([AC_PROG_CXX])dnl
637 AC_ARG_VAR([CXXCPP], [C++ preprocessor])dnl
638 _AC_ARG_VAR_CPPFLAGS()dnl
640 AC_MSG_CHECKING([how to run the C++ preprocessor])
641 if test -z "$CXXCPP"; then
642 AC_CACHE_VAL(ac_cv_prog_CXXCPP,
644 # Double quotes because CXXCPP needs to be expanded
645 for CXXCPP in "$CXX -E" "/lib/cpp"
647 _AC_PROG_PREPROC_WORKS_IFELSE([break])
649 ac_cv_prog_CXXCPP=$CXXCPP
651 CXXCPP=$ac_cv_prog_CXXCPP
653 ac_cv_prog_CXXCPP=$CXXCPP
655 AC_MSG_RESULT([$CXXCPP])
656 _AC_PROG_PREPROC_WORKS_IFELSE([],
657 [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
663 # AC_LANG_COMPILER(C++)
664 # ---------------------
665 # Find the C++ compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
666 AC_DEFUN([AC_LANG_COMPILER(C++)],
667 [AC_REQUIRE([AC_PROG_CXX])])
672 # We used to name the cache variable this way.
673 AU_DEFUN([ac_cv_prog_gxx],
674 [ac_cv_cxx_compiler_gnu])
677 # AC_PROG_CXX([LIST-OF-COMPILERS])
678 # --------------------------------
679 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
680 # for (if not specified, a default list is used). This just gives the
681 # user an opportunity to specify an alternative search list for the C++
683 # aCC HP-UX C++ compiler much better than `CC', so test before.
684 # FCC Fujitsu C++ compiler
685 # KCC KAI C++ compiler
687 # xlC_r AIX C Set++ (with support for reentrant code)
689 AN_MAKEVAR([CXX], [AC_PROG_CXX])
690 AN_PROGRAM([CC], [AC_PROG_CXX])
691 AN_PROGRAM([c++], [AC_PROG_CXX])
692 AN_PROGRAM([g++], [AC_PROG_CXX])
693 AC_DEFUN([AC_PROG_CXX],
694 [AC_LANG_PUSH(C++)dnl
695 AC_ARG_VAR([CXX], [C++ compiler command])dnl
696 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
697 _AC_ARG_VAR_LDFLAGS()dnl
698 _AC_ARG_VAR_LIBS()dnl
699 _AC_ARG_VAR_CPPFLAGS()dnl
700 _AC_ARG_VAR_PRECIOUS([CCC])dnl
701 if test -z "$CXX"; then
702 if test -n "$CCC"; then
707 [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
711 # Provide some information about the compiler.
712 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
715 for ac_option in --version -v -V -qversion; do
716 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
719 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
720 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
721 _AC_LANG_COMPILER_GNU
722 if test $ac_compiler_gnu = yes; then
734 # Check whether -g works, even if CXXFLAGS is set, in case the package
735 # plays around with CXXFLAGS (such as to build both debugging and
736 # normal versions of a library), tasteless as that idea is.
737 # Don't consider -g to work if it generates warnings when plain compiles don't.
738 m4_define([_AC_PROG_CXX_G],
739 [ac_test_CXXFLAGS=${CXXFLAGS+set}
740 ac_save_CXXFLAGS=$CXXFLAGS
741 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
742 [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
743 ac_cxx_werror_flag=yes
746 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
747 [ac_cv_prog_cxx_g=yes],
749 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
751 [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
753 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
754 [ac_cv_prog_cxx_g=yes])])])
755 ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
756 if test "$ac_test_CXXFLAGS" = set; then
757 CXXFLAGS=$ac_save_CXXFLAGS
758 elif test $ac_cv_prog_cxx_g = yes; then
759 if test "$GXX" = yes; then
765 if test "$GXX" = yes; then
776 # Test if the C++ compiler accepts the options `-c' and `-o'
777 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
778 AC_DEFUN([AC_PROG_CXX_C_O],
779 [AC_REQUIRE([AC_PROG_CXX])dnl
780 AC_LANG_PUSH([C++])dnl
781 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
782 [ac_cv_prog_cxx_c_o],
783 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
784 # We test twice because some compilers refuse to overwrite an existing
785 # `.o' file with `-o', although they will create one.
786 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
788 if _AC_DO_VAR(ac_try) &&
789 test -f conftest2.$ac_objext &&
790 _AC_DO_VAR(ac_try); then
791 ac_cv_prog_cxx_c_o=yes
793 ac_cv_prog_cxx_c_o=no
796 if test $ac_cv_prog_cxx_c_o = no; then
797 AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
798 [Define to 1 if your C++ compiler doesn't accept
799 -c and -o together.])
801 AC_LANG_POP([C++])dnl
806 # ------------------------------ #
807 # 3c. The Objective C compiler. #
808 # ------------------------------ #
811 # AC_LANG_PREPROC(Objective C)
812 # ----------------------------
813 # Find the Objective C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
814 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
815 [AC_REQUIRE([AC_PROG_OBJCPP])])
820 # Find a working Objective C preprocessor.
821 AC_DEFUN([AC_PROG_OBJCPP],
822 [AC_REQUIRE([AC_PROG_OBJC])dnl
823 AC_ARG_VAR([OBJCPP], [Objective C preprocessor])dnl
824 _AC_ARG_VAR_CPPFLAGS()dnl
825 AC_LANG_PUSH(Objective C)dnl
826 AC_MSG_CHECKING([how to run the Objective C preprocessor])
827 if test -z "$OBJCPP"; then
828 AC_CACHE_VAL(ac_cv_prog_OBJCPP,
830 # Double quotes because OBJCPP needs to be expanded
831 for OBJCPP in "$OBJC -E" "/lib/cpp"
833 _AC_PROG_PREPROC_WORKS_IFELSE([break])
835 ac_cv_prog_OBJCPP=$OBJCPP
837 OBJCPP=$ac_cv_prog_OBJCPP
839 ac_cv_prog_OBJCPP=$OBJCPP
841 AC_MSG_RESULT([$OBJCPP])
842 _AC_PROG_PREPROC_WORKS_IFELSE([],
843 [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
845 AC_LANG_POP(Objective C)dnl
849 # AC_LANG_COMPILER(Objective C)
850 # -----------------------------
851 # Find the Objective C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
852 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
853 [AC_REQUIRE([AC_PROG_OBJC])])
857 # AC_PROG_OBJC([LIST-OF-COMPILERS])
858 # ---------------------------------
859 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
860 # search for (if not specified, a default list is used). This just gives
861 # the user an opportunity to specify an alternative search list for the
862 # Objective C compiler.
863 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
864 # objc David Stes' POC. If you installed this, you likely want it.
865 # cc Native C compiler (for instance, Apple).
867 AN_MAKEVAR([OBJC], [AC_PROG_OBJC])
868 AN_PROGRAM([objcc], [AC_PROG_OBJC])
869 AN_PROGRAM([objc], [AC_PROG_OBJC])
870 AC_DEFUN([AC_PROG_OBJC],
871 [AC_LANG_PUSH(Objective C)dnl
872 AC_ARG_VAR([OBJC], [Objective C compiler command])dnl
873 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
874 _AC_ARG_VAR_LDFLAGS()dnl
875 _AC_ARG_VAR_LIBS()dnl
876 _AC_ARG_VAR_CPPFLAGS()dnl
877 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
879 [m4_default([$1], [gcc objcc objc cc CC])],
881 # Provide some information about the compiler.
882 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
885 for ac_option in --version -v -V -qversion; do
886 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
889 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
890 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
891 _AC_LANG_COMPILER_GNU
892 if test $ac_compiler_gnu = yes; then
898 AC_LANG_POP(Objective C)dnl
904 # Check whether -g works, even if OBJCFLAGS is set, in case the package
905 # plays around with OBJCFLAGS (such as to build both debugging and
906 # normal versions of a library), tasteless as that idea is.
907 # Don't consider -g to work if it generates warnings when plain compiles don't.
908 m4_define([_AC_PROG_OBJC_G],
909 [ac_test_OBJCFLAGS=${OBJCFLAGS+set}
910 ac_save_OBJCFLAGS=$OBJCFLAGS
911 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
912 [ac_save_objc_werror_flag=$ac_objc_werror_flag
913 ac_objc_werror_flag=yes
916 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
917 [ac_cv_prog_objc_g=yes],
919 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
921 [ac_objc_werror_flag=$ac_save_objc_werror_flag
923 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
924 [ac_cv_prog_objc_g=yes])])])
925 ac_objc_werror_flag=$ac_save_objc_werror_flag])
926 if test "$ac_test_OBJCFLAGS" = set; then
927 OBJCFLAGS=$ac_save_OBJCFLAGS
928 elif test $ac_cv_prog_objc_g = yes; then
929 if test "$GOBJC" = yes; then
935 if test "$GOBJC" = yes; then
945 # -------------------------------- #
946 # 3d. The Objective C++ compiler. #
947 # -------------------------------- #
950 # AC_LANG_PREPROC(Objective C++)
951 # ------------------------------
952 # Find the Objective C++ preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
953 AC_DEFUN([AC_LANG_PREPROC(Objective C++)],
954 [AC_REQUIRE([AC_PROG_OBJCXXCPP])])
959 # Find a working Objective C++ preprocessor.
960 AC_DEFUN([AC_PROG_OBJCXXCPP],
961 [AC_REQUIRE([AC_PROG_OBJCXX])dnl
962 AC_ARG_VAR([OBJCXXCPP], [Objective C++ preprocessor])dnl
963 _AC_ARG_VAR_CPPFLAGS()dnl
964 AC_LANG_PUSH(Objective C++)dnl
965 AC_MSG_CHECKING([how to run the Objective C++ preprocessor])
966 if test -z "$OBJCXXCPP"; then
967 AC_CACHE_VAL(ac_cv_prog_OBJCXXCPP,
969 # Double quotes because OBJCXXCPP needs to be expanded
970 for OBJCXXCPP in "$OBJCXX -E" "/lib/cpp"
972 _AC_PROG_PREPROC_WORKS_IFELSE([break])
974 ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
976 OBJCXXCPP=$ac_cv_prog_OBJCXXCPP
978 ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
980 AC_MSG_RESULT([$OBJCXXCPP])
981 _AC_PROG_PREPROC_WORKS_IFELSE([],
982 [AC_MSG_FAILURE([Objective C++ preprocessor "$OBJCXXCPP" fails sanity check])])
983 AC_SUBST(OBJCXXCPP)dnl
984 AC_LANG_POP(Objective C++)dnl
985 ])# AC_PROG_OBJCXXCPP
988 # AC_LANG_COMPILER(Objective C++)
989 # -------------------------------
990 # Find the Objective C++ compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
991 AC_DEFUN([AC_LANG_COMPILER(Objective C++)],
992 [AC_REQUIRE([AC_PROG_OBJCXX])])
996 # AC_PROG_OBJCXX([LIST-OF-COMPILERS])
997 # -----------------------------------
998 # LIST-OF-COMPILERS is a space separated list of Objective C++ compilers to
999 # search for (if not specified, a default list is used). This just gives
1000 # the user an opportunity to specify an alternative search list for the
1001 # Objective C++ compiler.
1002 # FIXME: this list is pure guesswork
1003 # objc++ StepStone Objective-C++ compiler (also "standard" name for OBJCXX)
1004 # objcxx David Stes' POC. If you installed this, you likely want it.
1005 # c++ Native C++ compiler (for instance, Apple).
1006 # CXX You never know.
1007 AN_MAKEVAR([OBJCXX], [AC_PROG_OBJCXX])
1008 AN_PROGRAM([objcxx], [AC_PROG_OBJCXX])
1009 AC_DEFUN([AC_PROG_OBJCXX],
1010 [AC_LANG_PUSH(Objective C++)dnl
1011 AC_ARG_VAR([OBJCXX], [Objective C++ compiler command])dnl
1012 AC_ARG_VAR([OBJCXXFLAGS], [Objective C++ compiler flags])dnl
1013 _AC_ARG_VAR_LDFLAGS()dnl
1014 _AC_ARG_VAR_LIBS()dnl
1015 _AC_ARG_VAR_CPPFLAGS()dnl
1016 _AC_ARG_VAR_PRECIOUS([OBJCXX])dnl
1017 AC_CHECK_TOOLS(OBJCXX,
1018 [m4_default([$1], [g++ objc++ objcxx c++ CXX])],
1020 # Provide some information about the compiler.
1021 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
1024 for ac_option in --version -v -V -qversion; do
1025 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
1028 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
1029 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
1030 _AC_LANG_COMPILER_GNU
1031 if test $ac_compiler_gnu = yes; then
1037 AC_LANG_POP(Objective C++)dnl
1043 # Check whether -g works, even if OBJCFLAGS is set, in case the package
1044 # plays around with OBJCFLAGS (such as to build both debugging and
1045 # normal versions of a library), tasteless as that idea is.
1046 # Don't consider -g to work if it generates warnings when plain compiles don't.
1047 m4_define([_AC_PROG_OBJCXX_G],
1048 [ac_test_OBJCXXFLAGS=${OBJCXXFLAGS+set}
1049 ac_save_OBJCXXFLAGS=$OBJCXXFLAGS
1050 AC_CACHE_CHECK(whether $OBJCXX accepts -g, ac_cv_prog_objcxx_g,
1051 [ac_save_objcxx_werror_flag=$ac_objcxx_werror_flag
1052 ac_objcxx_werror_flag=yes
1053 ac_cv_prog_objcxx_g=no
1055 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1056 [ac_cv_prog_objcxx_g=yes],
1058 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1060 [ac_objcxx_werror_flag=$ac_save_objcxx_werror_flag
1062 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1063 [ac_cv_prog_objcxx_g=yes])])])
1064 ac_objcxx_werror_flag=$ac_save_objcx_werror_flag])
1065 if test "$ac_test_OBJCXXFLAGS" = set; then
1066 OBJCXXFLAGS=$ac_save_OBJCXXFLAGS
1067 elif test $ac_cv_prog_objcxx_g = yes; then
1068 if test "$GOBJCXX" = yes; then
1069 OBJCXXFLAGS="-g -O2"
1074 if test "$GOBJCXX" = yes; then
1080 ])# _AC_PROG_OBJCXX_G
1084 ## ------------------------------- ##
1085 ## 4. Compilers' characteristics. ##
1086 ## ------------------------------- ##
1088 # -------------------------------- #
1089 # 4a. C compiler characteristics. #
1090 # -------------------------------- #
1093 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1094 # ----------------------------------------------------------------
1095 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1096 # to add an option to output variable CC to make it so. This macro
1097 # tries various options that select ANSI C89 on some system or
1098 # another. It considers the compiler to be in ANSI C89 mode if it
1099 # handles function prototypes correctly.
1100 AC_DEFUN([_AC_PROG_CC_C89],
1101 [_AC_C_STD_TRY([c89],
1102 [[#include <stdarg.h>
1105 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
1106 struct buf { int x; };
1107 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1108 static char *e (p, i)
1114 static char *f (char * (*g) (char **, int), char **p, ...)
1119 s = g (p, va_arg (v,int));
1124 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
1125 function prototypes and stuff, but not '\xHH' hex character constants.
1126 These don't provoke an error unfortunately, instead are silently treated
1127 as 'x'. The following induces an error, until -std is added to get
1128 proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
1129 array size at least. It's necessary to write '\x00'==0 to get something
1130 that's true only with -std. */
1131 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1133 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1134 inside strings and character constants. */
1136 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1138 int test (int i, double x);
1139 struct s1 {int (*f) (int a);};
1140 struct s2 {int (*f) (double a);};
1141 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1144 [[return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];]],
1145 dnl Don't try gcc -ansi; that turns off useful extensions and
1146 dnl breaks some systems' header files.
1147 dnl AIX circa 2003 -qlanglvl=extc89
1148 dnl old AIX -qlanglvl=ansi
1149 dnl Ultrix, OSF/1, Tru64 -std
1150 dnl HP-UX 10.20 and later -Ae
1151 dnl HP-UX older versions -Aa -D_HPUX_SOURCE
1152 dnl SVR4 -Xc -D__EXTENSIONS__
1153 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1154 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1158 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1159 # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1160 # --------------------------------------------------------------
1161 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1162 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
1163 # try again with each compiler option in the space-separated OPTION-LIST; if one
1164 # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
1165 # else ACTION-IF-UNAVAILABLE.
1166 AC_DEFUN([_AC_C_STD_TRY],
1167 [AC_MSG_CHECKING([for $CC option to enable ]m4_translit($1, [c], [C])[ features])
1168 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1169 [ac_cv_prog_cc_$1=no
1171 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1174 CC="$ac_save_CC $ac_arg"
1175 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1176 test "x$ac_cv_prog_cc_$1" != "xno" && break
1178 rm -f conftest.$ac_ext
1181 ac_prog_cc_stdc_options=
1182 case "x$ac_cv_prog_cc_$1" in
1184 AC_MSG_RESULT([none needed]) ;;
1186 AC_MSG_RESULT([unsupported]) ;;
1188 ac_prog_cc_stdc_options=" $ac_cv_prog_cc_$1"
1189 CC=$CC$ac_prog_cc_stdc_options
1190 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1192 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1195 # _AC_C_C99_TEST_HEADER
1196 # ---------------------
1197 # A C header suitable for testing for C99.
1198 AC_DEFUN([_AC_C_C99_TEST_HEADER],
1199 [[#include <stdarg.h>
1200 #include <stdbool.h>
1205 // Check varargs macros. These examples are taken from C99 6.10.3.5.
1206 #define debug(...) fprintf (stderr, __VA_ARGS__)
1207 #define showlist(...) puts (#__VA_ARGS__)
1208 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1210 test_varargs_macros (void)
1215 debug ("X = %d\n", x);
1216 showlist (The first, second, and third items.);
1217 report (x>y, "x is %d but y is %d", x, y);
1220 // Check long long types.
1221 #define BIG64 18446744073709551615ull
1222 #define BIG32 4294967295ul
1223 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1225 your preprocessor is broken;
1229 your preprocessor is broken;
1231 static long long int bignum = -9223372036854775807LL;
1232 static unsigned long long int ubignum = BIG64;
1234 struct incomplete_array
1242 const wchar_t *name;
1246 typedef const char *ccp;
1249 test_restrict (ccp restrict text)
1251 // See if C++-style comments work.
1252 // Iterate through items via the restricted pointer.
1253 // Also check for declarations in for loops.
1254 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
1259 // Check varargs and va_copy.
1261 test_varargs (const char *format, ...)
1264 va_start (args, format);
1266 va_copy (args_copy, args);
1277 str = va_arg (args_copy, const char *);
1280 number = va_arg (args_copy, int);
1283 fnumber = va_arg (args_copy, double);
1291 }]])# _AC_C_C99_TEST_HEADER
1293 # _AC_C_C99_TEST_BODY
1294 # -------------------
1295 # A C body suitable for testing for C99, assuming the corresponding header.
1296 AC_DEFUN([_AC_C_C99_TEST_BODY],
1299 _Bool success = false;
1302 if (test_restrict ("String literal") == 0)
1304 char *restrict newvar = "Another string";
1307 test_varargs ("s, d' f .", "string", 65, 34.234);
1308 test_varargs_macros ();
1310 // Check flexible array members.
1311 struct incomplete_array *ia =
1312 malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1314 for (int i = 0; i < ia->datasize; ++i)
1315 ia->data[i] = i * 1.234;
1317 // Check named initializers.
1318 struct named_init ni = {
1320 .name = L"Test wide string",
1321 .average = 543.34343,
1326 int dynamic_array[ni.number];
1327 dynamic_array[ni.number - 1] = 543;
1329 // work around unused variable warnings
1330 return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
1331 || dynamic_array[ni.number - 1] != 543);
1334 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1335 # ----------------------------------------------------------------
1336 # If the C compiler is not in ISO C99 mode by default, try to add an
1337 # option to output variable CC to make it so. This macro tries
1338 # various options that select ISO C99 on some system or another. It
1339 # considers the compiler to be in ISO C99 mode if it handles _Bool,
1340 # // comments, flexible array members, inline, long long int, mixed
1341 # code and declarations, named initialization of structs, restrict,
1342 # va_copy, varargs macros, variable declarations in for loops and
1343 # variable length arrays.
1344 AC_DEFUN([_AC_PROG_CC_C99],
1345 [_AC_C_STD_TRY([c99],
1346 [_AC_C_C99_TEST_HEADER],
1347 [_AC_C_C99_TEST_BODY],
1349 dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1350 dnl IBM XL C -qlanglvl=extc1x (V12.1; does not pass C11 test)
1351 dnl IBM XL C -qlanglvl=extc99
1352 dnl (pre-V12.1; unused restrictive mode: -qlanglvl=stdc99)
1354 dnl Intel ICC -std=c99, -c99 (deprecated)
1356 dnl Solaris -D_STDC_C99=
1357 dnl cc's -xc99 option uses linker magic to define the external
1358 dnl symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
1359 dnl behavior for C library functions. This is not wanted here,
1360 dnl because it means that a single module compiled with -xc99
1361 dnl alters C runtime behavior for the entire program, not for
1362 dnl just the module. Instead, define the (private) symbol
1363 dnl _STDC_C99, which suppresses a bogus failure in <stdbool.h>.
1364 dnl The resulting compiler passes the test case here, and that's
1365 dnl good enough. For more, please see the thread starting at:
1366 dnl http://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
1368 dnl with extended modes being tried first.
1369 [[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc1x -qlanglvl=extc99]], [$1], [$2])[]dnl
1373 # _AC_PROG_CC_C11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1374 # ----------------------------------------------------------------
1375 # If the C compiler is not in ISO C11 mode by default, try to add an
1376 # option to output variable CC to make it so. This macro tries
1377 # various options that select ISO C11 on some system or another. It
1378 # considers the compiler to be in ISO C11 mode if it handles _Alignas,
1379 # _Alignof, _Noreturn, _Static_assert, UTF-8 string literals,
1380 # duplicate typedefs, and anonymous structures and unions.
1381 AC_DEFUN([_AC_PROG_CC_C11],
1382 [_AC_C_STD_TRY([c11],
1383 [_AC_C_C99_TEST_HEADER[
1385 char _Alignas (double) aligned_as_double;
1386 char _Alignas (0) no_special_alignment;
1387 extern char aligned_as_int;
1388 char _Alignas (0) _Alignas (int) aligned_as_int;
1393 int_alignment = _Alignof (int),
1394 int_array_alignment = _Alignof (int[100]),
1395 char_alignment = _Alignof (char)
1397 _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
1400 int _Noreturn does_not_return (void) { for (;;) continue; }
1402 // Check _Static_assert.
1403 struct test_static_assert
1406 _Static_assert (sizeof (int) <= sizeof (long int),
1407 "_Static_assert does not work in struct");
1411 // Check UTF-8 literals.
1412 #define u8 syntax error!
1413 char const utf8_literal[] = u8"happens to be ASCII" "another string";
1415 // Check duplicate typedefs.
1416 typedef long *long_ptr;
1417 typedef long int *long_ptr;
1418 typedef long_ptr long_ptr;
1420 // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
1424 struct { int i; int j; };
1425 struct { int k; long int l; } w;
1430 [_AC_C_C99_TEST_BODY[
1433 _Static_assert (&v1.i == &v1.w.k, "Anonymous union alignment botch");
1436 dnl GCC -std=gnu11 (unused restrictive mode: -std=c11)
1437 dnl with extended modes being tried first.
1439 dnl Do not try -qlanglvl=extc1x, because IBM XL C V12.1 (the latest version as
1440 dnl of September 2012) does not pass the C11 test. For now, try extc1x when
1441 dnl compiling the C99 test instead, since it enables _Static_assert and
1442 dnl _Noreturn, which is a win. If -qlanglvl=extc11 or -qlanglvl=extc1x passes
1443 dnl the C11 test in some future version of IBM XL C, we'll add it here,
1444 dnl preferably extc11.
1445 [[-std=gnu11]], [$1], [$2])[]dnl
1451 AC_DEFUN([AC_PROG_CC_C89],
1452 [ AC_REQUIRE([AC_PROG_CC])dnl
1453 m4_warn([obsolete], [$0 is obsolete; use AC_PROG_CC])
1458 AC_DEFUN([AC_PROG_CC_C99],
1459 [ AC_REQUIRE([AC_PROG_CC])dnl
1460 m4_warn([obsolete], [$0 is obsolete; use AC_PROG_CC])
1465 AC_DEFUN([AC_PROG_CC_STDC],
1466 [ AC_REQUIRE([AC_PROG_CC])dnl
1467 m4_warn([obsolete], [$0 is obsolete; use AC_PROG_CC])
1473 AC_DEFUN([AC_C_BACKSLASH_A],
1475 AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1476 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1481 char buf['\a' == 'a' ? -1 : 1];
1483 return buf[0] != "\a"[0];
1485 [ac_cv_c_backslash_a=yes],
1486 [ac_cv_c_backslash_a=no])])
1487 if test $ac_cv_c_backslash_a = yes; then
1488 AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1489 [Define if backslash-a works in C strings.])
1496 # Has been merged into AC_PROG_CC.
1497 AU_DEFUN([AC_C_CROSS], [])
1500 # AC_C_CHAR_UNSIGNED
1501 # ------------------
1502 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1503 [AH_VERBATIM([__CHAR_UNSIGNED__],
1504 [/* Define to 1 if type `char' is unsigned and you are not using gcc. */
1505 #ifndef __CHAR_UNSIGNED__
1506 # undef __CHAR_UNSIGNED__
1508 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1509 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1510 [((char) -1) < 0])],
1511 ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1512 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1513 AC_DEFINE(__CHAR_UNSIGNED__)
1515 ])# AC_C_CHAR_UNSIGNED
1518 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1519 # [ACTION-IF-UNIVERSAL])
1520 # -------------------------------------------------------------------------
1521 AC_DEFUN([AC_C_BIGENDIAN],
1522 [AH_VERBATIM([WORDS_BIGENDIAN],
1523 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1524 significant byte first (like Motorola and SPARC, unlike Intel). */
1525 #if defined AC_APPLE_UNIVERSAL_BUILD
1526 # if defined __BIG_ENDIAN__
1527 # define WORDS_BIGENDIAN 1
1530 # ifndef WORDS_BIGENDIAN
1531 # undef WORDS_BIGENDIAN
1534 AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1535 [ac_cv_c_bigendian=unknown
1536 # See if we're dealing with a universal compiler.
1539 [[#ifndef __APPLE_CC__
1540 not a universal capable compiler
1545 # Check for potential -arch flags. It is not universal unless
1546 # there are at least two -arch flags with different values.
1549 for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
1550 if test -n "$ac_prev"; then
1552 i?86 | x86_64 | ppc | ppc64)
1553 if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
1556 ac_cv_c_bigendian=universal
1562 elif test "x$ac_word" = "x-arch"; then
1566 if test $ac_cv_c_bigendian = unknown; then
1567 # See if sys/param.h defines the BYTE_ORDER macro.
1570 [[#include <sys/types.h>
1571 #include <sys/param.h>
1573 [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1574 && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1579 [# It does; now see whether it defined to BIG_ENDIAN or not.
1582 [[#include <sys/types.h>
1583 #include <sys/param.h>
1585 [[#if BYTE_ORDER != BIG_ENDIAN
1589 [ac_cv_c_bigendian=yes],
1590 [ac_cv_c_bigendian=no])])
1592 if test $ac_cv_c_bigendian = unknown; then
1593 # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1596 [[#include <limits.h>
1598 [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1602 [# It does; now see whether it defined to _BIG_ENDIAN or not.
1605 [[#include <limits.h>
1607 [[#ifndef _BIG_ENDIAN
1611 [ac_cv_c_bigendian=yes],
1612 [ac_cv_c_bigendian=no])])
1614 if test $ac_cv_c_bigendian = unknown; then
1615 # Compile a test program.
1617 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1619 /* Are we little or big endian? From Harbison&Steele. */
1623 char c[sizeof (long int)];
1626 return u.c[sizeof (long int) - 1] == 1;
1628 [ac_cv_c_bigendian=no],
1629 [ac_cv_c_bigendian=yes],
1630 [# Try to guess by grepping values from an object file.
1633 [[short int ascii_mm[] =
1634 { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1635 short int ascii_ii[] =
1636 { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1637 int use_ascii (int i) {
1638 return ascii_mm[i] + ascii_ii[i];
1640 short int ebcdic_ii[] =
1641 { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1642 short int ebcdic_mm[] =
1643 { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1644 int use_ebcdic (int i) {
1645 return ebcdic_mm[i] + ebcdic_ii[i];
1649 [[return use_ascii (foo) == use_ebcdic (foo);]])],
1650 [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1651 ac_cv_c_bigendian=yes
1653 if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1654 if test "$ac_cv_c_bigendian" = unknown; then
1655 ac_cv_c_bigendian=no
1657 # finding both strings is unlikely to happen, but who knows?
1658 ac_cv_c_bigendian=unknown
1662 case $ac_cv_c_bigendian in #(
1665 [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1669 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
1670 dnl this is a necessity for proper config header operation. Warn if
1671 dnl the user did not specify a config header but is relying on the
1672 dnl default behavior for universal builds.
1674 [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
1675 [AC_DIAGNOSE([obsolete],
1676 [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
1677 AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
1678 [Define if building universal (internal helper macro)])])
1682 [AC_MSG_ERROR([unknown endianness
1683 presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1690 # Do nothing if the compiler accepts the inline keyword.
1691 # Otherwise define inline to __inline__ or __inline if one of those work,
1692 # otherwise define inline to be empty.
1694 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1695 # inline function, only builtin types.
1697 AN_IDENTIFIER([inline], [AC_C_INLINE])
1698 AC_DEFUN([AC_C_INLINE],
1699 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1701 for ac_kw in inline __inline__ __inline; do
1702 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1703 [#ifndef __cplusplus
1705 static $ac_kw foo_t static_foo () {return 0; }
1706 $ac_kw foo_t foo () {return 0; }
1709 [ac_cv_c_inline=$ac_kw])
1710 test "$ac_cv_c_inline" != no && break
1713 AH_VERBATIM([inline],
1714 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1715 calls it, or to nothing if 'inline' is not supported under any name. */
1719 case $ac_cv_c_inline in
1722 case $ac_cv_c_inline in
1724 *) ac_val=$ac_cv_c_inline;;
1726 cat >>confdefs.h <<_ACEOF
1728 #define inline $ac_val
1738 AC_DEFUN([AC_C_CONST],
1739 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1740 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1743 /* Ultrix mips cc rejects this sort of thing. */
1744 typedef int charset[2];
1745 const charset cs = { 0, 0 };
1746 /* SunOS 4.1.1 cc rejects this. */
1747 char const *const *pcpcc;
1749 /* NEC SVR4.0.2 mips cc rejects this. */
1750 struct point {int x, y;};
1751 static struct point const zero = {0,0};
1752 /* IBM XL C 1.02.0.0 rejects this.
1753 It does not let you subtract one const X* pointer from another in
1754 an arm of an if-expression whose if-part is not a constant
1756 const char *g = "string";
1757 pcpcc = &g + (g ? g-g : 0);
1758 /* HPUX 7.0 cc rejects these. */
1760 ppc = (char**) pcpcc;
1761 pcpcc = (char const *const *) ppc;
1762 { /* SCO 3.2v4 cc rejects this sort of thing. */
1765 char const *s = 0 ? (char *) 0 : (char const *) 0;
1770 { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
1772 const int *foo = &x[0];
1775 { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1776 typedef const int *iptr;
1780 { /* IBM XL C 1.02.0.0 rejects this sort of thing, saying
1781 "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1782 struct s { int j; const int *ap[3]; } bx;
1783 struct s *b = &bx; b->j = 5;
1785 { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1789 return !cs[0] && !zero.x;
1792 [ac_cv_c_const=yes],
1793 [ac_cv_c_const=no])])
1794 if test $ac_cv_c_const = no; then
1796 [Define to empty if `const' does not conform to ANSI C.])
1803 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1804 # http://autoconf-archive.cryp.to/acx_restrict.html
1806 # Determine whether the C/C++ compiler supports the "restrict" keyword
1807 # introduced in ANSI C99, or an equivalent. Define "restrict" to the alternate
1808 # spelling, if any; these are more likely to work in both C and C++ compilers of
1809 # the same family, and in the presence of varying compiler options. If only
1810 # plain "restrict" works, do nothing. Here are some variants:
1811 # - GCC supports both __restrict and __restrict__
1812 # - older DEC Alpha C compilers support only __restrict
1813 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1814 # Otherwise, define "restrict" to be empty.
1815 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1816 AC_DEFUN([AC_C_RESTRICT],
1817 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1818 [ac_cv_c_restrict=no
1819 # The order here caters to the fact that C++ does not require restrict.
1820 for ac_kw in __restrict __restrict__ _Restrict restrict; do
1821 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1822 [[typedef int * int_ptr;
1823 int foo (int_ptr $ac_kw ip) {
1830 [ac_cv_c_restrict=$ac_kw])
1831 test "$ac_cv_c_restrict" != no && break
1834 AH_VERBATIM([restrict],
1835 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1836 nothing if this is not supported. Do not define if restrict is
1837 supported directly. */
1839 /* Work around a bug in Sun C++: it does not support _Restrict or
1840 __restrict__, even though the corresponding Sun C compiler ends up with
1841 "#define restrict _Restrict" or "#define restrict __restrict__" in the
1842 previous line. Perhaps some future version of Sun C++ will work with
1843 restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
1844 #if defined __SUNPRO_CC && !defined __RESTRICT
1846 # define __restrict__
1848 case $ac_cv_c_restrict in
1850 no) AC_DEFINE([restrict], []) ;;
1851 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1858 # Note that, unlike const, #defining volatile to be the empty string can
1859 # actually turn a correct program into an incorrect one, since removing
1860 # uses of volatile actually grants the compiler permission to perform
1861 # optimizations that could break the user's code. So, do not #define
1862 # volatile away unless it is really necessary to allow the user's code
1863 # to compile cleanly. Benign compiler failures should be tolerated.
1864 AC_DEFUN([AC_C_VOLATILE],
1865 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1866 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1868 int * volatile y = (int *) 0;
1869 return !x && !y;])],
1870 [ac_cv_c_volatile=yes],
1871 [ac_cv_c_volatile=no])])
1872 if test $ac_cv_c_volatile = no; then
1873 AC_DEFINE(volatile,,
1874 [Define to empty if the keyword `volatile' does not work.
1875 Warning: valid code using `volatile' can become incorrect
1876 without. Disable with care.])
1883 # Checks if `#' can be used to glue strings together at the CPP level.
1884 # Defines HAVE_STRINGIZE if positive.
1885 AC_DEFUN([AC_C_STRINGIZE],
1886 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1887 [ac_cv_c_stringize],
1888 [AC_EGREP_CPP([@%:@teststring],
1891 char *s = x(teststring);],
1892 [ac_cv_c_stringize=no],
1893 [ac_cv_c_stringize=yes])])
1894 if test $ac_cv_c_stringize = yes; then
1895 AC_DEFINE(HAVE_STRINGIZE, 1,
1896 [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1903 # Check if the C compiler supports prototypes, included if it needs
1905 AC_DEFUN([AC_C_PROTOTYPES],
1906 [AC_REQUIRE([AC_PROG_CC])dnl
1907 if test "$ac_prog_cc_stdc" != no; then
1908 AC_DEFINE(PROTOTYPES, 1,
1909 [Define to 1 if the C compiler supports function prototypes.])
1910 AC_DEFINE(__PROTOTYPES, 1,
1911 [Define like PROTOTYPES; this can be used by system headers.])
1916 # AC_C_FLEXIBLE_ARRAY_MEMBER
1917 # --------------------------
1918 # Check whether the C compiler supports flexible array members.
1919 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1921 AC_CACHE_CHECK([for flexible array members],
1925 [[#include <stdlib.h>
1928 struct s { int n; double d[]; };]],
1929 [[int m = getchar ();
1930 struct s *p = malloc (offsetof (struct s, d)
1931 + m * sizeof (double));
1933 return p->d != (double *) NULL;]])],
1934 [ac_cv_c_flexmember=yes],
1935 [ac_cv_c_flexmember=no])])
1936 if test $ac_cv_c_flexmember = yes; then
1937 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1938 [Define to nothing if C supports flexible array members, and to
1939 1 if it does not. That way, with a declaration like `struct s
1940 { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1941 can be used with pre-C99 compilers.
1942 When computing the size of such an object, don't use 'sizeof (struct s)'
1943 as it overestimates the size. Use 'offsetof (struct s, d)' instead.
1944 Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1945 MSVC and with C++ compilers.])
1947 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1954 # Check whether the C compiler supports variable-length arrays.
1955 AC_DEFUN([AC_C_VARARRAYS],
1957 AC_CACHE_CHECK([for variable-length arrays],
1960 [AC_LANG_PROGRAM([],
1961 [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1962 [ac_cv_c_vararrays=yes],
1963 [ac_cv_c_vararrays=no])])
1964 if test $ac_cv_c_vararrays = yes; then
1965 AC_DEFINE([HAVE_C_VARARRAYS], 1,
1966 [Define to 1 if C supports variable-length arrays.])
1973 # Check if the C compiler supports GCC's typeof syntax.
1974 # The test case provokes incompatibilities in the Sun C compilers
1975 # (both Solaris 8 and Solaris 10).
1976 AC_DEFUN([AC_C_TYPEOF],
1978 AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1980 for ac_kw in typeof __typeof__ no; do
1981 test $ac_kw = no && break
1982 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1987 + ! (($ac_kw (value))
1988 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1989 ? ($ac_kw (value)) - 1
1990 : ~ (~ ($ac_kw (value)) 0
1991 << sizeof ($ac_kw (value)))))]; }
1994 (! ((void) ((ac__typeof_type_ *) 0), 0));
1996 [ac_cv_c_typeof=$ac_kw])
1997 test $ac_cv_c_typeof != no && break
1999 if test $ac_cv_c_typeof != no; then
2000 AC_DEFINE([HAVE_TYPEOF], 1,
2001 [Define to 1 if typeof works with your compiler.])
2002 if test $ac_cv_c_typeof != typeof; then
2003 AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
2004 [Define to __typeof__ if your compiler spells it that way.])
2012 # Expands to some language dependent source code for testing the presence of
2014 AC_DEFUN([_AC_LANG_OPENMP],
2015 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
2017 # _AC_LANG_OPENMP(C)
2018 # ------------------
2019 m4_define([_AC_LANG_OPENMP(C)],
2025 int main () { return omp_get_num_threads (); }
2028 # _AC_LANG_OPENMP(C++)
2029 # --------------------
2030 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
2032 # _AC_LANG_OPENMP(Fortran 77)
2033 # ---------------------------
2034 m4_define([_AC_LANG_OPENMP(Fortran 77)],
2040 call omp_set_num_threads(2)
2044 # _AC_LANG_OPENMP(Fortran)
2045 # ------------------------
2046 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
2050 # Check which options need to be passed to the C compiler to support OpenMP.
2051 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
2053 # The options are necessary at compile time (so the #pragmas are understood)
2054 # and at link time (so the appropriate library is linked with).
2055 # This macro takes care to not produce redundant options if $CC $CFLAGS already
2056 # supports OpenMP. It also is careful to not pass options to compilers that
2057 # misinterpret them; for example, most compilers accept "-openmp" and create
2058 # an output file called 'penmp' rather than activating OpenMP support.
2059 AC_DEFUN([AC_OPENMP],
2061 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
2062 AC_ARG_ENABLE([openmp],
2063 [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
2064 if test "$enable_openmp" != no; then
2065 AC_CACHE_CHECK([for $[]_AC_CC[] option to support OpenMP],
2066 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
2067 [AC_LINK_IFELSE([_AC_LANG_OPENMP],
2068 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
2069 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
2070 dnl Try these flags:
2071 dnl GCC >= 4.2 -fopenmp
2072 dnl SunPRO C -xopenmp
2074 dnl SGI C, PGI C -mp
2075 dnl Tru64 Compaq C -omp
2076 dnl IBM XL C (AIX, Linux) -qsmp=omp
2079 dnl Lahey Fortran (Linux) --openmp
2080 dnl If in this loop a compiler is passed an option that it doesn't
2081 dnl understand or that it misinterprets, the AC_LINK_IFELSE test
2082 dnl will fail (since we know that it failed without the option),
2083 dnl therefore the loop will continue searching for an option, and
2084 dnl no output file called 'penmp' or 'mp' is created.
2085 for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
2086 -Popenmp --openmp; do
2087 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
2088 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
2089 AC_LINK_IFELSE([_AC_LANG_OPENMP],
2090 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
2091 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
2092 if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
2096 case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
2097 "none needed" | unsupported)
2100 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
2103 AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])