* doc/autoconf.texi (Generating Sources): AC_LANG_PROGRAMS ->
[autoconf.git] / lib / autoconf / c.m4
blobb440a6c46fb5c6fdce6cf6fc74a8c029fb2a69e6
1 # This file is part of Autoconf.                       -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 # 02110-1301, USA.
20 # As a special exception, the Free Software Foundation gives unlimited
21 # permission to copy, distribute and modify the configure scripts that
22 # are the output of Autoconf.  You need not follow the terms of the GNU
23 # General Public License when using or distributing such scripts, even
24 # though portions of the text of Autoconf appear in them.  The GNU
25 # General Public License (GPL) does govern all other use of the material
26 # that constitutes the Autoconf program.
28 # Certain portions of the Autoconf source text are designed to be copied
29 # (in certain cases, depending on the input) into the output of
30 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
31 # source text consists of comments plus executable code that decides which
32 # of the data portions to output in any given case.  We call these
33 # comments and executable code the "non-data" portions.  Autoconf never
34 # copies any of the non-data portions into its output.
36 # This special exception to the GPL applies to versions of Autoconf
37 # released by the Free Software Foundation.  When you make and
38 # distribute a modified version of Autoconf, you may extend this special
39 # exception to the GPL to apply to your modified version as well, *unless*
40 # your modified version has the potential to copy into its output some
41 # of the text that was the non-data portion of the version that you started
42 # with.  (In other words, unless your change moves or copies text from
43 # the non-data portions to the data portions.)  If your modification has
44 # such potential, you must delete any notice of this special exception
45 # to the GPL from your modified version.
47 # Written by David MacKenzie, with help from
48 # Akim Demaille, Paul Eggert,
49 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
50 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
53 # -------------------- #
54 # 1b. The C language.  #
55 # -------------------- #
58 # AC_LANG(C)
59 # ----------
60 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
61 m4_define([AC_LANG(C)],
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 # _AC_LANG_ABBREV(C)
76 # ------------------
77 m4_define([_AC_LANG_ABBREV(C)], [c])
80 # _AC_LANG_PREFIX(C)
81 # ------------------
82 m4_define([_AC_LANG_PREFIX(C)], [C])
85 # ---------------------- #
86 # 1c. The C++ language.  #
87 # ---------------------- #
90 # AC_LANG(C++)
91 # ------------
92 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
93 m4_define([AC_LANG(C++)],
94 [ac_ext=cpp
95 ac_cpp='$CXXCPP $CPPFLAGS'
96 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
97 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
98 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
102 # AC_LANG_CPLUSPLUS
103 # -----------------
104 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
107 # _AC_LANG_ABBREV(C++)
108 # --------------------
109 m4_define([_AC_LANG_ABBREV(C++)], [cxx])
112 # _AC_LANG_PREFIX(C++)
113 # --------------------
114 m4_define([_AC_LANG_PREFIX(C++)], [CXX])
118 ## ---------------------- ##
119 ## 2.Producing programs.  ##
120 ## ---------------------- ##
123 # --------------- #
124 # 2b. C sources.  #
125 # --------------- #
127 # AC_LANG_SOURCE(C)(BODY)
128 # -----------------------
129 # We can't use '#line $LINENO "configure"' here, since
130 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
131 # rejects $LINENO greater than 32767, and some configure scripts
132 # are longer than 32767 lines.
133 m4_define([AC_LANG_SOURCE(C)],
134 [/* confdefs.h.  */
135 _ACEOF
136 cat confdefs.h >>conftest.$ac_ext
137 cat >>conftest.$ac_ext <<_ACEOF
138 /* end confdefs.h.  */
139 $1])
142 # AC_LANG_PROGRAM(C)([PROLOGUE], [BODY])
143 # --------------------------------------
144 m4_define([AC_LANG_PROGRAM(C)],
146 m4_ifdef([_AC_LANG_PROGRAM_C_F77_HOOKS], [_AC_LANG_PROGRAM_C_F77_HOOKS])[]dnl
147 m4_ifdef([_AC_LANG_PROGRAM_C_FC_HOOKS], [_AC_LANG_PROGRAM_C_FC_HOOKS])[]dnl
149 main ()
151 dnl Do *not* indent the following line: there may be CPP directives.
152 dnl Don't move the `;' right after for the same reason.
154   ;
155   return 0;
159 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
160 # -----------------------------------
161 # Avoid conflicting decl of main.
162 m4_define([AC_LANG_CALL(C)],
163 [AC_LANG_PROGRAM([$1
164 m4_if([$2], [main], ,
165 [/* Override any GCC internal prototype to avoid an error.
166    Use char because int might match the return type of a GCC
167    builtin and then its argument prototype would still apply.  */
168 #ifdef __cplusplus
169 extern "C"
170 #endif
171 char $2 ();])], [return $2 ();])])
174 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
175 # ----------------------------------
176 # Don't include <ctype.h> because on OSF/1 3.0 it includes
177 # <sys/types.h> which includes <sys/select.h> which contains a
178 # prototype for select.  Similarly for bzero.
180 # This test used to merely assign f=$1 in main(), but that was
181 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
182 # presumably on the basis that there's no need to do that store if the
183 # program is about to exit.  Conversely, the AIX linker optimizes an
184 # unused external declaration that initializes f=$1.  So this test
185 # program has both an external initialization of f, and a use of f in
186 # main that affects the exit status.
188 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
189 [AC_LANG_PROGRAM(
190 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
191    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
192 #define $1 innocuous_$1
194 /* System header to define __stub macros and hopefully few prototypes,
195     which can conflict with char $1 (); below.
196     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
197     <limits.h> exists even on freestanding compilers.  */
199 #ifdef __STDC__
200 # include <limits.h>
201 #else
202 # include <assert.h>
203 #endif
205 #undef $1
207 /* Override any GCC internal prototype to avoid an error.
208    Use char because int might match the return type of a GCC
209    builtin and then its argument prototype would still apply.  */
210 #ifdef __cplusplus
211 extern "C"
212 #endif
213 char $1 ();
214 /* The GNU C library defines this for functions which it implements
215     to always fail with ENOSYS.  Some functions are actually named
216     something starting with __ and the normal name is an alias.  */
217 #if defined (__stub_$1) || defined (__stub___$1)
218 choke me
219 #endif
220 ], [return $1 ();])])
223 # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION)
224 # -------------------------------------------------
225 # Return a program that is valid if EXPRESSION is nonzero.
226 # EXPRESSION must be an integer constant expression.
227 # Be sure to use this array to avoid `unused' warnings, which are even
228 # errors with `-W error'.
229 m4_define([AC_LANG_BOOL_COMPILE_TRY(C)],
230 [AC_LANG_PROGRAM([$1], [static int test_array @<:@1 - 2 * !($2)@:>@;
231 test_array @<:@0@:>@ = 0
232 ])])
235 # AC_LANG_INT_SAVE(C)(PROLOGUE, EXPRESSION)
236 # -----------------------------------------
237 # We need `stdio.h' to open a `FILE' and `stdlib.h' for `exit'.
238 # But we include them only after the EXPRESSION has been evaluated.
239 m4_define([AC_LANG_INT_SAVE(C)],
240 [AC_LANG_PROGRAM([$1
241 static long int longval () { return $2; }
242 static unsigned long int ulongval () { return $2; }
243 @%:@include <stdio.h>
244 @%:@include <stdlib.h>],
246   FILE *f = fopen ("conftest.val", "w");
247   if (! f)
248     exit (1);
249   if (($2) < 0)
250     {
251       long int i = longval ();
252       if (i != ($2))
253         exit (1);
254       fprintf (f, "%ld\n", i);
255     }
256   else
257     {
258       unsigned long int i = ulongval ();
259       if (i != ($2))
260         exit (1);
261       fprintf (f, "%lu\n", i);
262     }
263   exit (ferror (f) || fclose (f) != 0);
264 ])])
267 # ----------------- #
268 # 2c. C++ sources.  #
269 # ----------------- #
271 # AC_LANG_SOURCE(C++)(BODY)
272 # -------------------------
273 m4_copy([AC_LANG_SOURCE(C)], [AC_LANG_SOURCE(C++)])
276 # AC_LANG_PROGRAM(C++)([PROLOGUE], [BODY])
277 # ----------------------------------------
278 m4_copy([AC_LANG_PROGRAM(C)], [AC_LANG_PROGRAM(C++)])
281 # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
282 # -------------------------------------
283 m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(C++)])
286 # AC_LANG_FUNC_LINK_TRY(C++)(FUNCTION)
287 # ------------------------------------
288 m4_copy([AC_LANG_FUNC_LINK_TRY(C)], [AC_LANG_FUNC_LINK_TRY(C++)])
291 # AC_LANG_BOOL_COMPILE_TRY(C++)(PROLOGUE, EXPRESSION)
292 # ---------------------------------------------------
293 m4_copy([AC_LANG_BOOL_COMPILE_TRY(C)], [AC_LANG_BOOL_COMPILE_TRY(C++)])
296 # AC_LANG_INT_SAVE(C++)(PROLOGUE, EXPRESSION)
297 # -------------------------------------------
298 m4_copy([AC_LANG_INT_SAVE(C)], [AC_LANG_INT_SAVE(C++)])
302 ## -------------------------------------------- ##
303 ## 3. Looking for Compilers and Preprocessors.  ##
304 ## -------------------------------------------- ##
306 # -------------------- #
307 # 3b. The C compiler.  #
308 # -------------------- #
311 # _AC_ARG_VAR_CPPFLAGS
312 # --------------------
313 # Document and register CPPFLAGS, which is used by
314 # AC_PROG_{CC, CPP, CXX, CXXCPP}.
315 AC_DEFUN([_AC_ARG_VAR_CPPFLAGS],
316 [AC_ARG_VAR([CPPFLAGS],
317             [C/C++ preprocessor flags, e.g. -I<include dir> if you have
318              headers in a nonstandard directory <include dir>])])
321 # _AC_ARG_VAR_LDFLAGS
322 # -------------------
323 # Document and register LDFLAGS, which is used by
324 # AC_PROG_{CC, CXX, F77}.
325 AC_DEFUN([_AC_ARG_VAR_LDFLAGS],
326 [AC_ARG_VAR([LDFLAGS],
327             [linker flags, e.g. -L<lib dir> if you have libraries in a
328              nonstandard directory <lib dir>])])
332 # AC_LANG_PREPROC(C)
333 # -------------------
334 # Find the C preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
335 AC_DEFUN([AC_LANG_PREPROC(C)],
336 [AC_REQUIRE([AC_PROG_CPP])])
339 # _AC_PROG_PREPROC_WORKS_IFELSE(IF-WORKS, IF-NOT)
340 # -----------------------------------------------
341 # Check if $ac_cpp is a working preprocessor that can flag absent
342 # includes either by the exit status or by warnings.
343 # Set ac_cpp_err to a non-empty value if the preprocessor failed.
344 # This macro is for all languages, not only C.
345 AC_DEFUN([_AC_PROG_PREPROC_WORKS_IFELSE],
346 [ac_preproc_ok=false
347 for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
349   # Use a header file that comes with gcc, so configuring glibc
350   # with a fresh cross-compiler works.
351   # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
352   # <limits.h> exists even on freestanding compilers.
353   # On the NeXT, cc -E runs the code through the compiler's parser,
354   # not just through cpp. "Syntax error" is here to catch this case.
355   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@ifdef __STDC__
356 @%:@ include <limits.h>
357 @%:@else
358 @%:@ include <assert.h>
359 @%:@endif
360                      Syntax error]])],
361                      [],
362                      [# Broken: fails on valid input.
363 continue])
365   # OK, works on sane cases.  Now check whether non-existent headers
366   # can be detected and how.
367   _AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@%:@include <ac_nonexistent.h>]])],
368                      [# Broken: success on invalid input.
369 continue],
370                      [# Passes both tests.
371 ac_preproc_ok=:
372 break])
374 done
375 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
376 rm -f conftest.err conftest.$ac_ext
377 AS_IF([$ac_preproc_ok], [$1], [$2])])# _AC_PROG_PREPROC_WORKS_IFELSE
380 # AC_PROG_CPP
381 # -----------
382 # Find a working C preprocessor.
383 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
384 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CC.
385 AN_MAKEVAR([CPP], [AC_PROG_CPP])
386 AN_PROGRAM([cpp], [AC_PROG_CPP])
387 AC_DEFUN([AC_PROG_CPP],
388 [AC_REQUIRE([AC_PROG_CC])dnl
389 AC_ARG_VAR([CPP],      [C preprocessor])dnl
390 _AC_ARG_VAR_CPPFLAGS()dnl
391 AC_LANG_PUSH(C)dnl
392 AC_MSG_CHECKING([how to run the C preprocessor])
393 # On Suns, sometimes $CPP names a directory.
394 if test -n "$CPP" && test -d "$CPP"; then
395   CPP=
397 if test -z "$CPP"; then
398   AC_CACHE_VAL([ac_cv_prog_CPP],
399   [dnl
400     # Double quotes because CPP needs to be expanded
401     for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
402     do
403       _AC_PROG_PREPROC_WORKS_IFELSE([break])
404     done
405     ac_cv_prog_CPP=$CPP
406   ])dnl
407   CPP=$ac_cv_prog_CPP
408 else
409   ac_cv_prog_CPP=$CPP
411 AC_MSG_RESULT([$CPP])
412 _AC_PROG_PREPROC_WORKS_IFELSE([],
413                 [AC_MSG_FAILURE([C preprocessor "$CPP" fails sanity check])])
414 AC_SUBST(CPP)dnl
415 AC_LANG_POP(C)dnl
416 ])# AC_PROG_CPP
418 # AC_PROG_CPP_WERROR
419 # ------------------
420 # Treat warnings from the preprocessor as errors.
421 AC_DEFUN([AC_PROG_CPP_WERROR],
422 [AC_REQUIRE([AC_PROG_CPP])dnl
423 ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
425 # AC_LANG_COMPILER(C)
426 # -------------------
427 # Find the C compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
428 AC_DEFUN([AC_LANG_COMPILER(C)],
429 [AC_REQUIRE([AC_PROG_CC])])
432 # ac_cv_prog_gcc
433 # --------------
434 # We used to name the cache variable this way.
435 AU_DEFUN([ac_cv_prog_gcc],
436 [ac_cv_c_compiler_gnu])
439 # AC_PROG_CC([COMPILER ...])
440 # --------------------------
441 # COMPILER ... is a space separated list of C compilers to search for.
442 # This just gives the user an opportunity to specify an alternative
443 # search list for the C compiler.
444 AN_MAKEVAR([CC],  [AC_PROG_CC])
445 AN_PROGRAM([cc],  [AC_PROG_CC])
446 AN_PROGRAM([gcc], [AC_PROG_CC])
447 AC_DEFUN([AC_PROG_CC],
448 [AC_LANG_PUSH(C)dnl
449 AC_ARG_VAR([CC],     [C compiler command])dnl
450 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
451 _AC_ARG_VAR_LDFLAGS()dnl
452 _AC_ARG_VAR_CPPFLAGS()dnl
453 m4_ifval([$1],
454       [AC_CHECK_TOOLS(CC, [$1])],
455 [AC_CHECK_TOOL(CC, gcc)
456 if test -z "$CC"; then
457   dnl Here we want:
458   dnl   AC_CHECK_TOOL(CC, cc)
459   dnl but without the check for a tool without the prefix.
460   dnl Until the check is removed from there, copy the code:
461   if test -n "$ac_tool_prefix"; then
462     AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
463   fi
465 if test -z "$CC"; then
466   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
468 if test -z "$CC"; then
469   AC_CHECK_TOOLS(CC, cl.exe)
473 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
475 # Provide some information about the compiler.
476 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
477 ac_compiler=`set X $ac_compile; echo $[2]`
478 _AC_EVAL([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
479 _AC_EVAL([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
480 _AC_EVAL([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
482 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
483 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
484 _AC_LANG_COMPILER_GNU
485 GCC=`test $ac_compiler_gnu = yes && echo yes`
486 _AC_PROG_CC_G
487 _AC_PROG_CC_C89
488 # Some people use a C++ compiler to compile C.  Since we use `exit',
489 # in C++ we need to declare it.  In case someone uses the same compiler
490 # for both compiling C and C++ we need to have the C++ compiler decide
491 # the declaration of exit, since it's the most demanding environment.
492 _AC_COMPILE_IFELSE([@%:@ifndef __cplusplus
493   choke me
494 @%:@endif],
495                    [_AC_PROG_CXX_EXIT_DECLARATION])
496 AC_LANG_POP(C)dnl
497 ])# AC_PROG_CC
500 # _AC_PROG_CC_G
501 # -------------
502 # Check whether -g works, even if CFLAGS is set, in case the package
503 # plays around with CFLAGS (such as to build both debugging and normal
504 # versions of a library), tasteless as that idea is.
505 # Don't consider -g to work if it generates warnings when plain compiles don't.
506 m4_define([_AC_PROG_CC_G],
507 [ac_test_CFLAGS=${CFLAGS+set}
508 ac_save_CFLAGS=$CFLAGS
509 AC_CACHE_CHECK(whether $CC accepts -g, ac_cv_prog_cc_g,
510   [ac_save_c_werror_flag=$ac_c_werror_flag
511    ac_c_werror_flag=yes
512    ac_cv_prog_cc_g=no
513    CFLAGS="-g"
514    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
515      [ac_cv_prog_cc_g=yes],
516      [CFLAGS=""
517       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
518         [],
519         [ac_c_werror_flag=$ac_save_c_werror_flag
520          CFLAGS="-g"
521          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
522            [ac_cv_prog_cc_g=yes])])])
523    ac_c_werror_flag=$ac_save_c_werror_flag])
524 if test "$ac_test_CFLAGS" = set; then
525   CFLAGS=$ac_save_CFLAGS
526 elif test $ac_cv_prog_cc_g = yes; then
527   if test "$GCC" = yes; then
528     CFLAGS="-g -O2"
529   else
530     CFLAGS="-g"
531   fi
532 else
533   if test "$GCC" = yes; then
534     CFLAGS="-O2"
535   else
536     CFLAGS=
537   fi
538 fi[]dnl
539 ])# _AC_PROG_CC_G
542 # AC_PROG_GCC_TRADITIONAL
543 # -----------------------
544 AN_FUNCTION([ioctl],   [AC_PROG_GCC_TRADITIONAL])
545 AC_DEFUN([AC_PROG_GCC_TRADITIONAL],
546 [if test $ac_cv_c_compiler_gnu = yes; then
547     AC_CACHE_CHECK(whether $CC needs -traditional,
548       ac_cv_prog_gcc_traditional,
549 [  ac_pattern="Autoconf.*'x'"
550   AC_EGREP_CPP($ac_pattern, [#include <sgtty.h>
551 Autoconf TIOCGETP],
552   ac_cv_prog_gcc_traditional=yes, ac_cv_prog_gcc_traditional=no)
554   if test $ac_cv_prog_gcc_traditional = no; then
555     AC_EGREP_CPP($ac_pattern, [#include <termio.h>
556 Autoconf TCGETA],
557     ac_cv_prog_gcc_traditional=yes)
558   fi])
559   if test $ac_cv_prog_gcc_traditional = yes; then
560     CC="$CC -traditional"
561   fi
563 ])# AC_PROG_GCC_TRADITIONAL
566 # AC_PROG_CC_C_O
567 # --------------
568 AC_DEFUN([AC_PROG_CC_C_O],
569 [AC_REQUIRE([AC_PROG_CC])dnl
570 if test "x$CC" != xcc; then
571   AC_MSG_CHECKING([whether $CC and cc understand -c and -o together])
572 else
573   AC_MSG_CHECKING([whether cc understands -c and -o together])
575 set dummy $CC; ac_cc=`echo $[2] |
576                       sed 's/[[^a-zA-Z0-9_]]/_/g;s/^[[0-9]]/_/'`
577 AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
578 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
579 # Make sure it works both with $CC and with simple cc.
580 # We do the test twice because some compilers refuse to overwrite an
581 # existing .o file with -o, though they will create one.
582 ac_try='$CC -c conftest.$ac_ext -o conftest.$ac_objext >&AS_MESSAGE_LOG_FD'
583 if AC_TRY_EVAL(ac_try) &&
584    test -f conftest.$ac_objext && AC_TRY_EVAL(ac_try);
585 then
586   eval ac_cv_prog_cc_${ac_cc}_c_o=yes
587   if test "x$CC" != xcc; then
588     # Test first that cc exists at all.
589     if AC_TRY_COMMAND(cc -c conftest.$ac_ext >&AS_MESSAGE_LOG_FD); then
590       ac_try='cc -c conftest.$ac_ext -o conftest.$ac_objext >&AS_MESSAGE_LOG_FD'
591       if AC_TRY_EVAL(ac_try) &&
592          test -f conftest.$ac_objext && AC_TRY_EVAL(ac_try);
593       then
594         # cc works too.
595         :
596       else
597         # cc exists but doesn't like -o.
598         eval ac_cv_prog_cc_${ac_cc}_c_o=no
599       fi
600     fi
601   fi
602 else
603   eval ac_cv_prog_cc_${ac_cc}_c_o=no
605 rm -f conftest*
606 ])dnl
607 if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" = yes"; then
608   AC_MSG_RESULT([yes])
609 else
610   AC_MSG_RESULT([no])
611   AC_DEFINE(NO_MINUS_C_MINUS_O, 1,
612            [Define to 1 if your C compiler doesn't accept -c and -o together.])
614 ])# AC_PROG_CC_C_O
617 # ---------------------- #
618 # 3c. The C++ compiler.  #
619 # ---------------------- #
622 # AC_LANG_PREPROC(C++)
623 # ---------------------
624 # Find the C++ preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
625 AC_DEFUN([AC_LANG_PREPROC(C++)],
626 [AC_REQUIRE([AC_PROG_CXXCPP])])
629 # AC_PROG_CXXCPP
630 # --------------
631 # Find a working C++ preprocessor.
632 # We shouldn't have to require AC_PROG_CC, but this is due to the concurrency
633 # between the AC_LANG_COMPILER_REQUIRE family and that of AC_PROG_CXX.
634 AC_DEFUN([AC_PROG_CXXCPP],
635 [AC_REQUIRE([AC_PROG_CXX])dnl
636 AC_ARG_VAR([CXXCPP],   [C++ preprocessor])dnl
637 _AC_ARG_VAR_CPPFLAGS()dnl
638 AC_LANG_PUSH(C++)dnl
639 AC_MSG_CHECKING([how to run the C++ preprocessor])
640 if test -z "$CXXCPP"; then
641   AC_CACHE_VAL(ac_cv_prog_CXXCPP,
642   [dnl
643     # Double quotes because CXXCPP needs to be expanded
644     for CXXCPP in "$CXX -E" "/lib/cpp"
645     do
646       _AC_PROG_PREPROC_WORKS_IFELSE([break])
647     done
648     ac_cv_prog_CXXCPP=$CXXCPP
649   ])dnl
650   CXXCPP=$ac_cv_prog_CXXCPP
651 else
652   ac_cv_prog_CXXCPP=$CXXCPP
654 AC_MSG_RESULT([$CXXCPP])
655 _AC_PROG_PREPROC_WORKS_IFELSE([],
656           [AC_MSG_FAILURE([C++ preprocessor "$CXXCPP" fails sanity check])])
657 AC_SUBST(CXXCPP)dnl
658 AC_LANG_POP(C++)dnl
659 ])# AC_PROG_CXXCPP
662 # AC_LANG_COMPILER(C++)
663 # ---------------------
664 # Find the C++ compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
665 AC_DEFUN([AC_LANG_COMPILER(C++)],
666 [AC_REQUIRE([AC_PROG_CXX])])
669 # ac_cv_prog_gxx
670 # --------------
671 # We used to name the cache variable this way.
672 AU_DEFUN([ac_cv_prog_gxx],
673 [ac_cv_cxx_compiler_gnu])
676 # AC_PROG_CXX([LIST-OF-COMPILERS])
677 # --------------------------------
678 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
679 # for (if not specified, a default list is used).  This just gives the
680 # user an opportunity to specify an alternative search list for the C++
681 # compiler.
682 # aCC   HP-UX C++ compiler much better than `CC', so test before.
683 # FCC   Fujitsu C++ compiler
684 # KCC   KAI C++ compiler
685 # RCC   Rational C++
686 # xlC_r AIX C Set++ (with support for reentrant code)
687 # xlC   AIX C Set++
688 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
689 AN_PROGRAM([CC],   [AC_PROG_CXX])
690 AN_PROGRAM([c++],  [AC_PROG_CXX])
691 AN_PROGRAM([g++],  [AC_PROG_CXX])
692 AC_DEFUN([AC_PROG_CXX],
693 [AC_LANG_PUSH(C++)dnl
694 AC_ARG_VAR([CXX],      [C++ compiler command])dnl
695 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
696 _AC_ARG_VAR_LDFLAGS()dnl
697 _AC_ARG_VAR_CPPFLAGS()dnl
698 _AC_ARG_VAR_PRECIOUS([CCC])dnl
699 if test -z "$CXX"; then
700   if test -n "$CCC"; then
701     CXX=$CCC
702   else
703     AC_CHECK_TOOLS(CXX,
704                    [m4_default([$1],
705                                [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
706                    g++)
707   fi
709 # Provide some information about the compiler.
710 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
711 ac_compiler=`set X $ac_compile; echo $[2]`
712 _AC_EVAL([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
713 _AC_EVAL([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
714 _AC_EVAL([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
716 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
717 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
718 _AC_LANG_COMPILER_GNU
719 GXX=`test $ac_compiler_gnu = yes && echo yes`
720 _AC_PROG_CXX_G
721 _AC_PROG_CXX_EXIT_DECLARATION
722 AC_LANG_POP(C++)dnl
723 ])# AC_PROG_CXX
726 # _AC_PROG_CXX_G
727 # --------------
728 # Check whether -g works, even if CXXFLAGS is set, in case the package
729 # plays around with CXXFLAGS (such as to build both debugging and
730 # normal versions of a library), tasteless as that idea is.
731 # Don't consider -g to work if it generates warnings when plain compiles don't.
732 m4_define([_AC_PROG_CXX_G],
733 [ac_test_CXXFLAGS=${CXXFLAGS+set}
734 ac_save_CXXFLAGS=$CXXFLAGS
735 AC_CACHE_CHECK(whether $CXX accepts -g, ac_cv_prog_cxx_g,
736   [ac_save_cxx_werror_flag=$ac_cxx_werror_flag
737    ac_cxx_werror_flag=yes
738    ac_cv_prog_cxx_g=no
739    CXXFLAGS="-g"
740    _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
741      [ac_cv_prog_cxx_g=yes],
742      [CXXFLAGS=""
743       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
744         [],
745         [ac_cxx_werror_flag=$ac_save_cxx_werror_flag
746          CXXFLAGS="-g"
747          _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
748            [ac_cv_prog_cxx_g=yes])])])
749    ac_cxx_werror_flag=$ac_save_cxx_werror_flag])
750 if test "$ac_test_CXXFLAGS" = set; then
751   CXXFLAGS=$ac_save_CXXFLAGS
752 elif test $ac_cv_prog_cxx_g = yes; then
753   if test "$GXX" = yes; then
754     CXXFLAGS="-g -O2"
755   else
756     CXXFLAGS="-g"
757   fi
758 else
759   if test "$GXX" = yes; then
760     CXXFLAGS="-O2"
761   else
762     CXXFLAGS=
763   fi
764 fi[]dnl
765 ])# _AC_PROG_CXX_G
768 # _AC_PROG_CXX_EXIT_DECLARATION
769 # -----------------------------
770 # If <stdlib.h> doesn't already provide a valid prototype for exit,
771 # determine the appropriate prototype and put it in confdefs.h.
772 # This macro is run only when testing a C++ compiler, but it generates
773 # a prototype that is also appropriate for C compilers in order to
774 # support a mixed C/C++ configuration environment.
775 # We don't need to worry about this for C, since we include <stdlib.h>
776 # if it is available, and that method works for all C compilers.
777 m4_define([_AC_PROG_CXX_EXIT_DECLARATION],
778 [for ac_declaration in \
779    '' \
780    'extern "C" void std::exit (int) throw (); using std::exit;' \
781    'extern "C" void std::exit (int); using std::exit;' \
782    'extern "C" void exit (int) throw ();' \
783    'extern "C" void exit (int);' \
784    'void exit (int);'
786   _AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$ac_declaration
787 @%:@include <stdlib.h>],
788                                       [exit (42);])],
789                      [],
790                      [continue])
791   _AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$ac_declaration],
792                                       [exit (42);])],
793                      [break])
794 done
795 rm -f conftest*
796 if test -n "$ac_declaration"; then
797   echo '#ifdef __cplusplus' >>confdefs.h
798   echo $ac_declaration      >>confdefs.h
799   echo '#endif'             >>confdefs.h
801 ])# _AC_PROG_CXX_EXIT_DECLARATION
808 ## ------------------------------- ##
809 ## 4. Compilers' characteristics.  ##
810 ## ------------------------------- ##
813 # -------------------------------- #
814 # 4b. C compiler characteristics.  #
815 # -------------------------------- #
817 # _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
818 # ----------------------------------------------------------------
819 # If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
820 # to add an option to output variable CC to make it so.  This macro
821 # tries various options that select ANSI C89 on some system or
822 # another.  It considers the compiler to be in ANSI C89 mode if it
823 # handles function prototypes correctly.
824 AC_DEFUN([_AC_PROG_CC_C89],
825 [_AC_C_STD_TRY([c89],
826 [[#include <stdarg.h>
827 #include <stdio.h>
828 #include <sys/types.h>
829 #include <sys/stat.h>
830 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
831 struct buf { int x; };
832 FILE * (*rcsopen) (struct buf *, struct stat *, int);
833 static char *e (p, i)
834      char **p;
835      int i;
837   return p[i];
839 static char *f (char * (*g) (char **, int), char **p, ...)
841   char *s;
842   va_list v;
843   va_start (v,p);
844   s = g (p, va_arg (v,int));
845   va_end (v);
846   return s;
849 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
850    function prototypes and stuff, but not '\xHH' hex character constants.
851    These don't provoke an error unfortunately, instead are silently treated
852    as 'x'.  The following induces an error, until -std is added to get
853    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
854    array size at least.  It's necessary to write '\x00'==0 to get something
855    that's true only with -std.  */
856 int osf4_cc_array ['\x00' == 0 ? 1 : -1];
858 int test (int i, double x);
859 struct s1 {int (*f) (int a);};
860 struct s2 {int (*f) (double a);};
861 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
862 int argc;
863 char **argv;]],
864 [[return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];]],
865 dnl Don't try gcc -ansi; that turns off useful extensions and
866 dnl breaks some systems' header files.
867 dnl AIX circa 2003      -qlanglvl=extc89
868 dnl old AIX             -qlanglvl=ansi
869 dnl Ultrix, OSF/1, Tru64        -std
870 dnl HP-UX 10.20 and later       -Ae
871 dnl HP-UX older versions        -Aa -D_HPUX_SOURCE
872 dnl SVR4                        -Xc -D__EXTENSIONS__
873 [-qlanglvl=extc89 -qlanglvl=ansi -std \
874         -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
875 ])# _AC_PROG_CC_C89
878 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
879 #               ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
880 # --------------------------------------------------------------
881 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
882 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
883 # try again with each compiler option in the space-separated OPTION-LIST; if one
884 # helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
885 # else ACTION-IF-UNAVAILABLE.
886 AC_DEFUN([_AC_C_STD_TRY],
887 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
888 AC_CACHE_VAL(ac_cv_prog_cc_$1,
889 [ac_cv_prog_cc_$1=no
890 ac_save_CC=$CC
891 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
892 for ac_arg in '' $4
894   CC="$ac_save_CC $ac_arg"
895   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
896   test "x$ac_cv_prog_cc_$1" != "xno" && break
897 done
898 rm -f conftest.$ac_ext
899 CC=$ac_save_CC
900 ])# AC_CACHE_VAL
901 case "x$ac_cv_prog_cc_$1" in
902   x)
903     AC_MSG_RESULT([none needed]) ;;
904   xno)
905     AC_MSG_RESULT([unsupported]) ;;
906   *)
907     CC="$CC $ac_cv_prog_cc_$1"
908     AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
909 esac
910 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
911 ])# _AC_C_STD_TRY
914 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
915 # ----------------------------------------------------------------
916 # If the C compiler is not in ISO C99 mode by default, try to add an
917 # option to output variable CC to make it so.  This macro tries
918 # various options that select ISO C99 on some system or another.  It
919 # considers the compiler to be in ISO C99 mode if it handles mixed
920 # code and declarations, _Bool, inline and restrict.
921 AC_DEFUN([_AC_PROG_CC_C99],
922 [_AC_C_STD_TRY([c99],
923 [[#include <stdarg.h>
924 #include <stdbool.h>
925 #include <stdlib.h>
926 #include <wchar.h>
927 #include <stdio.h>
929 struct incomplete_array
931   int datasize;
932   double data[];
935 struct named_init {
936   int number;
937   const wchar_t *name;
938   double average;
941 static inline int
942 test_restrict(const char *restrict text)
944   // See if C++-style comments work.
945   // Iterate through items via the restricted pointer.
946   // Also check for declarations in for loops.
947   for (unsigned int i = 0; *(text+i) != '\0'; ++i)
948     continue;
949   return 0;
952 // Check varargs and va_copy work.
953 static void
954 test_varargs(const char *format, ...)
956   va_list args;
957   va_start(args, format);
958   va_list args_copy;
959   va_copy(args_copy, args);
961   const char *str;
962   int number;
963   float fnumber;
965   while (*format)
966     {
967       switch (*format++)
968         {
969         case 's': // string
970           str = va_arg(args_copy, const char *);
971           break;
972         case 'd': // int
973           number = va_arg(args_copy, int);
974           break;
975         case 'f': // float
976           fnumber = (float) va_arg(args_copy, double);
977           break;
978         default:
979           break;
980         }
981     }
982   va_end(args_copy);
983   va_end(args);
987   // Check bool and long long datatypes.
988   _Bool success = false;
989   long long int bignum = -1234567890LL;
990   unsigned long long int ubignum = 1234567890uLL;
992   // Check restrict.
993   if (test_restrict("String literal") != 0)
994     success = true;
995   char *restrict newvar = "Another string";
997   // Check varargs.
998   test_varargs("s, d' f .", "string", 65, 34.234);
1000   // Check incomplete arrays work.
1001   struct incomplete_array *ia =
1002     malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
1003   ia->datasize = 10;
1004   for (int i = 0; i < ia->datasize; ++i)
1005     ia->data[i] = (double) i * 1.234;
1007   // Check named initialisers.
1008   struct named_init ni = {
1009     .number = 34,
1010     .name = L"Test wide string",
1011     .average = 543.34343,
1012   };
1014   ni.number = 58;
1016   int dynamic_array[ni.number];
1017   dynamic_array[43] = 543;
1019 dnl Try
1020 dnl GCC         -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
1021 dnl AIX         -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
1022 dnl Intel ICC   -c99
1023 dnl IRIX        -c99
1024 dnl Solaris     (unused because it causes the compiler to assume C99 semantics for
1025 dnl             library functions, and this is invalid before Solaris 10: -xc99)
1026 dnl Tru64       -c99
1027 dnl with extended modes being tried first.
1028 [[-std=gnu99 -c99 -qlanglvl=extc99]], [$1], [$2])[]dnl
1029 ])# _AC_PROG_CC_C99
1032 # AC_PROG_CC_C89
1033 # --------------
1034 AC_DEFUN([AC_PROG_CC_C89],
1035 [ AC_REQUIRE([AC_PROG_CC])dnl
1036   _AC_PROG_CC_C89
1040 # AC_PROG_CC_C99
1041 # --------------
1042 AC_DEFUN([AC_PROG_CC_C99],
1043 [ AC_REQUIRE([AC_PROG_CC])dnl
1044   _AC_PROG_CC_C99
1048 # AC_PROG_CC_STDC
1049 # ---------------
1050 AC_DEFUN([AC_PROG_CC_STDC],
1051 [ AC_REQUIRE([AC_PROG_CC])dnl
1052   _AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
1053                   [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89], [no])])dnl
1054   AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
1055   AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
1056   case "x$ac_cv_prog_cc_stdc" in
1057     xno)
1058       AC_MSG_RESULT([unsupported])
1059       ;;
1060     *)
1061       if test "x$ac_cv_prog_cc_stdc" = x; then
1062         AC_MSG_RESULT([none needed])
1063       else
1064         AC_MSG_RESULT([$ac_cv_prog_cc_stdc])
1065       fi
1066       ;;
1067   esac
1071 # AC_C_BACKSLASH_A
1072 # ----------------
1073 AC_DEFUN([AC_C_BACKSLASH_A],
1075   AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
1076    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1077      [[
1078 #if '\a' == 'a'
1079       syntax error;
1080 #endif
1081       char buf['\a' == 'a' ? -1 : 1];
1082       buf[0] = '\a';
1083       return buf[0] != "\a"[0];
1084      ]])],
1085      [ac_cv_c_backslash_a=yes],
1086      [ac_cv_c_backslash_a=no])])
1087   if test $ac_cv_c_backslash_a = yes; then
1088     AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
1089       [Define if backslash-a works in C strings.])
1090   fi
1094 # AC_C_CROSS
1095 # ----------
1096 # Has been merged into AC_PROG_CC.
1097 AU_DEFUN([AC_C_CROSS], [])
1100 # AC_C_CHAR_UNSIGNED
1101 # ------------------
1102 AC_DEFUN([AC_C_CHAR_UNSIGNED],
1103 [AH_VERBATIM([__CHAR_UNSIGNED__],
1104 [/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
1105 #ifndef __CHAR_UNSIGNED__
1106 # undef __CHAR_UNSIGNED__
1107 #endif])dnl
1108 AC_CACHE_CHECK(whether char is unsigned, ac_cv_c_char_unsigned,
1109 [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([])],
1110                                              [((char) -1) < 0])],
1111                    ac_cv_c_char_unsigned=no, ac_cv_c_char_unsigned=yes)])
1112 if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
1113   AC_DEFINE(__CHAR_UNSIGNED__)
1115 ])# AC_C_CHAR_UNSIGNED
1118 # AC_C_LONG_DOUBLE
1119 # ----------------
1120 AC_DEFUN([AC_C_LONG_DOUBLE],
1121 [AC_CACHE_CHECK(
1122    [for working long double with more range or precision than double],
1123    [ac_cv_c_long_double],
1124    [AC_COMPILE_IFELSE(
1125       [AC_LANG_BOOL_COMPILE_TRY(
1126          [[#include <float.h>
1127            long double const a[] =
1128              {
1129                 0.0L, DBL_MIN, DBL_MAX, DBL_EPSILON,
1130                 LDBL_MIN, LDBL_MAX, LDBL_EPSILON
1131              };
1132            long double
1133            f (long double x)
1134            {
1135               return ((x + (unsigned long int) 10) * (-1 / x) + a[0]
1136                        + (x ? f (x) : 'c'));
1137            }
1138          ]],
1139          [[(0 < ((DBL_MAX_EXP < LDBL_MAX_EXP)
1140                   + (DBL_MANT_DIG < LDBL_MANT_DIG)
1141                   - (LDBL_MAX_EXP < DBL_MAX_EXP)
1142                   - (LDBL_MANT_DIG < DBL_MANT_DIG)))
1143            && (int) LDBL_EPSILON == 0
1144          ]])],
1145       ac_cv_c_long_double=yes,
1146       ac_cv_c_long_double=no)])
1147 if test $ac_cv_c_long_double = yes; then
1148   AC_DEFINE(HAVE_LONG_DOUBLE, 1,
1149             [Define to 1 if long double works and has more range or precision than double.])
1151 ])# AC_C_LONG_DOUBLE
1154 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN])
1155 # -------------------------------------------------------------------------
1156 AC_DEFUN([AC_C_BIGENDIAN],
1157 [AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian,
1158 [# See if sys/param.h defines the BYTE_ORDER macro.
1159 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1160 #include <sys/param.h>
1162 [#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
1163  bogus endian macros
1164 #endif
1165 ])],
1166 [# It does; now see whether it defined to BIG_ENDIAN or not.
1167 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1168 #include <sys/param.h>
1169 ], [#if BYTE_ORDER != BIG_ENDIAN
1170  not big endian
1171 #endif
1172 ])], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=no])],
1173 [# It does not; compile a test program.
1174 AC_RUN_IFELSE(
1175 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
1176   /* Are we little or big endian?  From Harbison&Steele.  */
1177   union
1178   {
1179     long int l;
1180     char c[sizeof (long int)];
1181   } u;
1182   u.l = 1;
1183   exit (u.c[sizeof (long int) - 1] == 1);
1184 ]])],
1185               [ac_cv_c_bigendian=no],
1186               [ac_cv_c_bigendian=yes],
1187 [# try to guess the endianness by grepping values into an object file
1188   ac_cv_c_bigendian=unknown
1189   AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1190 [[short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
1191 short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
1192 void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; }
1193 short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
1194 short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
1195 void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; }]],
1196 [[ _ascii (); _ebcdic (); ]])],
1197 [if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then
1198   ac_cv_c_bigendian=yes
1200 if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
1201   if test "$ac_cv_c_bigendian" = unknown; then
1202     ac_cv_c_bigendian=no
1203   else
1204     # finding both strings is unlikely to happen, but who knows?
1205     ac_cv_c_bigendian=unknown
1206   fi
1207 fi])])])])
1208 case $ac_cv_c_bigendian in
1209   yes)
1210     m4_default([$1],
1211       [AC_DEFINE([WORDS_BIGENDIAN], 1,
1212         [Define to 1 if your processor stores words with the most significant
1213          byte first (like Motorola and SPARC, unlike Intel and VAX).])]) ;;
1214   no)
1215     $2 ;;
1216   *)
1217     m4_default([$3],
1218       [AC_MSG_ERROR([unknown endianness
1219 presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
1220 esac
1221 ])# AC_C_BIGENDIAN
1224 # AC_C_INLINE
1225 # -----------
1226 # Do nothing if the compiler accepts the inline keyword.
1227 # Otherwise define inline to __inline__ or __inline if one of those work,
1228 # otherwise define inline to be empty.
1230 # HP C version B.11.11.04 doesn't allow a typedef as the return value for an
1231 # inline function, only builtin types.
1233 AN_IDENTIFIER([inline], [AC_C_INLINE])
1234 AC_DEFUN([AC_C_INLINE],
1235 [AC_CACHE_CHECK([for inline], ac_cv_c_inline,
1236 [ac_cv_c_inline=no
1237 for ac_kw in inline __inline__ __inline; do
1238   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1239 [#ifndef __cplusplus
1240 typedef int foo_t;
1241 static $ac_kw foo_t static_foo () {return 0; }
1242 $ac_kw foo_t foo () {return 0; }
1243 #endif
1244 ])],
1245                     [ac_cv_c_inline=$ac_kw; break])
1246 done
1248 AH_VERBATIM([inline],
1249 [/* Define to `__inline__' or `__inline' if that's what the C compiler
1250    calls it, or to nothing if 'inline' is not supported under any name.  */
1251 #ifndef __cplusplus
1252 #undef inline
1253 #endif])
1254 case $ac_cv_c_inline in
1255   inline | yes) ;;
1256   *)
1257     case $ac_cv_c_inline in
1258       no) ac_val=;;
1259       *) ac_val=$ac_cv_c_inline;;
1260     esac
1261     cat >>confdefs.h <<_ACEOF
1262 #ifndef __cplusplus
1263 #define inline $ac_val
1264 #endif
1265 _ACEOF
1266     ;;
1267 esac
1268 ])# AC_C_INLINE
1271 # AC_C_CONST
1272 # ----------
1273 AN_IDENTIFIER([const],  [AC_C_CONST])
1274 AC_DEFUN([AC_C_CONST],
1275 [AC_CACHE_CHECK([for an ANSI C-conforming const], ac_cv_c_const,
1276 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1277 [[/* FIXME: Include the comments suggested by Paul. */
1278 #ifndef __cplusplus
1279   /* Ultrix mips cc rejects this.  */
1280   typedef int charset[2];
1281   const charset x;
1282   /* SunOS 4.1.1 cc rejects this.  */
1283   char const *const *ccp;
1284   char **p;
1285   /* NEC SVR4.0.2 mips cc rejects this.  */
1286   struct point {int x, y;};
1287   static struct point const zero = {0,0};
1288   /* AIX XL C 1.02.0.0 rejects this.
1289      It does not let you subtract one const X* pointer from another in
1290      an arm of an if-expression whose if-part is not a constant
1291      expression */
1292   const char *g = "string";
1293   ccp = &g + (g ? g-g : 0);
1294   /* HPUX 7.0 cc rejects these. */
1295   ++ccp;
1296   p = (char**) ccp;
1297   ccp = (char const *const *) p;
1298   { /* SCO 3.2v4 cc rejects this.  */
1299     char *t;
1300     char const *s = 0 ? (char *) 0 : (char const *) 0;
1302     *t++ = 0;
1303   }
1304   { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
1305     int x[] = {25, 17};
1306     const int *foo = &x[0];
1307     ++foo;
1308   }
1309   { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
1310     typedef const int *iptr;
1311     iptr p = 0;
1312     ++p;
1313   }
1314   { /* AIX XL C 1.02.0.0 rejects this saying
1315        "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
1316     struct s { int j; const int *ap[3]; };
1317     struct s *b; b->j = 5;
1318   }
1319   { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
1320     const int foo = 10;
1321   }
1322 #endif
1323 ]])],
1324                    [ac_cv_c_const=yes],
1325                    [ac_cv_c_const=no])])
1326 if test $ac_cv_c_const = no; then
1327   AC_DEFINE(const,,
1328             [Define to empty if `const' does not conform to ANSI C.])
1330 ])# AC_C_CONST
1333 # AC_C_RESTRICT
1334 # -------------
1335 # based on acx_restrict.m4, from the GNU Autoconf Macro Archive at:
1336 # http://www.gnu.org/software/ac-archive/htmldoc/acx_restrict.html
1338 # Determine whether the C/C++ compiler supports the "restrict" keyword
1339 # introduced in ANSI C99, or an equivalent.  Do nothing if the compiler
1340 # accepts it.  Otherwise, if the compiler supports an equivalent,
1341 # define "restrict" to be that.  Here are some variants:
1342 # - GCC supports both __restrict and __restrict__
1343 # - older DEC Alpha C compilers support only __restrict
1344 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
1345 # Otherwise, define "restrict" to be empty.
1346 AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
1347 AC_DEFUN([AC_C_RESTRICT],
1348 [AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
1349   [ac_cv_c_restrict=no
1350    # Try the official restrict keyword, then gcc's __restrict, and
1351    # the less common variants.
1352    for ac_kw in restrict __restrict __restrict__ _Restrict; do
1353      AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1354       [float * $ac_kw x;])],
1355       [ac_cv_c_restrict=$ac_kw; break])
1356    done
1357   ])
1358  case $ac_cv_c_restrict in
1359    restrict) ;;
1360    no) AC_DEFINE(restrict,,
1361         [Define to equivalent of C99 restrict keyword, or to nothing if this
1362         is not supported.  Do not define if restrict is supported directly.]) ;;
1363    *)  AC_DEFINE_UNQUOTED(restrict, $ac_cv_c_restrict) ;;
1364  esac
1365 ])# AC_C_RESTRICT
1368 # AC_C_VOLATILE
1369 # -------------
1370 # Note that, unlike const, #defining volatile to be the empty string can
1371 # actually turn a correct program into an incorrect one, since removing
1372 # uses of volatile actually grants the compiler permission to perform
1373 # optimizations that could break the user's code.  So, do not #define
1374 # volatile away unless it is really necessary to allow the user's code
1375 # to compile cleanly.  Benign compiler failures should be tolerated.
1376 AN_IDENTIFIER([volatile], [AC_C_VOLATILE])
1377 AC_DEFUN([AC_C_VOLATILE],
1378 [AC_CACHE_CHECK([for working volatile], ac_cv_c_volatile,
1379 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1380 volatile int x;
1381 int * volatile y;])],
1382                    [ac_cv_c_volatile=yes],
1383                    [ac_cv_c_volatile=no])])
1384 if test $ac_cv_c_volatile = no; then
1385   AC_DEFINE(volatile,,
1386             [Define to empty if the keyword `volatile' does not work.
1387              Warning: valid code using `volatile' can become incorrect
1388              without.  Disable with care.])
1390 ])# AC_C_VOLATILE
1393 # AC_C_STRINGIZE
1394 # --------------
1395 # Checks if `#' can be used to glue strings together at the CPP level.
1396 # Defines HAVE_STRINGIZE if positive.
1397 AC_DEFUN([AC_C_STRINGIZE],
1398 [AC_CACHE_CHECK([for preprocessor stringizing operator],
1399                 [ac_cv_c_stringize],
1400 [AC_EGREP_CPP([@%:@teststring],
1401               [@%:@define x(y) #y
1403 char *s = x(teststring);],
1404               [ac_cv_c_stringize=no],
1405               [ac_cv_c_stringize=yes])])
1406 if test $ac_cv_c_stringize = yes; then
1407   AC_DEFINE(HAVE_STRINGIZE, 1,
1408             [Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
1410 ])# AC_C_STRINGIZE
1413 # AC_C_PROTOTYPES
1414 # ---------------
1415 # Check if the C compiler supports prototypes, included if it needs
1416 # options.
1417 AC_DEFUN([AC_C_PROTOTYPES],
1418 [AC_REQUIRE([AC_PROG_CC])dnl
1419 AC_MSG_CHECKING([for function prototypes])
1420 if test "$ac_cv_prog_cc_c89" != no; then
1421   AC_MSG_RESULT([yes])
1422   AC_DEFINE(PROTOTYPES, 1,
1423             [Define to 1 if the C compiler supports function prototypes.])
1424   AC_DEFINE(__PROTOTYPES, 1,
1425             [Define like PROTOTYPES; this can be used by system headers.])
1426 else
1427   AC_MSG_RESULT([no])
1429 ])# AC_C_PROTOTYPES
1432 # AC_C_TYPEOF
1433 # -----------
1434 # Check if the C compiler supports GCC's typeof syntax.
1435 # The test case provokes incompatibilities in the Sun C compilers
1436 # (both Solaris 8 and Solaris 10).
1437 AC_DEFUN([AC_C_TYPEOF],
1439   AC_CACHE_CHECK([for typeof syntax and keyword spelling], ac_cv_c_typeof,
1440     [ac_cv_c_typeof=no
1441      for ac_kw in typeof __typeof__ no; do
1442        test $ac_kw = no && break
1443        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
1444          [[
1445            int value;
1446            return
1447              (! ((void)
1448                  ((struct {
1449                    char a [1
1450                            + ! (($ac_kw (value))
1451                                 (($ac_kw (value)) 0 < ($ac_kw (value)) -1
1452                                  ? ($ac_kw (value)) - 1
1453                                  : ~ (~ ($ac_kw (value)) 0
1454                                       << sizeof ($ac_kw (value)))))]; } *)
1455                   0),
1456                  0));
1457          ]])],
1458          [ac_cv_c_typeof=$ac_kw])
1459        test $ac_cv_c_typeof != no && break
1460      done])
1461   if test $ac_cv_c_typeof != no; then
1462     AC_DEFINE([HAVE_TYPEOF], 1,
1463       [Define to 1 if typeof works with your compiler.])
1464     if test $ac_cv_c_typeof != typeof; then
1465       AC_DEFINE_UNQUOTED([typeof], [$ac_cv_c_typeof],
1466         [Define to __typeof__ if your compiler spells it that way.])
1467     fi
1468   fi