Reword the copyright notices to match what's suggested in GPLv3.
[autoconf/tsuna.git] / lib / autoconf / c.m4
bloba31b77271241e9f856695d1ea46e19b3ac62ec98
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
4 # Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the 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 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 # As a special exception, the Free Software Foundation gives unlimited
20 # permission to copy, distribute and modify the configure scripts that
21 # are the output of Autoconf.  You need not follow the terms of the GNU
22 # General Public License when using or distributing such scripts, even
23 # though portions of the text of Autoconf appear in them.  The GNU
24 # General Public License (GPL) does govern all other use of the material
25 # that constitutes the Autoconf program.
27 # Certain portions of the Autoconf source text are designed to be copied
28 # (in certain cases, depending on the input) into the output of
29 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
30 # source text consists of comments plus executable code that decides which
31 # of the data portions to output in any given case.  We call these
32 # comments and executable code the "non-data" portions.  Autoconf never
33 # copies any of the non-data portions into its output.
35 # This special exception to the GPL applies to versions of Autoconf
36 # released by the Free Software Foundation.  When you make and
37 # distribute a modified version of Autoconf, you may extend this special
38 # exception to the GPL to apply to your modified version as well, *unless*
39 # your modified version has the potential to copy into its output some
40 # of the text that was the non-data portion of the version that you started
41 # with.  (In other words, unless your change moves or copies text from
42 # the non-data portions to the data portions.)  If your modification has
43 # such potential, you must delete any notice of this special exception
44 # to the GPL from your modified version.
46 # Written by David MacKenzie, with help from
47 # Akim Demaille, Paul Eggert,
48 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
49 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
52 # Table of Contents:
54 # 1. Language selection
55 #    and routines to produce programs in a given language.
56 #      1a. C   1b. C++   1c. Objective C
58 # 2. Producing programs in a given language.
59 #      2a. C   2b. C++   2c. Objective C
61 # 3. Looking for a compiler
62 #    And possibly the associated preprocessor.
63 #      3a. C   3b. C++   3c. Objective C
65 # 4. Compilers' characteristics.
66 #      4a. C
70 ## ----------------------- ##
71 ## 1. Language selection.  ##
72 ## ----------------------- ##
74 # -------------------- #
75 # 1a. The C language.  #
76 # -------------------- #
79 # AC_LANG(C)
80 # ----------
81 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
82 m4_define([AC_LANG(C)],
83 [ac_ext=c
84 ac_cpp='$CPP $CPPFLAGS'
85 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
86 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
87 ac_compiler_gnu=$ac_cv_c_compiler_gnu
91 # AC_LANG_C
92 # ---------
93 AU_DEFUN([AC_LANG_C], [AC_LANG(C)])
96 # _AC_LANG_ABBREV(C)
97 # ------------------
98 m4_define([_AC_LANG_ABBREV(C)], [c])
101 # _AC_LANG_PREFIX(C)
102 # ------------------
103 m4_define([_AC_LANG_PREFIX(C)], [C])
107 # ---------------------- #
108 # 1b. The C++ language.  #
109 # ---------------------- #
112 # AC_LANG(C++)
113 # ------------
114 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
115 m4_define([AC_LANG(C++)],
116 [ac_ext=cpp
117 ac_cpp='$CXXCPP $CPPFLAGS'
118 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
119 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
120 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
124 # AC_LANG_CPLUSPLUS
125 # -----------------
126 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
129 # _AC_LANG_ABBREV(C++)
130 # --------------------
131 m4_define([_AC_LANG_ABBREV(C++)], [cxx])
134 # _AC_LANG_PREFIX(C++)
135 # --------------------
136 m4_define([_AC_LANG_PREFIX(C++)], [CXX])
140 # ------------------------------ #
141 # 1c. The Objective C language.  #
142 # ------------------------------ #
145 # AC_LANG(Objective C)
146 # --------------------
147 m4_define([AC_LANG(Objective C)],
148 [ac_ext=m
149 ac_cpp='$OBJCPP $CPPFLAGS'
150 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
151 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
152 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
156 # AC_LANG_OBJC
157 # ------------
158 AU_DEFUN([AC_LANG_OBJC], [AC_LANG(Objective C)])
161 # _AC_LANG_ABBREV(Objective C)
162 # ----------------------------
163 m4_define([_AC_LANG_ABBREV(Objective C)], [objc])
166 # _AC_LANG_PREFIX(Objective C)
167 # ----------------------------
168 m4_define([_AC_LANG_PREFIX(Objective C)], [OBJC])
172 ## ----------------------- ##
173 ## 2. Producing programs.  ##
174 ## ----------------------- ##
176 # --------------- #
177 # 2a. C sources.  #
178 # --------------- #
181 # AC_LANG_SOURCE(C)(BODY)
182 # -----------------------
183 # We can't use '#line $LINENO "configure"' here, since
184 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
185 # rejects $LINENO greater than 32767, and some configure scripts
186 # are longer than 32767 lines.
187 m4_define([AC_LANG_SOURCE(C)],
188 [/* confdefs.h.  */
189 _ACEOF
190 cat confdefs.h >>conftest.$ac_ext
191 cat >>conftest.$ac_ext <<_ACEOF
192 /* end confdefs.h.  */
193 $1])
196 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
197 # --------------------------------------
198 m4_define([AC_LANG_PROGRAM(C)],
200 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
201 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
203 main ()
205 dnl Do *not* indent the following line: there may be CPP directives.
206 dnl Don't move the `;' right after for the same reason.
208   ;
209   return 0;
213 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
214 # -----------------------------------
215 # Avoid conflicting decl of main.
216 m4_define([AC_LANG_CALL(C)],
217 [AC_LANG_PROGRAM([$1
218 m4_if([$2], [main], ,
219 [/* Override any GCC internal prototype to avoid an error.
220    Use char because int might match the return type of a GCC
221    builtin and then its argument prototype would still apply.  */
222 #ifdef __cplusplus
223 extern "C"
224 #endif
225 char $2 ();])], [return $2 ();])])
228 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
229 # ----------------------------------
230 # Don't include <ctype.h> because on OSF/1 3.0 it includes
231 # <sys/types.h> which includes <sys/select.h> which contains a
232 # prototype for select.  Similarly for bzero.
234 # This test used to merely assign f=$1 in main(), but that was
235 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
236 # presumably on the basis that there's no need to do that store if the
237 # program is about to exit.  Conversely, the AIX linker optimizes an
238 # unused external declaration that initializes f=$1.  So this test
239 # program has both an external initialization of f, and a use of f in
240 # main that affects the exit status.
242 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
243 [AC_LANG_PROGRAM(
244 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
245    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
246 #define $1 innocuous_$1
248 /* System header to define __stub macros and hopefully few prototypes,
249     which can conflict with char $1 (); below.
250     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
251     <limits.h> exists even on freestanding compilers.  */
253 #ifdef __STDC__
254 # include <limits.h>
255 #else
256 # include <assert.h>
257 #endif
259 #undef $1
261 /* Override any GCC internal prototype to avoid an error.
262    Use char because int might match the return type of a GCC
263    builtin and then its argument prototype would still apply.  */
264 #ifdef __cplusplus
265 extern "C"
266 #endif
267 char $1 ();
268 /* The GNU C library defines this for functions which it implements
269     to always fail with ENOSYS.  Some functions are actually named
270     something starting with __ and the normal name is an alias.  */
271 #if defined __stub_$1 || defined __stub___$1
272 choke me
273 #endif
274 ], [return $1 ();])])
277 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
278 # -------------------------------------------------
279 # Return a program that is valid if EXPRESSION is nonzero.
280 # EXPRESSION must be an integer constant expression.
281 # Be sure to use this array to avoid `unused' warnings, which are even
282 # errors with `-W error'.
283 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
284 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
285 test_array @<:@0@:>@ = 0
286 ])])
289 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
290 # -----------------------------------------
291 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
292 # But we include them only after the EXPRESSION has been evaluated.
293 m4_define([AC_LANG_INT_SAVE(C)],
294 [AC_LANG_PROGRAM([$1
295 static long int longval () { return $2; }
296 static unsigned long int ulongval () { return $2; }
297 @%:@include <stdio.h>
298 @%:@include <stdlib.h>],
300   FILE *f = fopen ("conftest.val", "w");
301   if (! f)
302     return 1;
303   if (($2) < 0)
304     {
305       long int i = longval ();
306       if (i != ($2))
307         return 1;
308       fprintf (f, "%ld", i);
309     }
310   else
311     {
312       unsigned long int i = ulongval ();
313       if (i != ($2))
314         return 1;
315       fprintf (f, "%lu", i);
316     }
317   /* Do not output a trailing newline, as this causes \r\n confusion
318      on some platforms.  */
319   return ferror (f) || fclose (f) != 0;
320 ])])
324 # ----------------- #
325 # 2b. C++ sources.  #
326 # ----------------- #
329 # AC_LANG_SOURCE(C++)(BODY)
330 # -------------------------
331 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(C++)])
334 # AC_LANG_PROGRAM(C++)([PROLOGUE], [BODY])
335 # ----------------------------------------
336 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(C++)])
339 # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
340 # -------------------------------------
341 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(C++)])
344 # AC_LANG_FUNC_LINK_TRY(C++)(FUNCTION)
345 # ------------------------------------
346 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(C++)])
349 # AC_LANG_BOOL_COMPILE_TRY(C++)(PROLOGUE, EXPRESSION)
350 # ---------------------------------------------------
351 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])
354 # AC_LANG_INT_SAVE(C++)(PROLOGUE, EXPRESSION)
355 # -------------------------------------------
356 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(C++)])
360 # ------------------------- #
361 # 2c. Objective C sources.  #
362 # ------------------------- #
365 # AC_LANG_SOURCE(Objective C)(BODY)
366 # ---------------------------------
367 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(Objective C)])
370 # AC_LANG_PROGRAM(Objective C)([PROLOGUE], [BODY])
371 # ------------------------------------------------
372 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(Objective C)])
375 # AC_LANG_CALL(Objective C)(PROLOGUE, FUNCTION)
376 # ---------------------------------------------
377 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(Objective C)])
380 # AC_LANG_FUNC_LINK_TRY(Objective C)(FUNCTION)
381 # --------------------------------------------
382 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(Objective C)])
385 # AC_LANG_BOOL_COMPILE_TRY(Objective C)(PROLOGUE, EXPRESSION)
386 # -----------------------------------------------------------
387 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(Objective C)])
390 # AC_LANG_INT_SAVE(Objective C)(PROLOGUE, EXPRESSION)
391 # ---------------------------------------------------
392 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(Objective C)])
396 ## -------------------------------------------- ##
397 ## 3. Looking for Compilers and Preprocessors.  ##
398 ## -------------------------------------------- ##
400 # -------------------- #
401 # 3a. The C compiler.  #
402 # -------------------- #
405 # _AC_ARG_VAR_CPPFLAGS
406 # --------------------
407 # Document and register CPPFLAGS, which is used by
408 # AC_PROG_{CC, CPP, CXX, CXXCPP, OBJC, OBJCPP}.
409 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
410 [AC_ARG_VAR([CPPFLAGS],
411             [C/C++/Objective C preprocessor flags, e.g. -I<include dir>
412              if you have headers in a nonstandard directory <include dir>])])
415 # _AC_ARG_VAR_LDFLAGS
416 # -------------------
417 # Document and register LDFLAGS, which is used by
418 # AC_PROG_{CC, CXX, F77, FC, OBJC}.
419 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
420 [AC_ARG_VAR([LDFLAGS],
421             [linker flags, e.g. -L<lib dir> if you have libraries in a
422              nonstandard directory <lib dir>])])
425 # _AC_ARG_VAR_LIBS
426 # ----------------
427 # Document and register LIBS, which is used by
428 # AC_PROG_{CC, CXX, F77, FC, OBJS}.
429 AC_DEFUN([_AC_ARG_VAR_LIBS],
430 [AC_ARG_VAR([LIBS],
431             [libraries to pass to the linker, e.g. -l<library>])])
434 # AC_LANG_PREPROC(C)
435 # -------------------
436 # Find the C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
437 AC_DEFUN([AC_LANG_PREPROC(C)],
438 [AC_REQUIRE([AC_PROG_CPP])])
441 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
442 # -----------------------------------------------
443 # Check if $ac_cpp is a working preprocessor that can flag absent
444 # includes either by the exit status or by warnings.
445 # This macro is for all languages, not only C.
446 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
447 [ac_preproc_ok=false
448 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
450   # Use a header file that comes with gcc, so configuring glibc
451   # with a fresh cross-compiler works.
452   # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
453   # <limits.h> exists even on freestanding compilers.
454   # On the NeXT, cc -E runs the code through the compiler's parser,
455   # not just through cpp. "Syntax error" is here to catch this case.
456   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@ifdef __STDC__
457 @%:@ include <limits.h>
458 @%:@else
459 @%:@ include <assert.h>
460 @%:@endif
461                      Syntax error]])],
462                      [],
463                      [# Broken: fails on valid input.
464 continue])
466   # OK, works on sane cases.  Now check whether nonexistent headers
467   # can be detected and how.
468   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
469                      [# Broken: success on invalid input.
470 continue],
471                      [# Passes both tests.
472 ac_preproc_ok=:
473 break])
475 done
476 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
477 rm -f conftest.err conftest.$ac_ext
478 AS_IF([$ac_preproc_ok], [$1], [$2])])# _AC_PROG_PREPROC_WORKS_IFELSE
481 # AC_PROG_CPP
482 # -----------
483 # Find a working C preprocessor.
484 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
485 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
486 AN_MAKEVAR([CPP], [AC_PROG_CPP])
487 AN_PROGRAM([cpp], [AC_PROG_CPP])
488 AC_DEFUN([AC_PROG_CPP],
489 [AC_REQUIRE([AC_PROG_CC])dnl
490 AC_ARG_VAR([CPP],      [C preprocessor])dnl
491 _AC_ARG_VAR_CPPFLAGS()dnl
492 AC_LANG_PUSH(C)dnl
493 AC_MSG_CHECKING([how to run the C preprocessor])
494 # On Suns, sometimes $CPP names a directory.
495 if test -n "$CPP" && test -d "$CPP"; then
496   CPP=
498 if test -z "$CPP"; then
499   AC_CACHE_VAL([ac_cv_prog_CPP],
500   [dnl
501     # Double quotes because CPP needs to be expanded
502     for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
503     do
504       _AC_PROG_PREPROC_WORKS_IFELSE([break])
505     done
506     ac_cv_prog_CPP=$CPP
507   ])dnl
508   CPP=$ac_cv_prog_CPP
509 else
510   ac_cv_prog_CPP=$CPP
512 AC_MSG_RESULT([$CPP])
513 _AC_PROG_PREPROC_WORKS_IFELSE([],
514                 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
515 AC_SUBST(CPP)dnl
516 AC_LANG_POP(C)dnl
517 ])# AC_PROG_CPP
519 # AC_PROG_CPP_WERROR
520 # ------------------
521 # Treat warnings from the preprocessor as errors.
522 AC_DEFUN([AC_PROG_CPP_WERROR],
523 [AC_REQUIRE([AC_PROG_CPP])dnl
524 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
526 # AC_LANG_COMPILER(C)
527 # -------------------
528 # Find the C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
529 AC_DEFUN([AC_LANG_COMPILER(C)],
530 [AC_REQUIRE([AC_PROG_CC])])
533 # ac_cv_prog_gcc
534 # --------------
535 # We used to name the cache variable this way.
536 AU_DEFUN([ac_cv_prog_gcc],
537 [ac_cv_c_compiler_gnu])
540 # AC_PROG_CC([COMPILER ...])
541 # --------------------------
542 # COMPILER ... is a space separated list of C compilers to search for.
543 # This just gives the user an opportunity to specify an alternative
544 # search list for the C compiler.
545 AN_MAKEVAR([CC],  [AC_PROG_CC])
546 AN_PROGRAM([cc],  [AC_PROG_CC])
547 AN_PROGRAM([gcc], [AC_PROG_CC])
548 AC_DEFUN([AC_PROG_CC],
549 [AC_LANG_PUSH(C)dnl
550 AC_ARG_VAR([CC],     [C compiler command])dnl
551 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
552 _AC_ARG_VAR_LDFLAGS()dnl
553 _AC_ARG_VAR_LIBS()dnl
554 _AC_ARG_VAR_CPPFLAGS()dnl
555 m4_ifval([$1],
556       [AC_CHECK_TOOLS(CC, [$1])],
557 [AC_CHECK_TOOL(CC, gcc)
558 if test -z "$CC"; then
559   dnl Here we want:
560   dnl   AC_CHECK_TOOL(CC, cc)
561   dnl but without the check for a tool without the prefix.
562   dnl Until the check is removed from there, copy the code:
563   if test -n "$ac_tool_prefix"; then
564     AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
565   fi
567 if test -z "$CC"; then
568   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
570 if test -z "$CC"; then
571   AC_CHECK_TOOLS(CC, cl.exe)
575 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
577 # Provide some information about the compiler.
578 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
579 set X $ac_compile
580 ac_compiler=$[2]
581 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
582 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
583 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
585 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
586 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
587 _AC_LANG_COMPILER_GNU
588 if test $ac_compiler_gnu = yes; then
589   GCC=yes
590 else
591   GCC=
593 _AC_PROG_CC_G
594 _AC_PROG_CC_C89
595 AC_LANG_POP(C)dnl
596 ])# AC_PROG_CC
599 # _AC_PROG_CC_G
600 # -------------
601 # Check whether -g works, even if CFLAGS is set, in case the package
602 # plays around with CFLAGS (such as to build both debugging and normal
603 # versions of a library), tasteless as that idea is.
604 # Don't consider -g to work if it generates warnings when plain compiles don't.
605 m4_define([_AC_PROG_CC_G],
606 [ac_test_CFLAGS=${CFLAGS+set}
607 ac_save_CFLAGS=$CFLAGS
608 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
609   [ac_save_c_werror_flag=$ac_c_werror_flag
610    ac_c_werror_flag=yes
611    ac_cv_prog_cc_g=no
612    CFLAGS="-g"
613    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
614      [ac_cv_prog_cc_g=yes],
615      [CFLAGS=""
616       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
617         [],
618         [ac_c_werror_flag=$ac_save_c_werror_flag
619          CFLAGS="-g"
620          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
621            [ac_cv_prog_cc_g=yes])])])
622    ac_c_werror_flag=$ac_save_c_werror_flag])
623 if test "$ac_test_CFLAGS" = set; then
624   CFLAGS=$ac_save_CFLAGS
625 elif test $ac_cv_prog_cc_g = yes; then
626   if test "$GCC" = yes; then
627     CFLAGS="-g -O2"
628   else
629     CFLAGS="-g"
630   fi
631 else
632   if test "$GCC" = yes; then
633     CFLAGS="-O2"
634   else
635     CFLAGS=
636   fi
637 fi[]dnl
638 ])# _AC_PROG_CC_G
641 # AC_PROG_GCC_TRADITIONAL
642 # -----------------------
643 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
644 [AC_REQUIRE([AC_PROG_CC])dnl
645 if test $ac_cv_c_compiler_gnu = yes; then
646     AC_CACHE_CHECK(whether $CC needs -traditional,
647       ac_cv_prog_gcc_traditional,
648 [  ac_pattern="Autoconf.*'x'"
649   AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
650 Autoconf TIOCGETP],
651   ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
653   if test $ac_cv_prog_gcc_traditional = no; then
654     AC_EGREP_CPP($ac_pattern, [#include <termio.h>
655 Autoconf TCGETA],
656     ac_cv_prog_gcc_traditional=yes)
657   fi])
658   if test $ac_cv_prog_gcc_traditional = yes; then
659     CC="$CC -traditional"
660   fi
662 ])# AC_PROG_GCC_TRADITIONAL
665 # AC_PROG_CC_C_O
666 # --------------
667 AC_DEFUN([AC_PROG_CC_C_O],
668 [AC_REQUIRE([AC_PROG_CC])dnl
669 if test "x$CC" != xcc; then
670   AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
671 else
672   AC_MSG_CHECKING([whether cc understands -c and -o together])
674 set dummy $CC; ac_cc=`AS_ECHO(["$[2]"]) |
675                       sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
676 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
677 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
678 # Make sure it works both with $CC and with simple cc.
679 # We do the test twice because some compilers refuse to overwrite an
680 # existing .o file with -o, though they will create one.
681 ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
682 rm -f conftest2.*
683 if _AC_DO_VAR(ac_try) &&
684    test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
685 then
686   eval ac_cv_prog_cc_${ac_cc}_c_o=yes
687   if test "x$CC" != xcc; then
688     # Test first that cc exists at all.
689     if _AC_DO_TOKENS(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
690       ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
691       rm -f conftest2.*
692       if _AC_DO_VAR(ac_try) &&
693          test -f conftest2.$ac_objext && _AC_DO_VAR(ac_try);
694       then
695         # cc works too.
696         :
697       else
698         # cc exists but doesn't like -o.
699         eval ac_cv_prog_cc_${ac_cc}_c_o=no
700       fi
701     fi
702   fi
703 else
704   eval ac_cv_prog_cc_${ac_cc}_c_o=no
706 rm -f core conftest*
707 ])dnl
708 if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
709   AC_MSG_RESULT([yes])
710 else
711   AC_MSG_RESULT([no])
712   AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
713            [Define to 1 if your C compiler doesn't accept -c and -o together.])
715 ])# AC_PROG_CC_C_O
719 # ---------------------- #
720 # 3b. The C++ compiler.  #
721 # ---------------------- #
724 # AC_LANG_PREPROC(C++)
725 # ---------------------
726 # Find the C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
727 AC_DEFUN([AC_LANG_PREPROC(C++)],
728 [AC_REQUIRE([AC_PROG_CXXCPP])])
731 # AC_PROG_CXXCPP
732 # --------------
733 # Find a working C++ preprocessor.
734 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
735 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
736 AC_DEFUN([AC_PROG_CXXCPP],
737 [AC_REQUIRE([AC_PROG_CXX])dnl
738 AC_ARG_VAR([CXXCPP],   [C++ preprocessor])dnl
739 _AC_ARG_VAR_CPPFLAGS()dnl
740 AC_LANG_PUSH(C++)dnl
741 AC_MSG_CHECKING([how to run the C++ preprocessor])
742 if test -z "$CXXCPP"; then
743   AC_CACHE_VAL(ac_cv_prog_CXXCPP,
744   [dnl
745     # Double quotes because CXXCPP needs to be expanded
746     for CXXCPP in "$CXX -E" "/lib/cpp"
747     do
748       _AC_PROG_PREPROC_WORKS_IFELSE([break])
749     done
750     ac_cv_prog_CXXCPP=$CXXCPP
751   ])dnl
752   CXXCPP=$ac_cv_prog_CXXCPP
753 else
754   ac_cv_prog_CXXCPP=$CXXCPP
756 AC_MSG_RESULT([$CXXCPP])
757 _AC_PROG_PREPROC_WORKS_IFELSE([],
758           [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
759 AC_SUBST(CXXCPP)dnl
760 AC_LANG_POP(C++)dnl
761 ])# AC_PROG_CXXCPP
764 # AC_LANG_COMPILER(C++)
765 # ---------------------
766 # Find the C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
767 AC_DEFUN([AC_LANG_COMPILER(C++)],
768 [AC_REQUIRE([AC_PROG_CXX])])
771 # ac_cv_prog_gxx
772 # --------------
773 # We used to name the cache variable this way.
774 AU_DEFUN([ac_cv_prog_gxx],
775 [ac_cv_cxx_compiler_gnu])
778 # AC_PROG_CXX([LIST-OF-COMPILERS])
779 # --------------------------------
780 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
781 # for (if not specified, a default list is used).  This just gives the
782 # user an opportunity to specify an alternative search list for the C++
783 # compiler.
784 # aCC   HP-UX C++ compiler much better than `CC', so test before.
785 # FCC   Fujitsu C++ compiler
786 # KCC   KAI C++ compiler
787 # RCC   Rational C++
788 # xlC_r AIX C Set++ (with support for reentrant code)
789 # xlC   AIX C Set++
790 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
791 AN_PROGRAM([CC],   [AC_PROG_CXX])
792 AN_PROGRAM([c++],  [AC_PROG_CXX])
793 AN_PROGRAM([g++],  [AC_PROG_CXX])
794 AC_DEFUN([AC_PROG_CXX],
795 [AC_LANG_PUSH(C++)dnl
796 AC_ARG_VAR([CXX],      [C++ compiler command])dnl
797 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
798 _AC_ARG_VAR_LDFLAGS()dnl
799 _AC_ARG_VAR_LIBS()dnl
800 _AC_ARG_VAR_CPPFLAGS()dnl
801 _AC_ARG_VAR_PRECIOUS([CCC])dnl
802 if test -z "$CXX"; then
803   if test -n "$CCC"; then
804     CXX=$CCC
805   else
806     AC_CHECK_TOOLS(CXX,
807                    [m4_default([$1],
808                                [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
809                    g++)
810   fi
812 # Provide some information about the compiler.
813 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
814 set X $ac_compile
815 ac_compiler=$[2]
816 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
817 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
818 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
820 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
821 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
822 _AC_LANG_COMPILER_GNU
823 if test $ac_compiler_gnu = yes; then
824   GXX=yes
825 else
826   GXX=
828 _AC_PROG_CXX_G
829 AC_LANG_POP(C++)dnl
830 ])# AC_PROG_CXX
833 # _AC_PROG_CXX_G
834 # --------------
835 # Check whether -g works, even if CXXFLAGS is set, in case the package
836 # plays around with CXXFLAGS (such as to build both debugging and
837 # normal versions of a library), tasteless as that idea is.
838 # Don't consider -g to work if it generates warnings when plain compiles don't.
839 m4_define([_AC_PROG_CXX_G],
840 [ac_test_CXXFLAGS=${CXXFLAGS+set}
841 ac_save_CXXFLAGS=$CXXFLAGS
842 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
843   [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
844    ac_cxx_werror_flag=yes
845    ac_cv_prog_cxx_g=no
846    CXXFLAGS="-g"
847    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
848      [ac_cv_prog_cxx_g=yes],
849      [CXXFLAGS=""
850       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
851         [],
852         [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
853          CXXFLAGS="-g"
854          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
855            [ac_cv_prog_cxx_g=yes])])])
856    ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
857 if test "$ac_test_CXXFLAGS" = set; then
858   CXXFLAGS=$ac_save_CXXFLAGS
859 elif test $ac_cv_prog_cxx_g = yes; then
860   if test "$GXX" = yes; then
861     CXXFLAGS="-g -O2"
862   else
863     CXXFLAGS="-g"
864   fi
865 else
866   if test "$GXX" = yes; then
867     CXXFLAGS="-O2"
868   else
869     CXXFLAGS=
870   fi
871 fi[]dnl
872 ])# _AC_PROG_CXX_G
875 # AC_PROG_CXX_C_O
876 # ---------------
877 # Test if the C++ compiler accepts the options `-c' and `-o'
878 # simultaneously, and define `CXX_NO_MINUS_C_MINUS_O' if it does not.
879 AC_DEFUN([AC_PROG_CXX_C_O],
880 [AC_REQUIRE([AC_PROG_CXX])dnl
881 AC_LANG_PUSH([C++])dnl
882 AC_CACHE_CHECK([whether $CXX understands -c and -o together],
883                [ac_cv_prog_cxx_c_o],
884 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
885 # We test twice because some compilers refuse to overwrite an existing
886 # `.o' file with `-o', although they will create one.
887 ac_try='$CXX $CXXFLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
888 rm -f conftest2.*
889 if _AC_DO_VAR(ac_try) &&
890      test -f conftest2.$ac_objext &&
891      _AC_DO_VAR(ac_try); then
892   ac_cv_prog_cxx_c_o=yes
893 else
894   ac_cv_prog_cxx_c_o=no
896 rm -f conftest*])
897 if test $ac_cv_prog_cxx_c_o = no; then
898   AC_DEFINE(CXX_NO_MINUS_C_MINUS_O, 1,
899             [Define to 1 if your C++ compiler doesn't accept
900              -c and -o together.])
902 AC_LANG_POP([C++])dnl
903 ])# AC_PROG_CXX_C_O
907 # ------------------------------ #
908 # 3c. The Objective C compiler.  #
909 # ------------------------------ #
912 # AC_LANG_PREPROC(Objective C)
913 # ----------------------------
914 # Find the Objective C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
915 AC_DEFUN([AC_LANG_PREPROC(Objective C)],
916 [AC_REQUIRE([AC_PROG_OBJCPP])])
919 # AC_PROG_OBJCPP
920 # --------------
921 # Find a working Objective C preprocessor.
922 AC_DEFUN([AC_PROG_OBJCPP],
923 [AC_REQUIRE([AC_PROG_OBJC])dnl
924 AC_ARG_VAR([OBJCPP],   [Objective C preprocessor])dnl
925 _AC_ARG_VAR_CPPFLAGS()dnl
926 AC_LANG_PUSH(Objective C)dnl
927 AC_MSG_CHECKING([how to run the Objective C preprocessor])
928 if test -z "$OBJCPP"; then
929   AC_CACHE_VAL(ac_cv_prog_OBJCPP,
930   [dnl
931     # Double quotes because OBJCPP needs to be expanded
932     for OBJCPP in "$OBJC -E" "/lib/cpp"
933     do
934       _AC_PROG_PREPROC_WORKS_IFELSE([break])
935     done
936     ac_cv_prog_OBJCPP=$OBJCPP
937   ])dnl
938   OBJCPP=$ac_cv_prog_OBJCPP
939 else
940   ac_cv_prog_OBJCPP=$OBJCPP
942 AC_MSG_RESULT([$OBJCPP])
943 _AC_PROG_PREPROC_WORKS_IFELSE([],
944           [AC_MSG_FAILURE([Objective C preprocessor "$OBJCPP" fails sanity check])])
945 AC_SUBST(OBJCPP)dnl
946 AC_LANG_POP(Objective C)dnl
947 ])# AC_PROG_OBJCPP
950 # AC_LANG_COMPILER(Objective C)
951 # -----------------------------
952 # Find the Objective C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
953 AC_DEFUN([AC_LANG_COMPILER(Objective C)],
954 [AC_REQUIRE([AC_PROG_OBJC])])
958 # AC_PROG_OBJC([LIST-OF-COMPILERS])
959 # ---------------------------------
960 # LIST-OF-COMPILERS is a space separated list of Objective C compilers to
961 # search for (if not specified, a default list is used).  This just gives
962 # the user an opportunity to specify an alternative search list for the
963 # Objective C compiler.
964 # objcc StepStone Objective-C compiler (also "standard" name for OBJC)
965 # objc  David Stes' POC.  If you installed this, you likely want it.
966 # cc    Native C compiler (for instance, Apple).
967 # CC    You never know.
968 AN_MAKEVAR([OBJC],  [AC_PROG_OBJC])
969 AN_PROGRAM([objcc],  [AC_PROG_OBJC])
970 AN_PROGRAM([objc],  [AC_PROG_OBJC])
971 AC_DEFUN([AC_PROG_OBJC],
972 [AC_LANG_PUSH(Objective C)dnl
973 AC_ARG_VAR([OBJC],      [Objective C compiler command])dnl
974 AC_ARG_VAR([OBJCFLAGS], [Objective C compiler flags])dnl
975 _AC_ARG_VAR_LDFLAGS()dnl
976 _AC_ARG_VAR_LIBS()dnl
977 _AC_ARG_VAR_CPPFLAGS()dnl
978 _AC_ARG_VAR_PRECIOUS([OBJC])dnl
979 AC_CHECK_TOOLS(OBJC,
980                [m4_default([$1], [gcc objcc objc cc CC])],
981                gcc)
982 # Provide some information about the compiler.
983 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
984 set X $ac_compile
985 ac_compiler=$[2]
986 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
987 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
988 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
990 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
991 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
992 _AC_LANG_COMPILER_GNU
993 if test $ac_compiler_gnu = yes; then
994   GOBJC=yes
995 else
996   GOBJC=
998 _AC_PROG_OBJC_G
999 AC_LANG_POP(Objective C)dnl
1000 ])# AC_PROG_OBJC
1003 # _AC_PROG_OBJC_G
1004 # ---------------
1005 # Check whether -g works, even if OBJCFLAGS is set, in case the package
1006 # plays around with OBJCFLAGS (such as to build both debugging and
1007 # normal versions of a library), tasteless as that idea is.
1008 # Don't consider -g to work if it generates warnings when plain compiles don't.
1009 m4_define([_AC_PROG_OBJC_G],
1010 [ac_test_OBJCFLAGS=${OBJCFLAGS+set}
1011 ac_save_OBJCFLAGS=$OBJCFLAGS
1012 AC_CACHE_CHECK(whether $OBJC accepts -g, ac_cv_prog_objc_g,
1013   [ac_save_objc_werror_flag=$ac_objc_werror_flag
1014    ac_objc_werror_flag=yes
1015    ac_cv_prog_objc_g=no
1016    OBJCFLAGS="-g"
1017    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1018      [ac_cv_prog_objc_g=yes],
1019      [OBJCFLAGS=""
1020       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1021         [],
1022         [ac_objc_werror_flag=$ac_save_objc_werror_flag
1023          OBJCFLAGS="-g"
1024          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
1025            [ac_cv_prog_objc_g=yes])])])
1026    ac_objc_werror_flag=$ac_save_objc_werror_flag])
1027 if test "$ac_test_OBJCFLAGS" = set; then
1028   OBJCFLAGS=$ac_save_OBJCFLAGS
1029 elif test $ac_cv_prog_objc_g = yes; then
1030   if test "$GOBJC" = yes; then
1031     OBJCFLAGS="-g -O2"
1032   else
1033     OBJCFLAGS="-g"
1034   fi
1035 else
1036   if test "$GOBJC" = yes; then
1037     OBJCFLAGS="-O2"
1038   else
1039     OBJCFLAGS=
1040   fi
1041 fi[]dnl
1042 ])# _AC_PROG_OBJC_G
1046 ## ------------------------------- ##
1047 ## 4. Compilers' characteristics.  ##
1048 ## ------------------------------- ##
1050 # -------------------------------- #
1051 # 4a. C compiler characteristics.  #
1052 # -------------------------------- #
1055 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1056 # ----------------------------------------------------------------
1057 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
1058 # to add an option to output variable CC to make it so.  This macro
1059 # tries various options that select ANSI C89 on some system or
1060 # another.  It considers the compiler to be in ANSI C89 mode if it
1061 # handles function prototypes correctly.
1062 AC_DEFUN([_AC_PROG_CC_C89],
1063 [_AC_C_STD_TRY([c89],
1064 [[#include <stdarg.h>
1065 #include <stdio.h>
1066 #include <sys/types.h>
1067 #include <sys/stat.h>
1068 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
1069 struct buf { int x; };
1070 FILE * (*rcsopen) (struct buf *, struct stat *, int);
1071 static char *e (p, i)
1072      char **p;
1073      int i;
1075   return p[i];
1077 static char *f (char * (*g) (char **, int), char **p, ...)
1079   char *s;
1080   va_list v;
1081   va_start (v,p);
1082   s = g (p, va_arg (v,int));
1083   va_end (v);
1084   return s;
1087 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
1088    function prototypes and stuff, but not '\xHH' hex character constants.
1089    These don't provoke an error unfortunately, instead are silently treated
1090    as 'x'.  The following induces an error, until -std is added to get
1091    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
1092    array size at least.  It's necessary to write '\x00'==0 to get something
1093    that's true only with -std.  */
1094 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
1096 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
1097    inside strings and character constants.  */
1098 #define FOO(x) 'x'
1099 int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
1101 int test (int i, double x);
1102 struct s1 {int (*f) (int a);};
1103 struct s2 {int (*f) (double a);};
1104 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
1105 int argc;
1106 char **argv;]],
1107 [[return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];]],
1108 dnl Don't try gcc -ansi; that turns off useful extensions and
1109 dnl breaks some systems' header files.
1110 dnl AIX circa 2003      -qlanglvl=extc89
1111 dnl old AIX             -qlanglvl=ansi
1112 dnl Ultrix, OSF/1, Tru64        -std
1113 dnl HP-UX 10.20 and later       -Ae
1114 dnl HP-UX older versions        -Aa -D_HPUX_SOURCE
1115 dnl SVR4                        -Xc -D__EXTENSIONS__
1116 [-qlanglvl=extc89 -qlanglvl=ansi -std \
1117         -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
1118 ])# _AC_PROG_CC_C89
1121 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
1122 #               ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
1123 # --------------------------------------------------------------
1124 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
1125 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
1126 # try again with each compiler option in the space-separated OPTION-LIST; if one
1127 # helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
1128 # else ACTION-IF-UNAVAILABLE.
1129 AC_DEFUN([_AC_C_STD_TRY],
1130 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
1131 AC_CACHE_VAL(ac_cv_prog_cc_$1,
1132 [ac_cv_prog_cc_$1=no
1133 ac_save_CC=$CC
1134 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
1135 for ac_arg in '' $4
1137   CC="$ac_save_CC $ac_arg"
1138   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
1139   test "x$ac_cv_prog_cc_$1" != "xno" && break
1140 done
1141 rm -f conftest.$ac_ext
1142 CC=$ac_save_CC
1143 ])# AC_CACHE_VAL
1144 case "x$ac_cv_prog_cc_$1" in
1145   x)
1146     AC_MSG_RESULT([none needed]) ;;
1147   xno)
1148     AC_MSG_RESULT([unsupported]) ;;
1149   *)
1150     CC="$CC $ac_cv_prog_cc_$1"
1151     AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
1152 esac
1153 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
1154 ])# _AC_C_STD_TRY
1157 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
1158 # ----------------------------------------------------------------
1159 # If the C compiler is not in ISO C99 mode by default, try to add an
1160 # option to output variable CC to make it so.  This macro tries
1161 # various options that select ISO C99 on some system or another.  It
1162 # considers the compiler to be in ISO C99 mode if it handles _Bool,
1163 # // comments, flexible array members, inline, long long int, mixed
1164 # code and declarations, named initialization of structs, restrict,
1165 # va_copy, varargs macros, variable declarations in for loops and
1166 # variable length arrays.
1167 AC_DEFUN([_AC_PROG_CC_C99],
1168 [_AC_C_STD_TRY([c99],
1169 [[#include <stdarg.h>
1170 #include <stdbool.h>
1171 #include <stdlib.h>
1172 #include <wchar.h>
1173 #include <stdio.h>
1175 // Check varargs macros.  These examples are taken from C99 6.10.3.5.
1176 #define debug(...) fprintf (stderr, __VA_ARGS__)
1177 #define showlist(...) puts (#__VA_ARGS__)
1178 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
1179 static void
1180 test_varargs_macros (void)
1182   int x = 1234;
1183   int y = 5678;
1184   debug ("Flag");
1185   debug ("X = %d\n", x);
1186   showlist (The first, second, and third items.);
1187   report (x>y, "x is %d but y is %d", x, y);
1190 // Check long long types.
1191 #define BIG64 18446744073709551615ull
1192 #define BIG32 4294967295ul
1193 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
1194 #if !BIG_OK
1195   your preprocessor is broken;
1196 #endif
1197 #if BIG_OK
1198 #else
1199   your preprocessor is broken;
1200 #endif
1201 static long long int bignum = -9223372036854775807LL;
1202 static unsigned long long int ubignum = BIG64;
1204 struct incomplete_array
1206   int datasize;
1207   double data[];
1210 struct named_init {
1211   int number;
1212   const wchar_t *name;
1213   double average;
1216 typedef const char *ccp;
1218 static inline int
1219 test_restrict (ccp restrict text)
1221   // See if C++-style comments work.
1222   // Iterate through items via the restricted pointer.
1223   // Also check for declarations in for loops.
1224   for (unsigned int i = 0; *(text+i) != '\0'; ++i)
1225     continue;
1226   return 0;
1229 // Check varargs and va_copy.
1230 static void
1231 test_varargs (const char *format, ...)
1233   va_list args;
1234   va_start (args, format);
1235   va_list args_copy;
1236   va_copy (args_copy, args);
1238   const char *str;
1239   int number;
1240   float fnumber;
1242   while (*format)
1243     {
1244       switch (*format++)
1245         {
1246         case 's': // string
1247           str = va_arg (args_copy, const char *);
1248           break;
1249         case 'd': // int
1250           number = va_arg (args_copy, int);
1251           break;
1252         case 'f': // float
1253           fnumber = va_arg (args_copy, double);
1254           break;
1255         default:
1256           break;
1257         }
1258     }
1259   va_end (args_copy);
1260   va_end (args);
1264   // Check bool.
1265   _Bool success = false;
1267   // Check restrict.
1268   if (test_restrict ("String literal") == 0)
1269     success = true;
1270   char *restrict newvar = "Another string";
1272   // Check varargs.
1273   test_varargs ("s, d' f .", "string", 65, 34.234);
1274   test_varargs_macros ();
1276   // Check flexible array members.
1277   struct incomplete_array *ia =
1278     malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
1279   ia->datasize = 10;
1280   for (int i = 0; i < ia->datasize; ++i)
1281     ia->data[i] = i * 1.234;
1283   // Check named initializers.
1284   struct named_init ni = {
1285     .number = 34,
1286     .name = L"Test wide string",
1287     .average = 543.34343,
1288   };
1290   ni.number = 58;
1292   int dynamic_array[ni.number];
1293   dynamic_array[ni.number - 1] = 543;
1295   // work around unused variable warnings
1296   return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
1297           || dynamic_array[ni.number - 1] != 543);
1299 dnl Try
1300 dnl GCC         -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1301 dnl AIX         -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
1302 dnl Intel ICC   -c99
1303 dnl IRIX        -c99
1304 dnl Solaris     -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
1305 dnl             as it incorrectly assumes C99 semantics for library functions)
1306 dnl Tru64       -c99
1307 dnl with extended modes being tried first.
1308 [[-std=gnu99 -c99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
1309 ])# _AC_PROG_CC_C99
1312 # AC_PROG_CC_C89
1313 # --------------
1314 AC_DEFUN([AC_PROG_CC_C89],
1315 [ AC_REQUIRE([AC_PROG_CC])dnl
1316   _AC_PROG_CC_C89
1320 # AC_PROG_CC_C99
1321 # --------------
1322 AC_DEFUN([AC_PROG_CC_C99],
1323 [ AC_REQUIRE([AC_PROG_CC])dnl
1324   _AC_PROG_CC_C99
1328 # AC_PROG_CC_STDC
1329 # ---------------
1330 AC_DEFUN([AC_PROG_CC_STDC],
1331 [ AC_REQUIRE([AC_PROG_CC])dnl
1332   AS_CASE([$ac_cv_prog_cc_stdc],
1333     [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
1334           [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1335              [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
1336                               [ac_cv_prog_cc_stdc=no])])])dnl
1337   AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1338   AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1339   AS_CASE([$ac_cv_prog_cc_stdc],
1340     [no], [AC_MSG_RESULT([unsupported])],
1341     [''], [AC_MSG_RESULT([none needed])],
1342           [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
1346 # AC_C_BACKSLASH_A
1347 # ----------------
1348 AC_DEFUN([AC_C_BACKSLASH_A],
1350   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1351    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1352      [[
1353 #if '\a' == 'a'
1354       syntax error;
1355 #endif
1356       char buf['\a' == 'a' ? -1 : 1];
1357       buf[0] = '\a';
1358       return buf[0] != "\a"[0];
1359      ]])],
1360      [ac_cv_c_backslash_a=yes],
1361      [ac_cv_c_backslash_a=no])])
1362   if test $ac_cv_c_backslash_a = yes; then
1363     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1364       [Define if backslash-a works in C strings.])
1365   fi
1369 # AC_C_CROSS
1370 # ----------
1371 # Has been merged into AC_PROG_CC.
1372 AU_DEFUN([AC_C_CROSS], [])
1375 # AC_C_CHAR_UNSIGNED
1376 # ------------------
1377 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1378 [AH_VERBATIM([__CHAR_UNSIGNED__],
1379 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1380 #ifndef __CHAR_UNSIGNED__
1381 # undef __CHAR_UNSIGNED__
1382 #endif])dnl
1383 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1384 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1385                                              [((char) -1) < 0])],
1386                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1387 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1388   AC_DEFINE(__CHAR_UNSIGNED__)
1390 ])# AC_C_CHAR_UNSIGNED
1393 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
1394 #                 [ACTION-IF-UNIVERSAL])
1395 # -------------------------------------------------------------------------
1396 AC_DEFUN([AC_C_BIGENDIAN],
1397 [AH_VERBATIM([WORDS_BIGENDIAN],
1398 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
1399    significant byte first (like Motorola and SPARC, unlike Intel and VAX). */
1400 #if defined __BIG_ENDIAN__
1401 # define WORDS_BIGENDIAN 1
1402 #elif ! defined __LITTLE_ENDIAN__
1403 /* #undef WORDS_BIGENDIAN */
1404 #endif])dnl
1405  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
1406    [ac_cv_c_bigendian=unknown
1407     m4_ifval(m4_ifdef([AH_HEADER], 1)[$4],
1408       [# See if __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined.
1409        AC_COMPILE_IFELSE(
1410          [AC_LANG_SOURCE(
1411             [[#if ! (defined __BIG_ENDIAN__ || defined __LITTLE_ENDIAN__)
1412                neither is defined;
1413              #endif
1414              typedef int dummy;
1415             ]])],
1416          [ac_cv_c_bigendian=universal])],
1417       [AC_DIAGNOSE([obsolete], [AC_C_BIGENDIAN suggests AC_CONFIG_HEADERS])])
1418     if test $ac_cv_c_bigendian = unknown; then
1419       # See if sys/param.h defines the BYTE_ORDER macro.
1420       AC_COMPILE_IFELSE(
1421         [AC_LANG_PROGRAM(
1422            [[#include <sys/types.h>
1423              #include <sys/param.h>
1424            ]],
1425            [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
1426                      && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
1427                      && LITTLE_ENDIAN)
1428               bogus endian macros
1429              #endif
1430            ]])],
1431         [# It does; now see whether it defined to BIG_ENDIAN or not.
1432          AC_COMPILE_IFELSE(
1433            [AC_LANG_PROGRAM(
1434               [[#include <sys/types.h>
1435                 #include <sys/param.h>
1436               ]],
1437               [[#if BYTE_ORDER != BIG_ENDIAN
1438                  not big endian
1439                 #endif
1440               ]])],
1441            [ac_cv_c_bigendian=yes],
1442            [ac_cv_c_bigendian=no])])
1443     fi
1444     if test $ac_cv_c_bigendian = unknown; then
1445       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
1446       AC_COMPILE_IFELSE(
1447         [AC_LANG_PROGRAM(
1448            [[#include <limits.h>
1449            ]],
1450            [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
1451               bogus endian macros
1452              #endif
1453            ]])],
1454         [# It does; now see whether it defined to _BIG_ENDIAN or not.
1455          AC_COMPILE_IFELSE(
1456            [AC_LANG_PROGRAM(
1457               [[#include <limits.h>
1458               ]],
1459               [[#ifndef _BIG_ENDIAN
1460                  not big endian
1461                 #endif
1462               ]])],
1463            [ac_cv_c_bigendian=yes],
1464            [ac_cv_c_bigendian=no])])
1465     fi
1466     if test $ac_cv_c_bigendian = unknown; then
1467       # Compile a test program.
1468       AC_RUN_IFELSE(
1469         [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
1470            [[
1471              /* Are we little or big endian?  From Harbison&Steele.  */
1472              union
1473              {
1474                long int l;
1475                char c[sizeof (long int)];
1476              } u;
1477              u.l = 1;
1478              return u.c[sizeof (long int) - 1] == 1;
1479            ]])],
1480         [ac_cv_c_bigendian=no],
1481         [ac_cv_c_bigendian=yes],
1482         [# Try to guess by grepping values from an object file.
1483          AC_COMPILE_IFELSE(
1484            [AC_LANG_PROGRAM(
1485               [[short int ascii_mm[] =
1486                   { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1487                 short int ascii_ii[] =
1488                   { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1489                 int use_ascii (int i) {
1490                   return ascii_mm[i] + ascii_ii[i];
1491                 }
1492                 short int ebcdic_ii[] =
1493                   { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1494                 short int ebcdic_mm[] =
1495                   { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1496                 int use_ebcdic (int i) {
1497                   return ebcdic_mm[i] + ebcdic_ii[i];
1498                 }
1499                 extern int foo;
1500               ]],
1501               [[return use_ascii (foo) == use_ebcdic (foo);]])],
1502            [if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
1503               ac_cv_c_bigendian=yes
1504             fi
1505             if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1506               if test "$ac_cv_c_bigendian" = unknown; then
1507                 ac_cv_c_bigendian=no
1508               else
1509                 # finding both strings is unlikely to happen, but who knows?
1510                 ac_cv_c_bigendian=unknown
1511               fi
1512             fi])])
1513     fi])
1514  case $ac_cv_c_bigendian in #(
1515    yes)
1516      m4_default([$1],
1517        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
1518    no)
1519      $2 ;; #(
1520    universal)
1521      $4 ;; #(
1522    *)
1523      m4_default([$3],
1524        [AC_MSG_ERROR([unknown endianness
1525  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1526  esac
1527 ])# AC_C_BIGENDIAN
1530 # AC_C_INLINE
1531 # -----------
1532 # Do nothing if the compiler accepts the inline keyword.
1533 # Otherwise define inline to __inline__ or __inline if one of those work,
1534 # otherwise define inline to be empty.
1536 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1537 # inline function, only builtin types.
1539 AN_IDENTIFIER([inline], [AC_C_INLINE])
1540 AC_DEFUN([AC_C_INLINE],
1541 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1542 [ac_cv_c_inline=no
1543 for ac_kw in inline __inline__ __inline; do
1544   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1545 [#ifndef __cplusplus
1546 typedef int foo_t;
1547 static $ac_kw foo_t static_foo () {return 0; }
1548 $ac_kw foo_t foo () {return 0; }
1549 #endif
1550 ])],
1551                     [ac_cv_c_inline=$ac_kw])
1552   test "$ac_cv_c_inline" != no && break
1553 done
1555 AH_VERBATIM([inline],
1556 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1557    calls it, or to nothing if 'inline' is not supported under any name.  */
1558 #ifndef __cplusplus
1559 #undef inline
1560 #endif])
1561 case $ac_cv_c_inline in
1562   inline | yes) ;;
1563   *)
1564     case $ac_cv_c_inline in
1565       no) ac_val=;;
1566       *) ac_val=$ac_cv_c_inline;;
1567     esac
1568     cat >>confdefs.h <<_ACEOF
1569 #ifndef __cplusplus
1570 #define inline $ac_val
1571 #endif
1572 _ACEOF
1573     ;;
1574 esac
1575 ])# AC_C_INLINE
1578 # AC_C_CONST
1579 # ----------
1580 AC_DEFUN([AC_C_CONST],
1581 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1582 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1583 [[/* FIXME: Include the comments suggested by Paul. */
1584 #ifndef __cplusplus
1585   /* Ultrix mips cc rejects this.  */
1586   typedef int charset[2];
1587   const charset cs;
1588   /* SunOS 4.1.1 cc rejects this.  */
1589   char const *const *pcpcc;
1590   char **ppc;
1591   /* NEC SVR4.0.2 mips cc rejects this.  */
1592   struct point {int x, y;};
1593   static struct point const zero = {0,0};
1594   /* AIX XL C 1.02.0.0 rejects this.
1595      It does not let you subtract one const X* pointer from another in
1596      an arm of an if-expression whose if-part is not a constant
1597      expression */
1598   const char *g = "string";
1599   pcpcc = &g + (g ? g-g : 0);
1600   /* HPUX 7.0 cc rejects these. */
1601   ++pcpcc;
1602   ppc = (char**) pcpcc;
1603   pcpcc = (char const *const *) ppc;
1604   { /* SCO 3.2v4 cc rejects this.  */
1605     char *t;
1606     char const *s = 0 ? (char *) 0 : (char const *) 0;
1608     *t++ = 0;
1609     if (s) return 0;
1610   }
1611   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1612     int x[] = {25, 17};
1613     const int *foo = &x[0];
1614     ++foo;
1615   }
1616   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1617     typedef const int *iptr;
1618     iptr p = 0;
1619     ++p;
1620   }
1621   { /* AIX XL C 1.02.0.0 rejects this saying
1622        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1623     struct s { int j; const int *ap[3]; };
1624     struct s *b; b->j = 5;
1625   }
1626   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1627     const int foo = 10;
1628     if (!foo) return 0;
1629   }
1630   return !cs[0] && !zero.x;
1631 #endif
1632 ]])],
1633                    [ac_cv_c_const=yes],
1634                    [ac_cv_c_const=no])])
1635 if test $ac_cv_c_const = no; then
1636   AC_DEFINE(const,,
1637             [Define to empty if `const' does not conform to ANSI C.])
1639 ])# AC_C_CONST
1642 # AC_C_RESTRICT
1643 # -------------
1644 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1645 # http://autoconf-archive.cryp.to/acx_restrict.html
1647 # Determine whether the C/C++ compiler supports the "restrict" keyword
1648 # introduced in ANSI C99, or an equivalent.  Define "restrict" to the alternate
1649 # spelling, if any; these are more likely to work in both C and C++ compilers of
1650 # the same family, and in the presence of varying compiler options.  If only
1651 # plain "restrict" works, do nothing.  Here are some variants:
1652 # - GCC supports both __restrict and __restrict__
1653 # - older DEC Alpha C compilers support only __restrict
1654 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1655 # Otherwise, define "restrict" to be empty.
1656 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1657 AC_DEFUN([AC_C_RESTRICT],
1658 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1659   [ac_cv_c_restrict=no
1660    # Try the official restrict keyword, then gcc's __restrict, and
1661    # the less common variants.
1662    for ac_kw in __restrict __restrict__ _Restrict restrict; do
1663      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1664       [[typedef int * int_ptr;
1665         int foo (int_ptr $ac_kw ip) {
1666         return ip[0];
1667        }]],
1668       [[int s[1];
1669         int * $ac_kw t = s;
1670         t[0] = 0;
1671         return foo(t)]])],
1672       [ac_cv_c_restrict=$ac_kw])
1673      test "$ac_cv_c_restrict" != no && break
1674    done
1675   ])
1676  case $ac_cv_c_restrict in
1677    restrict) ;;
1678    no) AC_DEFINE(restrict,,
1679         [Define to equivalent of C99 restrict keyword, or to nothing if this
1680         is not supported.  Do not define if restrict is supported directly.]) ;;
1681    *)  AC_DEFINE_UNQUOTED(restrict, $ac_cv_c_restrict) ;;
1682  esac
1683 ])# AC_C_RESTRICT
1686 # AC_C_VOLATILE
1687 # -------------
1688 # Note that, unlike const, #defining volatile to be the empty string can
1689 # actually turn a correct program into an incorrect one, since removing
1690 # uses of volatile actually grants the compiler permission to perform
1691 # optimizations that could break the user's code.  So, do not #define
1692 # volatile away unless it is really necessary to allow the user's code
1693 # to compile cleanly.  Benign compiler failures should be tolerated.
1694 AC_DEFUN([AC_C_VOLATILE],
1695 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1696 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1697 volatile int x;
1698 int * volatile y = (int *) 0;
1699 return !x && !y;])],
1700                    [ac_cv_c_volatile=yes],
1701                    [ac_cv_c_volatile=no])])
1702 if test $ac_cv_c_volatile = no; then
1703   AC_DEFINE(volatile,,
1704             [Define to empty if the keyword `volatile' does not work.
1705              Warning: valid code using `volatile' can become incorrect
1706              without.  Disable with care.])
1708 ])# AC_C_VOLATILE
1711 # AC_C_STRINGIZE
1712 # --------------
1713 # Checks if `#' can be used to glue strings together at the CPP level.
1714 # Defines HAVE_STRINGIZE if positive.
1715 AC_DEFUN([AC_C_STRINGIZE],
1716 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1717                 [ac_cv_c_stringize],
1718 [AC_EGREP_CPP([@%:@teststring],
1719               [@%:@define x(y) #y
1721 char *s = x(teststring);],
1722               [ac_cv_c_stringize=no],
1723               [ac_cv_c_stringize=yes])])
1724 if test $ac_cv_c_stringize = yes; then
1725   AC_DEFINE(HAVE_STRINGIZE, 1,
1726             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1728 ])# AC_C_STRINGIZE
1731 # AC_C_PROTOTYPES
1732 # ---------------
1733 # Check if the C compiler supports prototypes, included if it needs
1734 # options.
1735 AC_DEFUN([AC_C_PROTOTYPES],
1736 [AC_REQUIRE([AC_PROG_CC])dnl
1737 AC_MSG_CHECKING([for function prototypes])
1738 if test "$ac_cv_prog_cc_c89" != no; then
1739   AC_MSG_RESULT([yes])
1740   AC_DEFINE(PROTOTYPES, 1,
1741             [Define to 1 if the C compiler supports function prototypes.])
1742   AC_DEFINE(__PROTOTYPES, 1,
1743             [Define like PROTOTYPES; this can be used by system headers.])
1744 else
1745   AC_MSG_RESULT([no])
1747 ])# AC_C_PROTOTYPES
1750 # AC_C_FLEXIBLE_ARRAY_MEMBER
1751 # --------------------------
1752 # Check whether the C compiler supports flexible array members.
1753 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
1755   AC_CACHE_CHECK([for flexible array members],
1756     ac_cv_c_flexmember,
1757     [AC_COMPILE_IFELSE(
1758        [AC_LANG_PROGRAM(
1759           [[#include <stdlib.h>
1760             #include <stdio.h>
1761             #include <stddef.h>
1762             struct s { int n; double d[]; };]],
1763           [[int m = getchar ();
1764             struct s *p = malloc (offsetof (struct s, d)
1765                                   + m * sizeof (double));
1766             p->d[0] = 0.0;
1767             return p->d != (double *) NULL;]])],
1768        [ac_cv_c_flexmember=yes],
1769        [ac_cv_c_flexmember=no])])
1770   if test $ac_cv_c_flexmember = yes; then
1771     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
1772       [Define to nothing if C supports flexible array members, and to
1773        1 if it does not.  That way, with a declaration like `struct s
1774        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
1775        can be used with pre-C99 compilers.
1776        When computing the size of such an object, don't use 'sizeof (struct s)'
1777        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
1778        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
1779        MSVC and with C++ compilers.])
1780   else
1781     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
1782   fi
1786 # AC_C_VARARRAYS
1787 # --------------
1788 # Check whether the C compiler supports variable-length arrays.
1789 AC_DEFUN([AC_C_VARARRAYS],
1791   AC_CACHE_CHECK([for variable-length arrays],
1792     ac_cv_c_vararrays,
1793     [AC_COMPILE_IFELSE(
1794        [AC_LANG_PROGRAM([],
1795           [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
1796        [ac_cv_c_vararrays=yes],
1797        [ac_cv_c_vararrays=no])])
1798   if test $ac_cv_c_vararrays = yes; then
1799     AC_DEFINE([HAVE_C_VARARRAYS], 1,
1800       [Define to 1 if C supports variable-length arrays.])
1801   fi
1805 # AC_C_TYPEOF
1806 # -----------
1807 # Check if the C compiler supports GCC's typeof syntax.
1808 # The test case provokes incompatibilities in the Sun C compilers
1809 # (both Solaris 8 and Solaris 10).
1810 AC_DEFUN([AC_C_TYPEOF],
1812   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1813     [ac_cv_c_typeof=no
1814      for ac_kw in typeof __typeof__ no; do
1815        test $ac_kw = no && break
1816        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1817          [[
1818            int value;
1819            typedef struct {
1820                    char a [1
1821                            + ! (($ac_kw (value))
1822                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1823                                  ? ($ac_kw (value)) - 1
1824                                  : ~ (~ ($ac_kw (value)) 0
1825                                       << sizeof ($ac_kw (value)))))]; }
1826               ac__typeof_type_;
1827            return
1828              (! ((void) ((ac__typeof_type_ *) 0), 0));
1829          ]])],
1830          [ac_cv_c_typeof=$ac_kw])
1831        test $ac_cv_c_typeof != no && break
1832      done])
1833   if test $ac_cv_c_typeof != no; then
1834     AC_DEFINE([HAVE_TYPEOF], 1,
1835       [Define to 1 if typeof works with your compiler.])
1836     if test $ac_cv_c_typeof != typeof; then
1837       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1838         [Define to __typeof__ if your compiler spells it that way.])
1839     fi
1840   fi
1844 # _AC_LANG_OPENMP
1845 # ---------------
1846 # Expands to some language dependent source code for testing the presence of
1847 # OpenMP.
1848 AC_DEFUN([_AC_LANG_OPENMP],
1849 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
1851 # _AC_LANG_OPENMP(C)
1852 # ------------------
1853 m4_define([_AC_LANG_OPENMP(C)],
1855 #ifndef _OPENMP
1856  choke me
1857 #endif
1858 #include <omp.h>
1859 int main () { return omp_get_num_threads (); }
1862 # _AC_LANG_OPENMP(C++)
1863 # --------------------
1864 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
1866 # _AC_LANG_OPENMP(Fortran 77)
1867 # ---------------------------
1868 m4_define([_AC_LANG_OPENMP(Fortran 77)],
1869 [AC_LANG_FUNC_LINK_TRY([omp_get_num_threads])])
1871 # _AC_LANG_OPENMP(Fortran)
1872 # ---------------------------
1873 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
1875 # AC_OPENMP
1876 # ---------
1877 # Check which options need to be passed to the C compiler to support OpenMP.
1878 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
1879 # options.
1880 # The options are necessary at compile time (so the #pragmas are understood)
1881 # and at link time (so the appropriate library is linked with).
1882 # This macro takes care to not produce redundant options if $CC $CFLAGS already
1883 # supports OpenMP. It also is careful to not pass options to compilers that
1884 # misinterpret them; for example, most compilers accept "-openmp" and create
1885 # an output file called 'penmp' rather than activating OpenMP support.
1886 AC_DEFUN([AC_OPENMP],
1888   OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
1889   AC_ARG_ENABLE([openmp],
1890     [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
1891   if test "$enable_openmp" != no; then
1892     AC_CACHE_CHECK([for $CC option to support OpenMP],
1893       [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
1894       [AC_LINK_IFELSE([_AC_LANG_OPENMP],
1895          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
1896          [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
1897           dnl Try these flags:
1898           dnl   GCC >= 4.2           -fopenmp
1899           dnl   SunPRO C             -xopenmp
1900           dnl   Intel C              -openmp
1901           dnl   SGI C, PGI C         -mp
1902           dnl   Tru64 Compaq C       -omp
1903           dnl   IBM C (AIX, Linux)   -qsmp=omp
1904           dnl If in this loop a compiler is passed an option that it doesn't
1905           dnl understand or that it misinterprets, the AC_LINK_IFELSE test
1906           dnl will fail (since we know that it failed without the option),
1907           dnl therefore the loop will continue searching for an option, and
1908           dnl no output file called 'penmp' or 'mp' is created.
1909           for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
1910             ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
1911             _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
1912             AC_LINK_IFELSE([_AC_LANG_OPENMP],
1913               [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
1914             _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
1915             if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
1916               break
1917             fi
1918           done])])
1919     case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
1920       "none needed" | unsupported)
1921         ;; #(
1922       *)
1923         OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
1924     esac
1925   fi
1926   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])