Give a URL for COPYING.EXCEPTION in notices
[autoconf.git] / lib / autoconf / c.m4
blob40ed1175e63c9a13a64a8444c7af565e1c9c5ac8
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001-2017, 2020-2024 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.
32 # Table of Contents:
34 # 1. Language selection
35 # 2. and routines to produce programs in a given language.
36 #      1a. C   2a. C
37 #      1b. C++
38 #      1c. Objective C
39 #      1d. Objective C++
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.
46 #      4a. C
50 ## ----------------------- ##
51 ## 1a/2a. The C language.  ##
52 ## ----------------------- ##
55 # ------------------------ #
56 # 1a. Language selection.  #
57 # ------------------------ #
59 # AC_LANG(C)
60 # ----------
61 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
62 AC_LANG_DEFINE([C], [c], [C], [CC], [],
63 [ac_ext=c
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
71 # AC_LANG_C
72 # ---------
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
89 /* end confdefs.h.  */
91 _ACEOF])
94 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
95 # --------------------------------------
96 m4_define([AC_LANG_PROGRAM(C)],
97 [$1
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
101 main (void)
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.
106   ;
107   return 0;
111 # _AC_LANG_IO_PROGRAM(C)
112 # ----------------------
113 # Produce source that performs I/O, necessary for proper
114 # cross-compiler detection.
115 m4_define([_AC_LANG_IO_PROGRAM(C)],
116 [AC_LANG_PROGRAM([@%:@include <stdio.h>],
117 [FILE *f = fopen ("conftest.out", "w");
118  if (!f)
119   return 1;
120  return ferror (f) || fclose (f) != 0;
121 ])])
124 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
125 # -----------------------------------
126 # Avoid conflicting decl of main.
127 m4_define([AC_LANG_CALL(C)],
128 [AC_LANG_PROGRAM([$1
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).  */
136 #ifdef __cplusplus
137 extern "C"
138 #endif
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)],
157 [AC_LANG_PROGRAM(
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.  */
165 #include <limits.h>
166 #undef $1
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.  */
171 #ifdef __cplusplus
172 extern "C"
173 #endif
174 char $1 (void);
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
179 choke me
180 #endif
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@:>@;
194 ])])
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)],
202 [AC_LANG_PROGRAM([$1
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");
209   if (! f)
210     return 1;
211   if (($2) < 0)
212     {
213       long int i = longval ();
214       if (i != ($2))
215         return 1;
216       fprintf (f, "%ld", i);
217     }
218   else
219     {
220       unsigned long int i = ulongval ();
221       if (i != ($2))
222         return 1;
223       fprintf (f, "%lu", i);
224     }
225   /* Do not output a trailing newline, as this causes \r\n confusion
226      on some platforms.  */
227   return ferror (f) || fclose (f) != 0;
228 ])])
232 ## ---------------------- ##
233 ## 1b. The C++ language.  ##
234 ## ---------------------- ##
237 # AC_LANG(C++)
238 # ------------
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],
241 [ac_ext=cpp
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
263 namespace conftest {
264   extern "C" int $2 ();
265 }]],
266 [[return conftest::$2 ();]])])
269 # AC_LANG_CPLUSPLUS
270 # -----------------
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],
283 [ac_ext=m
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
291 # AC_LANG_OBJC
292 # ------------
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++],
305 [ac_ext=mm
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>])])
343 # _AC_ARG_VAR_LIBS
344 # ----------------
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],
348 [AC_ARG_VAR([LIBS],
349             [libraries to pass to the linker, e.g. -l<library>])])
352 # AC_LANG_PREPROC(C)
353 # ------------------
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],
365 [ac_preproc_ok=false
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>
373                      Syntax error]])],
374                      [],
375                      [# Broken: fails on valid input.
376 continue])
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.
382 continue],
383                      [# Passes both tests.
384 ac_preproc_ok=:
385 break])
387 done
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
394 # AC_PROG_CPP
395 # -----------
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
405 AC_LANG_PUSH(C)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
409   CPP=
411 if test -z "$CPP"; then
412   AC_CACHE_VAL([ac_cv_prog_CPP],
413   [dnl
414     # Double quotes because $CC needs to be expanded
415     for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp
416     do
417       _AC_PROG_PREPROC_WORKS_IFELSE([break])
418     done
419     ac_cv_prog_CPP=$CPP
420   ])dnl
421   CPP=$ac_cv_prog_CPP
422 else
423   ac_cv_prog_CPP=$CPP
425 AC_MSG_RESULT([$CPP])
426 _AC_PROG_PREPROC_WORKS_IFELSE([],
427                 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
428 AC_SUBST(CPP)dnl
429 AC_LANG_POP(C)dnl
430 ])# AC_PROG_CPP
432 # AC_PROG_CPP_WERROR
433 # ------------------
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])])
446 # ac_cv_prog_gcc
447 # --------------
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],
462 [AC_LANG_PUSH(C)dnl
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
468 m4_ifval([$1],
469       [AC_CHECK_TOOLS(CC, [$1])],
470 [AC_CHECK_TOOL(CC, gcc)
471 if test -z "$CC"; then
472   dnl Here we want:
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])
478   fi
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])
495 set X $ac_compile
496 ac_compiler=$[2]
497 for ac_option in --version -v -V -qversion -version; do
498   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
499 done
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
505   GCC=yes
506 else
507   GCC=
509 _AC_PROG_CC_G
510 _AC_PROG_CC_STDC_EDITION
511 AC_LANG_POP(C)dnl
512 ])# AC_PROG_CC
515 # _AC_PROG_CC_G
516 # -------------
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
526    ac_c_werror_flag=yes
527    ac_cv_prog_cc_g=no
528    CFLAGS="-g"
529    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
530      [ac_cv_prog_cc_g=yes],
531      [CFLAGS=""
532       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
533         [],
534         [ac_c_werror_flag=$ac_save_c_werror_flag
535          CFLAGS="-g"
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
543     CFLAGS="-g -O2"
544   else
545     CFLAGS="-g"
546   fi
547 else
548   if test "$GCC" = yes; then
549     CFLAGS="-O2"
550   else
551     CFLAGS=
552   fi
553 fi[]dnl
554 ])# _AC_PROG_CC_G
557 # AC_PROG_CC_C_O
558 # --------------
559 AC_DEFUN([AC_PROG_CC_C_O],
560 [AC_REQUIRE([AC_PROG_CC])dnl
561 AC_LANG_PUSH([C])
562 if test "x$CC" != xcc; then
563   AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
564 else
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'
575 rm -f conftest2.*
576 if _AC_DO_VAR(ac_try) &&
577    test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
578 then
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'
584       rm -f conftest2.*
585       if _AC_DO_VAR(ac_try) &&
586          test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
587       then
588         # cc works too.
589         :
590       else
591         # cc exists but doesn't like -o.
592         eval ac_cv_prog_cc_${ac_cc}_c_o=no
593       fi
594     fi
595   fi
596 else
597   eval ac_cv_prog_cc_${ac_cc}_c_o=no
599 rm -rf core conftest*
600 ])dnl
601 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
602   AC_MSG_RESULT([yes])
603 else
604   AC_MSG_RESULT([no])
605   AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
606            [Define to 1 if your C compiler doesn't accept -c and -o together.])
608 AC_LANG_POP([C])
609 ])# AC_PROG_CC_C_O
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])])
625 # AC_PROG_CXXCPP
626 # --------------
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
634 AC_LANG_PUSH(C++)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,
638   [dnl
639     # Double quotes because $CXX needs to be expanded
640     for CXXCPP in "$CXX -E" cpp /lib/cpp
641     do
642       _AC_PROG_PREPROC_WORKS_IFELSE([break])
643     done
644     ac_cv_prog_CXXCPP=$CXXCPP
645   ])dnl
646   CXXCPP=$ac_cv_prog_CXXCPP
647 else
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])])
653 AC_SUBST(CXXCPP)dnl
654 AC_LANG_POP(C++)dnl
655 ])# AC_PROG_CXXCPP
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])])
665 # ac_cv_prog_gxx
666 # --------------
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++
677 # compiler.
678 # aCC   HP-UX C++ compiler much better than 'CC', so test before.
679 # FCC   Fujitsu C++ compiler
680 # KCC   KAI C++ compiler
681 # RCC   Rational C++
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
698     CXX=$CCC
699   else
700     AC_CHECK_TOOLS(CXX,
701                    [m4_default([$1],
702                                [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC clang++])],
703                    g++)
704   fi
706 # Provide some information about the compiler.
707 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
708 set X $ac_compile
709 ac_compiler=$[2]
710 for ac_option in --version -v -V -qversion; do
711   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
712 done
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
718   GXX=yes
719 else
720   GXX=
722 _AC_PROG_CXX_G
723 AC_LANG_POP(C++)dnl
724 ])# AC_PROG_CXX
727 # _AC_PROG_CXX_G
728 # --------------
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
739    ac_cv_prog_cxx_g=no
740    CXXFLAGS="-g"
741    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
742      [ac_cv_prog_cxx_g=yes],
743      [CXXFLAGS=""
744       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
745         [],
746         [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
747          CXXFLAGS="-g"
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
755     CXXFLAGS="-g -O2"
756   else
757     CXXFLAGS="-g"
758   fi
759 else
760   if test "$GXX" = yes; then
761     CXXFLAGS="-O2"
762   else
763     CXXFLAGS=
764   fi
765 fi[]dnl
766 ])# _AC_PROG_CXX_G
769 # AC_PROG_CXX_C_O
770 # ---------------
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'
782 rm -f conftest2.*
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
787 else
788   ac_cv_prog_cxx_c_o=no
790 rm -rf conftest*])
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
797 ])# AC_PROG_CXX_C_O
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])])
813 # AC_PROG_OBJCPP
814 # --------------
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,
824   [dnl
825     # Double quotes because $OBJC needs to be expanded
826     for OBJCPP in "$OBJC -E" cpp /lib/cpp
827     do
828       _AC_PROG_PREPROC_WORKS_IFELSE([break])
829     done
830     ac_cv_prog_OBJCPP=$OBJCPP
831   ])dnl
832   OBJCPP=$ac_cv_prog_OBJCPP
833 else
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])])
839 AC_SUBST(OBJCPP)dnl
840 AC_LANG_POP(Objective C)dnl
841 ])# AC_PROG_OBJCPP
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).
864 # CC     You never know.
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
876 AC_CHECK_TOOLS(OBJC,
877                [m4_default([$1], [gobjc gcc objcc objc cc CC clang])],
878                gcc)
879 # Provide some information about the compiler.
880 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
881 set X $ac_compile
882 ac_compiler=$[2]
883 for ac_option in --version -v -V -qversion; do
884   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
885 done
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
891   GOBJC=yes
892 else
893   GOBJC=
895 _AC_PROG_OBJC_G
896 AC_LANG_POP(Objective C)dnl
897 ])# AC_PROG_OBJC
900 # _AC_PROG_OBJC_G
901 # ---------------
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
912    ac_cv_prog_objc_g=no
913    OBJCFLAGS="-g"
914    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
915      [ac_cv_prog_objc_g=yes],
916      [OBJCFLAGS=""
917       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
918         [],
919         [ac_objc_werror_flag=$ac_save_objc_werror_flag
920          OBJCFLAGS="-g"
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
928     OBJCFLAGS="-g -O2"
929   else
930     OBJCFLAGS="-g"
931   fi
932 else
933   if test "$GOBJC" = yes; then
934     OBJCFLAGS="-O2"
935   else
936     OBJCFLAGS=
937   fi
938 fi[]dnl
939 ])# _AC_PROG_OBJC_G
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])])
955 # AC_PROG_OBJCXXCPP
956 # -----------------
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,
966   [dnl
967     # Double quotes because $OBJCXX needs to be expanded
968     for OBJCXXCPP in "$OBJCXX -E" cpp /lib/cpp
969     do
970       _AC_PROG_PREPROC_WORKS_IFELSE([break])
971     done
972     ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
973   ])dnl
974   OBJCXXCPP=$ac_cv_prog_OBJCXXCPP
975 else
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])],
1017                g++)
1018 # Provide some information about the compiler.
1019 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
1020 set X $ac_compile
1021 ac_compiler=$[2]
1022 for ac_option in --version -v -V -qversion; do
1023   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
1024 done
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
1030   GOBJCXX=yes
1031 else
1032   GOBJCXX=
1034 _AC_PROG_OBJCXX_G
1035 AC_LANG_POP(Objective C++)dnl
1036 ])# AC_PROG_OBJCXX
1039 # _AC_PROG_OBJCXX_G
1040 # -----------------
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
1052    OBJCXXFLAGS="-g"
1053    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1054      [ac_cv_prog_objcxx_g=yes],
1055      [OBJCXXFLAGS=""
1056       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1057         [],
1058         [ac_objcxx_werror_flag=$ac_save_objcxx_werror_flag
1059          OBJCXXFLAGS="-g"
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"
1068   else
1069     OBJCXXFLAGS="-g"
1070   fi
1071 else
1072   if test "$GOBJCXX" = yes; then
1073     OBJCXXFLAGS="-O2"
1074   else
1075     OBJCXXFLAGS=
1076   fi
1077 fi[]dnl
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>
1117 # C99 adds:
1118 #     <iso646.h> <stdbool.h> <stdint.h>
1119 # C11 adds:
1120 #     <stdalign.h> <stdnoreturn.h>
1121 # C23 adds:
1122 #     <stdbit.h>
1124 AC_DEFUN([_AC_C_C89_TEST_GLOBALS],
1125 [m4_divert_text([INIT_PREPARE],
1126 [[# Test code for whether the C compiler supports C89 (global declarations)
1127 ac_c_conftest_c89_globals='
1128 /* Do not test the value of __STDC__, because some compilers define it to 0
1129    or do not define it, while otherwise adequately conforming.  */
1131 #include <stddef.h>
1132 #include <stdarg.h>
1133 struct stat;
1134 /* Most of the following tests are stolen from RCS 5.7 src/conf.sh.  */
1135 struct buf { int x; };
1136 struct buf * (*rcsopen) (struct buf *, struct stat *, int);
1137 static char *e (char **p, int i)
1139   return p[i];
1141 static char *f (char * (*g) (char **, int), char **p, ...)
1143   char *s;
1144   va_list v;
1145   va_start (v,p);
1146   s = g (p, va_arg (v,int));
1147   va_end (v);
1148   return s;
1151 /* C89 style stringification. */
1152 #define noexpand_stringify(a) #a
1153 const char *stringified = noexpand_stringify(arbitrary+token=sequence);
1155 /* C89 style token pasting.  Exercises some of the corner cases that
1156    e.g. old MSVC gets wrong, but not very hard. */
1157 #define noexpand_concat(a,b) a##b
1158 #define expand_concat(a,b) noexpand_concat(a,b)
1159 extern int vA;
1160 extern int vbee;
1161 #define aye A
1162 #define bee B
1163 int *pvA = &expand_concat(v,aye);
1164 int *pvbee = &noexpand_concat(v,bee);
1166 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
1167    function prototypes and stuff, but not \xHH hex character constants.
1168    These do not provoke an error unfortunately, instead are silently treated
1169    as an "x".  The following induces an error, until -std is added to get
1170    proper ANSI mode.  Curiously \x00 != x always comes out true, for an
1171    array size at least.  It is necessary to write \x00 == 0 to get something
1172    that is true only with -std.  */
1173 int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1];
1175 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1176    inside strings and character constants.  */
1177 #define FOO(x) '\''x'\''
1178 int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1];
1180 int test (int i, double x);
1181 struct s1 {int (*f) (int a);};
1182 struct s2 {int (*f) (double a);};
1183 int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int),
1184                int, int);'
1185 ]])])
1187 AC_DEFUN([_AC_C_C89_TEST_MAIN],
1188 [m4_divert_text([INIT_PREPARE],
1189 [[# Test code for whether the C compiler supports C89 (body of main).
1190 ac_c_conftest_c89_main='
1191 ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]);
1193 ]])])
1195 AC_DEFUN([_AC_C_C99_TEST_GLOBALS],
1196 [m4_divert_text([INIT_PREPARE],
1197 [[# Test code for whether the C compiler supports C99 (global declarations)
1198 ac_c_conftest_c99_globals='
1199 /* Does the compiler advertise C99 conformance? */
1200 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
1201 # error "Compiler does not advertise C99 conformance"
1202 #endif
1204 // See if C++-style comments work.
1206 #include <stdbool.h>
1207 extern int puts (const char *);
1208 extern int printf (const char *, ...);
1209 extern int dprintf (int, const char *, ...);
1210 extern void *malloc (size_t);
1211 extern void free (void *);
1213 // Check varargs macros.  These examples are taken from C99 6.10.3.5.
1214 // dprintf is used instead of fprintf to avoid needing to declare
1215 // FILE and stderr.
1216 #define debug(...) dprintf (2, __VA_ARGS__)
1217 #define showlist(...) puts (#__VA_ARGS__)
1218 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1219 static void
1220 test_varargs_macros (void)
1222   int x = 1234;
1223   int y = 5678;
1224   debug ("Flag");
1225   debug ("X = %d\n", x);
1226   showlist (The first, second, and third items.);
1227   report (x>y, "x is %d but y is %d", x, y);
1230 // Check long long types.
1231 #define BIG64 18446744073709551615ull
1232 #define BIG32 4294967295ul
1233 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1234 #if !BIG_OK
1235   #error "your preprocessor is broken"
1236 #endif
1237 #if BIG_OK
1238 #else
1239   #error "your preprocessor is broken"
1240 #endif
1241 static long long int bignum = -9223372036854775807LL;
1242 static unsigned long long int ubignum = BIG64;
1244 struct incomplete_array
1246   int datasize;
1247   double data[];
1250 struct named_init {
1251   int number;
1252   const wchar_t *name;
1253   double average;
1256 typedef const char *ccp;
1258 static inline int
1259 test_restrict (ccp restrict text)
1261   // Iterate through items via the restricted pointer.
1262   // Also check for declarations in for loops.
1263   for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i)
1264     continue;
1265   return 0;
1268 // Check varargs and va_copy.
1269 static bool
1270 test_varargs (const char *format, ...)
1272   va_list args;
1273   va_start (args, format);
1274   va_list args_copy;
1275   va_copy (args_copy, args);
1277   const char *str = "";
1278   int number = 0;
1279   float fnumber = 0;
1281   while (*format)
1282     {
1283       switch (*format++)
1284         {
1285         case '\''s'\'': // string
1286           str = va_arg (args_copy, const char *);
1287           break;
1288         case '\''d'\'': // int
1289           number = va_arg (args_copy, int);
1290           break;
1291         case '\''f'\'': // float
1292           fnumber = va_arg (args_copy, double);
1293           break;
1294         default:
1295           break;
1296         }
1297     }
1298   va_end (args_copy);
1299   va_end (args);
1301   return *str && number && fnumber;
1304 ]])])
1306 AC_DEFUN([_AC_C_C99_TEST_MAIN],
1307 [m4_divert_text([INIT_PREPARE],
1308 [[# Test code for whether the C compiler supports C99 (body of main).
1309 ac_c_conftest_c99_main='
1310   // Check bool.
1311   _Bool success = false;
1312   success |= (argc != 0);
1314   // Check restrict.
1315   if (test_restrict ("String literal") == 0)
1316     success = true;
1317   char *restrict newvar = "Another string";
1319   // Check varargs.
1320   success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234);
1321   test_varargs_macros ();
1323   // Check flexible array members.
1324   struct incomplete_array *ia =
1325     malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1326   ia->datasize = 10;
1327   for (int i = 0; i < ia->datasize; ++i)
1328     ia->data[i] = i * 1.234;
1329   // Work around memory leak warnings.
1330   free (ia);
1332   // Check named initializers.
1333   struct named_init ni = {
1334     .number = 34,
1335     .name = L"Test wide string",
1336     .average = 543.34343,
1337   };
1339   ni.number = 58;
1341   // Do not test for VLAs, as some otherwise-conforming compilers lack them.
1342   // C code should instead use __STDC_NO_VLA__; see Autoconf manual.
1344   // work around unused variable warnings
1345   ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\''
1346          || ni.number != 58);
1348 ]])])
1350 AC_DEFUN([_AC_C_C11_TEST_GLOBALS],
1351 [m4_divert_text([INIT_PREPARE],
1352 [[# Test code for whether the C compiler supports C11 (global declarations)
1353 ac_c_conftest_c11_globals='
1354 /* Does the compiler advertise C11 conformance? */
1355 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
1356 # error "Compiler does not advertise C11 conformance"
1357 #endif
1359 // Check _Alignas.
1360 char _Alignas (double) aligned_as_double;
1361 char _Alignas (0) no_special_alignment;
1362 extern char aligned_as_int;
1363 char _Alignas (0) _Alignas (int) aligned_as_int;
1365 // Check _Alignof.
1366 enum
1368   int_alignment = _Alignof (int),
1369   int_array_alignment = _Alignof (int[100]),
1370   char_alignment = _Alignof (char)
1372 _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
1374 // Check _Noreturn.
1375 int _Noreturn does_not_return (void) { for (;;) continue; }
1377 // Check _Static_assert.
1378 struct test_static_assert
1380   int x;
1381   _Static_assert (sizeof (int) <= sizeof (long int),
1382                   "_Static_assert does not work in struct");
1383   long int y;
1386 // Check UTF-8 literals.
1387 #define u8 syntax error!
1388 char const utf8_literal[] = u8"happens to be ASCII" "another string";
1390 // Check duplicate typedefs.
1391 typedef long *long_ptr;
1392 typedef long int *long_ptr;
1393 typedef long_ptr long_ptr;
1395 // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
1396 struct anonymous
1398   union {
1399     struct { int i; int j; };
1400     struct { int k; long int l; } w;
1401   };
1402   int m;
1403 } v1;
1405 ]])])
1407 AC_DEFUN([_AC_C_C11_TEST_MAIN],
1408 [m4_divert_text([INIT_PREPARE],
1409 [[# Test code for whether the C compiler supports C11 (body of main).
1410 ac_c_conftest_c11_main='
1411   _Static_assert ((offsetof (struct anonymous, i)
1412                    == offsetof (struct anonymous, w.k)),
1413                   "Anonymous union alignment botch");
1414   v1.i = 2;
1415   v1.w.k = 5;
1416   ok |= v1.i != 5;
1418 ]])])
1420 AC_DEFUN([_AC_C_C23_TEST_GLOBALS],
1421 [m4_divert_text([INIT_PREPARE],
1422 [[# Test code for whether the C compiler supports C23 (global declarations)
1423 ac_c_conftest_c23_globals='
1424 /* Does the compiler advertise conformance to C17 or earlier?
1425    Although GCC 14 does not do that, even with -std=gnu23,
1426    it is close enough, and defines __STDC_VERSION == 202000L.  */
1427 #if !defined __STDC_VERSION__ || __STDC_VERSION__ <= 201710L
1428 # error "Compiler advertises conformance to C17 or earlier"
1429 #endif
1431 // Check alignas.
1432 char alignas (double) c23_aligned_as_double;
1433 char alignas (0) c23_no_special_alignment;
1434 extern char c23_aligned_as_int;
1435 char alignas (0) alignas (int) c23_aligned_as_int;
1437 // Check alignof.
1438 enum
1440   c23_int_alignment = alignof (int),
1441   c23_int_array_alignment = alignof (int[100]),
1442   c23_char_alignment = alignof (char)
1444 static_assert (0 < -alignof (int), "alignof is signed");
1446 int function_with_unnamed_parameter (int) { return 0; }
1448 void c23_noreturn ();
1450 bool use_u8 = !u8"\xFF" == u8'\''x'\'';
1452 bool check_that_bool_works = true | false | !nullptr;
1453 #if !true
1454 # error "true does not work in #if"
1455 #endif
1456 #if false
1457 #elifdef __STDC_VERSION__
1458 #else
1459 # error "#elifdef does not work"
1460 #endif
1462 #ifndef __has_c_attribute
1463 # error "__has_c_attribute not defined"
1464 #endif
1466 #ifndef __has_include
1467 # error "__has_include not defined"
1468 #endif
1470 #define LPAREN() (
1471 #define FORTY_TWO(x) 42
1472 #define VA_OPT_TEST(r, x, ...) __VA_OPT__ (FORTY_TWO r x))
1473 static_assert (VA_OPT_TEST (LPAREN (), 0, <:-) == 42);
1475 static_assert (0b101010 == 42);
1476 static_assert (0B101010 == 42);
1477 static_assert (0xDEAD'\''BEEF == 3'\''735'\''928'\''559);
1478 static_assert (0.500'\''000'\''000 == 0.5);
1480 enum unsignedish : unsigned int { uione = 1 };
1481 static_assert (0 < -uione);
1483 #include <stddef.h>
1484 constexpr nullptr_t null_pointer = nullptr;
1486 #include <stdbit.h>
1487 static_assert (__STDC_ENDIAN_LITTLE__ != __STDC_ENDIAN_BIG__);
1489 static typeof (1 + 1L) two () { return 2; }
1490 static long int three () { return 3; }
1492 ]])])
1494 AC_DEFUN([_AC_C_C23_TEST_MAIN],
1495 [m4_divert_text([INIT_PREPARE],
1496 [[# Test code for whether the C compiler supports C23 (body of main).
1497 ac_c_conftest_c23_main='
1498   {
1499     label_before_declaration:
1500       int arr[10] = {};
1501       if (arr[0])
1502         goto label_before_declaration;
1503       if (!arr[0])
1504         goto label_at_end_of_block;
1505     label_at_end_of_block:
1506   }
1507   ok |= two != three;
1509 ]])])
1511 AC_DEFUN([_AC_C_C89_TEST_PROGRAM],
1512 [AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])dnl
1513 AC_REQUIRE([_AC_C_C89_TEST_MAIN])dnl
1514 m4_divert_text([INIT_PREPARE],
1515 [[# Test code for whether the C compiler supports C89 (complete).
1516 ac_c_conftest_c89_program="${ac_c_conftest_c89_globals}
1519 main (int argc, char **argv)
1521   int ok = 0;
1522   ${ac_c_conftest_c89_main}
1523   return ok;
1526 ]])])
1528 AC_DEFUN([_AC_C_C99_TEST_PROGRAM],
1529 [AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])dnl
1530 AC_REQUIRE([_AC_C_C89_TEST_MAIN])dnl
1531 AC_REQUIRE([_AC_C_C99_TEST_GLOBALS])dnl
1532 AC_REQUIRE([_AC_C_C99_TEST_MAIN])dnl
1533 m4_divert_text([INIT_PREPARE],
1534 [[# Test code for whether the C compiler supports C99 (complete).
1535 ac_c_conftest_c99_program="${ac_c_conftest_c89_globals}
1536 ${ac_c_conftest_c99_globals}
1539 main (int argc, char **argv)
1541   int ok = 0;
1542   ${ac_c_conftest_c89_main}
1543   ${ac_c_conftest_c99_main}
1544   return ok;
1547 ]])])
1549 AC_DEFUN([_AC_C_C11_TEST_PROGRAM],
1550 [AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])dnl
1551 AC_REQUIRE([_AC_C_C89_TEST_MAIN])dnl
1552 AC_REQUIRE([_AC_C_C99_TEST_GLOBALS])dnl
1553 AC_REQUIRE([_AC_C_C99_TEST_MAIN])dnl
1554 AC_REQUIRE([_AC_C_C11_TEST_GLOBALS])dnl
1555 AC_REQUIRE([_AC_C_C11_TEST_MAIN])dnl
1556 m4_divert_text([INIT_PREPARE],
1557 [[# Test code for whether the C compiler supports C11 (complete).
1558 ac_c_conftest_c11_program="${ac_c_conftest_c89_globals}
1559 ${ac_c_conftest_c99_globals}
1560 ${ac_c_conftest_c11_globals}
1563 main (int argc, char **argv)
1565   int ok = 0;
1566   ${ac_c_conftest_c89_main}
1567   ${ac_c_conftest_c99_main}
1568   ${ac_c_conftest_c11_main}
1569   return ok;
1572 ]])])
1574 AC_DEFUN([_AC_C_C23_TEST_PROGRAM],
1575 [AC_REQUIRE([_AC_C_C23_TEST_GLOBALS])dnl
1576 AC_REQUIRE([_AC_C_C23_TEST_MAIN])dnl
1577 m4_divert_text([INIT_PREPARE],
1578 [[# Test code for whether the C compiler supports C23 (complete).
1579 ac_c_conftest_c23_program="${ac_c_conftest_c23_globals}
1582 main (int, char **)
1584   int ok = 0;
1585   ${ac_c_conftest_c23_main}
1586   return ok;
1589 ]])])
1592 # _AC_C_C89_OPTIONS
1593 # -----------------
1594 # Whitespace-separated list of options that might put the C compiler
1595 # into a mode conforming to ISO C1990 with extensions.  Do not try
1596 # "strictly conforming" modes (e.g. gcc's -std=c90); they break some
1597 # systems' header files.  If more than one option is needed, put
1598 # shell quotes around the group.
1600 # AIX circa 2003         -qlanglvl=extc89
1601 # old AIX                -qlanglvl=ansi
1602 # Ultrix, OSF/1, Tru64   -std
1603 # HP-UX 10.20 and later  -Ae
1604 # HP-UX older versions   -Aa -D_HPUX_SOURCE
1605 # SVR4                   -Xc -D__EXTENSIONS__
1606 m4_define([_AC_C_C89_OPTIONS], [
1607     -qlanglvl=extc89
1608     -qlanglvl=ansi
1609     -std
1610     -Ae
1611     "-Aa -D_HPUX_SOURCE"
1612     "-Xc -D__EXTENSIONS__"
1616 # _AC_C_C99_OPTIONS
1617 # -----------------
1618 # Whitespace-separated list of options that might put the C compiler
1619 # into a mode conforming to ISO C1999 with extensions.  Do not try
1620 # "strictly conforming" modes (e.g. gcc's -std=c99); they break some
1621 # systems' header files.  If more than one option is needed, put
1622 # shell quotes around the group.
1624 # GCC, Clang    -std=gnu99
1625 # Intel ICC     -std=c99, -c99 (deprecated)
1626 #   Note: because -std=c99 puts GCC in strictly conforming mode,
1627 #   this option must be tested *after* -std=gnu99.
1628 # IRIX          -c99
1629 # Tru64         -c99
1630 # IBM XL C      -qlanglvl=extc1x (V12.1; does not pass C11 test)
1631 # IBM XL C      -qlanglvl=extc99 (pre-V12.1)
1632 # HP cc         -AC99
1633 # Solaris       -D_STDC_C99=
1634 #   Note: acc's -xc99 option uses linker magic to define the external
1635 #   symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
1636 #   behavior for C library functions.  This is not wanted here,
1637 #   because it means that a single module compiled with -xc99 alters
1638 #   C runtime behavior for the entire program, not for just the
1639 #   module.  Instead, define the (private) symbol _STDC_C99, which
1640 #   suppresses a bogus failure in <stdbool.h>.  The resulting compiler
1641 #   passes the test case here, and that's good enough.
1642 #   For more, please see the thread starting at:
1643 #   https://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
1644 m4_define([_AC_C_C99_OPTIONS], [
1645     -std=gnu99
1646     -std=c99
1647     -c99
1648     -qlanglvl=extc1x
1649     -qlanglvl=extc99
1650     -AC99
1651     -D_STDC_C99=
1655 # _AC_C_C11_OPTIONS
1656 # -----------------
1657 # Whitespace-separated list of options that might put the C compiler
1658 # into a mode conforming to ISO C2011 with extensions.  Do not try
1659 # "strictly conforming" modes (e.g. gcc's -std=c11); they break some
1660 # systems' header files.  If more than one option is needed, put
1661 # shell quotes around the group.
1663 # GCC, Clang    -std=gnu11
1664 # MSVC          -std:c11
1666 # For IBM XL C for AIX V16.1 or later, '-std=gnu11' should work if
1667 # the user configured with CC='xlclang'.  Otherwise, do not try
1668 # -qlanglvl=extc1x as xlc with IBM XL C V16.1 (the latest version as
1669 # of August 2020) does not pass the C11 test.  Instead, try extc1x when
1670 # compiling the C99 test instead, since it enables _Static_assert and
1671 # _Noreturn, which is a win.
1672 m4_define([_AC_C_C11_OPTIONS], [
1673     -std=gnu11
1674     -std:c11
1677 # _AC_C_C23_OPTIONS
1678 # -----------------
1679 # Whitespace-separated list of options that might put the C compiler
1680 # into a mode conforming to ISO C 2023 with extensions.  Do not try
1681 # "strictly conforming" modes (e.g. gcc's -std=c23); they break some
1682 # systems' header files.  If more than one option is needed, put
1683 # shell quotes around the group.
1685 # GCC, Clang    -std=gnu23
1686 m4_define([_AC_C_C23_OPTIONS], [
1687     -std=gnu23
1691 # _AC_PROG_CC_STDC_EDITION_TRY(EDITION)
1692 # -------------------------------------
1693 # Subroutine of _AC_PROG_CC_STDC_EDITION.  Not to be called directly.
1695 # Check whether the C compiler accepts features of EDITION of the
1696 # C standard.  EDITION should be a two-digit year (e.g. 89, 99, 11, 23).
1697 # (FIXME: Switch to four-digit years for futureproofing.)
1698 # This is done by compiling the test program defined by
1699 # _AC_C_C{EDITION}_TEST_PROGRAM, first with no additional
1700 # command-line options, and then with each of the options
1701 # in the space-separated list defined by _AC_C_C{EDITION}_OPTIONS.
1703 # If we find a way to make the test program compile, set cache variable
1704 # ac_cv_prog_cc_cEDITION to the options required (if any), and add those
1705 # options to $CC.  Set shell variable ac_prog_cc_stdc to 'cEDITION',
1706 # and set shell variable ac_cv_prog_cc_stdc to the options required.
1707 # (Neither of these variables is AC_SUBSTed.  ac_cv_prog_cc_stdc used
1708 # to be a cache variable and is preserved with this name for backward
1709 # compatibility.)  Otherwise, ac_cv_prog_cc_cEDITION is set to 'no'
1710 # and the other variables are not changed.
1712 # If ac_prog_cc_stdc is already set to a value other than 'no',
1713 # the shell code produced by this macro does nothing.  This is so
1714 # _AC_PROG_CC_STDC_EDITION can use m4_map to iterate through
1715 # all the editions.
1716 AC_DEFUN([_AC_PROG_CC_STDC_EDITION_TRY],
1717 [AC_LANG_ASSERT([C])]dnl
1718 [AC_REQUIRE([_AC_C_C$1_TEST_PROGRAM])]dnl
1719 [AS_IF([test x$ac_prog_cc_stdc = xno],
1720 [AC_MSG_CHECKING([for $CC option to enable C$1 features])
1721 AC_CACHE_VAL([ac_cv_prog_cc_c$1],
1722 [ac_cv_prog_cc_c$1=no
1723 ac_save_CC=$CC
1724 AC_LANG_CONFTEST([AC_LANG_DEFINES_PROVIDED][$][ac_c_conftest_c$1_program])
1725 for ac_arg in '' m4_normalize(m4_defn([_AC_C_C$1_OPTIONS]))
1727   CC="$ac_save_CC $ac_arg"
1728   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_c$1=$ac_arg])
1729   test "x$ac_cv_prog_cc_c$1" != "xno" && break
1730 done
1731 rm -f conftest.$ac_ext
1732 CC=$ac_save_CC])
1733 AS_IF([test "x$ac_cv_prog_cc_c$1" = xno],
1734   [AC_MSG_RESULT([unsupported])],
1735   [AS_IF([test "x$ac_cv_prog_cc_c$1" = x],
1736     [AC_MSG_RESULT([none needed])],
1737     [AC_MSG_RESULT([$ac_cv_prog_cc_c$1])
1738      CC="$CC $ac_cv_prog_cc_c$1"])
1739   ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c$1
1740   ac_prog_cc_stdc=c$1])])
1744 # _AC_PROG_CC_STDC_EDITION
1745 # ------------------------
1746 # Detect the most recent edition of the ISO C standard that is
1747 # supported by the C compiler.  Add command-line options to $CC, if
1748 # necessary, to enable support for this edition.  Set the shell
1749 # variable ac_prog_cc_stdc to indicate the edition.
1750 AC_DEFUN([_AC_PROG_CC_STDC_EDITION],
1751 [ac_prog_cc_stdc=no
1752 m4_map([_AC_PROG_CC_STDC_EDITION_TRY], [[23], [11], [99], [89]])])
1755 # _AC_PROG_CC_C89(ACTION-IF-SUPPORTED, ACTION-IF-NOT-SUPPORTED)
1756 # -------------------------------------------------------------
1757 # Obsolete internal macro.  No longer used by Autoconf itself, but
1758 # preserved for backward compatibility with pre-December 2020 versions
1759 # of Gnulib's std-gnu11.m4, which replaced the entire definition of
1760 # AC_PROG_CC *except* for this macro.  Can be removed once everyone is
1761 # using Autoconf 2.70 and/or a current std-gnu11.m4.
1762 AC_DEFUN([_AC_PROG_CC_C89],
1763 [AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])]dnl
1764 [AC_REQUIRE([_AC_C_C89_TEST_MAIN])]dnl
1765 [_AC_C_STD_TRY([c89],
1766   [$ac_c_conftest_c89_globals], [$ac_c_conftest_c89_main],
1767   m4_quote(m4_normalize(m4_defn([_AC_C_C89_OPTIONS]))),
1768   [$1],
1769   [$2])])
1773 # AC_PROG_CC_C89
1774 # --------------
1775 # Do not use AU_ALIAS here and in AC_PROG_CC_C99 and AC_PROG_CC_STDC,
1776 # as that'd be incompatible with how Automake redefines AC_PROG_CC.  See
1777 # <https://lists.gnu.org/archive/html/autoconf/2012-10/msg00048.html>.
1778 AU_DEFUN([AC_PROG_CC_C89],
1779   [AC_REQUIRE([AC_PROG_CC])],
1780   [$0 is obsolete; use AC_PROG_CC]
1783 # AC_PROG_CC_C99
1784 # --------------
1785 AU_DEFUN([AC_PROG_CC_C99],
1786   [AC_REQUIRE([AC_PROG_CC])],
1787   [$0 is obsolete; use AC_PROG_CC]
1790 # AC_PROG_CC_STDC
1791 # ---------------
1792 AU_DEFUN([AC_PROG_CC_STDC],
1793   [AC_REQUIRE([AC_PROG_CC])],
1794   [$0 is obsolete; use AC_PROG_CC]
1797 # AC_PROG_GCC_TRADITIONAL
1798 # -----------------------
1799 AU_DEFUN([AC_PROG_GCC_TRADITIONAL],
1800   [AC_REQUIRE([AC_PROG_CC])],
1801   [$0 is obsolete; use AC_PROG_CC]
1804 # AC_C_BACKSLASH_A
1805 # ----------------
1806 AC_DEFUN([AC_C_BACKSLASH_A],
1808   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1809    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1810      [[
1811 #if '\a' == 'a'
1812       syntax error;
1813 #endif
1814       char buf['\a' == 'a' ? -1 : 1];
1815       buf[0] = '\a';
1816       return buf[0] != "\a"[0];
1817      ]])],
1818      [ac_cv_c_backslash_a=yes],
1819      [ac_cv_c_backslash_a=no])])
1820   if test $ac_cv_c_backslash_a = yes; then
1821     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1822       [Define if backslash-a works in C strings.])
1823   fi
1827 # AC_C_CROSS
1828 # ----------
1829 # Has been merged into AC_PROG_CC.
1830 AU_DEFUN([AC_C_CROSS], [])
1833 # AC_C_CHAR_UNSIGNED
1834 # ------------------
1835 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1836 [AH_VERBATIM([__CHAR_UNSIGNED__],
1837 [/* Define to 1 if type 'char' is unsigned and your compiler does not
1838    predefine this macro.  */
1839 #ifndef __CHAR_UNSIGNED__
1840 # undef __CHAR_UNSIGNED__
1841 #endif])dnl
1842 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1843 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1844                                              [((char) -1) < 0])],
1845                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1846 if test $ac_cv_c_char_unsigned = yes; then
1847   AC_DEFINE(__CHAR_UNSIGNED__)
1849 ])# AC_C_CHAR_UNSIGNED
1852 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1853 #                 [ACTION-IF-UNIVERSAL])
1854 # -------------------------------------------------------------------------
1855 AC_DEFUN([AC_C_BIGENDIAN],
1856 [AH_VERBATIM([WORDS_BIGENDIAN],
1857 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1858    significant byte first (like Motorola and SPARC, unlike Intel). */
1859 #if defined AC_APPLE_UNIVERSAL_BUILD
1860 # if defined __BIG_ENDIAN__
1861 #  define WORDS_BIGENDIAN 1
1862 # endif
1863 #else
1864 # ifndef WORDS_BIGENDIAN
1865 #  undef WORDS_BIGENDIAN
1866 # endif
1867 #endif])dnl
1868  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1869    [ac_cv_c_bigendian=unknown
1870     # See if we're dealing with a universal compiler.
1871     AC_COMPILE_IFELSE(
1872          [AC_LANG_SOURCE(
1873             [[#ifndef __APPLE_CC__
1874                not a universal capable compiler
1875              #endif
1876              typedef int dummy;
1877             ]])],
1878          [
1879         # Check for potential -arch flags.  It is not universal unless
1880         # there are at least two -arch flags with different values.
1881         ac_arch=
1882         ac_prev=
1883         for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
1884          if test -n "$ac_prev"; then
1885            case $ac_word in
1886              i?86 | x86_64 | ppc | ppc64)
1887                if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
1888                  ac_arch=$ac_word
1889                else
1890                  ac_cv_c_bigendian=universal
1891                  break
1892                fi
1893                ;;
1894            esac
1895            ac_prev=
1896          elif test "x$ac_word" = "x-arch"; then
1897            ac_prev=arch
1898          fi
1899        done])
1900     if test $ac_cv_c_bigendian = unknown; then
1901       # See if sys/param.h defines the BYTE_ORDER macro.
1902       AC_COMPILE_IFELSE(
1903         [AC_LANG_PROGRAM(
1904            [[#include <sys/types.h>
1905              #include <sys/param.h>
1906            ]],
1907            [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \\
1908                      && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \\
1909                      && LITTLE_ENDIAN)
1910               bogus endian macros
1911              #endif
1912            ]])],
1913         [# It does; now see whether it defined to BIG_ENDIAN or not.
1914          AC_COMPILE_IFELSE(
1915            [AC_LANG_PROGRAM(
1916               [[#include <sys/types.h>
1917                 #include <sys/param.h>
1918               ]],
1919               [[#if BYTE_ORDER != BIG_ENDIAN
1920                  not big endian
1921                 #endif
1922               ]])],
1923            [ac_cv_c_bigendian=yes],
1924            [ac_cv_c_bigendian=no])])
1925     fi
1926     if test $ac_cv_c_bigendian = unknown; then
1927       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1928       AC_COMPILE_IFELSE(
1929         [AC_LANG_PROGRAM(
1930            [[#include <limits.h>
1931            ]],
1932            [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1933               bogus endian macros
1934              #endif
1935            ]])],
1936         [# It does; now see whether it defined to _BIG_ENDIAN or not.
1937          AC_COMPILE_IFELSE(
1938            [AC_LANG_PROGRAM(
1939               [[#include <limits.h>
1940               ]],
1941               [[#ifndef _BIG_ENDIAN
1942                  not big endian
1943                 #endif
1944               ]])],
1945            [ac_cv_c_bigendian=yes],
1946            [ac_cv_c_bigendian=no])])
1947     fi
1948     if test $ac_cv_c_bigendian = unknown; then
1949       # Compile a test program.
1950       AC_RUN_IFELSE(
1951         [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1952            [[
1953              /* Are we little or big endian?  From Harbison&Steele.  */
1954              union
1955              {
1956                long int l;
1957                char c[sizeof (long int)];
1958              } u;
1959              u.l = 1;
1960              return u.c[sizeof (long int) - 1] == 1;
1961            ]])],
1962         [ac_cv_c_bigendian=no],
1963         [ac_cv_c_bigendian=yes],
1964         [# Try to guess by grepping values from an object file.
1965          AC_LINK_IFELSE(
1966            [AC_LANG_SOURCE(
1967               [[unsigned short int ascii_mm[] =
1968                   { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1969                 unsigned short int ascii_ii[] =
1970                   { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1971                 int use_ascii (int i) {
1972                   return ascii_mm[i] + ascii_ii[i];
1973                 }
1974                 unsigned short int ebcdic_ii[] =
1975                   { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1976                 unsigned short int ebcdic_mm[] =
1977                   { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1978                 int use_ebcdic (int i) {
1979                   return ebcdic_mm[i] + ebcdic_ii[i];
1980                 }
1981                 int
1982                 main (int argc, char **argv)
1983                 {
1984                   /* Intimidate the compiler so that it does not
1985                      optimize the arrays away.  */
1986                   char *p = argv[0];
1987                   ascii_mm[1] = *p++; ebcdic_mm[1] = *p++;
1988                   ascii_ii[1] = *p++; ebcdic_ii[1] = *p++;
1989                   return use_ascii (argc) == use_ebcdic (*p);
1990                 }]])],
1991            [if grep BIGenDianSyS conftest$ac_exeext >/dev/null; then
1992               ac_cv_c_bigendian=yes
1993             fi
1994             if grep LiTTleEnDian conftest$ac_exeext >/dev/null ; then
1995               if test "$ac_cv_c_bigendian" = unknown; then
1996                 ac_cv_c_bigendian=no
1997               else
1998                 # finding both strings is unlikely to happen, but who knows?
1999                 ac_cv_c_bigendian=unknown
2000               fi
2001             fi])])
2002     fi])
2003  case $ac_cv_c_bigendian in #(
2004    yes)
2005      m4_default([$1],
2006        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
2007    no)
2008      $2 ;; #(
2009    universal)
2010 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
2011 dnl this is a necessity for proper config header operation.  Warn if
2012 dnl the user did not specify a config header but is relying on the
2013 dnl default behavior for universal builds.
2014      m4_default([$4],
2015        [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
2016          [m4_warn([obsolete],
2017            [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
2018         AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
2019           [Define if building universal (internal helper macro)])])
2020      ;; #(
2021    *)
2022      m4_default([$3],
2023        [AC_MSG_ERROR([unknown endianness
2024  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
2025  esac
2026 ])# AC_C_BIGENDIAN
2029 # AC_C__GENERIC
2030 # -------------
2031 # Define HAVE_C__GENERIC if _Generic works, a la C11.
2032 AN_IDENTIFIER([_Generic], [AC_C__GENERIC])
2033 AC_DEFUN([AC_C__GENERIC],
2034 [AC_CACHE_CHECK([for _Generic], ac_cv_c__Generic,
2035 [AC_COMPILE_IFELSE(
2036    [AC_LANG_SOURCE(
2037       [[int
2038          main (int argc, char **argv)
2039          {
2040            int a = _Generic (argc, int: argc = 1);
2041            int *b = &_Generic (argc, default: argc);
2042            char ***c = _Generic (argv, int: argc, default: argv ? &argv : 0);
2043            _Generic (1 ? 0 : b, int: a, default: b) = &argc;
2044            _Generic (a = 1, default: a) = 3;
2045            return a + !b + !c;
2046          }
2047       ]])],
2048    [ac_cv_c__Generic=yes],
2049    [ac_cv_c__Generic=no])])
2050 if test $ac_cv_c__Generic = yes; then
2051   AC_DEFINE([HAVE_C__GENERIC], 1,
2052             [Define to 1 if C11-style _Generic works.])
2054 ])# AC_C__GENERIC
2056 # AC_C_INLINE
2057 # -----------
2058 # Do nothing if the compiler accepts the inline keyword.
2059 # Otherwise define inline to __inline__ or __inline if one of those work,
2060 # otherwise define inline to be empty.
2062 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
2063 # inline function, only builtin types.
2065 AN_IDENTIFIER([inline], [AC_C_INLINE])
2066 AC_DEFUN([AC_C_INLINE],
2067 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
2068 [ac_cv_c_inline=no
2069 for ac_kw in inline __inline__ __inline; do
2070   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
2071 [#ifndef __cplusplus
2072 typedef int foo_t;
2073 static $ac_kw foo_t static_foo (void) {return 0; }
2074 $ac_kw foo_t foo (void) {return 0; }
2075 #endif
2076 ])],
2077                     [ac_cv_c_inline=$ac_kw])
2078   test "$ac_cv_c_inline" != no && break
2079 done
2081 AH_VERBATIM([inline],
2082 [/* Define to '__inline__' or '__inline' if that's what the C compiler
2083    calls it, or to nothing if 'inline' is not supported under any name.  */
2084 #ifndef __cplusplus
2085 #undef inline
2086 #endif])
2087 case $ac_cv_c_inline in
2088   inline | yes) ;;
2089   *)
2090     case $ac_cv_c_inline in
2091       no) ac_val=;;
2092       *) ac_val=$ac_cv_c_inline;;
2093     esac
2094     cat >>confdefs.h <<_ACEOF
2095 #ifndef __cplusplus
2096 #define inline $ac_val
2097 #endif
2098 _ACEOF
2099     ;;
2100 esac
2101 ])# AC_C_INLINE
2104 # AC_C_CONST
2105 # ----------
2106 AC_DEFUN([AC_C_CONST],
2107 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
2108 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
2110 #ifndef __cplusplus
2111   /* Ultrix mips cc rejects this sort of thing.  */
2112   typedef int charset[2];
2113   const charset cs = { 0, 0 };
2114   /* SunOS 4.1.1 cc rejects this.  */
2115   char const *const *pcpcc;
2116   char **ppc;
2117   /* NEC SVR4.0.2 mips cc rejects this.  */
2118   struct point {int x, y;};
2119   static struct point const zero = {0,0};
2120   /* IBM XL C 1.02.0.0 rejects this.
2121      It does not let you subtract one const X* pointer from another in
2122      an arm of an if-expression whose if-part is not a constant
2123      expression */
2124   const char *g = "string";
2125   pcpcc = &g + (g ? g-g : 0);
2126   /* HPUX 7.0 cc rejects these. */
2127   ++pcpcc;
2128   ppc = (char**) pcpcc;
2129   pcpcc = (char const *const *) ppc;
2130   { /* SCO 3.2v4 cc rejects this sort of thing.  */
2131     char tx;
2132     char *t = &tx;
2133     char const *s = 0 ? (char *) 0 : (char const *) 0;
2135     *t++ = 0;
2136     if (s) return 0;
2137   }
2138   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
2139     int x[] = {25, 17};
2140     const int *foo = &x[0];
2141     ++foo;
2142   }
2143   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
2144     typedef const int *iptr;
2145     iptr p = 0;
2146     ++p;
2147   }
2148   { /* IBM XL C 1.02.0.0 rejects this sort of thing, saying
2149        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
2150     struct s { int j; const int *ap[3]; } bx;
2151     struct s *b = &bx; b->j = 5;
2152   }
2153   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
2154     const int foo = 10;
2155     if (!foo) return 0;
2156   }
2157   return !cs[0] && !zero.x;
2158 #endif
2159 ]])],
2160                    [ac_cv_c_const=yes],
2161                    [ac_cv_c_const=no])])
2162 if test $ac_cv_c_const = no; then
2163   AC_DEFINE(const,,
2164             [Define to empty if 'const' does not conform to ANSI C.])
2166 ])# AC_C_CONST
2169 # AC_C_RESTRICT
2170 # -------------
2171 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive
2173 # Determine whether the C/C++ compiler supports the "restrict" keyword
2174 # introduced in ANSI C99, or an equivalent.  Define "restrict" to the alternate
2175 # spelling, if any; these are more likely to work in both C and C++ compilers of
2176 # the same family, and in the presence of varying compiler options.  If only
2177 # plain "restrict" works, do nothing.  Here are some variants:
2178 # - GCC supports both __restrict and __restrict__
2179 # - older DEC Alpha C compilers support only __restrict
2180 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
2181 # Otherwise, define "restrict" to be empty.
2182 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
2183 AC_DEFUN([AC_C_RESTRICT],
2184 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
2185   [ac_cv_c_restrict=no
2186    # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
2187    # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
2188    # Put 'restrict' last, because C++ lacks it.
2189    for ac_kw in __restrict__ __restrict _Restrict restrict; do
2190      AC_COMPILE_IFELSE(
2191       [AC_LANG_PROGRAM(
2192          [[typedef int *int_ptr;
2193            int foo (int_ptr $ac_kw ip) { return ip[0]; }
2194            int bar (int [$ac_kw]); /* Catch GCC bug 14050.  */
2195            int bar (int ip[$ac_kw]) { return ip[0]; }
2196          ]],
2197          [[int s[1];
2198            int *$ac_kw t = s;
2199            t[0] = 0;
2200            return foo (t) + bar (t);
2201          ]])],
2202       [ac_cv_c_restrict=$ac_kw])
2203      test "$ac_cv_c_restrict" != no && break
2204    done
2205   ])
2206  AH_VERBATIM([restrict],
2207 [/* Define to the equivalent of the C99 'restrict' keyword, or to
2208    nothing if this is not supported.  Do not define if restrict is
2209    supported only directly.  */
2210 #undef restrict
2211 /* Work around a bug in older versions of Sun C++, which did not
2212    #define __restrict__ or support _Restrict or __restrict__
2213    even though the corresponding Sun C compiler ended up with
2214    "#define restrict _Restrict" or "#define restrict __restrict__"
2215    in the previous line.  This workaround can be removed once
2216    we assume Oracle Developer Studio 12.5 (2016) or later.  */
2217 #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
2218 # define _Restrict
2219 # define __restrict__
2220 #endif])
2221  case $ac_cv_c_restrict in
2222    restrict) ;;
2223    no) AC_DEFINE([restrict], []) ;;
2224    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
2225  esac
2226 ])# AC_C_RESTRICT
2229 # AC_C_VOLATILE
2230 # -------------
2231 # Note that, unlike const, #defining volatile to be the empty string can
2232 # actually turn a correct program into an incorrect one, since removing
2233 # uses of volatile actually grants the compiler permission to perform
2234 # optimizations that could break the user's code.  So, do not #define
2235 # volatile away unless it is really necessary to allow the user's code
2236 # to compile cleanly.  Benign compiler failures should be tolerated.
2237 AC_DEFUN([AC_C_VOLATILE],
2238 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
2239 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
2240 volatile int x;
2241 int * volatile y = (int *) 0;
2242 return !x && !y;])],
2243                    [ac_cv_c_volatile=yes],
2244                    [ac_cv_c_volatile=no])])
2245 if test $ac_cv_c_volatile = no; then
2246   AC_DEFINE(volatile,,
2247             [Define to empty if the keyword 'volatile' does not work.
2248              Warning: valid code using 'volatile' can become incorrect
2249              without.  Disable with care.])
2251 ])# AC_C_VOLATILE
2254 # AC_C_STRINGIZE
2255 # --------------
2256 # Checks if '#' can be used to glue strings together at the CPP level.
2257 # Defines HAVE_STRINGIZE if positive.
2258 # Obsolete - new code should assume C89 compliance.
2259 AC_DEFUN([AC_C_STRINGIZE],
2260 [AC_REQUIRE([AC_PROG_CC])
2261 if test "$ac_prog_cc_stdc" != no; then
2262   AC_DEFINE(HAVE_STRINGIZE, 1,
2263             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
2265 ])# AC_C_STRINGIZE
2268 # AC_C_PROTOTYPES
2269 # ---------------
2270 # Check if the C compiler supports prototypes.
2271 # Obsolete - new code should assume C89 compliance.
2272 AC_DEFUN([AC_C_PROTOTYPES],
2273 [AC_REQUIRE([AC_PROG_CC])dnl
2274 if test "$ac_prog_cc_stdc" != no; then
2275   AC_DEFINE(PROTOTYPES, 1,
2276             [Define to 1 if the C compiler supports function prototypes.])
2277   AC_DEFINE(__PROTOTYPES, 1,
2278             [Define like PROTOTYPES; this can be used by system headers.])
2280 ])# AC_C_PROTOTYPES
2283 # AC_C_FLEXIBLE_ARRAY_MEMBER
2284 # --------------------------
2285 # Check whether the C compiler supports flexible array members.
2286 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
2288   AC_CACHE_CHECK([for flexible array members],
2289     ac_cv_c_flexmember,
2290     [AC_COMPILE_IFELSE(
2291        [AC_LANG_PROGRAM(
2292           [[#include <stdlib.h>
2293             #include <stdio.h>
2294             #include <stddef.h>
2295             struct s { int n; double d[]; };]],
2296           [[int m = getchar ();
2297             struct s *p = (struct s *) malloc (offsetof (struct s, d)
2298                                                + m * sizeof (double));
2299             p->d[0] = 0.0;
2300             m = p->d != (double *) NULL;
2301             free (p);
2302             return m;]])],
2303        [ac_cv_c_flexmember=yes],
2304        [ac_cv_c_flexmember=no])])
2305   if test $ac_cv_c_flexmember = yes; then
2306     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
2307       [Define to nothing if C supports flexible array members, and to
2308        1 if it does not.  That way, with a declaration like 'struct s
2309        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
2310        can be used with pre-C99 compilers.
2311        When computing the size of such an object, don't use 'sizeof (struct s)'
2312        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
2313        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
2314        MSVC and with C++ compilers.])
2315   else
2316     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
2317   fi
2321 # AC_C_VARARRAYS
2322 # --------------
2323 # Check whether the C compiler supports variable-length arrays.
2324 AC_DEFUN([AC_C_VARARRAYS],
2326   AC_CACHE_CHECK([for variable-length arrays],
2327     ac_cv_c_vararrays,
2328     [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
2329 [[      #ifndef __STDC_NO_VLA__
2330         #error __STDC_NO_VLA__ not defined
2331         #endif
2332 ]])],
2333        [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
2334        [AC_COMPILE_IFELSE(
2335           [AC_LANG_PROGRAM(
2336              [[/* Test for VLA support.  This test is partly inspired
2337                   from examples in the C standard.  Use at least two VLA
2338                   functions to detect the GCC 3.4.3 bug described in:
2339                   https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
2340                   */
2341                #ifdef __STDC_NO_VLA__
2342                 syntax error;
2343                #else
2344                  extern int n;
2345                  int B[100];
2346                  int fvla (int m, int C[m][m]);
2348                  int
2349                  simple (int count, int all[static count])
2350                  {
2351                    return all[count - 1];
2352                  }
2354                  int
2355                  fvla (int m, int C[m][m])
2356                  {
2357                    typedef int VLA[m][m];
2358                    VLA x;
2359                    int D[m];
2360                    static int (*q)[m] = &B;
2361                    int (*s)[n] = q;
2362                    return C && &x[0][0] == &D[0] && &D[0] == s[0];
2363                  }
2364                #endif
2365                ]])],
2366           [ac_cv_c_vararrays=yes],
2367           [ac_cv_c_vararrays=no])])])
2368   if test "$ac_cv_c_vararrays" = yes; then
2369     dnl This is for compatibility with Autoconf 2.61-2.69.
2370     AC_DEFINE([HAVE_C_VARARRAYS], 1,
2371       [Define to 1 if C supports variable-length arrays.])
2372   elif test "$ac_cv_c_vararrays" = no; then
2373     AC_DEFINE([__STDC_NO_VLA__], 1,
2374       [Define to 1 if C does not support variable-length arrays, and
2375        if the compiler does not already define this.])
2376   fi
2380 # AC_C_TYPEOF
2381 # -----------
2382 # Check if the C compiler supports GCC's typeof syntax.
2383 # The test case provokes incompatibilities in the Sun C compilers
2384 # (both Solaris 8 and Solaris 10).
2385 AC_DEFUN([AC_C_TYPEOF],
2387   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
2388     [ac_cv_c_typeof=no
2389      for ac_kw in typeof __typeof__ no; do
2390        test $ac_kw = no && break
2391        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
2392          [[
2393            int value;
2394            typedef struct {
2395                    char a [1
2396                            + ! (($ac_kw (value))
2397                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
2398                                  ? ($ac_kw (value)) - 1
2399                                  : ~ (~ ($ac_kw (value)) 0
2400                                       << sizeof ($ac_kw (value)))))]; }
2401               ac__typeof_type_;
2402            return
2403              (! ((void) ((ac__typeof_type_ *) 0), 0));
2404          ]])],
2405          [ac_cv_c_typeof=$ac_kw])
2406        test $ac_cv_c_typeof != no && break
2407      done])
2408   if test $ac_cv_c_typeof != no; then
2409     AC_DEFINE([HAVE_TYPEOF], 1,
2410       [Define to 1 if typeof works with your compiler.])
2411     if test $ac_cv_c_typeof != typeof; then
2412       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
2413         [Define to __typeof__ if your compiler spells it that way.])
2414     fi
2415   fi
2419 # _AC_LANG_OPENMP
2420 # ---------------
2421 # Expands to some language dependent source code for testing the presence of
2422 # OpenMP.
2423 AC_DEFUN([_AC_LANG_OPENMP],
2424 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
2426 # _AC_LANG_OPENMP(C)
2427 # ------------------
2428 m4_define([_AC_LANG_OPENMP(C)],
2430 #ifndef _OPENMP
2431 #error "OpenMP not supported"
2432 #endif
2433 #include <omp.h>
2434 int main (void) { return omp_get_num_threads (); }
2437 # _AC_LANG_OPENMP(C++)
2438 # --------------------
2439 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
2441 # _AC_LANG_OPENMP(Fortran 77)
2442 # ---------------------------
2443 m4_define([_AC_LANG_OPENMP(Fortran 77)],
2445       program main
2446       implicit none
2447 !\$    integer tid
2448       tid = 42
2449       call omp_set_num_threads(2)
2450       end
2453 # _AC_LANG_OPENMP(Fortran)
2454 # ------------------------
2455 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
2457 # AC_OPENMP
2458 # ---------
2459 # Check which options need to be passed to the C compiler to support OpenMP.
2460 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
2461 # options.
2462 # The options are necessary at compile time (so the #pragmas are understood)
2463 # and at link time (so the appropriate library is linked with).
2464 # This macro takes care to not produce redundant options if $CC $CFLAGS already
2465 # supports OpenMP.
2467 # For each candidate option, we do a compile test first, then a link test;
2468 # if the compile test succeeds but the link test fails, that means we have
2469 # found the correct option but it doesn't work because the libraries are
2470 # broken.  (This can happen, for instance, with SunPRO C and a bad combination
2471 # of operating system patches.)
2473 # Several of the options in our candidate list can be misinterpreted by
2474 # compilers that don't use them to activate OpenMP support; for example,
2475 # many compilers understand "-openmp" to mean "write output to a file
2476 # named 'penmp'" rather than "enable OpenMP".  We can't completely avoid
2477 # the possibility of clobbering files named 'penmp' or 'mp' in configure's
2478 # working directory; therefore, this macro will bomb out if any such file
2479 # already exists when it's invoked.
2480 AC_DEFUN([AC_OPENMP],
2481 [AC_REQUIRE([_AC_OPENMP_SAFE_WD])]dnl
2482 [AC_ARG_ENABLE([openmp],
2483    [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])]dnl
2485   OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
2486   if test "$enable_openmp" != no; then
2487     AC_CACHE_CHECK([for $[]_AC_CC[] option to support OpenMP],
2488       [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
2489       [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='not found'
2490       dnl Try these flags:
2491       dnl   (on by default)      ''
2492       dnl   GCC >= 4.2           -fopenmp
2493       dnl   SunPRO C             -xopenmp
2494       dnl   Intel C              -openmp
2495       dnl   SGI C, PGI C         -mp
2496       dnl   Tru64 Compaq C       -omp
2497       dnl   IBM XL C (AIX, Linux) -qsmp=omp
2498       dnl   Cray CCE             -homp
2499       dnl   NEC SX               -Popenmp
2500       dnl   Lahey Fortran (Linux)  --openmp
2501       for ac_option in '' -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
2502                        -Popenmp --openmp; do
2504         ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
2505         _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
2506         AC_COMPILE_IFELSE([_AC_LANG_OPENMP],
2507           [AC_LINK_IFELSE([_AC_LANG_OPENMP],
2508             [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option],
2509             [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'])])
2510         _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
2512         if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != 'not found'; then
2513           break
2514         fi
2515       done
2516       if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" = 'not found'; then
2517         ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
2518       elif test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" = ''; then
2519         ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'
2520       fi
2521       dnl _AC_OPENMP_SAFE_WD checked that these files did not exist before we
2522       dnl started probing for OpenMP support, so if they exist now, they were
2523       dnl created by the probe loop and it's safe to delete them.
2524       rm -f penmp mp])
2525     if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != 'unsupported' && \
2526        test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != 'none needed'; then
2527       OPENMP_[]_AC_LANG_PREFIX[]FLAGS="$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp"
2528     fi
2529   fi
2530   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
2533 # _AC_OPENMP_SAFE_WD
2534 # ------------------
2535 # AC_REQUIREd by AC_OPENMP.  Checks both at autoconf time and at
2536 # configure time for files that AC_OPENMP clobbers.
2537 AC_DEFUN([_AC_OPENMP_SAFE_WD],
2538 [m4_syscmd([test ! -e penmp && test ! -e mp])]dnl
2539 [m4_if(sysval, [0], [], [m4_fatal(m4_normalize(
2540   [AC_OPENMP clobbers files named 'mp' and 'penmp'.
2541    To use AC_OPENMP you must not have either of these files
2542    at the top level of your source tree.]))])]dnl
2543 [if test -e penmp || test -e mp; then
2544   AC_MSG_ERROR(m4_normalize(
2545     [AC@&t@_OPENMP clobbers files named 'mp' and 'penmp'.
2546      Aborting configure because one of these files already exists.]))
2547 fi])