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