1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001-2017, 2020-2025 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 <https://www.gnu.org/licenses/> and
24 # <https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob_plain;f=COPYING.EXCEPTION>.
26 # Written by David MacKenzie, with help from
27 # Akim Demaille, Paul Eggert,
28 # Franç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");
120 return ferror (f) || fclose (f) != 0;
124 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
125 # -----------------------------------
126 # Avoid conflicting decl of main.
127 m4_define([AC_LANG_CALL(C)],
129 m4_if([$2], [main], ,
130 [/* Override any GCC internal prototype to avoid an error.
131 Use char because int might match the return type of a GCC
132 builtin and then its argument prototype would still apply.
133 The 'extern "C"' is for builds by C++ compilers;
134 although this is not generally supported in C code supporting it here
135 has little cost and some practical benefit (sr 110532). */
139 char $2 (void);])], [return $2 ();])])
142 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
143 # ----------------------------------
144 # Don't include <ctype.h> because on OSF/1 3.0 it includes
145 # <sys/types.h> which includes <sys/select.h> which contains a
146 # prototype for select. Similarly for bzero.
148 # This test used to merely assign f=$1 in main(), but that was
149 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
150 # presumably on the basis that there's no need to do that store if the
151 # program is about to exit. Conversely, the AIX linker optimizes an
152 # unused external declaration that initializes f=$1. So this test
153 # program has both an external initialization of f, and a use of f in
154 # main that affects the exit status.
156 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
158 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
159 For example, HP-UX 11i <limits.h> declares gettimeofday. */
160 #define $1 innocuous_$1
162 /* System header to define __stub macros and hopefully few prototypes,
163 which can conflict with char $1 (void); below. */
168 /* Override any GCC internal prototype to avoid an error.
169 Use char because int might match the return type of a GCC
170 builtin and then its argument prototype would still apply. */
175 /* The GNU C library defines this for functions which it implements
176 to always fail with ENOSYS. Some functions are actually named
177 something starting with __ and the normal name is an alias. */
178 #if defined __stub_$1 || defined __stub___$1
181 ], [return $1 ();])])
184 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
185 # -------------------------------------------------
186 # Return a program that is valid if EXPRESSION is nonzero.
187 # EXPRESSION must be an integer constant expression.
188 # Be sure to use this array to avoid 'unused' warnings, which are even
189 # errors with '-W error'.
190 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
191 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
192 test_array @<:@0@:>@ = 0;
193 return test_array @<:@0@:>@;
197 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
198 # -----------------------------------------
199 # We need 'stdio.h' to open a 'FILE' and 'stdlib.h' for 'exit'.
200 # But we include them only after the EXPRESSION has been evaluated.
201 m4_define([AC_LANG_INT_SAVE(C)],
203 static long int longval (void) { return $2; }
204 static unsigned long int ulongval (void) { return $2; }
205 @%:@include <stdio.h>
206 @%:@include <stdlib.h>],
208 FILE *f = fopen ("conftest.val", "w");
213 long int i = longval ();
216 fprintf (f, "%ld", i);
220 unsigned long int i = ulongval ();
223 fprintf (f, "%lu", i);
225 /* Do not output a trailing newline, as this causes \r\n confusion
226 on some platforms. */
227 return ferror (f) || fclose (f) != 0;
232 ## ---------------------- ##
233 ## 1b. The C++ language. ##
234 ## ---------------------- ##
239 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
240 AC_LANG_DEFINE([C++], [cxx], [CXX], [CXX], [C],
242 ac_cpp='$CXXCPP $CPPFLAGS'
243 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
244 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
245 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
249 # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
250 # -------------------------------------
251 m4_define([AC_LANG_CALL(C++)],
252 dnl We do not know the function signature of the real $2.
253 dnl Declare it in a namespace so the compiler doesn't recognize it
254 dnl (with, most likely, a clashing prototype); the 'extern "C"' hides
255 dnl the namespace from the linker.
256 dnl Use 'int' for the return type, because some C++ compilers consider
257 dnl 'namespace conftest { extern "C" void main (); }' to be an
258 dnl erroneous redeclaration of ::main, namespace notwithstanding.
259 dnl The logic they're applying could be extended in the future to
260 dnl other built-in extern "C" functions, but let's worry about that
261 dnl when it actually happens.
262 [AC_LANG_PROGRAM([[$1
264 extern "C" int $2 ();
266 [[return conftest::$2 ();]])])
271 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
275 ## ------------------------------ ##
276 ## 1c. The Objective C language. ##
277 ## ------------------------------ ##
280 # AC_LANG(Objective C)
281 # --------------------
282 AC_LANG_DEFINE([Objective C], [objc], [OBJC], [OBJC], [C],
284 ac_cpp='$OBJCPP $CPPFLAGS'
285 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
286 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
287 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
293 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
297 ## -------------------------------- ##
298 ## 1d. The Objective C++ language. ##
299 ## -------------------------------- ##
302 # AC_LANG(Objective C++)
303 # ----------------------
304 AC_LANG_DEFINE([Objective C++], [objcxx], [OBJCXX], [OBJCXX], [C++],
306 ac_cpp='$OBJCXXCPP $CPPFLAGS'
307 ac_compile='$OBJCXX -c $OBJCXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
308 ac_link='$OBJCXX -o conftest$ac_exeext $OBJCXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
309 ac_compiler_gnu=$ac_cv_objcxx_compiler_gnu
314 ## -------------------------------------------- ##
315 ## 3. Looking for Compilers and Preprocessors. ##
316 ## -------------------------------------------- ##
318 # -------------------- #
319 # 3a. The C compiler. #
320 # -------------------- #
323 # _AC_ARG_VAR_CPPFLAGS
324 # --------------------
325 # Document and register CPPFLAGS, which is used by
326 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP, OBJCXX, OBJCXXCPP}.
327 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
328 [AC_ARG_VAR([CPPFLAGS],
329 [(Objective) C/C++ preprocessor flags, e.g. -I<include dir>
330 if you have headers in a nonstandard directory <include dir>])])
333 # _AC_ARG_VAR_LDFLAGS
334 # -------------------
335 # Document and register LDFLAGS, which is used by
336 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
337 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
338 [AC_ARG_VAR([LDFLAGS],
339 [linker flags, e.g. -L<lib dir> if you have libraries in a
340 nonstandard directory <lib dir>])])
345 # Document and register LIBS, which is used by
346 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
347 AC_DEFUN([_AC_ARG_VAR_LIBS],
349 [libraries to pass to the linker, e.g. -l<library>])])
354 # Find the C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
355 AC_DEFUN([AC_LANG_PREPROC(C)],
356 [AC_REQUIRE([AC_PROG_CPP])])
359 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
360 # -----------------------------------------------
361 # Check if $ac_cpp is a working preprocessor that can flag absent
362 # includes either by the exit status or by warnings.
363 # This macro is for all languages, not only C.
364 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
366 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
368 # Use a header file that comes with gcc, so configuring glibc
369 # with a fresh cross-compiler works.
370 # On the NeXT, cc -E runs the code through the compiler's parser,
371 # not just through cpp. "Syntax error" is here to catch this case.
372 _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <limits.h>
375 [# Broken: fails on valid input.
378 # OK, works on sane cases. Now check whether nonexistent headers
379 # can be detected and how.
380 _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
381 [# Broken: success on invalid input.
383 [# Passes both tests.
388 # Because of 'break', _AC_PREPROC_IFELSE's cleaning code was skipped.
389 rm -f conftest.i conftest.err conftest.$ac_ext
390 AS_IF([$ac_preproc_ok], [$1], [$2])
391 ])# _AC_PROG_PREPROC_WORKS_IFELSE
396 # Find a working C preprocessor.
397 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
398 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
399 AN_MAKEVAR([CPP], [AC_PROG_CPP])
400 AN_PROGRAM([cpp], [AC_PROG_CPP])
401 AC_DEFUN([AC_PROG_CPP],
402 [AC_REQUIRE([AC_PROG_CC])dnl
403 AC_ARG_VAR([CPP], [C preprocessor])dnl
404 _AC_ARG_VAR_CPPFLAGS()dnl
406 AC_MSG_CHECKING([how to run the C preprocessor])
407 # On Suns, sometimes $CPP names a directory.
408 if test -n "$CPP" && test -d "$CPP"; then
411 if test -z "$CPP"; then
412 AC_CACHE_VAL([ac_cv_prog_CPP],
414 # Double quotes because $CC needs to be expanded
415 for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp
417 _AC_PROG_PREPROC_WORKS_IFELSE([break])
425 AC_MSG_RESULT([$CPP])
426 _AC_PROG_PREPROC_WORKS_IFELSE([],
427 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
434 # Treat warnings from the preprocessor as errors.
435 AC_DEFUN([AC_PROG_CPP_WERROR],
436 [AC_REQUIRE([AC_PROG_CPP])dnl
437 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
439 # AC_LANG_COMPILER(C)
440 # -------------------
441 # Find the C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
442 AC_DEFUN([AC_LANG_COMPILER(C)],
443 [AC_REQUIRE([AC_PROG_CC])])
448 # We used to name the cache variable this way.
449 AU_DEFUN([ac_cv_prog_gcc],
450 [ac_cv_c_compiler_gnu])
453 # AC_PROG_CC([COMPILER ...])
454 # --------------------------
455 # COMPILER ... is a space separated list of C compilers to search for.
456 # This just gives the user an opportunity to specify an alternative
457 # search list for the C compiler.
458 AN_MAKEVAR([CC], [AC_PROG_CC])
459 AN_PROGRAM([cc], [AC_PROG_CC])
460 AN_PROGRAM([gcc], [AC_PROG_CC])
461 AC_DEFUN([AC_PROG_CC],
463 AC_ARG_VAR([CC], [C compiler command])dnl
464 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
465 _AC_ARG_VAR_LDFLAGS()dnl
466 _AC_ARG_VAR_LIBS()dnl
467 _AC_ARG_VAR_CPPFLAGS()dnl
469 [AC_CHECK_TOOLS(CC, [$1])],
470 [AC_CHECK_TOOL(CC, gcc)
471 if test -z "$CC"; then
473 dnl AC_CHECK_TOOL(CC, cc)
474 dnl but without the check for a tool without the prefix.
475 dnl Until the check is removed from there, copy the code:
476 if test -n "$ac_tool_prefix"; then
477 AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
480 if test -z "$CC"; then
481 AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
483 if test -z "$CC"; then
484 AC_CHECK_TOOLS(CC, cl.exe)
486 if test -z "$CC"; then
487 AC_CHECK_TOOL(CC, clang)
491 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
493 # Provide some information about the compiler.
494 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
497 for ac_option in --version -v -V -qversion -version; do
498 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
501 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
502 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
503 _AC_LANG_COMPILER_GNU
504 if test $ac_compiler_gnu = yes; then
510 _AC_PROG_CC_STDC_EDITION
517 # Check whether -g works, even if CFLAGS is set, in case the package
518 # plays around with CFLAGS (such as to build both debugging and normal
519 # versions of a library), tasteless as that idea is.
520 # Don't consider -g to work if it generates warnings when plain compiles don't.
521 m4_define([_AC_PROG_CC_G],
522 [ac_test_CFLAGS=${CFLAGS+y}
523 ac_save_CFLAGS=$CFLAGS
524 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
525 [ac_save_c_werror_flag=$ac_c_werror_flag
529 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
530 [ac_cv_prog_cc_g=yes],
532 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
534 [ac_c_werror_flag=$ac_save_c_werror_flag
536 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
537 [ac_cv_prog_cc_g=yes])])])
538 ac_c_werror_flag=$ac_save_c_werror_flag])
539 if test $ac_test_CFLAGS; then
540 CFLAGS=$ac_save_CFLAGS
541 elif test $ac_cv_prog_cc_g = yes; then
542 if test "$GCC" = yes; then
548 if test "$GCC" = yes; then
559 AC_DEFUN([AC_PROG_CC_C_O],
560 [AC_REQUIRE([AC_PROG_CC])dnl
562 if test "x$CC" != xcc; then
563 AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
565 AC_MSG_CHECKING([whether cc understands -c and -o together])
567 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
568 sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
569 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
570 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
571 # Make sure it works both with $CC and with simple cc.
572 # We do the test twice because some compilers refuse to overwrite an
573 # existing .o file with -o, though they will create one.
574 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
576 if _AC_DO_VAR(ac_try) &&
577 test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
579 eval ac_cv_prog_cc_${ac_cc}_c_o=yes
580 if test "x$CC" != xcc; then
581 # Test first that cc exists at all.
582 if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
583 ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
585 if _AC_DO_VAR(ac_try) &&
586 test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
591 # cc exists but doesn't like -o.
592 eval ac_cv_prog_cc_${ac_cc}_c_o=no
597 eval ac_cv_prog_cc_${ac_cc}_c_o=no
599 rm -rf core conftest*
601 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
605 AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
606 [Define to 1 if your C compiler doesn't accept -c and -o together.])
613 # ---------------------- #
614 # 3b. The C++ compiler. #
615 # ---------------------- #
618 # AC_LANG_PREPROC(C++)
619 # --------------------
620 # Find the C++ preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
621 AC_DEFUN([AC_LANG_PREPROC(C++)],
622 [AC_REQUIRE([AC_PROG_CXXCPP])])
627 # Find a working C++ preprocessor.
628 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
629 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
630 AC_DEFUN([AC_PROG_CXXCPP],
631 [AC_REQUIRE([AC_PROG_CXX])dnl
632 AC_ARG_VAR([CXXCPP], [C++ preprocessor])dnl
633 _AC_ARG_VAR_CPPFLAGS()dnl
635 AC_MSG_CHECKING([how to run the C++ preprocessor])
636 if test -z "$CXXCPP"; then
637 AC_CACHE_VAL(ac_cv_prog_CXXCPP,
639 # Double quotes because $CXX needs to be expanded
640 for CXXCPP in "$CXX -E" cpp /lib/cpp
642 _AC_PROG_PREPROC_WORKS_IFELSE([break])
644 ac_cv_prog_CXXCPP=$CXXCPP
646 CXXCPP=$ac_cv_prog_CXXCPP
648 ac_cv_prog_CXXCPP=$CXXCPP
650 AC_MSG_RESULT([$CXXCPP])
651 _AC_PROG_PREPROC_WORKS_IFELSE([],
652 [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
658 # AC_LANG_COMPILER(C++)
659 # ---------------------
660 # Find the C++ compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
661 AC_DEFUN([AC_LANG_COMPILER(C++)],
662 [AC_REQUIRE([AC_PROG_CXX])])
667 # We used to name the cache variable this way.
668 AU_DEFUN([ac_cv_prog_gxx],
669 [ac_cv_cxx_compiler_gnu])
672 # AC_PROG_CXX([LIST-OF-COMPILERS])
673 # --------------------------------
674 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
675 # for (if not specified, a default list is used). This just gives the
676 # user an opportunity to specify an alternative search list for the C++
678 # aCC HP-UX C++ compiler much better than 'CC', so test before.
679 # FCC Fujitsu C++ compiler
680 # KCC KAI C++ compiler
682 # xlC_r IBM XL C++ for AIX (with support for reentrant code)
683 # xlC IBM XL C++ for AIX
684 AN_MAKEVAR([CXX], [AC_PROG_CXX])
685 AN_PROGRAM([CC], [AC_PROG_CXX])
686 AN_PROGRAM([c++], [AC_PROG_CXX])
687 AN_PROGRAM([g++], [AC_PROG_CXX])
688 AC_DEFUN([AC_PROG_CXX],
689 [AC_LANG_PUSH(C++)dnl
690 AC_ARG_VAR([CXX], [C++ compiler command])dnl
691 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
692 _AC_ARG_VAR_LDFLAGS()dnl
693 _AC_ARG_VAR_LIBS()dnl
694 _AC_ARG_VAR_CPPFLAGS()dnl
695 _AC_ARG_VAR_PRECIOUS([CCC])dnl
696 if test -z "$CXX"; then
697 if test -n "$CCC"; then
702 [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC clang++])],
706 # Provide some information about the compiler.
707 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
710 for ac_option in --version -v -V -qversion; do
711 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
714 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
715 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
716 _AC_LANG_COMPILER_GNU
717 if test $ac_compiler_gnu = yes; then
729 # Check whether -g works, even if CXXFLAGS is set, in case the package
730 # plays around with CXXFLAGS (such as to build both debugging and
731 # normal versions of a library), tasteless as that idea is.
732 # Don't consider -g to work if it generates warnings when plain compiles don't.
733 m4_define([_AC_PROG_CXX_G],
734 [ac_test_CXXFLAGS=${CXXFLAGS+y}
735 ac_save_CXXFLAGS=$CXXFLAGS
736 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
737 [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
738 ac_cxx_werror_flag=yes
741 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
742 [ac_cv_prog_cxx_g=yes],
744 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
746 [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
748 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
749 [ac_cv_prog_cxx_g=yes])])])
750 ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
751 if test $ac_test_CXXFLAGS; then
752 CXXFLAGS=$ac_save_CXXFLAGS
753 elif test $ac_cv_prog_cxx_g = yes; then
754 if test "$GXX" = yes; then
760 if test "$GXX" = yes; then
771 # Test if the C++ compiler accepts the options '-c' and '-o'
772 # simultaneously, and define 'CXX_NO_MINUS_C_MINUS_O' if it does not.
773 AC_DEFUN([AC_PROG_CXX_C_O],
774 [AC_REQUIRE([AC_PROG_CXX])dnl
775 AC_LANG_PUSH([C++])dnl
776 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
777 [ac_cv_prog_cxx_c_o],
778 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
779 # We test twice because some compilers refuse to overwrite an existing
780 # '.o' file with '-o', although they will create one.
781 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
783 if _AC_DO_VAR(ac_try) &&
784 test -f conftest2.$ac_objext &&
785 _AC_DO_VAR(ac_try); then
786 ac_cv_prog_cxx_c_o=yes
788 ac_cv_prog_cxx_c_o=no
791 if test $ac_cv_prog_cxx_c_o = no; then
792 AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
793 [Define to 1 if your C++ compiler doesn't accept
794 -c and -o together.])
796 AC_LANG_POP([C++])dnl
801 # ------------------------------ #
802 # 3c. The Objective C compiler. #
803 # ------------------------------ #
806 # AC_LANG_PREPROC(Objective C)
807 # ----------------------------
808 # Find the Objective C preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
809 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
810 [AC_REQUIRE([AC_PROG_OBJCPP])])
815 # Find a working Objective C preprocessor.
816 AC_DEFUN([AC_PROG_OBJCPP],
817 [AC_REQUIRE([AC_PROG_OBJC])dnl
818 AC_ARG_VAR([OBJCPP], [Objective C preprocessor])dnl
819 _AC_ARG_VAR_CPPFLAGS()dnl
820 AC_LANG_PUSH(Objective C)dnl
821 AC_MSG_CHECKING([how to run the Objective C preprocessor])
822 if test -z "$OBJCPP"; then
823 AC_CACHE_VAL(ac_cv_prog_OBJCPP,
825 # Double quotes because $OBJC needs to be expanded
826 for OBJCPP in "$OBJC -E" cpp /lib/cpp
828 _AC_PROG_PREPROC_WORKS_IFELSE([break])
830 ac_cv_prog_OBJCPP=$OBJCPP
832 OBJCPP=$ac_cv_prog_OBJCPP
834 ac_cv_prog_OBJCPP=$OBJCPP
836 AC_MSG_RESULT([$OBJCPP])
837 _AC_PROG_PREPROC_WORKS_IFELSE([],
838 [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
840 AC_LANG_POP(Objective C)dnl
844 # AC_LANG_COMPILER(Objective C)
845 # -----------------------------
846 # Find the Objective C compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
847 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
848 [AC_REQUIRE([AC_PROG_OBJC])])
852 # AC_PROG_OBJC([LIST-OF-COMPILERS])
853 # ---------------------------------
854 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
855 # search for (if not specified, a default list is used). This just gives
856 # the user an opportunity to specify an alternative search list for the
857 # Objective C compiler.
858 # gobjc GNU Objective-C compiler packaged in EPEL (for systems where gcc
859 # does not support Objective-C)
860 # gcc GNU Objective-C compiler on most systems
861 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
862 # objc David Stes' POC. If you installed this, you likely want it.
863 # cc Native C compiler (for instance, Apple).
865 AN_MAKEVAR([OBJC], [AC_PROG_OBJC])
866 AN_PROGRAM([objcc], [AC_PROG_OBJC])
867 AN_PROGRAM([objc], [AC_PROG_OBJC])
868 AC_DEFUN([AC_PROG_OBJC],
869 [AC_LANG_PUSH(Objective C)dnl
870 AC_ARG_VAR([OBJC], [Objective C compiler command])dnl
871 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
872 _AC_ARG_VAR_LDFLAGS()dnl
873 _AC_ARG_VAR_LIBS()dnl
874 _AC_ARG_VAR_CPPFLAGS()dnl
875 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
877 [m4_default([$1], [gobjc gcc objcc objc cc CC clang])],
879 # Provide some information about the compiler.
880 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
883 for ac_option in --version -v -V -qversion; do
884 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
887 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
888 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
889 _AC_LANG_COMPILER_GNU
890 if test $ac_compiler_gnu = yes; then
896 AC_LANG_POP(Objective C)dnl
902 # Check whether -g works, even if OBJCFLAGS is set, in case the package
903 # plays around with OBJCFLAGS (such as to build both debugging and
904 # normal versions of a library), tasteless as that idea is.
905 # Don't consider -g to work if it generates warnings when plain compiles don't.
906 m4_define([_AC_PROG_OBJC_G],
907 [ac_test_OBJCFLAGS=${OBJCFLAGS+y}
908 ac_save_OBJCFLAGS=$OBJCFLAGS
909 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
910 [ac_save_objc_werror_flag=$ac_objc_werror_flag
911 ac_objc_werror_flag=yes
914 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
915 [ac_cv_prog_objc_g=yes],
917 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
919 [ac_objc_werror_flag=$ac_save_objc_werror_flag
921 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
922 [ac_cv_prog_objc_g=yes])])])
923 ac_objc_werror_flag=$ac_save_objc_werror_flag])
924 if test $ac_test_OBJCFLAGS; then
925 OBJCFLAGS=$ac_save_OBJCFLAGS
926 elif test $ac_cv_prog_objc_g = yes; then
927 if test "$GOBJC" = yes; then
933 if test "$GOBJC" = yes; then
943 # -------------------------------- #
944 # 3d. The Objective C++ compiler. #
945 # -------------------------------- #
948 # AC_LANG_PREPROC(Objective C++)
949 # ------------------------------
950 # Find the Objective C++ preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
951 AC_DEFUN([AC_LANG_PREPROC(Objective C++)],
952 [AC_REQUIRE([AC_PROG_OBJCXXCPP])])
957 # Find a working Objective C++ preprocessor.
958 AC_DEFUN([AC_PROG_OBJCXXCPP],
959 [AC_REQUIRE([AC_PROG_OBJCXX])dnl
960 AC_ARG_VAR([OBJCXXCPP], [Objective C++ preprocessor])dnl
961 _AC_ARG_VAR_CPPFLAGS()dnl
962 AC_LANG_PUSH(Objective C++)dnl
963 AC_MSG_CHECKING([how to run the Objective C++ preprocessor])
964 if test -z "$OBJCXXCPP"; then
965 AC_CACHE_VAL(ac_cv_prog_OBJCXXCPP,
967 # Double quotes because $OBJCXX needs to be expanded
968 for OBJCXXCPP in "$OBJCXX -E" cpp /lib/cpp
970 _AC_PROG_PREPROC_WORKS_IFELSE([break])
972 ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
974 OBJCXXCPP=$ac_cv_prog_OBJCXXCPP
976 ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
978 AC_MSG_RESULT([$OBJCXXCPP])
979 _AC_PROG_PREPROC_WORKS_IFELSE([],
980 [AC_MSG_FAILURE([Objective C++ preprocessor "$OBJCXXCPP" fails sanity check])])
981 AC_SUBST(OBJCXXCPP)dnl
982 AC_LANG_POP(Objective C++)dnl
983 ])# AC_PROG_OBJCXXCPP
986 # AC_LANG_COMPILER(Objective C++)
987 # -------------------------------
988 # Find the Objective C++ compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
989 AC_DEFUN([AC_LANG_COMPILER(Objective C++)],
990 [AC_REQUIRE([AC_PROG_OBJCXX])])
994 # AC_PROG_OBJCXX([LIST-OF-COMPILERS])
995 # -----------------------------------
996 # LIST-OF-COMPILERS is a space separated list of Objective C++ compilers to
997 # search for (if not specified, a default list is used). This just gives
998 # the user an opportunity to specify an alternative search list for the
999 # Objective C++ compiler.
1000 # FIXME: this list is pure guesswork
1001 # objc++ StepStone Objective-C++ compiler (also "standard" name for OBJCXX)
1002 # objcxx David Stes' POC. If you installed this, you likely want it.
1003 # c++ Native C++ compiler (for instance, Apple).
1004 # CXX You never know.
1005 AN_MAKEVAR([OBJCXX], [AC_PROG_OBJCXX])
1006 AN_PROGRAM([objcxx], [AC_PROG_OBJCXX])
1007 AC_DEFUN([AC_PROG_OBJCXX],
1008 [AC_LANG_PUSH(Objective C++)dnl
1009 AC_ARG_VAR([OBJCXX], [Objective C++ compiler command])dnl
1010 AC_ARG_VAR([OBJCXXFLAGS], [Objective C++ compiler flags])dnl
1011 _AC_ARG_VAR_LDFLAGS()dnl
1012 _AC_ARG_VAR_LIBS()dnl
1013 _AC_ARG_VAR_CPPFLAGS()dnl
1014 _AC_ARG_VAR_PRECIOUS([OBJCXX])dnl
1015 AC_CHECK_TOOLS(OBJCXX,
1016 [m4_default([$1], [g++ objc++ objcxx c++ CXX])],
1018 # Provide some information about the compiler.
1019 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
1022 for ac_option in --version -v -V -qversion; do
1023 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
1026 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
1027 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
1028 _AC_LANG_COMPILER_GNU
1029 if test $ac_compiler_gnu = yes; then
1035 AC_LANG_POP(Objective C++)dnl
1041 # Check whether -g works, even if OBJCFLAGS is set, in case the package
1042 # plays around with OBJCFLAGS (such as to build both debugging and
1043 # normal versions of a library), tasteless as that idea is.
1044 # Don't consider -g to work if it generates warnings when plain compiles don't.
1045 m4_define([_AC_PROG_OBJCXX_G],
1046 [ac_test_OBJCXXFLAGS=${OBJCXXFLAGS+y}
1047 ac_save_OBJCXXFLAGS=$OBJCXXFLAGS
1048 AC_CACHE_CHECK(whether $OBJCXX accepts -g, ac_cv_prog_objcxx_g,
1049 [ac_save_objcxx_werror_flag=$ac_objcxx_werror_flag
1050 ac_objcxx_werror_flag=yes
1051 ac_cv_prog_objcxx_g=no
1053 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1054 [ac_cv_prog_objcxx_g=yes],
1056 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1058 [ac_objcxx_werror_flag=$ac_save_objcxx_werror_flag
1060 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1061 [ac_cv_prog_objcxx_g=yes])])])
1062 ac_objcxx_werror_flag=$ac_save_objcx_werror_flag])
1063 if test $ac_test_OBJCXXFLAGS; then
1064 OBJCXXFLAGS=$ac_save_OBJCXXFLAGS
1065 elif test $ac_cv_prog_objcxx_g = yes; then
1066 if test "$GOBJCXX" = yes; then
1067 OBJCXXFLAGS="-g -O2"
1072 if test "$GOBJCXX" = yes; then
1078 ])# _AC_PROG_OBJCXX_G
1082 ## ------------------------------- ##
1083 ## 4. Compilers' characteristics. ##
1084 ## ------------------------------- ##
1086 # -------------------------------- #
1087 # 4a. C compiler characteristics. #
1088 # -------------------------------- #
1090 # Fragments of these programs are emitted as shell variables in the
1091 # INIT_PREPARE diversion, because they can get long and we want only
1092 # one copy of each fragment in the generated configure. This also
1093 # makes quoting control a bit easier. Try to avoid using ', however,
1094 # because putting single quotes into a single-quoted shell string is
1095 # awkward (you must write '\'' for each ' you want in the program).
1097 # Warning: to avoid incorrect answers due to unused-variable warnings
1098 # and/or overly aggressive optimizers, each variable (global or not)
1099 # in these programs should be used, and each function should be
1100 # called. Unlike how AC_LANG_PROGRAM(C) usually does it, we declare
1101 # main with its usual two arguments, to give the test fragments some
1102 # convenient non-compile-time-constant values to pass around. In main,
1103 # there is an int variable 'ok' which will eventually become the return
1104 # value; use 'ok |= ...' to consume the results of operations.
1106 # Warning: each test program may only use the headers required to
1107 # exist in the relevant standard's *freestanding* environment, in case
1108 # the C compiler targets such an environment. (Therefore, almost no
1109 # features of the C89/C99/C11/C23 standard *library* are probed. Use
1110 # AC_CHECK_HEADER, AC_CHECK_FUNC, etc. for that.) However, these
1111 # programs are only compiled and not linked, so it is ok to declare
1112 # external functions and then call them without worrying about whether
1113 # they actually exist.
1115 # The C89 freestanding headers are:
1116 # <float.h> <limits.h> <stdarg.h> <stddef.h>
1118 # <iso646.h> <stdbool.h> <stdint.h>
1120 # <stdalign.h> <stdnoreturn.h>
1121 # C23 adds the following. Do not test it, though, as compiler options like
1122 # -std=gnu23 are useful even when <stdbit.h> is supplied by a non-C23 library,
1123 # not by the compiler:
1126 AC_DEFUN([_AC_C_C89_TEST_GLOBALS],
1127 [m4_divert_text([INIT_PREPARE],
1128 [[# Test code for whether the C compiler supports C89 (global declarations)
1129 ac_c_conftest_c89_globals='
1130 /* Do not test the value of __STDC__, because some compilers define it to 0
1131 or do not define it, while otherwise adequately conforming. */
1136 /* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */
1137 struct buf { int x; };
1138 struct buf * (*rcsopen) (struct buf *, struct stat *, int);
1139 static char *e (char **p, int i)
1143 static char *f (char * (*g) (char **, int), char **p, ...)
1148 s = g (p, va_arg (v,int));
1153 /* C89 style stringification. */
1154 #define noexpand_stringify(a) #a
1155 const char *stringified = noexpand_stringify(arbitrary+token=sequence);
1157 /* C89 style token pasting. Exercises some of the corner cases that
1158 e.g. old MSVC gets wrong, but not very hard. */
1159 #define noexpand_concat(a,b) a##b
1160 #define expand_concat(a,b) noexpand_concat(a,b)
1165 int *pvA = &expand_concat(v,aye);
1166 int *pvbee = &noexpand_concat(v,bee);
1168 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
1169 function prototypes and stuff, but not \xHH hex character constants.
1170 These do not provoke an error unfortunately, instead are silently treated
1171 as an "x". The following induces an error, until -std is added to get
1172 proper ANSI mode. Curiously \x00 != x always comes out true, for an
1173 array size at least. It is necessary to write \x00 == 0 to get something
1174 that is true only with -std. */
1175 int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1];
1177 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1178 inside strings and character constants. */
1179 #define FOO(x) '\''x'\''
1180 int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1];
1182 int test (int i, double x);
1183 struct s1 {int (*f) (int a);};
1184 struct s2 {int (*f) (double a);};
1185 int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int),
1189 AC_DEFUN([_AC_C_C89_TEST_MAIN],
1190 [m4_divert_text([INIT_PREPARE],
1191 [[# Test code for whether the C compiler supports C89 (body of main).
1192 ac_c_conftest_c89_main='
1193 ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]);
1197 AC_DEFUN([_AC_C_C99_TEST_GLOBALS],
1198 [m4_divert_text([INIT_PREPARE],
1199 [[# Test code for whether the C compiler supports C99 (global declarations)
1200 ac_c_conftest_c99_globals='
1201 /* Does the compiler advertise C99 conformance? */
1202 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
1203 # error "Compiler does not advertise C99 conformance"
1206 // See if C++-style comments work.
1208 #include <stdbool.h>
1209 extern int puts (const char *);
1210 extern int printf (const char *, ...);
1211 extern int dprintf (int, const char *, ...);
1212 extern void *malloc (size_t);
1213 extern void free (void *);
1215 // Check varargs macros. These examples are taken from C99 6.10.3.5.
1216 // dprintf is used instead of fprintf to avoid needing to declare
1218 #define debug(...) dprintf (2, __VA_ARGS__)
1219 #define showlist(...) puts (#__VA_ARGS__)
1220 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1222 test_varargs_macros (void)
1227 debug ("X = %d\n", x);
1228 showlist (The first, second, and third items.);
1229 report (x>y, "x is %d but y is %d", x, y);
1232 // Check long long types.
1233 #define BIG64 18446744073709551615ull
1234 #define BIG32 4294967295ul
1235 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1237 #error "your preprocessor is broken"
1241 #error "your preprocessor is broken"
1243 static long long int bignum = -9223372036854775807LL;
1244 static unsigned long long int ubignum = BIG64;
1246 struct incomplete_array
1254 const wchar_t *name;
1258 typedef const char *ccp;
1261 test_restrict (ccp restrict text)
1263 // Iterate through items via the restricted pointer.
1264 // Also check for declarations in for loops.
1265 for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i)
1270 // Check varargs and va_copy.
1272 test_varargs (const char *format, ...)
1275 va_start (args, format);
1277 va_copy (args_copy, args);
1279 const char *str = "";
1287 case '\''s'\'': // string
1288 str = va_arg (args_copy, const char *);
1290 case '\''d'\'': // int
1291 number = va_arg (args_copy, int);
1293 case '\''f'\'': // float
1294 fnumber = va_arg (args_copy, double);
1303 return *str && number && fnumber;
1308 AC_DEFUN([_AC_C_C99_TEST_MAIN],
1309 [m4_divert_text([INIT_PREPARE],
1310 [[# Test code for whether the C compiler supports C99 (body of main).
1311 ac_c_conftest_c99_main='
1313 _Bool success = false;
1314 success |= (argc != 0);
1317 if (test_restrict ("String literal") == 0)
1319 char *restrict newvar = "Another string";
1322 success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234);
1323 test_varargs_macros ();
1325 // Check flexible array members.
1326 struct incomplete_array *ia =
1327 malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1329 for (int i = 0; i < ia->datasize; ++i)
1330 ia->data[i] = i * 1.234;
1331 // Work around memory leak warnings.
1334 // Check named initializers.
1335 struct named_init ni = {
1337 .name = L"Test wide string",
1338 .average = 543.34343,
1343 // Do not test for VLAs, as some otherwise-conforming compilers lack them.
1344 // C code should instead use __STDC_NO_VLA__; see Autoconf manual.
1346 // work around unused variable warnings
1347 ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\''
1348 || ni.number != 58);
1352 AC_DEFUN([_AC_C_C11_TEST_GLOBALS],
1353 [m4_divert_text([INIT_PREPARE],
1354 [[# Test code for whether the C compiler supports C11 (global declarations)
1355 ac_c_conftest_c11_globals='
1356 /* Does the compiler advertise C11 conformance? */
1357 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
1358 # error "Compiler does not advertise C11 conformance"
1362 char _Alignas (double) aligned_as_double;
1363 char _Alignas (0) no_special_alignment;
1364 extern char aligned_as_int;
1365 char _Alignas (0) _Alignas (int) aligned_as_int;
1370 int_alignment = _Alignof (int),
1371 int_array_alignment = _Alignof (int[100]),
1372 char_alignment = _Alignof (char)
1374 _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
1377 int _Noreturn does_not_return (void) { for (;;) continue; }
1379 // Check _Static_assert.
1380 struct test_static_assert
1383 _Static_assert (sizeof (int) <= sizeof (long int),
1384 "_Static_assert does not work in struct");
1388 // Check UTF-8 literals.
1389 #define u8 syntax error!
1390 char const utf8_literal[] = u8"happens to be ASCII" "another string";
1392 // Check duplicate typedefs.
1393 typedef long *long_ptr;
1394 typedef long int *long_ptr;
1395 typedef long_ptr long_ptr;
1397 // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
1401 struct { int i; int j; };
1402 struct { int k; long int l; } w;
1409 AC_DEFUN([_AC_C_C11_TEST_MAIN],
1410 [m4_divert_text([INIT_PREPARE],
1411 [[# Test code for whether the C compiler supports C11 (body of main).
1412 ac_c_conftest_c11_main='
1413 _Static_assert ((offsetof (struct anonymous, i)
1414 == offsetof (struct anonymous, w.k)),
1415 "Anonymous union alignment botch");
1422 AC_DEFUN([_AC_C_C23_TEST_GLOBALS],
1423 [m4_divert_text([INIT_PREPARE],
1424 [[# Test code for whether the C compiler supports C23 (global declarations)
1425 ac_c_conftest_c23_globals='
1426 /* Does the compiler advertise conformance to C17 or earlier?
1427 Although GCC 14 does not do that, even with -std=gnu23,
1428 it is close enough, and defines __STDC_VERSION == 202000L. */
1429 #if !defined __STDC_VERSION__ || __STDC_VERSION__ <= 201710L
1430 # error "Compiler advertises conformance to C17 or earlier"
1434 char alignas (double) c23_aligned_as_double;
1435 char alignas (0) c23_no_special_alignment;
1436 extern char c23_aligned_as_int;
1437 char alignas (0) alignas (int) c23_aligned_as_int;
1442 c23_int_alignment = alignof (int),
1443 c23_int_array_alignment = alignof (int[100]),
1444 c23_char_alignment = alignof (char)
1446 static_assert (0 < -alignof (int), "alignof is signed");
1448 int function_with_unnamed_parameter (int) { return 0; }
1450 void c23_noreturn ();
1452 /* Test parsing of string and char UTF-8 literals (including hex escapes).
1453 The parens pacify GCC 15. */
1454 bool use_u8 = (!sizeof u8"\xFF") == (!u8'\''x'\'');
1456 bool check_that_bool_works = true | false | !nullptr;
1458 # error "true does not work in #if"
1461 #elifdef __STDC_VERSION__
1463 # error "#elifdef does not work"
1466 #ifndef __has_c_attribute
1467 # error "__has_c_attribute not defined"
1470 #ifndef __has_include
1471 # error "__has_include not defined"
1475 #define FORTY_TWO(x) 42
1476 #define VA_OPT_TEST(r, x, ...) __VA_OPT__ (FORTY_TWO r x))
1477 static_assert (VA_OPT_TEST (LPAREN (), 0, <:-) == 42);
1479 static_assert (0b101010 == 42);
1480 static_assert (0B101010 == 42);
1481 static_assert (0xDEAD'\''BEEF == 3'\''735'\''928'\''559);
1482 static_assert (0.500'\''000'\''000 == 0.5);
1484 enum unsignedish : unsigned int { uione = 1 };
1485 static_assert (0 < -uione);
1488 constexpr nullptr_t null_pointer = nullptr;
1490 static typeof (1 + 1L) two () { return 2; }
1491 static long int three () { return 3; }
1495 AC_DEFUN([_AC_C_C23_TEST_MAIN],
1496 [m4_divert_text([INIT_PREPARE],
1497 [[# Test code for whether the C compiler supports C23 (body of main).
1498 ac_c_conftest_c23_main='
1500 label_before_declaration:
1503 goto label_before_declaration;
1505 goto label_at_end_of_block;
1506 label_at_end_of_block:
1508 ok |= !null_pointer;
1513 AC_DEFUN([_AC_C_C89_TEST_PROGRAM],
1514 [AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])dnl
1515 AC_REQUIRE([_AC_C_C89_TEST_MAIN])dnl
1516 m4_divert_text([INIT_PREPARE],
1517 [[# Test code for whether the C compiler supports C89 (complete).
1518 ac_c_conftest_c89_program="${ac_c_conftest_c89_globals}
1521 main (int argc, char **argv)
1524 ${ac_c_conftest_c89_main}
1530 AC_DEFUN([_AC_C_C99_TEST_PROGRAM],
1531 [AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])dnl
1532 AC_REQUIRE([_AC_C_C89_TEST_MAIN])dnl
1533 AC_REQUIRE([_AC_C_C99_TEST_GLOBALS])dnl
1534 AC_REQUIRE([_AC_C_C99_TEST_MAIN])dnl
1535 m4_divert_text([INIT_PREPARE],
1536 [[# Test code for whether the C compiler supports C99 (complete).
1537 ac_c_conftest_c99_program="${ac_c_conftest_c89_globals}
1538 ${ac_c_conftest_c99_globals}
1541 main (int argc, char **argv)
1544 ${ac_c_conftest_c89_main}
1545 ${ac_c_conftest_c99_main}
1551 AC_DEFUN([_AC_C_C11_TEST_PROGRAM],
1552 [AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])dnl
1553 AC_REQUIRE([_AC_C_C89_TEST_MAIN])dnl
1554 AC_REQUIRE([_AC_C_C99_TEST_GLOBALS])dnl
1555 AC_REQUIRE([_AC_C_C99_TEST_MAIN])dnl
1556 AC_REQUIRE([_AC_C_C11_TEST_GLOBALS])dnl
1557 AC_REQUIRE([_AC_C_C11_TEST_MAIN])dnl
1558 m4_divert_text([INIT_PREPARE],
1559 [[# Test code for whether the C compiler supports C11 (complete).
1560 ac_c_conftest_c11_program="${ac_c_conftest_c89_globals}
1561 ${ac_c_conftest_c99_globals}
1562 ${ac_c_conftest_c11_globals}
1565 main (int argc, char **argv)
1568 ${ac_c_conftest_c89_main}
1569 ${ac_c_conftest_c99_main}
1570 ${ac_c_conftest_c11_main}
1576 AC_DEFUN([_AC_C_C23_TEST_PROGRAM],
1577 [AC_REQUIRE([_AC_C_C23_TEST_GLOBALS])dnl
1578 AC_REQUIRE([_AC_C_C23_TEST_MAIN])dnl
1579 m4_divert_text([INIT_PREPARE],
1580 [[# Test code for whether the C compiler supports C23 (complete).
1581 ac_c_conftest_c23_program="${ac_c_conftest_c23_globals}
1587 ${ac_c_conftest_c23_main}
1596 # Whitespace-separated list of options that might put the C compiler
1597 # into a mode conforming to ISO C1990 with extensions. Do not try
1598 # "strictly conforming" modes (e.g. gcc's -std=c90); they break some
1599 # systems' header files. If more than one option is needed, put
1600 # shell quotes around the group.
1602 # AIX circa 2003 -qlanglvl=extc89
1603 # old AIX -qlanglvl=ansi
1604 # Ultrix, OSF/1, Tru64 -std
1605 # HP-UX 10.20 and later -Ae
1606 # HP-UX older versions -Aa -D_HPUX_SOURCE
1607 # SVR4 -Xc -D__EXTENSIONS__
1608 m4_define([_AC_C_C89_OPTIONS], [
1613 "-Aa -D_HPUX_SOURCE"
1614 "-Xc -D__EXTENSIONS__"
1620 # Whitespace-separated list of options that might put the C compiler
1621 # into a mode conforming to ISO C1999 with extensions. Do not try
1622 # "strictly conforming" modes (e.g. gcc's -std=c99); they break some
1623 # systems' header files. If more than one option is needed, put
1624 # shell quotes around the group.
1626 # GCC, Clang -std=gnu99
1627 # Intel ICC -std=c99, -c99 (deprecated)
1628 # Note: because -std=c99 puts GCC in strictly conforming mode,
1629 # this option must be tested *after* -std=gnu99.
1632 # IBM XL C -qlanglvl=extc1x (V12.1; does not pass C11 test)
1633 # IBM XL C -qlanglvl=extc99 (pre-V12.1)
1635 # Solaris -D_STDC_C99=
1636 # Note: acc's -xc99 option uses linker magic to define the external
1637 # symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
1638 # behavior for C library functions. This is not wanted here,
1639 # because it means that a single module compiled with -xc99 alters
1640 # C runtime behavior for the entire program, not for just the
1641 # module. Instead, define the (private) symbol _STDC_C99, which
1642 # suppresses a bogus failure in <stdbool.h>. The resulting compiler
1643 # passes the test case here, and that's good enough.
1644 # For more, please see the thread starting at:
1645 # https://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
1646 m4_define([_AC_C_C99_OPTIONS], [
1659 # Whitespace-separated list of options that might put the C compiler
1660 # into a mode conforming to ISO C2011 with extensions. Do not try
1661 # "strictly conforming" modes (e.g. gcc's -std=c11); they break some
1662 # systems' header files. If more than one option is needed, put
1663 # shell quotes around the group.
1665 # GCC, Clang -std=gnu11
1668 # For IBM XL C for AIX V16.1 or later, '-std=gnu11' should work if
1669 # the user configured with CC='xlclang'. Otherwise, do not try
1670 # -qlanglvl=extc1x as xlc with IBM XL C V16.1 (the latest version as
1671 # of August 2020) does not pass the C11 test. Instead, try extc1x when
1672 # compiling the C99 test instead, since it enables _Static_assert and
1673 # _Noreturn, which is a win.
1674 m4_define([_AC_C_C11_OPTIONS], [
1681 # Whitespace-separated list of options that might put the C compiler
1682 # into a mode conforming to ISO C 2023 with extensions. Do not try
1683 # "strictly conforming" modes (e.g. gcc's -std=c23); they break some
1684 # systems' header files. If more than one option is needed, put
1685 # shell quotes around the group.
1687 # GCC, Clang -std=gnu23
1688 m4_define([_AC_C_C23_OPTIONS], [
1693 # _AC_PROG_CC_STDC_EDITION_TRY(EDITION)
1694 # -------------------------------------
1695 # Subroutine of _AC_PROG_CC_STDC_EDITION. Not to be called directly.
1697 # Check whether the C compiler accepts features of EDITION of the
1698 # C standard. EDITION should be a two-digit year (e.g. 89, 99, 11, 23).
1699 # (FIXME: Switch to four-digit years for futureproofing.)
1700 # This is done by compiling the test program defined by
1701 # _AC_C_C{EDITION}_TEST_PROGRAM, first with no additional
1702 # command-line options, and then with each of the options
1703 # in the space-separated list defined by _AC_C_C{EDITION}_OPTIONS.
1705 # If we find a way to make the test program compile, set cache variable
1706 # ac_cv_prog_cc_cEDITION to the options required (if any), and add those
1707 # options to $CC. Set shell variable ac_prog_cc_stdc to 'cEDITION',
1708 # and set shell variable ac_cv_prog_cc_stdc to the options required.
1709 # (Neither of these variables is AC_SUBSTed. ac_cv_prog_cc_stdc used
1710 # to be a cache variable and is preserved with this name for backward
1711 # compatibility.) Otherwise, ac_cv_prog_cc_cEDITION is set to 'no'
1712 # and the other variables are not changed.
1714 # If ac_prog_cc_stdc is already set to a value other than 'no',
1715 # the shell code produced by this macro does nothing. This is so
1716 # _AC_PROG_CC_STDC_EDITION can use m4_map to iterate through
1718 AC_DEFUN([_AC_PROG_CC_STDC_EDITION_TRY],
1719 [AC_LANG_ASSERT([C])]dnl
1720 [AC_REQUIRE([_AC_C_C$1_TEST_PROGRAM])]dnl
1721 [AS_IF([test x$ac_prog_cc_stdc = xno],
1722 [AC_MSG_CHECKING([for $CC option to enable C$1 features])
1723 AC_CACHE_VAL([ac_cv_prog_cc_c$1],
1724 [ac_cv_prog_cc_c$1=no
1726 AC_LANG_CONFTEST([AC_LANG_DEFINES_PROVIDED][$][ac_c_conftest_c$1_program])
1727 for ac_arg in '' m4_normalize(m4_defn([_AC_C_C$1_OPTIONS]))
1729 CC="$ac_save_CC $ac_arg"
1730 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_c$1=$ac_arg])
1731 test "x$ac_cv_prog_cc_c$1" != "xno" && break
1733 rm -f conftest.$ac_ext
1735 AS_IF([test "x$ac_cv_prog_cc_c$1" = xno],
1736 [AC_MSG_RESULT([unsupported])],
1737 [AS_IF([test "x$ac_cv_prog_cc_c$1" = x],
1738 [AC_MSG_RESULT([none needed])],
1739 [AC_MSG_RESULT([$ac_cv_prog_cc_c$1])
1740 CC="$CC $ac_cv_prog_cc_c$1"])
1741 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c$1
1742 ac_prog_cc_stdc=c$1])])
1746 # _AC_PROG_CC_STDC_EDITION
1747 # ------------------------
1748 # Detect the most recent edition of the ISO C standard that is
1749 # supported by the C compiler. Add command-line options to $CC, if
1750 # necessary, to enable support for this edition. Set the shell
1751 # variable ac_prog_cc_stdc to indicate the edition.
1752 AC_DEFUN([_AC_PROG_CC_STDC_EDITION],
1754 m4_map([_AC_PROG_CC_STDC_EDITION_TRY], [[23], [11], [99], [89]])])
1757 # _AC_PROG_CC_C89(ACTION-IF-SUPPORTED, ACTION-IF-NOT-SUPPORTED)
1758 # -------------------------------------------------------------
1759 # Obsolete internal macro. No longer used by Autoconf itself, but
1760 # preserved for backward compatibility with pre-December 2020 versions
1761 # of Gnulib's std-gnu11.m4, which replaced the entire definition of
1762 # AC_PROG_CC *except* for this macro. Can be removed once everyone is
1763 # using Autoconf 2.70 and/or a current std-gnu11.m4.
1764 AC_DEFUN([_AC_PROG_CC_C89],
1765 [AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])]dnl
1766 [AC_REQUIRE([_AC_C_C89_TEST_MAIN])]dnl
1767 [_AC_C_STD_TRY([c89],
1768 [$ac_c_conftest_c89_globals], [$ac_c_conftest_c89_main],
1769 m4_quote(m4_normalize(m4_defn([_AC_C_C89_OPTIONS]))),
1777 # Do not use AU_ALIAS here and in AC_PROG_CC_C99 and AC_PROG_CC_STDC,
1778 # as that'd be incompatible with how Automake redefines AC_PROG_CC. See
1779 # <https://lists.gnu.org/archive/html/autoconf/2012-10/msg00048.html>.
1780 AU_DEFUN([AC_PROG_CC_C89],
1781 [AC_REQUIRE([AC_PROG_CC])],
1782 [$0 is obsolete; use AC_PROG_CC]
1787 AU_DEFUN([AC_PROG_CC_C99],
1788 [AC_REQUIRE([AC_PROG_CC])],
1789 [$0 is obsolete; use AC_PROG_CC]
1794 AU_DEFUN([AC_PROG_CC_STDC],
1795 [AC_REQUIRE([AC_PROG_CC])],
1796 [$0 is obsolete; use AC_PROG_CC]
1799 # AC_PROG_GCC_TRADITIONAL
1800 # -----------------------
1801 AU_DEFUN([AC_PROG_GCC_TRADITIONAL],
1802 [AC_REQUIRE([AC_PROG_CC])],
1803 [$0 is obsolete; use AC_PROG_CC]
1808 AC_DEFUN([AC_C_BACKSLASH_A],
1810 AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1811 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1816 char buf['\a' == 'a' ? -1 : 1];
1818 return buf[0] != "\a"[0];
1820 [ac_cv_c_backslash_a=yes],
1821 [ac_cv_c_backslash_a=no])])
1822 if test $ac_cv_c_backslash_a = yes; then
1823 AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1824 [Define if backslash-a works in C strings.])
1831 # Has been merged into AC_PROG_CC.
1832 AU_DEFUN([AC_C_CROSS], [])
1835 # AC_C_CHAR_UNSIGNED
1836 # ------------------
1837 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1838 [AH_VERBATIM([__CHAR_UNSIGNED__],
1839 [/* Define to 1 if type 'char' is unsigned and your compiler does not
1840 predefine this macro. */
1841 #ifndef __CHAR_UNSIGNED__
1842 # undef __CHAR_UNSIGNED__
1844 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1845 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1846 [((char) -1) < 0])],
1847 ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1848 if test $ac_cv_c_char_unsigned = yes; then
1849 AC_DEFINE(__CHAR_UNSIGNED__)
1851 ])# AC_C_CHAR_UNSIGNED
1854 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1855 # [ACTION-IF-UNIVERSAL])
1856 # -------------------------------------------------------------------------
1857 AC_DEFUN([AC_C_BIGENDIAN],
1858 [AH_VERBATIM([WORDS_BIGENDIAN],
1859 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1860 significant byte first (like Motorola and SPARC, unlike Intel). */
1861 #if defined AC_APPLE_UNIVERSAL_BUILD
1862 # if defined __BIG_ENDIAN__
1863 # define WORDS_BIGENDIAN 1
1866 # ifndef WORDS_BIGENDIAN
1867 # undef WORDS_BIGENDIAN
1870 AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1871 [ac_cv_c_bigendian=unknown
1872 # See if we're dealing with a universal compiler.
1875 [[#ifndef __APPLE_CC__
1876 not a universal capable compiler
1881 # Check for potential -arch flags. It is not universal unless
1882 # there are at least two -arch flags with different values.
1885 for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
1886 if test -n "$ac_prev"; then
1888 i?86 | x86_64 | ppc | ppc64)
1889 if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
1892 ac_cv_c_bigendian=universal
1898 elif test "x$ac_word" = "x-arch"; then
1902 if test $ac_cv_c_bigendian = unknown; then
1903 # See if sys/param.h defines the BYTE_ORDER macro.
1906 [[#include <sys/types.h>
1907 #include <sys/param.h>
1909 [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \\
1910 && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \\
1915 [# It does; now see whether it defined to BIG_ENDIAN or not.
1918 [[#include <sys/types.h>
1919 #include <sys/param.h>
1921 [[#if BYTE_ORDER != BIG_ENDIAN
1925 [ac_cv_c_bigendian=yes],
1926 [ac_cv_c_bigendian=no])])
1928 if test $ac_cv_c_bigendian = unknown; then
1929 # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1932 [[#include <limits.h>
1934 [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1938 [# It does; now see whether it defined to _BIG_ENDIAN or not.
1941 [[#include <limits.h>
1943 [[#ifndef _BIG_ENDIAN
1947 [ac_cv_c_bigendian=yes],
1948 [ac_cv_c_bigendian=no])])
1950 if test $ac_cv_c_bigendian = unknown; then
1951 # Compile a test program.
1953 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1955 /* Are we little or big endian? From Harbison&Steele. */
1959 char c[sizeof (long int)];
1962 return u.c[sizeof (long int) - 1] == 1;
1964 [ac_cv_c_bigendian=no],
1965 [ac_cv_c_bigendian=yes],
1966 [# Try to guess by grepping values from an object file.
1969 [[unsigned short int ascii_mm[] =
1970 { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1971 unsigned short int ascii_ii[] =
1972 { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1973 int use_ascii (int i) {
1974 return ascii_mm[i] + ascii_ii[i];
1976 unsigned short int ebcdic_ii[] =
1977 { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1978 unsigned short int ebcdic_mm[] =
1979 { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1980 int use_ebcdic (int i) {
1981 return ebcdic_mm[i] + ebcdic_ii[i];
1984 main (int argc, char **argv)
1986 /* Intimidate the compiler so that it does not
1987 optimize the arrays away. */
1989 ascii_mm[1] = *p++; ebcdic_mm[1] = *p++;
1990 ascii_ii[1] = *p++; ebcdic_ii[1] = *p++;
1991 return use_ascii (argc) == use_ebcdic (*p);
1993 [if grep BIGenDianSyS conftest$ac_exeext >/dev/null; then
1994 ac_cv_c_bigendian=yes
1996 if grep LiTTleEnDian conftest$ac_exeext >/dev/null ; then
1997 if test "$ac_cv_c_bigendian" = unknown; then
1998 ac_cv_c_bigendian=no
2000 # finding both strings is unlikely to happen, but who knows?
2001 ac_cv_c_bigendian=unknown
2005 case $ac_cv_c_bigendian in #(
2008 [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
2012 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
2013 dnl this is a necessity for proper config header operation. Warn if
2014 dnl the user did not specify a config header but is relying on the
2015 dnl default behavior for universal builds.
2017 [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
2018 [m4_warn([obsolete],
2019 [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
2020 AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
2021 [Define if building universal (internal helper macro)])])
2025 [AC_MSG_ERROR([unknown endianness
2026 presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
2033 # Define HAVE_C__GENERIC if _Generic works, a la C11.
2034 AN_IDENTIFIER([_Generic], [AC_C__GENERIC])
2035 AC_DEFUN([AC_C__GENERIC],
2036 [AC_CACHE_CHECK([for _Generic], ac_cv_c__Generic,
2040 main (int argc, char **argv)
2042 int a = _Generic (argc, int: argc = 1);
2043 int *b = &_Generic (argc, default: argc);
2044 char ***c = _Generic (argv, int: argc, default: argv ? &argv : 0);
2045 _Generic (1 ? 0 : b, int: a, default: b) = &argc;
2046 _Generic (a = 1, default: a) = 3;
2050 [ac_cv_c__Generic=yes],
2051 [ac_cv_c__Generic=no])])
2052 if test $ac_cv_c__Generic = yes; then
2053 AC_DEFINE([HAVE_C__GENERIC], 1,
2054 [Define to 1 if C11-style _Generic works.])
2060 # Do nothing if the compiler accepts the inline keyword.
2061 # Otherwise define inline to __inline__ or __inline if one of those work,
2062 # otherwise define inline to be empty.
2064 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
2065 # inline function, only builtin types.
2067 AN_IDENTIFIER([inline], [AC_C_INLINE])
2068 AC_DEFUN([AC_C_INLINE],
2069 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
2071 for ac_kw in inline __inline__ __inline; do
2072 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
2073 [#ifndef __cplusplus
2075 static $ac_kw foo_t static_foo (void) {return 0; }
2076 $ac_kw foo_t foo (void) {return 0; }
2079 [ac_cv_c_inline=$ac_kw])
2080 test "$ac_cv_c_inline" != no && break
2083 AH_VERBATIM([inline],
2084 [/* Define to '__inline__' or '__inline' if that's what the C compiler
2085 calls it, or to nothing if 'inline' is not supported under any name. */
2089 case $ac_cv_c_inline in
2092 case $ac_cv_c_inline in
2094 *) ac_val=$ac_cv_c_inline;;
2096 cat >>confdefs.h <<_ACEOF
2098 #define inline $ac_val
2108 AC_DEFUN([AC_C_CONST],
2109 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
2110 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
2113 /* Ultrix mips cc rejects this sort of thing. */
2114 typedef int charset[2];
2115 const charset cs = { 0, 0 };
2116 /* SunOS 4.1.1 cc rejects this. */
2117 char const *const *pcpcc;
2119 /* NEC SVR4.0.2 mips cc rejects this. */
2120 struct point {int x, y;};
2121 static struct point const zero = {0,0};
2122 /* IBM XL C 1.02.0.0 rejects this.
2123 It does not let you subtract one const X* pointer from another in
2124 an arm of an if-expression whose if-part is not a constant
2126 const char *g = "string";
2127 pcpcc = &g + (g ? g-g : 0);
2128 /* HPUX 7.0 cc rejects these. */
2130 ppc = (char**) pcpcc;
2131 pcpcc = (char const *const *) ppc;
2132 { /* SCO 3.2v4 cc rejects this sort of thing. */
2135 char const *s = 0 ? (char *) 0 : (char const *) 0;
2140 { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
2142 const int *foo = &x[0];
2145 { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
2146 typedef const int *iptr;
2150 { /* IBM XL C 1.02.0.0 rejects this sort of thing, saying
2151 "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
2152 struct s { int j; const int *ap[3]; } bx;
2153 struct s *b = &bx; b->j = 5;
2155 { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
2159 return !cs[0] && !zero.x;
2162 [ac_cv_c_const=yes],
2163 [ac_cv_c_const=no])])
2164 if test $ac_cv_c_const = no; then
2166 [Define to empty if 'const' does not conform to ANSI C.])
2173 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive
2175 # Determine whether the C/C++ compiler supports the "restrict" keyword
2176 # introduced in ANSI C99, or an equivalent. Define "restrict" to the alternate
2177 # spelling, if any; these are more likely to work in both C and C++ compilers of
2178 # the same family, and in the presence of varying compiler options. If only
2179 # plain "restrict" works, do nothing. Here are some variants:
2180 # - GCC supports both __restrict and __restrict__
2181 # - older DEC Alpha C compilers support only __restrict
2182 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
2183 # Otherwise, define "restrict" to be empty.
2184 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
2185 AC_DEFUN([AC_C_RESTRICT],
2186 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
2187 [ac_cv_c_restrict=no
2188 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
2189 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
2190 # Put 'restrict' last, because C++ lacks it.
2191 for ac_kw in __restrict__ __restrict _Restrict restrict; do
2194 [[typedef int *int_ptr;
2195 int foo (int_ptr $ac_kw ip) { return ip[0]; }
2196 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
2197 int bar (int ip[$ac_kw]) { return ip[0]; }
2202 return foo (t) + bar (t);
2204 [ac_cv_c_restrict=$ac_kw])
2205 test "$ac_cv_c_restrict" != no && break
2208 AH_VERBATIM([restrict],
2209 [/* Define to the equivalent of the C99 'restrict' keyword, or to
2210 nothing if this is not supported. Do not define if restrict is
2211 supported only directly. */
2213 /* Work around a bug in older versions of Sun C++, which did not
2214 #define __restrict__ or support _Restrict or __restrict__
2215 even though the corresponding Sun C compiler ended up with
2216 "#define restrict _Restrict" or "#define restrict __restrict__"
2217 in the previous line. This workaround can be removed once
2218 we assume Oracle Developer Studio 12.5 (2016) or later. */
2219 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
2221 # define __restrict__
2223 case $ac_cv_c_restrict in
2225 no) AC_DEFINE([restrict], []) ;;
2226 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
2233 # Note that, unlike const, #defining volatile to be the empty string can
2234 # actually turn a correct program into an incorrect one, since removing
2235 # uses of volatile actually grants the compiler permission to perform
2236 # optimizations that could break the user's code. So, do not #define
2237 # volatile away unless it is really necessary to allow the user's code
2238 # to compile cleanly. Benign compiler failures should be tolerated.
2239 AC_DEFUN([AC_C_VOLATILE],
2240 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
2241 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
2243 int * volatile y = (int *) 0;
2244 return !x && !y;])],
2245 [ac_cv_c_volatile=yes],
2246 [ac_cv_c_volatile=no])])
2247 if test $ac_cv_c_volatile = no; then
2248 AC_DEFINE(volatile,,
2249 [Define to empty if the keyword 'volatile' does not work.
2250 Warning: valid code using 'volatile' can become incorrect
2251 without. Disable with care.])
2258 # Checks if '#' can be used to glue strings together at the CPP level.
2259 # Defines HAVE_STRINGIZE if positive.
2260 # Obsolete - new code should assume C89 compliance.
2261 AC_DEFUN([AC_C_STRINGIZE],
2262 [AC_REQUIRE([AC_PROG_CC])
2263 if test "$ac_prog_cc_stdc" != no; then
2264 AC_DEFINE(HAVE_STRINGIZE, 1,
2265 [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
2272 # Check if the C compiler supports prototypes.
2273 # Obsolete - new code should assume C89 compliance.
2274 AC_DEFUN([AC_C_PROTOTYPES],
2275 [AC_REQUIRE([AC_PROG_CC])dnl
2276 if test "$ac_prog_cc_stdc" != no; then
2277 AC_DEFINE(PROTOTYPES, 1,
2278 [Define to 1 if the C compiler supports function prototypes.])
2279 AC_DEFINE(__PROTOTYPES, 1,
2280 [Define like PROTOTYPES; this can be used by system headers.])
2285 # AC_C_FLEXIBLE_ARRAY_MEMBER
2286 # --------------------------
2287 # Check whether the C compiler supports flexible array members.
2288 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
2290 AC_CACHE_CHECK([for flexible array members],
2294 [[#include <stdlib.h>
2297 struct s { int n; double d[]; };]],
2298 [[int m = getchar ();
2299 struct s *p = (struct s *) malloc (offsetof (struct s, d)
2300 + m * sizeof (double));
2302 m = p->d != (double *) NULL;
2305 [ac_cv_c_flexmember=yes],
2306 [ac_cv_c_flexmember=no])])
2307 if test $ac_cv_c_flexmember = yes; then
2308 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
2309 [Define to nothing if C supports flexible array members, and to
2310 1 if it does not. That way, with a declaration like 'struct s
2311 { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
2312 can be used with pre-C99 compilers.
2313 When computing the size of such an object, don't use 'sizeof (struct s)'
2314 as it overestimates the size. Use 'offsetof (struct s, d)' instead.
2315 Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
2316 MSVC and with C++ compilers.])
2318 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
2325 # Check whether the C compiler supports variable-length arrays.
2326 AC_DEFUN([AC_C_VARARRAYS],
2328 AC_CACHE_CHECK([for variable-length arrays],
2330 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
2331 [[ #ifndef __STDC_NO_VLA__
2332 #error __STDC_NO_VLA__ not defined
2335 [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
2338 [[/* Test for VLA support. This test is partly inspired
2339 from examples in the C standard. Use at least two VLA
2340 functions to detect the GCC 3.4.3 bug described in:
2341 https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
2343 #ifdef __STDC_NO_VLA__
2348 int fvla (int m, int C[m][m]);
2351 simple (int count, int all[static count])
2353 return all[count - 1];
2357 fvla (int m, int C[m][m])
2359 typedef int VLA[m][m];
2362 static int (*q)[m] = &B;
2364 return C && &x[0][0] == &D[0] && &D[0] == s[0];
2368 [ac_cv_c_vararrays=yes],
2369 [ac_cv_c_vararrays=no])])])
2370 if test "$ac_cv_c_vararrays" = yes; then
2371 dnl This is for compatibility with Autoconf 2.61-2.69.
2372 AC_DEFINE([HAVE_C_VARARRAYS], 1,
2373 [Define to 1 if C supports variable-length arrays.])
2374 elif test "$ac_cv_c_vararrays" = no; then
2375 AC_DEFINE([__STDC_NO_VLA__], 1,
2376 [Define to 1 if C does not support variable-length arrays, and
2377 if the compiler does not already define this.])
2384 # Check if the C compiler supports GCC's typeof syntax.
2385 # The test case provokes incompatibilities in the Sun C compilers
2386 # (both Solaris 8 and Solaris 10).
2387 AC_DEFUN([AC_C_TYPEOF],
2389 AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
2391 for ac_kw in typeof __typeof__ no; do
2392 test $ac_kw = no && break
2393 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
2398 + ! (($ac_kw (value))
2399 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
2400 ? ($ac_kw (value)) - 1
2401 : ~ (~ ($ac_kw (value)) 0
2402 << sizeof ($ac_kw (value)))))]; }
2405 (! ((void) ((ac__typeof_type_ *) 0), 0));
2407 [ac_cv_c_typeof=$ac_kw])
2408 test $ac_cv_c_typeof != no && break
2410 if test $ac_cv_c_typeof != no; then
2411 AC_DEFINE([HAVE_TYPEOF], 1,
2412 [Define to 1 if typeof works with your compiler.])
2413 if test $ac_cv_c_typeof != typeof; then
2414 AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
2415 [Define to __typeof__ if your compiler spells it that way.])
2423 # Expands to some language dependent source code for testing the presence of
2425 AC_DEFUN([_AC_LANG_OPENMP],
2426 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
2428 # _AC_LANG_OPENMP(C)
2429 # ------------------
2430 m4_define([_AC_LANG_OPENMP(C)],
2433 #error "OpenMP not supported"
2436 int main (void) { return omp_get_num_threads (); }
2439 # _AC_LANG_OPENMP(C++)
2440 # --------------------
2441 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
2443 # _AC_LANG_OPENMP(Fortran 77)
2444 # ---------------------------
2445 m4_define([_AC_LANG_OPENMP(Fortran 77)],
2451 call omp_set_num_threads(2)
2455 # _AC_LANG_OPENMP(Fortran)
2456 # ------------------------
2457 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
2461 # Check which options need to be passed to the C compiler to support OpenMP.
2462 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
2464 # The options are necessary at compile time (so the #pragmas are understood)
2465 # and at link time (so the appropriate library is linked with).
2466 # This macro takes care to not produce redundant options if $CC $CFLAGS already
2469 # For each candidate option, we do a compile test first, then a link test;
2470 # if the compile test succeeds but the link test fails, that means we have
2471 # found the correct option but it doesn't work because the libraries are
2472 # broken. (This can happen, for instance, with SunPRO C and a bad combination
2473 # of operating system patches.)
2475 # Several of the options in our candidate list can be misinterpreted by
2476 # compilers that don't use them to activate OpenMP support; for example,
2477 # many compilers understand "-openmp" to mean "write output to a file
2478 # named 'penmp'" rather than "enable OpenMP". We can't completely avoid
2479 # the possibility of clobbering files named 'penmp' or 'mp' in configure's
2480 # working directory; therefore, this macro will bomb out if any such file
2481 # already exists when it's invoked.
2482 AC_DEFUN([AC_OPENMP],
2483 [AC_REQUIRE([_AC_OPENMP_SAFE_WD])]dnl
2484 [AC_ARG_ENABLE([openmp],
2485 [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])]dnl
2487 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
2488 if test "$enable_openmp" != no; then
2489 AC_CACHE_CHECK([for $[]_AC_CC[] option to support OpenMP],
2490 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
2491 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='not found'
2492 dnl Try these flags:
2493 dnl (on by default) ''
2494 dnl GCC >= 4.2 -fopenmp
2495 dnl SunPRO C -xopenmp
2497 dnl SGI C, PGI C -mp
2498 dnl Tru64 Compaq C -omp
2499 dnl IBM XL C (AIX, Linux) -qsmp=omp
2502 dnl Lahey Fortran (Linux) --openmp
2503 for ac_option in '' -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
2504 -Popenmp --openmp; do
2506 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
2507 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
2508 AC_COMPILE_IFELSE([_AC_LANG_OPENMP],
2509 [AC_LINK_IFELSE([_AC_LANG_OPENMP],
2510 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option],
2511 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'])])
2512 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
2514 if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != 'not found'; then
2518 if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" = 'not found'; then
2519 ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
2520 elif test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" = ''; then
2521 ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'
2523 dnl _AC_OPENMP_SAFE_WD checked that these files did not exist before we
2524 dnl started probing for OpenMP support, so if they exist now, they were
2525 dnl created by the probe loop and it's safe to delete them.
2527 if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != 'unsupported' && \
2528 test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != 'none needed'; then
2529 OPENMP_[]_AC_LANG_PREFIX[]FLAGS="$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp"
2532 AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
2535 # _AC_OPENMP_SAFE_WD
2536 # ------------------
2537 # AC_REQUIREd by AC_OPENMP. Checks both at autoconf time and at
2538 # configure time for files that AC_OPENMP clobbers.
2539 AC_DEFUN([_AC_OPENMP_SAFE_WD],
2540 [m4_syscmd([test ! -e penmp && test ! -e mp])]dnl
2541 [m4_if(sysval, [0], [], [m4_fatal(m4_normalize(
2542 [AC_OPENMP clobbers files named 'mp' and 'penmp'.
2543 To use AC_OPENMP you must not have either of these files
2544 at the top level of your source tree.]))])]dnl
2545 [if test -e penmp || test -e mp; then
2546 AC_MSG_ERROR(m4_normalize(
2547 [AC@&t@_OPENMP clobbers files named 'mp' and 'penmp'.
2548 Aborting configure because one of these files already exists.]))