maint: update URLs
[autoconf.git] / lib / autoconf / c.m4
blob42c6ac1b1c29748ef7a9f9792301e3280b5be049
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001-2017 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/>.
25 # Written by David MacKenzie, with help from
26 # Akim Demaille, Paul Eggert,
27 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
28 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
31 # Table of Contents:
33 # 1. Language selection
34 # 2. and routines to produce programs in a given language.
35 #      1a. C   2a. C
36 #      1b. C++
37 #      1c. Objective C
38 #      1d. Objective C++
40 # 3. Looking for a compiler
41 #    And possibly the associated preprocessor.
42 #      3a. C   3b. C++   3c. Objective C   3d. Objective C++
44 # 4. Compilers' characteristics.
45 #      4a. C
49 ## ----------------------- ##
50 ## 1a/2a. The C language.  ##
51 ## ----------------------- ##
54 # ------------------------ #
55 # 1a. Language selection.  #
56 # ------------------------ #
58 # AC_LANG(C)
59 # ----------
60 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
61 AC_LANG_DEFINE([C], [c], [C], [CC], [],
62 [ac_ext=c
63 ac_cpp='$CPP $CPPFLAGS'
64 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
65 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
66 ac_compiler_gnu=$ac_cv_c_compiler_gnu
70 # AC_LANG_C
71 # ---------
72 AU_DEFUN([AC_LANG_C], [AC_LANG(C)])
75 # ------------------------ #
76 # 2a. Producing programs.  #
77 # ------------------------ #
80 # AC_LANG_CONFTEST(C)(BODY)
81 # -------------------------
82 # We can't use '#line $LINENO "configure"' here, since
83 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
84 # rejects $LINENO greater than 32767, and some configure scripts
85 # are longer than 32767 lines.
86 m4_define([AC_LANG_CONFTEST(C)],
87 [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
88 /* end confdefs.h.  */
90 _ACEOF])
93 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
94 # --------------------------------------
95 m4_define([AC_LANG_PROGRAM(C)],
96 [$1
97 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
98 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
99 int
100 main (void)
102 dnl Do *not* indent the following line: there may be CPP directives.
103 dnl Don't move the `;' right after for the same reason.
105   ;
106   return 0;
110 # _AC_LANG_IO_PROGRAM(C)
111 # ----------------------
112 # Produce source that performs I/O, necessary for proper
113 # cross-compiler detection.
114 m4_define([_AC_LANG_IO_PROGRAM(C)],
115 [AC_LANG_PROGRAM([@%:@include <stdio.h>],
116 [FILE *f = fopen ("conftest.out", "w");
117  return ferror (f) || fclose (f) != 0;
118 ])])
121 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
122 # -----------------------------------
123 # Avoid conflicting decl of main.
124 m4_define([AC_LANG_CALL(C)],
125 [AC_LANG_PROGRAM([$1
126 m4_if([$2], [main], ,
127 [/* Override any GCC internal prototype to avoid an error.
128    Use char because int might match the return type of a GCC
129    builtin and then its argument prototype would still apply.  */
130 #ifdef __cplusplus
131 extern "C"
132 #endif
133 char $2 ();])], [return $2 ();])])
136 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
137 # ----------------------------------
138 # Don't include <ctype.h> because on OSF/1 3.0 it includes
139 # <sys/types.h> which includes <sys/select.h> which contains a
140 # prototype for select.  Similarly for bzero.
142 # This test used to merely assign f=$1 in main(), but that was
143 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
144 # presumably on the basis that there's no need to do that store if the
145 # program is about to exit.  Conversely, the AIX linker optimizes an
146 # unused external declaration that initializes f=$1.  So this test
147 # program has both an external initialization of f, and a use of f in
148 # main that affects the exit status.
150 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
151 [AC_LANG_PROGRAM(
152 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
153    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
154 #define $1 innocuous_$1
156 /* System header to define __stub macros and hopefully few prototypes,
157    which can conflict with char $1 (); below.  */
159 #include <limits.h>
160 #undef $1
162 /* Override any GCC internal prototype to avoid an error.
163    Use char because int might match the return type of a GCC
164    builtin and then its argument prototype would still apply.  */
165 #ifdef __cplusplus
166 extern "C"
167 #endif
168 char $1 ();
169 /* The GNU C library defines this for functions which it implements
170     to always fail with ENOSYS.  Some functions are actually named
171     something starting with __ and the normal name is an alias.  */
172 #if defined __stub_$1 || defined __stub___$1
173 choke me
174 #endif
175 ], [return $1 ();])])
178 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
179 # -------------------------------------------------
180 # Return a program that is valid if EXPRESSION is nonzero.
181 # EXPRESSION must be an integer constant expression.
182 # Be sure to use this array to avoid `unused' warnings, which are even
183 # errors with `-W error'.
184 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
185 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
186 test_array @<:@0@:>@ = 0;
187 return test_array @<:@0@:>@;
188 ])])
191 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
192 # -----------------------------------------
193 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
194 # But we include them only after the EXPRESSION has been evaluated.
195 m4_define([AC_LANG_INT_SAVE(C)],
196 [AC_LANG_PROGRAM([$1
197 static long int longval () { return $2; }
198 static unsigned long int ulongval () { return $2; }
199 @%:@include <stdio.h>
200 @%:@include <stdlib.h>],
202   FILE *f = fopen ("conftest.val", "w");
203   if (! f)
204     return 1;
205   if (($2) < 0)
206     {
207       long int i = longval ();
208       if (i != ($2))
209         return 1;
210       fprintf (f, "%ld", i);
211     }
212   else
213     {
214       unsigned long int i = ulongval ();
215       if (i != ($2))
216         return 1;
217       fprintf (f, "%lu", i);
218     }
219   /* Do not output a trailing newline, as this causes \r\n confusion
220      on some platforms.  */
221   return ferror (f) || fclose (f) != 0;
222 ])])
226 ## ---------------------- ##
227 ## 1b. The C++ language.  ##
228 ## ---------------------- ##
231 # AC_LANG(C++)
232 # ------------
233 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
234 AC_LANG_DEFINE([C++], [cxx], [CXX], [CXX], [C],
235 [ac_ext=cpp
236 ac_cpp='$CXXCPP $CPPFLAGS'
237 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
238 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
239 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
243 # AC_LANG_CPLUSPLUS
244 # -----------------
245 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
249 ## ------------------------------ ##
250 ## 1c. The Objective C language.  ##
251 ## ------------------------------ ##
254 # AC_LANG(Objective C)
255 # --------------------
256 AC_LANG_DEFINE([Objective C], [objc], [OBJC], [OBJC], [C],
257 [ac_ext=m
258 ac_cpp='$OBJCPP $CPPFLAGS'
259 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
260 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
261 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
265 # AC_LANG_OBJC
266 # ------------
267 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
271 ## -------------------------------- ##
272 ## 1d. The Objective C++ language.  ##
273 ## -------------------------------- ##
276 # AC_LANG(Objective C++)
277 # ----------------------
278 AC_LANG_DEFINE([Objective C++], [objcxx], [OBJCXX], [OBJCXX], [C++],
279 [ac_ext=mm
280 ac_cpp='$OBJCXXCPP $CPPFLAGS'
281 ac_compile='$OBJCXX -c $OBJCXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
282 ac_link='$OBJCXX -o conftest$ac_exeext $OBJCXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
283 ac_compiler_gnu=$ac_cv_objcxx_compiler_gnu
288 ## -------------------------------------------- ##
289 ## 3. Looking for Compilers and Preprocessors.  ##
290 ## -------------------------------------------- ##
292 # -------------------- #
293 # 3a. The C compiler.  #
294 # -------------------- #
297 # _AC_ARG_VAR_CPPFLAGS
298 # --------------------
299 # Document and register CPPFLAGS, which is used by
300 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP, OBJCXX, OBJCXXCPP}.
301 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
302 [AC_ARG_VAR([CPPFLAGS],
303             [(Objective) C/C++ preprocessor flags, e.g. -I<include dir>
304              if you have headers in a nonstandard directory <include dir>])])
307 # _AC_ARG_VAR_LDFLAGS
308 # -------------------
309 # Document and register LDFLAGS, which is used by
310 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
311 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
312 [AC_ARG_VAR([LDFLAGS],
313             [linker flags, e.g. -L<lib dir> if you have libraries in a
314              nonstandard directory <lib dir>])])
317 # _AC_ARG_VAR_LIBS
318 # ----------------
319 # Document and register LIBS, which is used by
320 # AC_PROG_{CC, CXX, F77, FC, OBJC, OBJCXX}.
321 AC_DEFUN([_AC_ARG_VAR_LIBS],
322 [AC_ARG_VAR([LIBS],
323             [libraries to pass to the linker, e.g. -l<library>])])
326 # AC_LANG_PREPROC(C)
327 # ------------------
328 # Find the C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
329 AC_DEFUN([AC_LANG_PREPROC(C)],
330 [AC_REQUIRE([AC_PROG_CPP])])
333 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
334 # -----------------------------------------------
335 # Check if $ac_cpp is a working preprocessor that can flag absent
336 # includes either by the exit status or by warnings.
337 # This macro is for all languages, not only C.
338 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
339 [ac_preproc_ok=false
340 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
342   # Use a header file that comes with gcc, so configuring glibc
343   # with a fresh cross-compiler works.
344   # On the NeXT, cc -E runs the code through the compiler's parser,
345   # not just through cpp. "Syntax error" is here to catch this case.
346   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <limits.h>
347                      Syntax error]])],
348                      [],
349                      [# Broken: fails on valid input.
350 continue])
352   # OK, works on sane cases.  Now check whether nonexistent headers
353   # can be detected and how.
354   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
355                      [# Broken: success on invalid input.
356 continue],
357                      [# Passes both tests.
358 ac_preproc_ok=:
359 break])
361 done
362 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
363 rm -f conftest.i conftest.err conftest.$ac_ext
364 AS_IF([$ac_preproc_ok], [$1], [$2])
365 ])# _AC_PROG_PREPROC_WORKS_IFELSE
368 # AC_PROG_CPP
369 # -----------
370 # Find a working C preprocessor.
371 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
372 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
373 AN_MAKEVAR([CPP], [AC_PROG_CPP])
374 AN_PROGRAM([cpp], [AC_PROG_CPP])
375 AC_DEFUN([AC_PROG_CPP],
376 [AC_REQUIRE([AC_PROG_CC])dnl
377 AC_ARG_VAR([CPP],      [C preprocessor])dnl
378 _AC_ARG_VAR_CPPFLAGS()dnl
379 AC_LANG_PUSH(C)dnl
380 AC_MSG_CHECKING([how to run the C preprocessor])
381 # On Suns, sometimes $CPP names a directory.
382 if test -n "$CPP" && test -d "$CPP"; then
383   CPP=
385 if test -z "$CPP"; then
386   AC_CACHE_VAL([ac_cv_prog_CPP],
387   [dnl
388     # Double quotes because CPP needs to be expanded
389     for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
390     do
391       _AC_PROG_PREPROC_WORKS_IFELSE([break])
392     done
393     ac_cv_prog_CPP=$CPP
394   ])dnl
395   CPP=$ac_cv_prog_CPP
396 else
397   ac_cv_prog_CPP=$CPP
399 AC_MSG_RESULT([$CPP])
400 _AC_PROG_PREPROC_WORKS_IFELSE([],
401                 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
402 AC_SUBST(CPP)dnl
403 AC_LANG_POP(C)dnl
404 ])# AC_PROG_CPP
406 # AC_PROG_CPP_WERROR
407 # ------------------
408 # Treat warnings from the preprocessor as errors.
409 AC_DEFUN([AC_PROG_CPP_WERROR],
410 [AC_REQUIRE([AC_PROG_CPP])dnl
411 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
413 # AC_LANG_COMPILER(C)
414 # -------------------
415 # Find the C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
416 AC_DEFUN([AC_LANG_COMPILER(C)],
417 [AC_REQUIRE([AC_PROG_CC])])
420 # ac_cv_prog_gcc
421 # --------------
422 # We used to name the cache variable this way.
423 AU_DEFUN([ac_cv_prog_gcc],
424 [ac_cv_c_compiler_gnu])
427 # AC_PROG_CC([COMPILER ...])
428 # --------------------------
429 # COMPILER ... is a space separated list of C compilers to search for.
430 # This just gives the user an opportunity to specify an alternative
431 # search list for the C compiler.
432 AN_MAKEVAR([CC],  [AC_PROG_CC])
433 AN_PROGRAM([cc],  [AC_PROG_CC])
434 AN_PROGRAM([gcc], [AC_PROG_CC])
435 AC_DEFUN_ONCE([AC_PROG_CC],
436 [AC_LANG_PUSH(C)dnl
437 AC_ARG_VAR([CC],     [C compiler command])dnl
438 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
439 _AC_ARG_VAR_LDFLAGS()dnl
440 _AC_ARG_VAR_LIBS()dnl
441 _AC_ARG_VAR_CPPFLAGS()dnl
442 m4_ifval([$1],
443       [AC_CHECK_TOOLS(CC, [$1])],
444 [AC_CHECK_TOOL(CC, gcc)
445 if test -z "$CC"; then
446   dnl Here we want:
447   dnl   AC_CHECK_TOOL(CC, cc)
448   dnl but without the check for a tool without the prefix.
449   dnl Until the check is removed from there, copy the code:
450   if test -n "$ac_tool_prefix"; then
451     AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
452   fi
454 if test -z "$CC"; then
455   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
457 if test -z "$CC"; then
458   AC_CHECK_TOOLS(CC, cl.exe)
460 if test -z "$CC"; then
461   AC_CHECK_TOOL(CC, clang)
465 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
467 # Provide some information about the compiler.
468 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
469 set X $ac_compile
470 ac_compiler=$[2]
471 for ac_option in --version -v -V -qversion -version; do
472   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
473 done
475 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
476 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
477 _AC_LANG_COMPILER_GNU
478 if test $ac_compiler_gnu = yes; then
479   GCC=yes
480 else
481   GCC=
483 _AC_PROG_CC_G
485 dnl Set ac_prog_cc_stdc to the supported C version.
486 dnl Also set the documented variable ac_cv_prog_cc_stdc;
487 dnl its name was chosen when it was cached, but it is no longer cached.
488 _AC_PROG_CC_C11([ac_prog_cc_stdc=c11
489                  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11],
490   [_AC_PROG_CC_C99([ac_prog_cc_stdc=c99
491                     ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
492      [_AC_PROG_CC_C89([ac_prog_cc_stdc=c89
493                        ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
494                       [ac_prog_cc_stdc=no
495                        ac_cv_prog_cc_stdc=no])])])
497 AC_LANG_POP(C)dnl
498 ])# AC_PROG_CC
501 # _AC_PROG_CC_G
502 # -------------
503 # Check whether -g works, even if CFLAGS is set, in case the package
504 # plays around with CFLAGS (such as to build both debugging and normal
505 # versions of a library), tasteless as that idea is.
506 # Don't consider -g to work if it generates warnings when plain compiles don't.
507 m4_define([_AC_PROG_CC_G],
508 [ac_test_CFLAGS=${CFLAGS+y}
509 ac_save_CFLAGS=$CFLAGS
510 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
511   [ac_save_c_werror_flag=$ac_c_werror_flag
512    ac_c_werror_flag=yes
513    ac_cv_prog_cc_g=no
514    CFLAGS="-g"
515    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
516      [ac_cv_prog_cc_g=yes],
517      [CFLAGS=""
518       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
519         [],
520         [ac_c_werror_flag=$ac_save_c_werror_flag
521          CFLAGS="-g"
522          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
523            [ac_cv_prog_cc_g=yes])])])
524    ac_c_werror_flag=$ac_save_c_werror_flag])
525 if test $ac_test_CFLAGS; then
526   CFLAGS=$ac_save_CFLAGS
527 elif test $ac_cv_prog_cc_g = yes; then
528   if test "$GCC" = yes; then
529     CFLAGS="-g -O2"
530   else
531     CFLAGS="-g"
532   fi
533 else
534   if test "$GCC" = yes; then
535     CFLAGS="-O2"
536   else
537     CFLAGS=
538   fi
539 fi[]dnl
540 ])# _AC_PROG_CC_G
543 # AC_PROG_GCC_TRADITIONAL
544 # -----------------------
545 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
546 [AC_REQUIRE([AC_PROG_CC])dnl
547 if test $ac_cv_c_compiler_gnu = yes; then
548     AC_CACHE_CHECK(whether $CC needs -traditional,
549       ac_cv_prog_gcc_traditional,
550 [  ac_pattern="Autoconf.*'x'"
551   AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
552 Autoconf TIOCGETP],
553   ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
555   if test $ac_cv_prog_gcc_traditional = no; then
556     AC_EGREP_CPP($ac_pattern, [#include <termio.h>
557 Autoconf TCGETA],
558     ac_cv_prog_gcc_traditional=yes)
559   fi])
560   if test $ac_cv_prog_gcc_traditional = yes; then
561     CC="$CC -traditional"
562   fi
564 ])# AC_PROG_GCC_TRADITIONAL
567 # AC_PROG_CC_C_O
568 # --------------
569 AC_DEFUN([AC_PROG_CC_C_O],
570 [AC_REQUIRE([AC_PROG_CC])dnl
571 if test "x$CC" != xcc; then
572   AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
573 else
574   AC_MSG_CHECKING([whether cc understands -c and -o together])
576 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
577                       sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
578 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
579 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
580 # Make sure it works both with $CC and with simple cc.
581 # We do the test twice because some compilers refuse to overwrite an
582 # existing .o file with -o, though they will create one.
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   eval ac_cv_prog_cc_${ac_cc}_c_o=yes
589   if test "x$CC" != xcc; then
590     # Test first that cc exists at all.
591     if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
592       ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
593       rm -f conftest2.*
594       if _AC_DO_VAR(ac_try) &&
595          test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
596       then
597         # cc works too.
598         :
599       else
600         # cc exists but doesn't like -o.
601         eval ac_cv_prog_cc_${ac_cc}_c_o=no
602       fi
603     fi
604   fi
605 else
606   eval ac_cv_prog_cc_${ac_cc}_c_o=no
608 rm -rf core conftest*
609 ])dnl
610 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
611   AC_MSG_RESULT([yes])
612 else
613   AC_MSG_RESULT([no])
614   AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
615            [Define to 1 if your C compiler doesn't accept -c and -o together.])
617 ])# AC_PROG_CC_C_O
621 # ---------------------- #
622 # 3b. The C++ compiler.  #
623 # ---------------------- #
626 # AC_LANG_PREPROC(C++)
627 # --------------------
628 # Find the C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
629 AC_DEFUN([AC_LANG_PREPROC(C++)],
630 [AC_REQUIRE([AC_PROG_CXXCPP])])
633 # AC_PROG_CXXCPP
634 # --------------
635 # Find a working C++ preprocessor.
636 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
637 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
638 AC_DEFUN([AC_PROG_CXXCPP],
639 [AC_REQUIRE([AC_PROG_CXX])dnl
640 AC_ARG_VAR([CXXCPP],   [C++ preprocessor])dnl
641 _AC_ARG_VAR_CPPFLAGS()dnl
642 AC_LANG_PUSH(C++)dnl
643 AC_MSG_CHECKING([how to run the C++ preprocessor])
644 if test -z "$CXXCPP"; then
645   AC_CACHE_VAL(ac_cv_prog_CXXCPP,
646   [dnl
647     # Double quotes because CXXCPP needs to be expanded
648     for CXXCPP in "$CXX -E" "/lib/cpp"
649     do
650       _AC_PROG_PREPROC_WORKS_IFELSE([break])
651     done
652     ac_cv_prog_CXXCPP=$CXXCPP
653   ])dnl
654   CXXCPP=$ac_cv_prog_CXXCPP
655 else
656   ac_cv_prog_CXXCPP=$CXXCPP
658 AC_MSG_RESULT([$CXXCPP])
659 _AC_PROG_PREPROC_WORKS_IFELSE([],
660           [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
661 AC_SUBST(CXXCPP)dnl
662 AC_LANG_POP(C++)dnl
663 ])# AC_PROG_CXXCPP
666 # AC_LANG_COMPILER(C++)
667 # ---------------------
668 # Find the C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
669 AC_DEFUN([AC_LANG_COMPILER(C++)],
670 [AC_REQUIRE([AC_PROG_CXX])])
673 # ac_cv_prog_gxx
674 # --------------
675 # We used to name the cache variable this way.
676 AU_DEFUN([ac_cv_prog_gxx],
677 [ac_cv_cxx_compiler_gnu])
680 # AC_PROG_CXX([LIST-OF-COMPILERS])
681 # --------------------------------
682 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
683 # for (if not specified, a default list is used).  This just gives the
684 # user an opportunity to specify an alternative search list for the C++
685 # compiler.
686 # aCC   HP-UX C++ compiler much better than `CC', so test before.
687 # FCC   Fujitsu C++ compiler
688 # KCC   KAI C++ compiler
689 # RCC   Rational C++
690 # xlC_r AIX C Set++ (with support for reentrant code)
691 # xlC   AIX C Set++
692 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
693 AN_PROGRAM([CC],   [AC_PROG_CXX])
694 AN_PROGRAM([c++],  [AC_PROG_CXX])
695 AN_PROGRAM([g++],  [AC_PROG_CXX])
696 AC_DEFUN([AC_PROG_CXX],
697 [AC_LANG_PUSH(C++)dnl
698 AC_ARG_VAR([CXX],      [C++ compiler command])dnl
699 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
700 _AC_ARG_VAR_LDFLAGS()dnl
701 _AC_ARG_VAR_LIBS()dnl
702 _AC_ARG_VAR_CPPFLAGS()dnl
703 _AC_ARG_VAR_PRECIOUS([CCC])dnl
704 if test -z "$CXX"; then
705   if test -n "$CCC"; then
706     CXX=$CCC
707   else
708     AC_CHECK_TOOLS(CXX,
709                    [m4_default([$1],
710                                [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC clang++])],
711                    g++)
712   fi
714 # Provide some information about the compiler.
715 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
716 set X $ac_compile
717 ac_compiler=$[2]
718 for ac_option in --version -v -V -qversion; do
719   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
720 done
722 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
723 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
724 _AC_LANG_COMPILER_GNU
725 if test $ac_compiler_gnu = yes; then
726   GXX=yes
727 else
728   GXX=
730 _AC_PROG_CXX_G
731 _AC_PROG_CXX_CXX11([ac_prog_cxx_stdcxx=cxx11
732                     ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11
733                     ac_cv_prog_cxx_cxx98=$ac_cv_prog_cxx_cxx11],
734    [_AC_PROG_CXX_CXX98([ac_prog_cxx_stdcxx=cxx98
735                         ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98],
736                        [ac_prog_cxx_stdcxx=no
737                         ac_cv_prog_cxx_stdcxx=no])])
738 AC_LANG_POP(C++)dnl
739 ])# AC_PROG_CXX
742 # _AC_PROG_CXX_G
743 # --------------
744 # Check whether -g works, even if CXXFLAGS is set, in case the package
745 # plays around with CXXFLAGS (such as to build both debugging and
746 # normal versions of a library), tasteless as that idea is.
747 # Don't consider -g to work if it generates warnings when plain compiles don't.
748 m4_define([_AC_PROG_CXX_G],
749 [ac_test_CXXFLAGS=${CXXFLAGS+y}
750 ac_save_CXXFLAGS=$CXXFLAGS
751 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
752   [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
753    ac_cxx_werror_flag=yes
754    ac_cv_prog_cxx_g=no
755    CXXFLAGS="-g"
756    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
757      [ac_cv_prog_cxx_g=yes],
758      [CXXFLAGS=""
759       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
760         [],
761         [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
762          CXXFLAGS="-g"
763          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
764            [ac_cv_prog_cxx_g=yes])])])
765    ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
766 if test $ac_test_CXXFLAGS; then
767   CXXFLAGS=$ac_save_CXXFLAGS
768 elif test $ac_cv_prog_cxx_g = yes; then
769   if test "$GXX" = yes; then
770     CXXFLAGS="-g -O2"
771   else
772     CXXFLAGS="-g"
773   fi
774 else
775   if test "$GXX" = yes; then
776     CXXFLAGS="-O2"
777   else
778     CXXFLAGS=
779   fi
780 fi[]dnl
781 ])# _AC_PROG_CXX_G
784 # AC_PROG_CXX_C_O
785 # ---------------
786 # Test if the C++ compiler accepts the options `-c' and `-o'
787 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
788 AC_DEFUN([AC_PROG_CXX_C_O],
789 [AC_REQUIRE([AC_PROG_CXX])dnl
790 AC_LANG_PUSH([C++])dnl
791 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
792                [ac_cv_prog_cxx_c_o],
793 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
794 # We test twice because some compilers refuse to overwrite an existing
795 # `.o' file with `-o', although they will create one.
796 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
797 rm -f conftest2.*
798 if _AC_DO_VAR(ac_try) &&
799      test -f conftest2.$ac_objext &&
800      _AC_DO_VAR(ac_try); then
801   ac_cv_prog_cxx_c_o=yes
802 else
803   ac_cv_prog_cxx_c_o=no
805 rm -rf conftest*])
806 if test $ac_cv_prog_cxx_c_o = no; then
807   AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
808             [Define to 1 if your C++ compiler doesn't accept
809              -c and -o together.])
811 AC_LANG_POP([C++])dnl
812 ])# AC_PROG_CXX_C_O
816 # ------------------------------ #
817 # 3c. The Objective C compiler.  #
818 # ------------------------------ #
821 # AC_LANG_PREPROC(Objective C)
822 # ----------------------------
823 # Find the Objective C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
824 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
825 [AC_REQUIRE([AC_PROG_OBJCPP])])
828 # AC_PROG_OBJCPP
829 # --------------
830 # Find a working Objective C preprocessor.
831 AC_DEFUN([AC_PROG_OBJCPP],
832 [AC_REQUIRE([AC_PROG_OBJC])dnl
833 AC_ARG_VAR([OBJCPP],   [Objective C preprocessor])dnl
834 _AC_ARG_VAR_CPPFLAGS()dnl
835 AC_LANG_PUSH(Objective C)dnl
836 AC_MSG_CHECKING([how to run the Objective C preprocessor])
837 if test -z "$OBJCPP"; then
838   AC_CACHE_VAL(ac_cv_prog_OBJCPP,
839   [dnl
840     # Double quotes because OBJCPP needs to be expanded
841     for OBJCPP in "$OBJC -E" "/lib/cpp"
842     do
843       _AC_PROG_PREPROC_WORKS_IFELSE([break])
844     done
845     ac_cv_prog_OBJCPP=$OBJCPP
846   ])dnl
847   OBJCPP=$ac_cv_prog_OBJCPP
848 else
849   ac_cv_prog_OBJCPP=$OBJCPP
851 AC_MSG_RESULT([$OBJCPP])
852 _AC_PROG_PREPROC_WORKS_IFELSE([],
853           [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
854 AC_SUBST(OBJCPP)dnl
855 AC_LANG_POP(Objective C)dnl
856 ])# AC_PROG_OBJCPP
859 # AC_LANG_COMPILER(Objective C)
860 # -----------------------------
861 # Find the Objective C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
862 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
863 [AC_REQUIRE([AC_PROG_OBJC])])
867 # AC_PROG_OBJC([LIST-OF-COMPILERS])
868 # ---------------------------------
869 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
870 # search for (if not specified, a default list is used).  This just gives
871 # the user an opportunity to specify an alternative search list for the
872 # Objective C compiler.
873 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
874 # objc  David Stes' POC.  If you installed this, you likely want it.
875 # cc    Native C compiler (for instance, Apple).
876 # CC    You never know.
877 AN_MAKEVAR([OBJC],  [AC_PROG_OBJC])
878 AN_PROGRAM([objcc],  [AC_PROG_OBJC])
879 AN_PROGRAM([objc],  [AC_PROG_OBJC])
880 AC_DEFUN([AC_PROG_OBJC],
881 [AC_LANG_PUSH(Objective C)dnl
882 AC_ARG_VAR([OBJC],      [Objective C compiler command])dnl
883 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
884 _AC_ARG_VAR_LDFLAGS()dnl
885 _AC_ARG_VAR_LIBS()dnl
886 _AC_ARG_VAR_CPPFLAGS()dnl
887 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
888 AC_CHECK_TOOLS(OBJC,
889                [m4_default([$1], [gcc objcc objc cc CC clang])],
890                gcc)
891 # Provide some information about the compiler.
892 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
893 set X $ac_compile
894 ac_compiler=$[2]
895 for ac_option in --version -v -V -qversion; do
896   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
897 done
899 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
900 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
901 _AC_LANG_COMPILER_GNU
902 if test $ac_compiler_gnu = yes; then
903   GOBJC=yes
904 else
905   GOBJC=
907 _AC_PROG_OBJC_G
908 AC_LANG_POP(Objective C)dnl
909 ])# AC_PROG_OBJC
912 # _AC_PROG_OBJC_G
913 # ---------------
914 # Check whether -g works, even if OBJCFLAGS is set, in case the package
915 # plays around with OBJCFLAGS (such as to build both debugging and
916 # normal versions of a library), tasteless as that idea is.
917 # Don't consider -g to work if it generates warnings when plain compiles don't.
918 m4_define([_AC_PROG_OBJC_G],
919 [ac_test_OBJCFLAGS=${OBJCFLAGS+y}
920 ac_save_OBJCFLAGS=$OBJCFLAGS
921 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
922   [ac_save_objc_werror_flag=$ac_objc_werror_flag
923    ac_objc_werror_flag=yes
924    ac_cv_prog_objc_g=no
925    OBJCFLAGS="-g"
926    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
927      [ac_cv_prog_objc_g=yes],
928      [OBJCFLAGS=""
929       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
930         [],
931         [ac_objc_werror_flag=$ac_save_objc_werror_flag
932          OBJCFLAGS="-g"
933          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
934            [ac_cv_prog_objc_g=yes])])])
935    ac_objc_werror_flag=$ac_save_objc_werror_flag])
936 if test $ac_test_OBJCFLAGS; then
937   OBJCFLAGS=$ac_save_OBJCFLAGS
938 elif test $ac_cv_prog_objc_g = yes; then
939   if test "$GOBJC" = yes; then
940     OBJCFLAGS="-g -O2"
941   else
942     OBJCFLAGS="-g"
943   fi
944 else
945   if test "$GOBJC" = yes; then
946     OBJCFLAGS="-O2"
947   else
948     OBJCFLAGS=
949   fi
950 fi[]dnl
951 ])# _AC_PROG_OBJC_G
955 # -------------------------------- #
956 # 3d. The Objective C++ compiler.  #
957 # -------------------------------- #
960 # AC_LANG_PREPROC(Objective C++)
961 # ------------------------------
962 # Find the Objective C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
963 AC_DEFUN([AC_LANG_PREPROC(Objective C++)],
964 [AC_REQUIRE([AC_PROG_OBJCXXCPP])])
967 # AC_PROG_OBJCXXCPP
968 # -----------------
969 # Find a working Objective C++ preprocessor.
970 AC_DEFUN([AC_PROG_OBJCXXCPP],
971 [AC_REQUIRE([AC_PROG_OBJCXX])dnl
972 AC_ARG_VAR([OBJCXXCPP],   [Objective C++ preprocessor])dnl
973 _AC_ARG_VAR_CPPFLAGS()dnl
974 AC_LANG_PUSH(Objective C++)dnl
975 AC_MSG_CHECKING([how to run the Objective C++ preprocessor])
976 if test -z "$OBJCXXCPP"; then
977   AC_CACHE_VAL(ac_cv_prog_OBJCXXCPP,
978   [dnl
979     # Double quotes because OBJCXXCPP needs to be expanded
980     for OBJCXXCPP in "$OBJCXX -E" "/lib/cpp"
981     do
982       _AC_PROG_PREPROC_WORKS_IFELSE([break])
983     done
984     ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
985   ])dnl
986   OBJCXXCPP=$ac_cv_prog_OBJCXXCPP
987 else
988   ac_cv_prog_OBJCXXCPP=$OBJCXXCPP
990 AC_MSG_RESULT([$OBJCXXCPP])
991 _AC_PROG_PREPROC_WORKS_IFELSE([],
992           [AC_MSG_FAILURE([Objective C++ preprocessor "$OBJCXXCPP" fails sanity check])])
993 AC_SUBST(OBJCXXCPP)dnl
994 AC_LANG_POP(Objective C++)dnl
995 ])# AC_PROG_OBJCXXCPP
998 # AC_LANG_COMPILER(Objective C++)
999 # -------------------------------
1000 # Find the Objective C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
1001 AC_DEFUN([AC_LANG_COMPILER(Objective C++)],
1002 [AC_REQUIRE([AC_PROG_OBJCXX])])
1006 # AC_PROG_OBJCXX([LIST-OF-COMPILERS])
1007 # -----------------------------------
1008 # LIST-OF-COMPILERS is a space separated list of Objective C++ compilers to
1009 # search for (if not specified, a default list is used).  This just gives
1010 # the user an opportunity to specify an alternative search list for the
1011 # Objective C++ compiler.
1012 # FIXME: this list is pure guesswork
1013 # objc++ StepStone Objective-C++ compiler (also "standard" name for OBJCXX)
1014 # objcxx David Stes' POC.  If you installed this, you likely want it.
1015 # c++    Native C++ compiler (for instance, Apple).
1016 # CXX    You never know.
1017 AN_MAKEVAR([OBJCXX],  [AC_PROG_OBJCXX])
1018 AN_PROGRAM([objcxx],  [AC_PROG_OBJCXX])
1019 AC_DEFUN([AC_PROG_OBJCXX],
1020 [AC_LANG_PUSH(Objective C++)dnl
1021 AC_ARG_VAR([OBJCXX],      [Objective C++ compiler command])dnl
1022 AC_ARG_VAR([OBJCXXFLAGS], [Objective C++ compiler flags])dnl
1023 _AC_ARG_VAR_LDFLAGS()dnl
1024 _AC_ARG_VAR_LIBS()dnl
1025 _AC_ARG_VAR_CPPFLAGS()dnl
1026 _AC_ARG_VAR_PRECIOUS([OBJCXX])dnl
1027 AC_CHECK_TOOLS(OBJCXX,
1028                [m4_default([$1], [g++ objc++ objcxx c++ CXX])],
1029                g++)
1030 # Provide some information about the compiler.
1031 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
1032 set X $ac_compile
1033 ac_compiler=$[2]
1034 for ac_option in --version -v -V -qversion; do
1035   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
1036 done
1038 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
1039 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
1040 _AC_LANG_COMPILER_GNU
1041 if test $ac_compiler_gnu = yes; then
1042   GOBJCXX=yes
1043 else
1044   GOBJCXX=
1046 _AC_PROG_OBJCXX_G
1047 AC_LANG_POP(Objective C++)dnl
1048 ])# AC_PROG_OBJCXX
1051 # _AC_PROG_OBJCXX_G
1052 # -----------------
1053 # Check whether -g works, even if OBJCFLAGS is set, in case the package
1054 # plays around with OBJCFLAGS (such as to build both debugging and
1055 # normal versions of a library), tasteless as that idea is.
1056 # Don't consider -g to work if it generates warnings when plain compiles don't.
1057 m4_define([_AC_PROG_OBJCXX_G],
1058 [ac_test_OBJCXXFLAGS=${OBJCXXFLAGS+y}
1059 ac_save_OBJCXXFLAGS=$OBJCXXFLAGS
1060 AC_CACHE_CHECK(whether $OBJCXX accepts -g, ac_cv_prog_objcxx_g,
1061   [ac_save_objcxx_werror_flag=$ac_objcxx_werror_flag
1062    ac_objcxx_werror_flag=yes
1063    ac_cv_prog_objcxx_g=no
1064    OBJCXXFLAGS="-g"
1065    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1066      [ac_cv_prog_objcxx_g=yes],
1067      [OBJCXXFLAGS=""
1068       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1069         [],
1070         [ac_objcxx_werror_flag=$ac_save_objcxx_werror_flag
1071          OBJCXXFLAGS="-g"
1072          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1073            [ac_cv_prog_objcxx_g=yes])])])
1074    ac_objcxx_werror_flag=$ac_save_objcx_werror_flag])
1075 if test $ac_test_OBJCXXFLAGS; then
1076   OBJCXXFLAGS=$ac_save_OBJCXXFLAGS
1077 elif test $ac_cv_prog_objcxx_g = yes; then
1078   if test "$GOBJCXX" = yes; then
1079     OBJCXXFLAGS="-g -O2"
1080   else
1081     OBJCXXFLAGS="-g"
1082   fi
1083 else
1084   if test "$GOBJCXX" = yes; then
1085     OBJCXXFLAGS="-O2"
1086   else
1087     OBJCXXFLAGS=
1088   fi
1089 fi[]dnl
1090 ])# _AC_PROG_OBJCXX_G
1094 ## ------------------------------- ##
1095 ## 4. Compilers' characteristics.  ##
1096 ## ------------------------------- ##
1098 # -------------------------------- #
1099 # 4a. C compiler characteristics.  #
1100 # -------------------------------- #
1103 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1104 # ----------------------------------------------------------------
1105 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1106 # to add an option to output variable CC to make it so.  This macro
1107 # tries various options that select ANSI C89 on some system or
1108 # another.  It considers the compiler to be in ANSI C89 mode if it
1109 # handles function prototypes correctly.
1110 AC_DEFUN([_AC_PROG_CC_C89],
1111 [_AC_C_STD_TRY([c89],
1112 [[#include <stdarg.h>
1113 #include <stdio.h>
1114 struct stat;
1115 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
1116 struct buf { int x; };
1117 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1118 static char *e (p, i)
1119      char **p;
1120      int i;
1122   return p[i];
1124 static char *f (char * (*g) (char **, int), char **p, ...)
1126   char *s;
1127   va_list v;
1128   va_start (v,p);
1129   s = g (p, va_arg (v,int));
1130   va_end (v);
1131   return s;
1134 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
1135    function prototypes and stuff, but not '\xHH' hex character constants.
1136    These don't provoke an error unfortunately, instead are silently treated
1137    as 'x'.  The following induces an error, until -std is added to get
1138    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
1139    array size at least.  It's necessary to write '\x00'==0 to get something
1140    that's true only with -std.  */
1141 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1143 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1144    inside strings and character constants.  */
1145 #define FOO(x) 'x'
1146 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1148 int test (int i, double x);
1149 struct s1 {int (*f) (int a);};
1150 struct s2 {int (*f) (double a);};
1151 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1152 int argc;
1153 char **argv;]],
1154 [[return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];]],
1155 dnl Don't try gcc -ansi; that turns off useful extensions and
1156 dnl breaks some systems' header files.
1157 dnl AIX circa 2003      -qlanglvl=extc89
1158 dnl old AIX             -qlanglvl=ansi
1159 dnl Ultrix, OSF/1, Tru64        -std
1160 dnl HP-UX 10.20 and later       -Ae
1161 dnl HP-UX older versions        -Aa -D_HPUX_SOURCE
1162 dnl SVR4                        -Xc -D__EXTENSIONS__
1163 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1164         -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1165 ])# _AC_PROG_CC_C89
1168 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1169 #               ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1170 # --------------------------------------------------------------
1171 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1172 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
1173 # try again with each compiler option in the space-separated OPTION-LIST; if one
1174 # helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
1175 # else ACTION-IF-UNAVAILABLE.
1176 AC_DEFUN([_AC_C_STD_TRY],
1177 [AC_MSG_CHECKING([for $CC option to enable ]m4_translit($1, [c], [C])[ features])
1178 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1179 [ac_cv_prog_cc_$1=no
1180 ac_save_CC=$CC
1181 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1182 for ac_arg in '' $4
1184   CC="$ac_save_CC $ac_arg"
1185   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1186   test "x$ac_cv_prog_cc_$1" != "xno" && break
1187 done
1188 rm -f conftest.$ac_ext
1189 CC=$ac_save_CC
1190 ])# AC_CACHE_VAL
1191 ac_prog_cc_stdc_options=
1192 case "x$ac_cv_prog_cc_$1" in
1193   x)
1194     AC_MSG_RESULT([none needed]) ;;
1195   xno)
1196     AC_MSG_RESULT([unsupported]) ;;
1197   *)
1198     ac_prog_cc_stdc_options=" $ac_cv_prog_cc_$1"
1199     CC=$CC$ac_prog_cc_stdc_options
1200     AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1201 esac
1202 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1203 ])# _AC_C_STD_TRY
1205 # _AC_C_C99_TEST_HEADER
1206 # ---------------------
1207 # A C header suitable for testing for C99.
1208 AC_DEFUN([_AC_C_C99_TEST_HEADER],
1209 [[#include <stdarg.h>
1210 #include <stdbool.h>
1211 #include <stddef.h>
1212 #include <stdlib.h>
1213 #include <wchar.h>
1214 #include <stdio.h>
1216 // Check varargs macros.  These examples are taken from C99 6.10.3.5.
1217 #define debug(...) fprintf (stderr, __VA_ARGS__)
1218 #define showlist(...) puts (#__VA_ARGS__)
1219 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1220 static void
1221 test_varargs_macros (void)
1223   int x = 1234;
1224   int y = 5678;
1225   debug ("Flag");
1226   debug ("X = %d\n", x);
1227   showlist (The first, second, and third items.);
1228   report (x>y, "x is %d but y is %d", x, y);
1231 // Check long long types.
1232 #define BIG64 18446744073709551615ull
1233 #define BIG32 4294967295ul
1234 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1235 #if !BIG_OK
1236   your preprocessor is broken;
1237 #endif
1238 #if BIG_OK
1239 #else
1240   your preprocessor is broken;
1241 #endif
1242 static long long int bignum = -9223372036854775807LL;
1243 static unsigned long long int ubignum = BIG64;
1245 struct incomplete_array
1247   int datasize;
1248   double data[];
1251 struct named_init {
1252   int number;
1253   const wchar_t *name;
1254   double average;
1257 typedef const char *ccp;
1259 static inline int
1260 test_restrict (ccp restrict text)
1262   // See if C++-style comments work.
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)
1266     continue;
1267   return 0;
1270 // Check varargs and va_copy.
1271 static bool
1272 test_varargs (const char *format, ...)
1274   va_list args;
1275   va_start (args, format);
1276   va_list args_copy;
1277   va_copy (args_copy, args);
1279   const char *str = "";
1280   int number = 0;
1281   float fnumber = 0;
1283   while (*format)
1284     {
1285       switch (*format++)
1286         {
1287         case 's': // string
1288           str = va_arg (args_copy, const char *);
1289           break;
1290         case 'd': // int
1291           number = va_arg (args_copy, int);
1292           break;
1293         case 'f': // float
1294           fnumber = va_arg (args_copy, double);
1295           break;
1296         default:
1297           break;
1298         }
1299     }
1300   va_end (args_copy);
1301   va_end (args);
1303   return *str && number && fnumber;
1304 }]])# _AC_C_C99_TEST_HEADER
1306 # _AC_C_C99_TEST_BODY
1307 # -------------------
1308 # A C body suitable for testing for C99, assuming the corresponding header.
1309 AC_DEFUN([_AC_C_C99_TEST_BODY],
1311   // Check bool.
1312   _Bool success = false;
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;
1330   // Check named initializers.
1331   struct named_init ni = {
1332     .number = 34,
1333     .name = L"Test wide string",
1334     .average = 543.34343,
1335   };
1337   ni.number = 58;
1339   int dynamic_array[ni.number];
1340   dynamic_array[ni.number - 1] = 543;
1342   // work around unused variable warnings
1343   return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
1344           || dynamic_array[ni.number - 1] != 543);
1347 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1348 # ----------------------------------------------------------------
1349 # If the C compiler is not in ISO C99 mode by default, try to add an
1350 # option to output variable CC to make it so.  This macro tries
1351 # various options that select ISO C99 on some system or another.  It
1352 # considers the compiler to be in ISO C99 mode if it handles _Bool,
1353 # // comments, flexible array members, inline, long long int, mixed
1354 # code and declarations, named initialization of structs, restrict,
1355 # va_copy, varargs macros, variable declarations in for loops and
1356 # variable length arrays.
1357 AC_DEFUN([_AC_PROG_CC_C99],
1358 [_AC_C_STD_TRY([c99],
1359 [_AC_C_C99_TEST_HEADER],
1360 [_AC_C_C99_TEST_BODY],
1361 dnl Try
1362 dnl GCC         -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1363 dnl IBM XL C    -qlanglvl=extc1x (V12.1; does not pass C11 test)
1364 dnl IBM XL C    -qlanglvl=extc99
1365 dnl             (pre-V12.1; unused restrictive mode: -qlanglvl=stdc99)
1366 dnl HP cc       -AC99
1367 dnl Intel ICC   -std=c99, -c99 (deprecated)
1368 dnl IRIX        -c99
1369 dnl Solaris     -D_STDC_C99=
1370 dnl             cc's -xc99 option uses linker magic to define the external
1371 dnl             symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
1372 dnl             behavior for C library functions.  This is not wanted here,
1373 dnl             because it means that a single module compiled with -xc99
1374 dnl             alters C runtime behavior for the entire program, not for
1375 dnl             just the module.  Instead, define the (private) symbol
1376 dnl             _STDC_C99, which suppresses a bogus failure in <stdbool.h>.
1377 dnl             The resulting compiler passes the test case here, and that's
1378 dnl             good enough.  For more, please see the thread starting at:
1379 dnl           https://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
1380 dnl Tru64       -c99
1381 dnl with extended modes being tried first.
1382 [[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc1x -qlanglvl=extc99]], [$1], [$2])[]dnl
1383 ])# _AC_PROG_CC_C99
1386 # _AC_PROG_CC_C11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1387 # ----------------------------------------------------------------
1388 # If the C compiler is not in ISO C11 mode by default, try to add an
1389 # option to output variable CC to make it so.  This macro tries
1390 # various options that select ISO C11 on some system or another.  It
1391 # considers the compiler to be in ISO C11 mode if it handles _Alignas,
1392 # _Alignof, _Noreturn, _Static_assert, UTF-8 string literals,
1393 # duplicate typedefs, and anonymous structures and unions.
1394 AC_DEFUN([_AC_PROG_CC_C11],
1395 [_AC_C_STD_TRY([c11],
1396 [_AC_C_C99_TEST_HEADER[
1397 // Check _Alignas.
1398 char _Alignas (double) aligned_as_double;
1399 char _Alignas (0) no_special_alignment;
1400 extern char aligned_as_int;
1401 char _Alignas (0) _Alignas (int) aligned_as_int;
1403 // Check _Alignof.
1404 enum
1406   int_alignment = _Alignof (int),
1407   int_array_alignment = _Alignof (int[100]),
1408   char_alignment = _Alignof (char)
1410 _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
1412 // Check _Noreturn.
1413 int _Noreturn does_not_return (void) { for (;;) continue; }
1415 // Check _Static_assert.
1416 struct test_static_assert
1418   int x;
1419   _Static_assert (sizeof (int) <= sizeof (long int),
1420                   "_Static_assert does not work in struct");
1421   long int y;
1424 // Check UTF-8 literals.
1425 #define u8 syntax error!
1426 char const utf8_literal[] = u8"happens to be ASCII" "another string";
1428 // Check duplicate typedefs.
1429 typedef long *long_ptr;
1430 typedef long int *long_ptr;
1431 typedef long_ptr long_ptr;
1433 // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
1434 struct anonymous
1436   union {
1437     struct { int i; int j; };
1438     struct { int k; long int l; } w;
1439   };
1440   int m;
1441 } v1;
1443 [_AC_C_C99_TEST_BODY[
1444   v1.i = 2;
1445   v1.w.k = 5;
1446   _Static_assert ((offsetof (struct anonymous, i)
1447                    == offsetof (struct anonymous, w.k)),
1448                   "Anonymous union alignment botch");
1450 dnl Try
1451 dnl GCC         -std=gnu11 (unused restrictive mode: -std=c11)
1452 dnl with extended modes being tried first.
1454 dnl Do not try -qlanglvl=extc1x, because IBM XL C V12.1 (the latest version as
1455 dnl of September 2012) does not pass the C11 test.  For now, try extc1x when
1456 dnl compiling the C99 test instead, since it enables _Static_assert and
1457 dnl _Noreturn, which is a win.  If -qlanglvl=extc11 or -qlanglvl=extc1x passes
1458 dnl the C11 test in some future version of IBM XL C, we'll add it here,
1459 dnl preferably extc11.
1460 [[-std=gnu11]], [$1], [$2])[]dnl
1461 ])# _AC_PROG_CC_C11
1464 # AC_PROG_CC_C89
1465 # --------------
1466 # Do not use AU_ALIAS here and in AC_PROG_CC_C99 and AC_PROG_CC_STDC,
1467 # as that'd be incompatible with how Automake redefines AC_PROG_CC.  See
1468 # <https://lists.gnu.org/archive/html/autoconf/2012-10/msg00048.html>.
1469 AU_DEFUN([AC_PROG_CC_C89],
1470   [AC_REQUIRE([AC_PROG_CC])],
1471   [$0 is obsolete; use AC_PROG_CC]
1474 # AC_PROG_CC_C99
1475 # --------------
1476 AU_DEFUN([AC_PROG_CC_C99],
1477   [AC_REQUIRE([AC_PROG_CC])],
1478   [$0 is obsolete; use AC_PROG_CC]
1481 # AC_PROG_CC_STDC
1482 # ---------------
1483 AU_DEFUN([AC_PROG_CC_STDC],
1484   [AC_REQUIRE([AC_PROG_CC])],
1485   [$0 is obsolete; use AC_PROG_CC]
1489 # AC_C_BACKSLASH_A
1490 # ----------------
1491 AC_DEFUN([AC_C_BACKSLASH_A],
1493   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1494    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1495      [[
1496 #if '\a' == 'a'
1497       syntax error;
1498 #endif
1499       char buf['\a' == 'a' ? -1 : 1];
1500       buf[0] = '\a';
1501       return buf[0] != "\a"[0];
1502      ]])],
1503      [ac_cv_c_backslash_a=yes],
1504      [ac_cv_c_backslash_a=no])])
1505   if test $ac_cv_c_backslash_a = yes; then
1506     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1507       [Define if backslash-a works in C strings.])
1508   fi
1512 # AC_C_CROSS
1513 # ----------
1514 # Has been merged into AC_PROG_CC.
1515 AU_DEFUN([AC_C_CROSS], [])
1518 # AC_C_CHAR_UNSIGNED
1519 # ------------------
1520 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1521 [AH_VERBATIM([__CHAR_UNSIGNED__],
1522 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1523 #ifndef __CHAR_UNSIGNED__
1524 # undef __CHAR_UNSIGNED__
1525 #endif])dnl
1526 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1527 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1528                                              [((char) -1) < 0])],
1529                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1530 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1531   AC_DEFINE(__CHAR_UNSIGNED__)
1533 ])# AC_C_CHAR_UNSIGNED
1536 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1537 #                 [ACTION-IF-UNIVERSAL])
1538 # -------------------------------------------------------------------------
1539 AC_DEFUN([AC_C_BIGENDIAN],
1540 [AH_VERBATIM([WORDS_BIGENDIAN],
1541 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1542    significant byte first (like Motorola and SPARC, unlike Intel). */
1543 #if defined AC_APPLE_UNIVERSAL_BUILD
1544 # if defined __BIG_ENDIAN__
1545 #  define WORDS_BIGENDIAN 1
1546 # endif
1547 #else
1548 # ifndef WORDS_BIGENDIAN
1549 #  undef WORDS_BIGENDIAN
1550 # endif
1551 #endif])dnl
1552  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1553    [ac_cv_c_bigendian=unknown
1554     # See if we're dealing with a universal compiler.
1555     AC_COMPILE_IFELSE(
1556          [AC_LANG_SOURCE(
1557             [[#ifndef __APPLE_CC__
1558                not a universal capable compiler
1559              #endif
1560              typedef int dummy;
1561             ]])],
1562          [
1563         # Check for potential -arch flags.  It is not universal unless
1564         # there are at least two -arch flags with different values.
1565         ac_arch=
1566         ac_prev=
1567         for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
1568          if test -n "$ac_prev"; then
1569            case $ac_word in
1570              i?86 | x86_64 | ppc | ppc64)
1571                if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
1572                  ac_arch=$ac_word
1573                else
1574                  ac_cv_c_bigendian=universal
1575                  break
1576                fi
1577                ;;
1578            esac
1579            ac_prev=
1580          elif test "x$ac_word" = "x-arch"; then
1581            ac_prev=arch
1582          fi
1583        done])
1584     if test $ac_cv_c_bigendian = unknown; then
1585       # See if sys/param.h defines the BYTE_ORDER macro.
1586       AC_COMPILE_IFELSE(
1587         [AC_LANG_PROGRAM(
1588            [[#include <sys/types.h>
1589              #include <sys/param.h>
1590            ]],
1591            [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1592                      && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1593                      && LITTLE_ENDIAN)
1594               bogus endian macros
1595              #endif
1596            ]])],
1597         [# It does; now see whether it defined to BIG_ENDIAN or not.
1598          AC_COMPILE_IFELSE(
1599            [AC_LANG_PROGRAM(
1600               [[#include <sys/types.h>
1601                 #include <sys/param.h>
1602               ]],
1603               [[#if BYTE_ORDER != BIG_ENDIAN
1604                  not big endian
1605                 #endif
1606               ]])],
1607            [ac_cv_c_bigendian=yes],
1608            [ac_cv_c_bigendian=no])])
1609     fi
1610     if test $ac_cv_c_bigendian = unknown; then
1611       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1612       AC_COMPILE_IFELSE(
1613         [AC_LANG_PROGRAM(
1614            [[#include <limits.h>
1615            ]],
1616            [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1617               bogus endian macros
1618              #endif
1619            ]])],
1620         [# It does; now see whether it defined to _BIG_ENDIAN or not.
1621          AC_COMPILE_IFELSE(
1622            [AC_LANG_PROGRAM(
1623               [[#include <limits.h>
1624               ]],
1625               [[#ifndef _BIG_ENDIAN
1626                  not big endian
1627                 #endif
1628               ]])],
1629            [ac_cv_c_bigendian=yes],
1630            [ac_cv_c_bigendian=no])])
1631     fi
1632     if test $ac_cv_c_bigendian = unknown; then
1633       # Compile a test program.
1634       AC_RUN_IFELSE(
1635         [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1636            [[
1637              /* Are we little or big endian?  From Harbison&Steele.  */
1638              union
1639              {
1640                long int l;
1641                char c[sizeof (long int)];
1642              } u;
1643              u.l = 1;
1644              return u.c[sizeof (long int) - 1] == 1;
1645            ]])],
1646         [ac_cv_c_bigendian=no],
1647         [ac_cv_c_bigendian=yes],
1648         [# Try to guess by grepping values from an object file.
1649          AC_COMPILE_IFELSE(
1650            [AC_LANG_PROGRAM(
1651               [[short int ascii_mm[] =
1652                   { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1653                 short int ascii_ii[] =
1654                   { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1655                 int use_ascii (int i) {
1656                   return ascii_mm[i] + ascii_ii[i];
1657                 }
1658                 short int ebcdic_ii[] =
1659                   { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1660                 short int ebcdic_mm[] =
1661                   { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1662                 int use_ebcdic (int i) {
1663                   return ebcdic_mm[i] + ebcdic_ii[i];
1664                 }
1665                 extern int foo;
1666               ]],
1667               [[return use_ascii (foo) == use_ebcdic (foo);]])],
1668            [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1669               ac_cv_c_bigendian=yes
1670             fi
1671             if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1672               if test "$ac_cv_c_bigendian" = unknown; then
1673                 ac_cv_c_bigendian=no
1674               else
1675                 # finding both strings is unlikely to happen, but who knows?
1676                 ac_cv_c_bigendian=unknown
1677               fi
1678             fi])])
1679     fi])
1680  case $ac_cv_c_bigendian in #(
1681    yes)
1682      m4_default([$1],
1683        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1684    no)
1685      $2 ;; #(
1686    universal)
1687 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
1688 dnl this is a necessity for proper config header operation.  Warn if
1689 dnl the user did not specify a config header but is relying on the
1690 dnl default behavior for universal builds.
1691      m4_default([$4],
1692        [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
1693          [AC_DIAGNOSE([obsolete],
1694            [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
1695         AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
1696           [Define if building universal (internal helper macro)])])
1697      ;; #(
1698    *)
1699      m4_default([$3],
1700        [AC_MSG_ERROR([unknown endianness
1701  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1702  esac
1703 ])# AC_C_BIGENDIAN
1706 # AC_C__GENERIC
1707 # -------------
1708 # Define HAVE_C__GENERIC if _Generic works, a la C11.
1709 AN_IDENTIFIER([_Generic], [AC_C__GENERIC])
1710 AC_DEFUN([AC_C__GENERIC],
1711 [AC_CACHE_CHECK([for _Generic], ac_cv_c__Generic,
1712 [AC_COMPILE_IFELSE(
1713    [AC_LANG_SOURCE(
1714       [[int
1715          main (int argc, char **argv)
1716          {
1717            int a = _Generic (argc, int: argc = 1);
1718            int *b = &_Generic (argc, default: argc);
1719            char ***c = _Generic (argv, int: argc, default: argv ? &argv : 0);
1720            _Generic (1 ? 0 : b, int: a, default: b) = &argc;
1721            _Generic (a = 1, default: a) = 3;
1722            return a + !b + !c;
1723          }
1724       ]])],
1725    [ac_cv_c__Generic=yes],
1726    [ac_cv_c__Generic=no])])
1727 if test $ac_cv_c__Generic = yes; then
1728   AC_DEFINE([HAVE_C__GENERIC], 1,
1729             [Define to 1 if C11-style _Generic works.])
1731 ])# AC_C__GENERIC
1733 # AC_C_INLINE
1734 # -----------
1735 # Do nothing if the compiler accepts the inline keyword.
1736 # Otherwise define inline to __inline__ or __inline if one of those work,
1737 # otherwise define inline to be empty.
1739 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1740 # inline function, only builtin types.
1742 AN_IDENTIFIER([inline], [AC_C_INLINE])
1743 AC_DEFUN([AC_C_INLINE],
1744 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1745 [ac_cv_c_inline=no
1746 for ac_kw in inline __inline__ __inline; do
1747   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1748 [#ifndef __cplusplus
1749 typedef int foo_t;
1750 static $ac_kw foo_t static_foo () {return 0; }
1751 $ac_kw foo_t foo () {return 0; }
1752 #endif
1753 ])],
1754                     [ac_cv_c_inline=$ac_kw])
1755   test "$ac_cv_c_inline" != no && break
1756 done
1758 AH_VERBATIM([inline],
1759 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1760    calls it, or to nothing if 'inline' is not supported under any name.  */
1761 #ifndef __cplusplus
1762 #undef inline
1763 #endif])
1764 case $ac_cv_c_inline in
1765   inline | yes) ;;
1766   *)
1767     case $ac_cv_c_inline in
1768       no) ac_val=;;
1769       *) ac_val=$ac_cv_c_inline;;
1770     esac
1771     cat >>confdefs.h <<_ACEOF
1772 #ifndef __cplusplus
1773 #define inline $ac_val
1774 #endif
1775 _ACEOF
1776     ;;
1777 esac
1778 ])# AC_C_INLINE
1781 # AC_C_CONST
1782 # ----------
1783 AC_DEFUN([AC_C_CONST],
1784 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1785 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1787 #ifndef __cplusplus
1788   /* Ultrix mips cc rejects this sort of thing.  */
1789   typedef int charset[2];
1790   const charset cs = { 0, 0 };
1791   /* SunOS 4.1.1 cc rejects this.  */
1792   char const *const *pcpcc;
1793   char **ppc;
1794   /* NEC SVR4.0.2 mips cc rejects this.  */
1795   struct point {int x, y;};
1796   static struct point const zero = {0,0};
1797   /* IBM XL C 1.02.0.0 rejects this.
1798      It does not let you subtract one const X* pointer from another in
1799      an arm of an if-expression whose if-part is not a constant
1800      expression */
1801   const char *g = "string";
1802   pcpcc = &g + (g ? g-g : 0);
1803   /* HPUX 7.0 cc rejects these. */
1804   ++pcpcc;
1805   ppc = (char**) pcpcc;
1806   pcpcc = (char const *const *) ppc;
1807   { /* SCO 3.2v4 cc rejects this sort of thing.  */
1808     char tx;
1809     char *t = &tx;
1810     char const *s = 0 ? (char *) 0 : (char const *) 0;
1812     *t++ = 0;
1813     if (s) return 0;
1814   }
1815   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1816     int x[] = {25, 17};
1817     const int *foo = &x[0];
1818     ++foo;
1819   }
1820   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1821     typedef const int *iptr;
1822     iptr p = 0;
1823     ++p;
1824   }
1825   { /* IBM XL C 1.02.0.0 rejects this sort of thing, saying
1826        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1827     struct s { int j; const int *ap[3]; } bx;
1828     struct s *b = &bx; b->j = 5;
1829   }
1830   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1831     const int foo = 10;
1832     if (!foo) return 0;
1833   }
1834   return !cs[0] && !zero.x;
1835 #endif
1836 ]])],
1837                    [ac_cv_c_const=yes],
1838                    [ac_cv_c_const=no])])
1839 if test $ac_cv_c_const = no; then
1840   AC_DEFINE(const,,
1841             [Define to empty if `const' does not conform to ANSI C.])
1843 ])# AC_C_CONST
1846 # AC_C_RESTRICT
1847 # -------------
1848 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive
1850 # Determine whether the C/C++ compiler supports the "restrict" keyword
1851 # introduced in ANSI C99, or an equivalent.  Define "restrict" to the alternate
1852 # spelling, if any; these are more likely to work in both C and C++ compilers of
1853 # the same family, and in the presence of varying compiler options.  If only
1854 # plain "restrict" works, do nothing.  Here are some variants:
1855 # - GCC supports both __restrict and __restrict__
1856 # - older DEC Alpha C compilers support only __restrict
1857 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1858 # Otherwise, define "restrict" to be empty.
1859 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1860 AC_DEFUN([AC_C_RESTRICT],
1861 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
1862   [ac_cv_c_restrict=no
1863    # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
1864    # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
1865    # Put 'restrict' last, because C++ lacks it.
1866    for ac_kw in __restrict__ __restrict _Restrict restrict; do
1867      AC_COMPILE_IFELSE(
1868       [AC_LANG_PROGRAM(
1869          [[typedef int *int_ptr;
1870            int foo (int_ptr $ac_kw ip) { return ip[0]; }
1871            int bar (int [$ac_kw]); /* Catch GCC bug 14050.  */
1872            int bar (int ip[$ac_kw]) { return ip[0]; }
1873          ]],
1874          [[int s[1];
1875            int *$ac_kw t = s;
1876            t[0] = 0;
1877            return foo (t) + bar (t);
1878          ]])],
1879       [ac_cv_c_restrict=$ac_kw])
1880      test "$ac_cv_c_restrict" != no && break
1881    done
1882   ])
1883  AH_VERBATIM([restrict],
1884 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1885    nothing if this is not supported.  Do not define if restrict is
1886    supported only directly.  */
1887 #undef restrict
1888 /* Work around a bug in Sun C++ 5.13: it does not support _Restrict or
1889    __restrict__, even though the corresponding Sun C compiler ends up with
1890    "#define restrict _Restrict" or "#define restrict __restrict__".
1891    Perhaps some future version of Sun C++ will work with restrict;
1892    if so, hopefully it defines __RESTRICT like Sun C does.  */
1893 #if defined __SUNPRO_CC && !defined __RESTRICT
1894 # define _Restrict
1895 # define __restrict__
1896 #endif])
1897  case $ac_cv_c_restrict in
1898    restrict) ;;
1899    no) AC_DEFINE([restrict], []) ;;
1900    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1901  esac
1902 ])# AC_C_RESTRICT
1905 # AC_C_VOLATILE
1906 # -------------
1907 # Note that, unlike const, #defining volatile to be the empty string can
1908 # actually turn a correct program into an incorrect one, since removing
1909 # uses of volatile actually grants the compiler permission to perform
1910 # optimizations that could break the user's code.  So, do not #define
1911 # volatile away unless it is really necessary to allow the user's code
1912 # to compile cleanly.  Benign compiler failures should be tolerated.
1913 AC_DEFUN([AC_C_VOLATILE],
1914 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1915 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1916 volatile int x;
1917 int * volatile y = (int *) 0;
1918 return !x && !y;])],
1919                    [ac_cv_c_volatile=yes],
1920                    [ac_cv_c_volatile=no])])
1921 if test $ac_cv_c_volatile = no; then
1922   AC_DEFINE(volatile,,
1923             [Define to empty if the keyword `volatile' does not work.
1924              Warning: valid code using `volatile' can become incorrect
1925              without.  Disable with care.])
1927 ])# AC_C_VOLATILE
1930 # AC_C_STRINGIZE
1931 # --------------
1932 # Checks if `#' can be used to glue strings together at the CPP level.
1933 # Defines HAVE_STRINGIZE if positive.
1934 AC_DEFUN([AC_C_STRINGIZE],
1935 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1936                 [ac_cv_c_stringize],
1937 [AC_EGREP_CPP([@%:@teststring],
1938               [@%:@define x(y) #y
1940 char *s = x(teststring);],
1941               [ac_cv_c_stringize=no],
1942               [ac_cv_c_stringize=yes])])
1943 if test $ac_cv_c_stringize = yes; then
1944   AC_DEFINE(HAVE_STRINGIZE, 1,
1945             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1947 ])# AC_C_STRINGIZE
1950 # AC_C_PROTOTYPES
1951 # ---------------
1952 # Check if the C compiler supports prototypes, included if it needs
1953 # options.
1954 AC_DEFUN([AC_C_PROTOTYPES],
1955 [AC_REQUIRE([AC_PROG_CC])dnl
1956 if test "$ac_prog_cc_stdc" != no; then
1957   AC_DEFINE(PROTOTYPES, 1,
1958             [Define to 1 if the C compiler supports function prototypes.])
1959   AC_DEFINE(__PROTOTYPES, 1,
1960             [Define like PROTOTYPES; this can be used by system headers.])
1962 ])# AC_C_PROTOTYPES
1965 # AC_C_FLEXIBLE_ARRAY_MEMBER
1966 # --------------------------
1967 # Check whether the C compiler supports flexible array members.
1968 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1970   AC_CACHE_CHECK([for flexible array members],
1971     ac_cv_c_flexmember,
1972     [AC_COMPILE_IFELSE(
1973        [AC_LANG_PROGRAM(
1974           [[#include <stdlib.h>
1975             #include <stdio.h>
1976             #include <stddef.h>
1977             struct s { int n; double d[]; };]],
1978           [[int m = getchar ();
1979             struct s *p = malloc (offsetof (struct s, d)
1980                                   + m * sizeof (double));
1981             p->d[0] = 0.0;
1982             return p->d != (double *) NULL;]])],
1983        [ac_cv_c_flexmember=yes],
1984        [ac_cv_c_flexmember=no])])
1985   if test $ac_cv_c_flexmember = yes; then
1986     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1987       [Define to nothing if C supports flexible array members, and to
1988        1 if it does not.  That way, with a declaration like `struct s
1989        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1990        can be used with pre-C99 compilers.
1991        When computing the size of such an object, don't use 'sizeof (struct s)'
1992        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
1993        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1994        MSVC and with C++ compilers.])
1995   else
1996     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1997   fi
2001 # AC_C_VARARRAYS
2002 # --------------
2003 # Check whether the C compiler supports variable-length arrays.
2004 AC_DEFUN([AC_C_VARARRAYS],
2006   AC_CACHE_CHECK([for variable-length arrays],
2007     ac_cv_c_vararrays,
2008     [AC_EGREP_CPP([defined],
2009        [#ifdef __STDC_NO_VLA__
2010         defined
2011         #endif
2012        ],
2013        [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
2014        [AC_COMPILE_IFELSE(
2015           [AC_LANG_PROGRAM(
2016              [[/* Test for VLA support.  This test is partly inspired
2017                   from examples in the C standard.  Use at least two VLA
2018                   functions to detect the GCC 3.4.3 bug described in:
2019                   https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
2020                   */
2021                #ifdef __STDC_NO_VLA__
2022                 syntax error;
2023                #else
2024                  extern int n;
2025                  int B[100];
2026                  int fvla (int m, int C[m][m]);
2028                  int
2029                  simple (int count, int all[static count])
2030                  {
2031                    return all[count - 1];
2032                  }
2034                  int
2035                  fvla (int m, int C[m][m])
2036                  {
2037                    typedef int VLA[m][m];
2038                    VLA x;
2039                    int D[m];
2040                    static int (*q)[m] = &B;
2041                    int (*s)[n] = q;
2042                    return C && &x[0][0] == &D[0] && &D[0] == s[0];
2043                  }
2044                #endif
2045                ]])],
2046           [ac_cv_c_vararrays=yes],
2047           [ac_cv_c_vararrays=no])])])
2048   if test "$ac_cv_c_vararrays" = yes; then
2049     dnl This is for compatibility with Autoconf 2.61-2.69.
2050     AC_DEFINE([HAVE_C_VARARRAYS], 1,
2051       [Define to 1 if C supports variable-length arrays.])
2052   elif test "$ac_cv_c_vararrays" = no; then
2053     AC_DEFINE([__STDC_NO_VLA__], 1,
2054       [Define to 1 if C does not support variable-length arrays, and
2055        if the compiler does not already define this.])
2056   fi
2060 # AC_C_TYPEOF
2061 # -----------
2062 # Check if the C compiler supports GCC's typeof syntax.
2063 # The test case provokes incompatibilities in the Sun C compilers
2064 # (both Solaris 8 and Solaris 10).
2065 AC_DEFUN([AC_C_TYPEOF],
2067   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
2068     [ac_cv_c_typeof=no
2069      for ac_kw in typeof __typeof__ no; do
2070        test $ac_kw = no && break
2071        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
2072          [[
2073            int value;
2074            typedef struct {
2075                    char a [1
2076                            + ! (($ac_kw (value))
2077                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
2078                                  ? ($ac_kw (value)) - 1
2079                                  : ~ (~ ($ac_kw (value)) 0
2080                                       << sizeof ($ac_kw (value)))))]; }
2081               ac__typeof_type_;
2082            return
2083              (! ((void) ((ac__typeof_type_ *) 0), 0));
2084          ]])],
2085          [ac_cv_c_typeof=$ac_kw])
2086        test $ac_cv_c_typeof != no && break
2087      done])
2088   if test $ac_cv_c_typeof != no; then
2089     AC_DEFINE([HAVE_TYPEOF], 1,
2090       [Define to 1 if typeof works with your compiler.])
2091     if test $ac_cv_c_typeof != typeof; then
2092       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
2093         [Define to __typeof__ if your compiler spells it that way.])
2094     fi
2095   fi
2099 # _AC_LANG_OPENMP
2100 # ---------------
2101 # Expands to some language dependent source code for testing the presence of
2102 # OpenMP.
2103 AC_DEFUN([_AC_LANG_OPENMP],
2104 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
2106 # _AC_LANG_OPENMP(C)
2107 # ------------------
2108 m4_define([_AC_LANG_OPENMP(C)],
2110 #ifndef _OPENMP
2111  choke me
2112 #endif
2113 #include <omp.h>
2114 int main (void) { return omp_get_num_threads (); }
2117 # _AC_LANG_OPENMP(C++)
2118 # --------------------
2119 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
2121 # _AC_LANG_OPENMP(Fortran 77)
2122 # ---------------------------
2123 m4_define([_AC_LANG_OPENMP(Fortran 77)],
2125       program main
2126       implicit none
2127 !$    integer tid
2128       tid = 42
2129       call omp_set_num_threads(2)
2130       end
2133 # _AC_LANG_OPENMP(Fortran)
2134 # ------------------------
2135 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
2137 # AC_OPENMP
2138 # ---------
2139 # Check which options need to be passed to the C compiler to support OpenMP.
2140 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
2141 # options.
2142 # The options are necessary at compile time (so the #pragmas are understood)
2143 # and at link time (so the appropriate library is linked with).
2144 # This macro takes care to not produce redundant options if $CC $CFLAGS already
2145 # supports OpenMP. It also is careful to not pass options to compilers that
2146 # misinterpret them; for example, most compilers accept "-openmp" and create
2147 # an output file called 'penmp' rather than activating OpenMP support.
2148 AC_DEFUN([AC_OPENMP],
2150   OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
2151   AC_ARG_ENABLE([openmp],
2152     [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
2153   if test "$enable_openmp" != no; then
2154     AC_CACHE_CHECK([for $[]_AC_CC[] option to support OpenMP],
2155       [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
2156       [AC_LINK_IFELSE([_AC_LANG_OPENMP],
2157          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
2158          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
2159           dnl Try these flags:
2160           dnl   GCC >= 4.2           -fopenmp
2161           dnl   SunPRO C             -xopenmp
2162           dnl   Intel C              -openmp
2163           dnl   SGI C, PGI C         -mp
2164           dnl   Tru64 Compaq C       -omp
2165           dnl   IBM XL C (AIX, Linux) -qsmp=omp
2166           dnl   Cray CCE             -homp
2167           dnl   NEC SX               -Popenmp
2168           dnl   Lahey Fortran (Linux)  --openmp
2169           dnl If in this loop a compiler is passed an option that it doesn't
2170           dnl understand or that it misinterprets, the AC_LINK_IFELSE test
2171           dnl will fail (since we know that it failed without the option),
2172           dnl therefore the loop will continue searching for an option, and
2173           dnl no output file called 'penmp' or 'mp' is created.
2174           for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
2175                            -Popenmp --openmp; do
2176             ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
2177             _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
2178             AC_LINK_IFELSE([_AC_LANG_OPENMP],
2179               [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
2180             _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
2181             if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
2182               break
2183             fi
2184           done])])
2185     case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
2186       "none needed" | unsupported)
2187         ;; #(
2188       *)
2189         OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
2190     esac
2191   fi
2192   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
2195 # _AC_CXX_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
2196 #                 ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
2197 # ----------------------------------------------------------------
2198 # Check whether the C++ compiler accepts features of STANDARD (e.g
2199 # `cxx98', `cxx11') by trying to compile a program of TEST-PROLOGUE
2200 # and TEST-BODY.  If this fails, try again with each compiler option
2201 # in the space-separated OPTION-LIST; if one helps, append it to CXX.
2202 # If eventually successful, run ACTION-IF-AVAILABLE, else
2203 # ACTION-IF-UNAVAILABLE.
2204 AC_DEFUN([_AC_CXX_STD_TRY],
2205 [AC_MSG_CHECKING([for $CXX option to enable ]m4_translit(m4_translit($1, [x], [+]), [a-z], [A-Z])[ features])
2206 AC_LANG_PUSH(C++)dnl
2207 AC_CACHE_VAL(ac_cv_prog_cxx_$1,
2208 [ac_cv_prog_cxx_$1=no
2209 ac_save_CXX=$CXX
2210 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
2211 for ac_arg in '' $4
2213   CXX="$ac_save_CXX $ac_arg"
2214   _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_$1=$ac_arg])
2215   test "x$ac_cv_prog_cxx_$1" != "xno" && break
2216 done
2217 rm -f conftest.$ac_ext
2218 CXX=$ac_save_CXX
2219 ])# AC_CACHE_VAL
2220 ac_prog_cxx_stdcxx_options=
2221 case "x$ac_cv_prog_cxx_$1" in
2222   x)
2223     AC_MSG_RESULT([none needed]) ;;
2224   xno)
2225     AC_MSG_RESULT([unsupported]) ;;
2226   *)
2227     ac_prog_cxx_stdcxx_options=" $ac_cv_prog_cxx_$1"
2228     CXX=$CXX$ac_prog_cxx_stdcxx_options
2229     AC_MSG_RESULT([$ac_cv_prog_cxx_$1]) ;;
2230 esac
2231 AC_LANG_POP(C++)dnl
2232 AS_IF([test "x$ac_cv_prog_cxx_$1" != xno], [$5], [$6])
2233 ])# _AC_CXX_STD_TRY
2235 # _AC_CXX_CXX98_TEST_HEADER
2236 # -------------------------
2237 # A C++ header suitable for testing for CXX98.
2238 AC_DEFUN([_AC_CXX_CXX98_TEST_HEADER],
2240 #include <algorithm>
2241 #include <cstdlib>
2242 #include <fstream>
2243 #include <iomanip>
2244 #include <iostream>
2245 #include <list>
2246 #include <map>
2247 #include <set>
2248 #include <sstream>
2249 #include <stdexcept>
2250 #include <string>
2251 #include <utility>
2252 #include <vector>
2254 namespace test {
2255   typedef std::vector<std::string> string_vec;
2256   typedef std::pair<int,bool> map_value;
2257   typedef std::map<std::string,map_value> map_type;
2258   typedef std::set<int> set_type;
2260   template<typename T>
2261   class printer {
2262   public:
2263     printer(std::ostringstream& os): os(os) {}
2264     void operator() (T elem) { os << elem << std::endl; }
2265   private:
2266     std::ostringstream& os;
2267   };
2269 ]])# _AC_CXX_CXX98_TEST_HEADER
2271 # _AC_CXX_CXX98_TEST_BODY
2272 # -----------------------
2273 # A C++ body suitable for testing for CXX98, assuming the corresponding header.
2274 AC_DEFUN([_AC_CXX_CXX98_TEST_BODY],
2277 try {
2278   // Basic string.
2279   std::string teststr("ASCII text");
2280   teststr += " string";
2282   // Simple vector.
2283   test::string_vec testvec;
2284   testvec.push_back(teststr);
2285   testvec.push_back("foo");
2286   testvec.push_back("bar");
2287   if (testvec.size() != 3) {
2288     throw std::runtime_error("vector size is not 1");
2289   }
2291   // Dump vector into stringstream and obtain string.
2292   std::ostringstream os;
2293   for (test::string_vec::const_iterator i = testvec.begin();
2294        i != testvec.end(); ++i) {
2295     if (i + 1 != testvec.end()) {
2296       os << teststr << '\n';
2297     }
2298   }
2299   // Check algorithms work.
2300   std::for_each(testvec.begin(), testvec.end(), test::printer<std::string>(os));
2301   std::string os_out = os.str();
2303   // Test pair and map.
2304   test::map_type testmap;
2305   testmap.insert(std::make_pair(std::string("key"),
2306                                 std::make_pair(53,false)));
2308   // Test set.
2309   int values[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
2310   test::set_type testset(values, values + sizeof(values)/sizeof(values[0]));
2311   std::list<int> testlist(testset.begin(), testset.end());
2312   std::copy(testset.begin(), testset.end(), std::back_inserter(testlist));
2313 } catch (const std::exception& e) {
2314   std::cerr << "Caught exception: " << e.what() << std::endl;
2316   // Test fstream
2317   std::ofstream of("test.txt");
2318   of << "Test ASCII text\n" << std::flush;
2319   of << "N= " << std::hex << std::setw(8) << std::left << 534 << std::endl;
2320   of.close();
2322 std::exit(0);
2325 # _AC_CXX_CXX11_TEST_HEADER
2326 # -------------------------
2327 # A C++ header suitable for testing for CXX11.
2328 AC_DEFUN([_AC_CXX_CXX11_TEST_HEADER],
2330 #include <deque>
2331 #include <functional>
2332 #include <memory>
2333 #include <tuple>
2334 #include <array>
2335 #include <regex>
2336 #include <iostream>
2338 namespace cxx11test
2340   typedef std::shared_ptr<std::string> sptr;
2341   typedef std::weak_ptr<std::string> wptr;
2343   typedef std::tuple<std::string,int,double> tp;
2344   typedef std::array<int, 20> int_array;
2346   constexpr int get_val() { return 20; }
2348   struct testinit
2349   {
2350     int i;
2351     double d;
2352   };
2354   class delegate  {
2355   public:
2356     delegate(int n) : n(n) {}
2357     delegate(): delegate(2354) {}
2359     virtual int getval() { return this->n; };
2360   protected:
2361     int n;
2362   };
2364   class overridden : public delegate {
2365   public:
2366     overridden(int n): delegate(n) {}
2367     virtual int getval() override final { return this->n * 2; }
2368   };
2370   class nocopy {
2371   public:
2372     nocopy(int i): i(i) {}
2373     nocopy() = default;
2374     nocopy(const nocopy&) = delete;
2375     nocopy & operator=(const nocopy&) = delete;
2376   private:
2377     int i;
2378   };
2380 ]])# _AC_CXX_CXX11_TEST_HEADER
2382 # _AC_CXX_CXX11_TEST_BODY
2383 # -----------------------
2384 # A C++ body suitable for testing for CXX11, assuming the corresponding header.
2385 AC_DEFUN([_AC_CXX_CXX11_TEST_BODY],
2388   // Test auto and decltype
2389   std::deque<int> d;
2390   d.push_front(43);
2391   d.push_front(484);
2392   d.push_front(3);
2393   d.push_front(844);
2394   int total = 0;
2395   for (auto i = d.begin(); i != d.end(); ++i) { total += *i; }
2397   auto a1 = 6538;
2398   auto a2 = 48573953.4;
2399   auto a3 = "String literal";
2401   decltype(a2) a4 = 34895.034;
2404   // Test constexpr
2405   short sa[cxx11test::get_val()] = { 0 };
2408   // Test initializer lists
2409   cxx11test::testinit il = { 4323, 435234.23544 };
2412   // Test range-based for and lambda
2413   cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
2414   for (int &x : array) { x += 23; }
2415   std::for_each(array.begin(), array.end(), [](int v1){ std::cout << v1; });
2418   using cxx11test::sptr;
2419   using cxx11test::wptr;
2421   sptr sp(new std::string("ASCII string"));
2422   wptr wp(sp);
2423   sptr sp2(wp);
2426   cxx11test::tp tuple("test", 54, 45.53434);
2427   double d = std::get<2>(tuple);
2428   std::string s;
2429   int i;
2430   std::tie(s,i,d) = tuple;
2433   static std::regex filename_regex("^_?([a-z0-9_.]+-)+[a-z0-9]+$");
2434   std::string testmatch("Test if this string matches");
2435   bool match = std::regex_search(testmatch, filename_regex);
2438   cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
2439   cxx11test::int_array::size_type size = array.size();
2442   // Test constructor delegation
2443   cxx11test::delegate d1;
2444   cxx11test::delegate d2();
2445   cxx11test::delegate d3(45);
2448   // Test override and final
2449   cxx11test::overridden o1(55464);
2452   // Test nullptr
2453   char *c = nullptr;
2456   // Test template brackets
2457   std::vector<std::pair<int,char*>> v1;
2460   // Unicode literals
2461   char const *utf8 = u8"UTF-8 string \u2500";
2462   char16_t const *utf16 = u"UTF-8 string \u2500";
2463   char32_t const *utf32 = U"UTF-32 string \u2500";
2467 # _AC_PROG_CXX_CXX98 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
2468 # -------------------------------------------------------------------
2470 # If the C++ compiler is not in ISO C++98 mode by default, try to add
2471 # an option to output variable CXX to make it so.  This macro tries
2472 # various options that select ISO C++98 on some system or another.  It
2473 # considers the compiler to be in ISO C++98 mode if it handles basic
2474 # features of the std namespace including: string, containers (list,
2475 # map, set, vector), streams (fstreams, iostreams, stringstreams,
2476 # iomanip), pair, exceptions and algorithms.
2479 AC_DEFUN([_AC_PROG_CXX_CXX98],
2480 [_AC_CXX_STD_TRY([cxx98],
2481 [_AC_CXX_CXX98_TEST_HEADER],
2482 [_AC_CXX_CXX98_TEST_BODY],
2483 dnl Try
2484 dnl GCC         -std=gnu++98 (unused restrictive mode: -std=c++98)
2485 dnl IBM XL C    -qlanglvl=extended
2486 dnl HP aC++     -AA
2487 dnl Intel ICC   -std=gnu++98
2488 dnl Solaris     N/A (default)
2489 dnl Tru64       N/A (default, but -std gnu could be used)
2490 dnl with extended modes being tried first.
2491 [[-std=gnu++98 -std=c++98 -qlanglvl=extended -AA]], [$1], [$2])[]dnl
2492 ])# _AC_PROG_CXX_CXX98
2494 # _AC_PROG_CXX_CXX11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
2495 # -------------------------------------------------------------------
2496 # If the C++ compiler is not in ISO CXX11 mode by default, try to add
2497 # an option to output variable CXX to make it so.  This macro tries
2498 # various options that select ISO C++11 on some system or another.  It
2499 # considers the compiler to be in ISO C++11 mode if it handles all the
2500 # tests from the C++98 checks, plus the following: Language features
2501 # (auto, constexpr, decltype, default/deleted constructors, delegate
2502 # constructors, final, initializer lists, lambda functions, nullptr,
2503 # override, range-based for loops, template brackets without spaces,
2504 # unicode literals) and library features (array, memory (shared_ptr,
2505 # weak_ptr), regex and tuple types).
2506 AC_DEFUN([_AC_PROG_CXX_CXX11],
2507 [_AC_CXX_STD_TRY([cxx11],
2508 [_AC_CXX_CXX11_TEST_HEADER
2509 _AC_CXX_CXX98_TEST_HEADER],
2510 [_AC_CXX_CXX11_TEST_BODY
2511 _AC_CXX_CXX98_TEST_BODY],
2512 dnl Try
2513 dnl GCC         -std=gnu++11 (unused restrictive mode: -std=c++11) [and 0x variants]
2514 dnl IBM XL C    -qlanglvl=extended0x
2515 dnl             (pre-V12.1; unused restrictive mode: -qlanglvl=stdcxx11)
2516 dnl HP aC++     -AA
2517 dnl Intel ICC   -std=c++11 -std=c++0x
2518 dnl Solaris     N/A (no support)
2519 dnl Tru64       N/A (no support)
2520 dnl with extended modes being tried first.
2521 [[-std=gnu++11 -std=c++11 -std=gnu++0x -std=c++0x -qlanglvl=extended0x -AA]], [$1], [$2])[]dnl
2522 ])# _AC_PROG_CXX_CXX11