Prefer HTTPS to FTP and HTTP
[autoconf.git] / lib / autoconf / c.m4
blobe66b1580e8f897ef9d7339975cee3dabadbe8941
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 at:
1849 # http://autoconf-archive.cryp.to/acx_restrict.html
1851 # Determine whether the C/C++ compiler supports the "restrict" keyword
1852 # introduced in ANSI C99, or an equivalent.  Define "restrict" to the alternate
1853 # spelling, if any; these are more likely to work in both C and C++ compilers of
1854 # the same family, and in the presence of varying compiler options.  If only
1855 # plain "restrict" works, do nothing.  Here are some variants:
1856 # - GCC supports both __restrict and __restrict__
1857 # - older DEC Alpha C compilers support only __restrict
1858 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1859 # Otherwise, define "restrict" to be empty.
1860 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1861 AC_DEFUN([AC_C_RESTRICT],
1862 [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
1863   [ac_cv_c_restrict=no
1864    # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
1865    # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
1866    # Put 'restrict' last, because C++ lacks it.
1867    for ac_kw in __restrict__ __restrict _Restrict restrict; do
1868      AC_COMPILE_IFELSE(
1869       [AC_LANG_PROGRAM(
1870          [[typedef int *int_ptr;
1871            int foo (int_ptr $ac_kw ip) { return ip[0]; }
1872            int bar (int [$ac_kw]); /* Catch GCC bug 14050.  */
1873            int bar (int ip[$ac_kw]) { return ip[0]; }
1874          ]],
1875          [[int s[1];
1876            int *$ac_kw t = s;
1877            t[0] = 0;
1878            return foo (t) + bar (t);
1879          ]])],
1880       [ac_cv_c_restrict=$ac_kw])
1881      test "$ac_cv_c_restrict" != no && break
1882    done
1883   ])
1884  AH_VERBATIM([restrict],
1885 [/* Define to the equivalent of the C99 'restrict' keyword, or to
1886    nothing if this is not supported.  Do not define if restrict is
1887    supported only directly.  */
1888 #undef restrict
1889 /* Work around a bug in Sun C++ 5.13: it does not support _Restrict or
1890    __restrict__, even though the corresponding Sun C compiler ends up with
1891    "#define restrict _Restrict" or "#define restrict __restrict__".
1892    Perhaps some future version of Sun C++ will work with restrict;
1893    if so, hopefully it defines __RESTRICT like Sun C does.  */
1894 #if defined __SUNPRO_CC && !defined __RESTRICT
1895 # define _Restrict
1896 # define __restrict__
1897 #endif])
1898  case $ac_cv_c_restrict in
1899    restrict) ;;
1900    no) AC_DEFINE([restrict], []) ;;
1901    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
1902  esac
1903 ])# AC_C_RESTRICT
1906 # AC_C_VOLATILE
1907 # -------------
1908 # Note that, unlike const, #defining volatile to be the empty string can
1909 # actually turn a correct program into an incorrect one, since removing
1910 # uses of volatile actually grants the compiler permission to perform
1911 # optimizations that could break the user's code.  So, do not #define
1912 # volatile away unless it is really necessary to allow the user's code
1913 # to compile cleanly.  Benign compiler failures should be tolerated.
1914 AC_DEFUN([AC_C_VOLATILE],
1915 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1916 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1917 volatile int x;
1918 int * volatile y = (int *) 0;
1919 return !x && !y;])],
1920                    [ac_cv_c_volatile=yes],
1921                    [ac_cv_c_volatile=no])])
1922 if test $ac_cv_c_volatile = no; then
1923   AC_DEFINE(volatile,,
1924             [Define to empty if the keyword `volatile' does not work.
1925              Warning: valid code using `volatile' can become incorrect
1926              without.  Disable with care.])
1928 ])# AC_C_VOLATILE
1931 # AC_C_STRINGIZE
1932 # --------------
1933 # Checks if `#' can be used to glue strings together at the CPP level.
1934 # Defines HAVE_STRINGIZE if positive.
1935 AC_DEFUN([AC_C_STRINGIZE],
1936 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1937                 [ac_cv_c_stringize],
1938 [AC_EGREP_CPP([@%:@teststring],
1939               [@%:@define x(y) #y
1941 char *s = x(teststring);],
1942               [ac_cv_c_stringize=no],
1943               [ac_cv_c_stringize=yes])])
1944 if test $ac_cv_c_stringize = yes; then
1945   AC_DEFINE(HAVE_STRINGIZE, 1,
1946             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1948 ])# AC_C_STRINGIZE
1951 # AC_C_PROTOTYPES
1952 # ---------------
1953 # Check if the C compiler supports prototypes, included if it needs
1954 # options.
1955 AC_DEFUN([AC_C_PROTOTYPES],
1956 [AC_REQUIRE([AC_PROG_CC])dnl
1957 if test "$ac_prog_cc_stdc" != no; then
1958   AC_DEFINE(PROTOTYPES, 1,
1959             [Define to 1 if the C compiler supports function prototypes.])
1960   AC_DEFINE(__PROTOTYPES, 1,
1961             [Define like PROTOTYPES; this can be used by system headers.])
1963 ])# AC_C_PROTOTYPES
1966 # AC_C_FLEXIBLE_ARRAY_MEMBER
1967 # --------------------------
1968 # Check whether the C compiler supports flexible array members.
1969 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1971   AC_CACHE_CHECK([for flexible array members],
1972     ac_cv_c_flexmember,
1973     [AC_COMPILE_IFELSE(
1974        [AC_LANG_PROGRAM(
1975           [[#include <stdlib.h>
1976             #include <stdio.h>
1977             #include <stddef.h>
1978             struct s { int n; double d[]; };]],
1979           [[int m = getchar ();
1980             struct s *p = malloc (offsetof (struct s, d)
1981                                   + m * sizeof (double));
1982             p->d[0] = 0.0;
1983             return p->d != (double *) NULL;]])],
1984        [ac_cv_c_flexmember=yes],
1985        [ac_cv_c_flexmember=no])])
1986   if test $ac_cv_c_flexmember = yes; then
1987     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1988       [Define to nothing if C supports flexible array members, and to
1989        1 if it does not.  That way, with a declaration like `struct s
1990        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1991        can be used with pre-C99 compilers.
1992        When computing the size of such an object, don't use 'sizeof (struct s)'
1993        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
1994        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1995        MSVC and with C++ compilers.])
1996   else
1997     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1998   fi
2002 # AC_C_VARARRAYS
2003 # --------------
2004 # Check whether the C compiler supports variable-length arrays.
2005 AC_DEFUN([AC_C_VARARRAYS],
2007   AC_CACHE_CHECK([for variable-length arrays],
2008     ac_cv_c_vararrays,
2009     [AC_EGREP_CPP([defined],
2010        [#ifdef __STDC_NO_VLA__
2011         defined
2012         #endif
2013        ],
2014        [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
2015        [AC_COMPILE_IFELSE(
2016           [AC_LANG_PROGRAM(
2017              [[/* Test for VLA support.  This test is partly inspired
2018                   from examples in the C standard.  Use at least two VLA
2019                   functions to detect the GCC 3.4.3 bug described in:
2020                   https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
2021                   */
2022                #ifdef __STDC_NO_VLA__
2023                 syntax error;
2024                #else
2025                  extern int n;
2026                  int B[100];
2027                  int fvla (int m, int C[m][m]);
2029                  int
2030                  simple (int count, int all[static count])
2031                  {
2032                    return all[count - 1];
2033                  }
2035                  int
2036                  fvla (int m, int C[m][m])
2037                  {
2038                    typedef int VLA[m][m];
2039                    VLA x;
2040                    int D[m];
2041                    static int (*q)[m] = &B;
2042                    int (*s)[n] = q;
2043                    return C && &x[0][0] == &D[0] && &D[0] == s[0];
2044                  }
2045                #endif
2046                ]])],
2047           [ac_cv_c_vararrays=yes],
2048           [ac_cv_c_vararrays=no])])])
2049   if test "$ac_cv_c_vararrays" = yes; then
2050     dnl This is for compatibility with Autoconf 2.61-2.69.
2051     AC_DEFINE([HAVE_C_VARARRAYS], 1,
2052       [Define to 1 if C supports variable-length arrays.])
2053   elif test "$ac_cv_c_vararrays" = no; then
2054     AC_DEFINE([__STDC_NO_VLA__], 1,
2055       [Define to 1 if C does not support variable-length arrays, and
2056        if the compiler does not already define this.])
2057   fi
2061 # AC_C_TYPEOF
2062 # -----------
2063 # Check if the C compiler supports GCC's typeof syntax.
2064 # The test case provokes incompatibilities in the Sun C compilers
2065 # (both Solaris 8 and Solaris 10).
2066 AC_DEFUN([AC_C_TYPEOF],
2068   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
2069     [ac_cv_c_typeof=no
2070      for ac_kw in typeof __typeof__ no; do
2071        test $ac_kw = no && break
2072        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
2073          [[
2074            int value;
2075            typedef struct {
2076                    char a [1
2077                            + ! (($ac_kw (value))
2078                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
2079                                  ? ($ac_kw (value)) - 1
2080                                  : ~ (~ ($ac_kw (value)) 0
2081                                       << sizeof ($ac_kw (value)))))]; }
2082               ac__typeof_type_;
2083            return
2084              (! ((void) ((ac__typeof_type_ *) 0), 0));
2085          ]])],
2086          [ac_cv_c_typeof=$ac_kw])
2087        test $ac_cv_c_typeof != no && break
2088      done])
2089   if test $ac_cv_c_typeof != no; then
2090     AC_DEFINE([HAVE_TYPEOF], 1,
2091       [Define to 1 if typeof works with your compiler.])
2092     if test $ac_cv_c_typeof != typeof; then
2093       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
2094         [Define to __typeof__ if your compiler spells it that way.])
2095     fi
2096   fi
2100 # _AC_LANG_OPENMP
2101 # ---------------
2102 # Expands to some language dependent source code for testing the presence of
2103 # OpenMP.
2104 AC_DEFUN([_AC_LANG_OPENMP],
2105 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
2107 # _AC_LANG_OPENMP(C)
2108 # ------------------
2109 m4_define([_AC_LANG_OPENMP(C)],
2111 #ifndef _OPENMP
2112  choke me
2113 #endif
2114 #include <omp.h>
2115 int main (void) { return omp_get_num_threads (); }
2118 # _AC_LANG_OPENMP(C++)
2119 # --------------------
2120 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
2122 # _AC_LANG_OPENMP(Fortran 77)
2123 # ---------------------------
2124 m4_define([_AC_LANG_OPENMP(Fortran 77)],
2126       program main
2127       implicit none
2128 !$    integer tid
2129       tid = 42
2130       call omp_set_num_threads(2)
2131       end
2134 # _AC_LANG_OPENMP(Fortran)
2135 # ------------------------
2136 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
2138 # AC_OPENMP
2139 # ---------
2140 # Check which options need to be passed to the C compiler to support OpenMP.
2141 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
2142 # options.
2143 # The options are necessary at compile time (so the #pragmas are understood)
2144 # and at link time (so the appropriate library is linked with).
2145 # This macro takes care to not produce redundant options if $CC $CFLAGS already
2146 # supports OpenMP. It also is careful to not pass options to compilers that
2147 # misinterpret them; for example, most compilers accept "-openmp" and create
2148 # an output file called 'penmp' rather than activating OpenMP support.
2149 AC_DEFUN([AC_OPENMP],
2151   OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
2152   AC_ARG_ENABLE([openmp],
2153     [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
2154   if test "$enable_openmp" != no; then
2155     AC_CACHE_CHECK([for $[]_AC_CC[] option to support OpenMP],
2156       [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
2157       [AC_LINK_IFELSE([_AC_LANG_OPENMP],
2158          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
2159          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
2160           dnl Try these flags:
2161           dnl   GCC >= 4.2           -fopenmp
2162           dnl   SunPRO C             -xopenmp
2163           dnl   Intel C              -openmp
2164           dnl   SGI C, PGI C         -mp
2165           dnl   Tru64 Compaq C       -omp
2166           dnl   IBM XL C (AIX, Linux) -qsmp=omp
2167           dnl   Cray CCE             -homp
2168           dnl   NEC SX               -Popenmp
2169           dnl   Lahey Fortran (Linux)  --openmp
2170           dnl If in this loop a compiler is passed an option that it doesn't
2171           dnl understand or that it misinterprets, the AC_LINK_IFELSE test
2172           dnl will fail (since we know that it failed without the option),
2173           dnl therefore the loop will continue searching for an option, and
2174           dnl no output file called 'penmp' or 'mp' is created.
2175           for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
2176                            -Popenmp --openmp; do
2177             ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
2178             _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
2179             AC_LINK_IFELSE([_AC_LANG_OPENMP],
2180               [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
2181             _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
2182             if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
2183               break
2184             fi
2185           done])])
2186     case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
2187       "none needed" | unsupported)
2188         ;; #(
2189       *)
2190         OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
2191     esac
2192   fi
2193   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
2196 # _AC_CXX_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
2197 #                 ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
2198 # ----------------------------------------------------------------
2199 # Check whether the C++ compiler accepts features of STANDARD (e.g
2200 # `cxx98', `cxx11') by trying to compile a program of TEST-PROLOGUE
2201 # and TEST-BODY.  If this fails, try again with each compiler option
2202 # in the space-separated OPTION-LIST; if one helps, append it to CXX.
2203 # If eventually successful, run ACTION-IF-AVAILABLE, else
2204 # ACTION-IF-UNAVAILABLE.
2205 AC_DEFUN([_AC_CXX_STD_TRY],
2206 [AC_MSG_CHECKING([for $CXX option to enable ]m4_translit(m4_translit($1, [x], [+]), [a-z], [A-Z])[ features])
2207 AC_LANG_PUSH(C++)dnl
2208 AC_CACHE_VAL(ac_cv_prog_cxx_$1,
2209 [ac_cv_prog_cxx_$1=no
2210 ac_save_CXX=$CXX
2211 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
2212 for ac_arg in '' $4
2214   CXX="$ac_save_CXX $ac_arg"
2215   _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_$1=$ac_arg])
2216   test "x$ac_cv_prog_cxx_$1" != "xno" && break
2217 done
2218 rm -f conftest.$ac_ext
2219 CXX=$ac_save_CXX
2220 ])# AC_CACHE_VAL
2221 ac_prog_cxx_stdcxx_options=
2222 case "x$ac_cv_prog_cxx_$1" in
2223   x)
2224     AC_MSG_RESULT([none needed]) ;;
2225   xno)
2226     AC_MSG_RESULT([unsupported]) ;;
2227   *)
2228     ac_prog_cxx_stdcxx_options=" $ac_cv_prog_cxx_$1"
2229     CXX=$CXX$ac_prog_cxx_stdcxx_options
2230     AC_MSG_RESULT([$ac_cv_prog_cxx_$1]) ;;
2231 esac
2232 AC_LANG_POP(C++)dnl
2233 AS_IF([test "x$ac_cv_prog_cxx_$1" != xno], [$5], [$6])
2234 ])# _AC_CXX_STD_TRY
2236 # _AC_CXX_CXX98_TEST_HEADER
2237 # -------------------------
2238 # A C++ header suitable for testing for CXX98.
2239 AC_DEFUN([_AC_CXX_CXX98_TEST_HEADER],
2241 #include <algorithm>
2242 #include <cstdlib>
2243 #include <fstream>
2244 #include <iomanip>
2245 #include <iostream>
2246 #include <list>
2247 #include <map>
2248 #include <set>
2249 #include <sstream>
2250 #include <stdexcept>
2251 #include <string>
2252 #include <utility>
2253 #include <vector>
2255 namespace test {
2256   typedef std::vector<std::string> string_vec;
2257   typedef std::pair<int,bool> map_value;
2258   typedef std::map<std::string,map_value> map_type;
2259   typedef std::set<int> set_type;
2261   template<typename T>
2262   class printer {
2263   public:
2264     printer(std::ostringstream& os): os(os) {}
2265     void operator() (T elem) { os << elem << std::endl; }
2266   private:
2267     std::ostringstream& os;
2268   };
2270 ]])# _AC_CXX_CXX98_TEST_HEADER
2272 # _AC_CXX_CXX98_TEST_BODY
2273 # -----------------------
2274 # A C++ body suitable for testing for CXX98, assuming the corresponding header.
2275 AC_DEFUN([_AC_CXX_CXX98_TEST_BODY],
2278 try {
2279   // Basic string.
2280   std::string teststr("ASCII text");
2281   teststr += " string";
2283   // Simple vector.
2284   test::string_vec testvec;
2285   testvec.push_back(teststr);
2286   testvec.push_back("foo");
2287   testvec.push_back("bar");
2288   if (testvec.size() != 3) {
2289     throw std::runtime_error("vector size is not 1");
2290   }
2292   // Dump vector into stringstream and obtain string.
2293   std::ostringstream os;
2294   for (test::string_vec::const_iterator i = testvec.begin();
2295        i != testvec.end(); ++i) {
2296     if (i + 1 != testvec.end()) {
2297       os << teststr << '\n';
2298     }
2299   }
2300   // Check algorithms work.
2301   std::for_each(testvec.begin(), testvec.end(), test::printer<std::string>(os));
2302   std::string os_out = os.str();
2304   // Test pair and map.
2305   test::map_type testmap;
2306   testmap.insert(std::make_pair(std::string("key"),
2307                                 std::make_pair(53,false)));
2309   // Test set.
2310   int values[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
2311   test::set_type testset(values, values + sizeof(values)/sizeof(values[0]));
2312   std::list<int> testlist(testset.begin(), testset.end());
2313   std::copy(testset.begin(), testset.end(), std::back_inserter(testlist));
2314 } catch (const std::exception& e) {
2315   std::cerr << "Caught exception: " << e.what() << std::endl;
2317   // Test fstream
2318   std::ofstream of("test.txt");
2319   of << "Test ASCII text\n" << std::flush;
2320   of << "N= " << std::hex << std::setw(8) << std::left << 534 << std::endl;
2321   of.close();
2323 std::exit(0);
2326 # _AC_CXX_CXX11_TEST_HEADER
2327 # -------------------------
2328 # A C++ header suitable for testing for CXX11.
2329 AC_DEFUN([_AC_CXX_CXX11_TEST_HEADER],
2331 #include <deque>
2332 #include <functional>
2333 #include <memory>
2334 #include <tuple>
2335 #include <array>
2336 #include <regex>
2337 #include <iostream>
2339 namespace cxx11test
2341   typedef std::shared_ptr<std::string> sptr;
2342   typedef std::weak_ptr<std::string> wptr;
2344   typedef std::tuple<std::string,int,double> tp;
2345   typedef std::array<int, 20> int_array;
2347   constexpr int get_val() { return 20; }
2349   struct testinit
2350   {
2351     int i;
2352     double d;
2353   };
2355   class delegate  {
2356   public:
2357     delegate(int n) : n(n) {}
2358     delegate(): delegate(2354) {}
2360     virtual int getval() { return this->n; };
2361   protected:
2362     int n;
2363   };
2365   class overridden : public delegate {
2366   public:
2367     overridden(int n): delegate(n) {}
2368     virtual int getval() override final { return this->n * 2; }
2369   };
2371   class nocopy {
2372   public:
2373     nocopy(int i): i(i) {}
2374     nocopy() = default;
2375     nocopy(const nocopy&) = delete;
2376     nocopy & operator=(const nocopy&) = delete;
2377   private:
2378     int i;
2379   };
2381 ]])# _AC_CXX_CXX11_TEST_HEADER
2383 # _AC_CXX_CXX11_TEST_BODY
2384 # -----------------------
2385 # A C++ body suitable for testing for CXX11, assuming the corresponding header.
2386 AC_DEFUN([_AC_CXX_CXX11_TEST_BODY],
2389   // Test auto and decltype
2390   std::deque<int> d;
2391   d.push_front(43);
2392   d.push_front(484);
2393   d.push_front(3);
2394   d.push_front(844);
2395   int total = 0;
2396   for (auto i = d.begin(); i != d.end(); ++i) { total += *i; }
2398   auto a1 = 6538;
2399   auto a2 = 48573953.4;
2400   auto a3 = "String literal";
2402   decltype(a2) a4 = 34895.034;
2405   // Test constexpr
2406   short sa[cxx11test::get_val()] = { 0 };
2409   // Test initializer lists
2410   cxx11test::testinit il = { 4323, 435234.23544 };
2413   // Test range-based for and lambda
2414   cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
2415   for (int &x : array) { x += 23; }
2416   std::for_each(array.begin(), array.end(), [](int v1){ std::cout << v1; });
2419   using cxx11test::sptr;
2420   using cxx11test::wptr;
2422   sptr sp(new std::string("ASCII string"));
2423   wptr wp(sp);
2424   sptr sp2(wp);
2427   cxx11test::tp tuple("test", 54, 45.53434);
2428   double d = std::get<2>(tuple);
2429   std::string s;
2430   int i;
2431   std::tie(s,i,d) = tuple;
2434   static std::regex filename_regex("^_?([a-z0-9_.]+-)+[a-z0-9]+$");
2435   std::string testmatch("Test if this string matches");
2436   bool match = std::regex_search(testmatch, filename_regex);
2439   cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
2440   cxx11test::int_array::size_type size = array.size();
2443   // Test constructor delegation
2444   cxx11test::delegate d1;
2445   cxx11test::delegate d2();
2446   cxx11test::delegate d3(45);
2449   // Test override and final
2450   cxx11test::overridden o1(55464);
2453   // Test nullptr
2454   char *c = nullptr;
2457   // Test template brackets
2458   std::vector<std::pair<int,char*>> v1;
2461   // Unicode literals
2462   char const *utf8 = u8"UTF-8 string \u2500";
2463   char16_t const *utf16 = u"UTF-8 string \u2500";
2464   char32_t const *utf32 = U"UTF-32 string \u2500";
2468 # _AC_PROG_CXX_CXX98 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
2469 # -------------------------------------------------------------------
2471 # If the C++ compiler is not in ISO C++98 mode by default, try to add
2472 # an option to output variable CXX to make it so.  This macro tries
2473 # various options that select ISO C++98 on some system or another.  It
2474 # considers the compiler to be in ISO C++98 mode if it handles basic
2475 # features of the std namespace including: string, containers (list,
2476 # map, set, vector), streams (fstreams, iostreams, stringstreams,
2477 # iomanip), pair, exceptions and algorithms.
2480 AC_DEFUN([_AC_PROG_CXX_CXX98],
2481 [_AC_CXX_STD_TRY([cxx98],
2482 [_AC_CXX_CXX98_TEST_HEADER],
2483 [_AC_CXX_CXX98_TEST_BODY],
2484 dnl Try
2485 dnl GCC         -std=gnu++98 (unused restrictive mode: -std=c++98)
2486 dnl IBM XL C    -qlanglvl=extended
2487 dnl HP aC++     -AA
2488 dnl Intel ICC   -std=gnu++98
2489 dnl Solaris     N/A (default)
2490 dnl Tru64       N/A (default, but -std gnu could be used)
2491 dnl with extended modes being tried first.
2492 [[-std=gnu++98 -std=c++98 -qlanglvl=extended -AA]], [$1], [$2])[]dnl
2493 ])# _AC_PROG_CXX_CXX98
2495 # _AC_PROG_CXX_CXX11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
2496 # -------------------------------------------------------------------
2497 # If the C++ compiler is not in ISO CXX11 mode by default, try to add
2498 # an option to output variable CXX to make it so.  This macro tries
2499 # various options that select ISO C++11 on some system or another.  It
2500 # considers the compiler to be in ISO C++11 mode if it handles all the
2501 # tests from the C++98 checks, plus the following: Language features
2502 # (auto, constexpr, decltype, default/deleted constructors, delegate
2503 # constructors, final, initializer lists, lambda functions, nullptr,
2504 # override, range-based for loops, template brackets without spaces,
2505 # unicode literals) and library features (array, memory (shared_ptr,
2506 # weak_ptr), regex and tuple types).
2507 AC_DEFUN([_AC_PROG_CXX_CXX11],
2508 [_AC_CXX_STD_TRY([cxx11],
2509 [_AC_CXX_CXX11_TEST_HEADER
2510 _AC_CXX_CXX98_TEST_HEADER],
2511 [_AC_CXX_CXX11_TEST_BODY
2512 _AC_CXX_CXX98_TEST_BODY],
2513 dnl Try
2514 dnl GCC         -std=gnu++11 (unused restrictive mode: -std=c++11) [and 0x variants]
2515 dnl IBM XL C    -qlanglvl=extended0x
2516 dnl             (pre-V12.1; unused restrictive mode: -qlanglvl=stdcxx11)
2517 dnl HP aC++     -AA
2518 dnl Intel ICC   -std=c++11 -std=c++0x
2519 dnl Solaris     N/A (no support)
2520 dnl Tru64       N/A (no support)
2521 dnl with extended modes being tried first.
2522 [[-std=gnu++11 -std=c++11 -std=gnu++0x -std=c++0x -qlanglvl=extended0x -AA]], [$1], [$2])[]dnl
2523 ])# _AC_PROG_CXX_CXX11