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