1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Programming languages support.
3 # Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 Free Software
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # As a special exception, the Free Software Foundation gives unlimited
20 # permission to copy, distribute and modify the configure scripts that
21 # are the output of Autoconf. You need not follow the terms of the GNU
22 # General Public License when using or distributing such scripts, even
23 # though portions of the text of Autoconf appear in them. The GNU
24 # General Public License (GPL) does govern all other use of the material
25 # that constitutes the Autoconf program.
27 # Certain portions of the Autoconf source text are designed to be copied
28 # (in certain cases, depending on the input) into the output of
29 # Autoconf. We call these the "data" portions. The rest of the Autoconf
30 # source text consists of comments plus executable code that decides which
31 # of the data portions to output in any given case. We call these
32 # comments and executable code the "non-data" portions. Autoconf never
33 # copies any of the non-data portions into its output.
35 # This special exception to the GPL applies to versions of Autoconf
36 # released by the Free Software Foundation. When you make and
37 # distribute a modified version of Autoconf, you may extend this special
38 # exception to the GPL to apply to your modified version as well, *unless*
39 # your modified version has the potential to copy into its output some
40 # of the text that was the non-data portion of the version that you started
41 # with. (In other words, unless your change moves or copies text from
42 # the non-data portions to the data portions.) If your modification has
43 # such potential, you must delete any notice of this special exception
44 # to the GPL from your modified version.
46 # Written by David MacKenzie, with help from
47 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
48 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
53 # 1. Language selection
54 # and routines to produce programs in a given language.
56 # 2. Producing programs in a given language.
58 # 3. Looking for a compiler
59 # And possibly the associated preprocessor.
61 # 3a. Computing EXEEXT and OBJEXT.
63 # 4. Compilers' characteristics.
67 ## ----------------------- ##
68 ## 1. Language selection. ##
69 ## ----------------------- ##
72 # AC_LANG_CASE(LANG1, IF-LANG1, LANG2, IF-LANG2, ..., DEFAULT)
73 # ------------------------------------------------------------
74 # Expand into IF-LANG1 if the current language is LANG1 etc. else
76 m4_define([AC_LANG_CASE],
77 [m4_case(_AC_LANG, $@)])
80 # _AC_LANG_DISPATCH(MACRO, LANG, ARGS)
81 # ------------------------------------
82 # Call the specialization of MACRO for LANG with ARGS. Complain if
84 m4_define([_AC_LANG_DISPATCH],
86 [m4_indir([$1($2)], m4_shiftn(2, $@))],
87 [AC_FATAL([$1: unknown language: $2])])])
90 # _AC_LANG_SET(OLD, NEW)
91 # ----------------------
92 # Output the shell code needed to switch from OLD language to NEW language.
93 # Do not try to optimize like this:
95 # m4_defun([_AC_LANG_SET],
96 # [m4_if([$1], [$2], [],
97 # [_AC_LANG_DISPATCH([AC_LANG], [$2])])])
99 # as it can introduce differences between the sh-current language and the
100 # m4-current-language when m4_require is used. Something more subtle
101 # might be possible, but at least for the time being, play it safe.
102 m4_defun([_AC_LANG_SET],
103 [_AC_LANG_DISPATCH([AC_LANG], [$2])])
108 # Set the current language to LANG.
110 [_AC_LANG_SET(m4_ifdef([_AC_LANG], [m4_defn([_AC_LANG])]),
112 m4_define([_AC_LANG], [$1])])
117 # Save the current language, and use LANG.
118 m4_defun([AC_LANG_PUSH],
119 [_AC_LANG_SET(m4_ifdef([_AC_LANG], [m4_defn([_AC_LANG])]),
121 m4_pushdef([_AC_LANG], [$1])])
124 # AC_LANG_POP([LANG])
125 # -------------------
126 # If given, check that the current language is LANG, and restore the
128 m4_defun([AC_LANG_POP],
130 [m4_if([$1], m4_defn([_AC_LANG]), [],
131 [m4_fatal([$0($1): unexpected current language: ]m4_defn([_AC_LANG]))])])dnl
132 m4_pushdef([$0 OLD], m4_defn([_AC_LANG]))dnl
133 m4_popdef([_AC_LANG])dnl
134 _AC_LANG_SET(m4_defn([$0 OLD]), m4_defn([_AC_LANG]))dnl
135 m4_popdef([$0 OLD])dnl
141 # Save the current language, but don't change language.
142 AU_DEFUN([AC_LANG_SAVE],
144 [Instead of using `AC_LANG', `AC_LANG_SAVE', and `AC_LANG_RESTORE',
145 you should use `AC_LANG_PUSH' and `AC_LANG_POP'.])
146 AC_DEFUN([AC_LANG_SAVE],
147 [m4_pushdef([_AC_LANG], _AC_LANG)dnl
148 AC_DIAGNOSE([obsolete], [The macro `AC_LANG_SAVE' is obsolete.
149 You should run autoupdate.])])
154 # Restore the current language from the stack.
155 AU_DEFUN([AC_LANG_RESTORE], [AC_LANG_POP($@)])
160 # Return a short signature of _AC_LANG which can be used in shell
161 # variable names, or in M4 macro names.
162 m4_defun([_AC_LANG_ABBREV],
163 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
168 # Return a short (upper case) signature of _AC_LANG that is used to
169 # prefix environment variables like FLAGS.
170 m4_defun([_AC_LANG_PREFIX],
171 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
174 # AC_LANG_ASSERT(LANG)
175 # --------------------
176 # Current language must be LANG.
177 m4_defun([AC_LANG_ASSERT],
178 [m4_if(_AC_LANG, $1, [],
179 [m4_fatal([$0: current language is not $1: ] _AC_LANG)])])
183 ## ----------------------- ##
184 ## 2. Producing programs. ##
185 ## ----------------------- ##
188 # AC_LANG_CONFTEST(BODY)
189 # ----------------------
190 # Save the BODY in `conftest.$ac_ext'. Add a trailing new line.
191 AC_DEFUN([AC_LANG_CONFTEST],
192 [cat >conftest.$ac_ext <<_ACEOF
197 # AC_LANG_SOURCE(BODY)
198 # --------------------
199 # Produce a valid source for the current language, which includes the
200 # BODY, and as much as possible `confdefs.h'.
201 AC_DEFUN([AC_LANG_SOURCE],
202 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
205 # AC_LANG_PROGRAM([PROLOGUE], [BODY])
206 # -----------------------------------
207 # Produce a valid source for the current language. Prepend the
208 # PROLOGUE (typically CPP directives and/or declarations) to an
209 # execution the BODY (typically glued inside the `main' function, or
211 AC_DEFUN([AC_LANG_PROGRAM],
212 [AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])
215 # AC_LANG_CALL(PROLOGUE, FUNCTION)
216 # --------------------------------
218 AC_DEFUN([AC_LANG_CALL],
219 [m4_ifval([$2], [], [m4_warn([syntax], [$0: no function given])])dnl
220 _AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
223 # AC_LANG_FUNC_LINK_TRY(FUNCTION)
224 # -------------------------------
225 # Produce a source which links correctly iff the FUNCTION exists.
226 AC_DEFUN([AC_LANG_FUNC_LINK_TRY],
227 [m4_ifval([$1], [], [m4_warn([syntax], [$0: no function given])])dnl
228 _AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
231 # AC_LANG_BOOL_COMPILE_TRY(PROLOGUE, EXPRESSION)
232 # ----------------------------------------------
233 # Produce a program that compiles with success iff the boolean EXPRESSION
234 # evaluates to true at compile time.
235 AC_DEFUN([AC_LANG_BOOL_COMPILE_TRY],
236 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
239 # AC_LANG_INT_SAVE(PROLOGUE, EXPRESSION)
240 # --------------------------------------
241 # Produce a program that saves the runtime evaluation of the integer
242 # EXPRESSION into `conftest.val'.
243 AC_DEFUN([AC_LANG_INT_SAVE],
244 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
248 ## -------------------------------------------- ##
249 ## 3. Looking for Compilers and Preprocessors. ##
250 ## -------------------------------------------- ##
255 # Find a compiler for the current LANG. Be sure to be run before
258 # Note that because we might AC_REQUIRE `AC_LANG_COMPILER(C)' for
259 # instance, the latter must be AC_DEFUN'd, not just define'd.
260 m4_define([AC_LANG_COMPILER],
261 [AC_BEFORE([AC_LANG_COMPILER(]_AC_LANG[)],
262 [AC_LANG_PREPROC(]_AC_LANG[)])dnl
263 _AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
266 # AC_LANG_COMPILER_REQUIRE
267 # ------------------------
268 # Ensure we have a compiler for the current LANG.
269 AC_DEFUN([AC_LANG_COMPILER_REQUIRE],
270 [m4_require([AC_LANG_COMPILER(]_AC_LANG[)],
271 [AC_LANG_COMPILER])])
275 # _AC_LANG_COMPILER_GNU
276 # ---------------------
277 # Check whether the compiler for the current language is GNU.
279 # It doesn't seem necessary right now to have a different source
280 # according to the current language, since this works fine. Some day
281 # it might be needed. Nevertheless, pay attention to the fact that
282 # the position of `choke me' on the seventh column is meant: otherwise
283 # some Fortran compilers (e.g., SGI) might consider it's a
284 # continuation line, and warn instead of reporting an error.
285 m4_define([_AC_LANG_COMPILER_GNU],
286 [AC_CACHE_CHECK([whether we are using the GNU _AC_LANG compiler],
287 [ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu],
288 [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __GNUC__
292 [ac_compiler_gnu=yes],
293 [ac_compiler_gnu=no])
294 ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu=$ac_compiler_gnu
295 ])])# _AC_LANG_COMPILER_GNU
300 # Find a preprocessor for the current language. Note that because we
301 # might AC_REQUIRE `AC_LANG_PREPROC(C)' for instance, the latter must
302 # be AC_DEFUN'd, not just define'd. Since the preprocessor depends
303 # upon the compiler, look for the compiler.
304 m4_define([AC_LANG_PREPROC],
305 [AC_LANG_COMPILER_REQUIRE()dnl
306 _AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
309 # AC_LANG_PREPROC_REQUIRE
310 # -----------------------
311 # Ensure we have a preprocessor for the current language.
312 AC_DEFUN([AC_LANG_PREPROC_REQUIRE],
313 [m4_require([AC_LANG_PREPROC(]_AC_LANG[)],
319 # Require the preprocessor for the current language.
320 # FIXME: AU_ALIAS once AC_LANG is officially documented (2.51?).
321 AC_DEFUN([AC_REQUIRE_CPP],
322 [AC_LANG_PREPROC_REQUIRE])
328 # FIXME: The GCC team has specific needs which the current Autoconf
329 # framework cannot solve elegantly. This macro implements a dirty
330 # hack until Autoconf is able to provide the services its users
333 # Several of the support libraries that are often built with GCC can't
334 # assume the tool-chain is already capable of linking a program: the
335 # compiler often expects to be able to link with some of such
338 # In several of these libraries, workarounds have been introduced to
339 # avoid the AC_PROG_CC_WORKS test, that would just abort their
340 # configuration. The introduction of AC_EXEEXT, enabled either by
341 # libtool or by CVS autoconf, have just made matters worse.
343 # Unlike an earlier version of this macro, using AC_NO_EXECUTABLES does
344 # not disable link tests at autoconf time, but at configure time.
345 # This allows AC_NO_EXECUTABLES to be invoked conditionally.
346 AC_DEFUN_ONCE([AC_NO_EXECUTABLES],
347 [m4_divert_push([KILL])
348 m4_divert_text([DEFAULTS], [ac_no_link=no])
350 AC_BEFORE([$0], [_AC_COMPILER_EXEEXT])
351 AC_BEFORE([$0], [AC_LINK_IFELSE])
353 m4_define([_AC_COMPILER_EXEEXT],
354 [AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
355 if _AC_DO_VAR(ac_link); then
357 ]m4_defn([_AC_COMPILER_EXEEXT])[
360 # Setting cross_compile will disable run tests; it will
361 # also disable AC_CHECK_FILE but that's generally
362 # correct if we can't link.
365 _AC_COMPILER_EXEEXT_CROSS
369 m4_define([AC_LINK_IFELSE],
370 [if test x$ac_no_link = xyes; then
371 AC_MSG_ERROR([Link tests are not allowed after AC@&t@_NO_EXECUTABLES.])
373 ]m4_defn([AC_LINK_IFELSE]))
376 ])# AC_NO_EXECUTABLES
380 # --------------------------------- #
381 # 3a. Computing EXEEXT and OBJEXT. #
382 # --------------------------------- #
387 # Ignore .d files produced by CFLAGS=-MD.
389 # On UWIN (which uses a cc wrapper for MSVC), the compiler also generates
392 # When the w32 free Borland C++ command line compiler links a program
393 # (conftest.exe), it also produces a file named `conftest.tds' in
394 # addition to `conftest.obj'.
397 # Created per object by GCC when given -ftest-coverage.
400 # Created on BeOS. Seems to be per executable.
403 # Created by the Green Hills compiler.
406 # _AC_COMPILER_OBJEXT_REJECT
407 # --------------------------
408 # Case/esac pattern matching the files to be ignored when looking for
409 # compiled object files.
410 m4_define([_AC_COMPILER_OBJEXT_REJECT],
411 [*.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf])
414 # _AC_COMPILER_EXEEXT_REJECT
415 # --------------------------
416 # Case/esac pattern matching the files to be ignored when looking for
417 # compiled executables.
418 m4_define([_AC_COMPILER_EXEEXT_REJECT],
419 [_AC_COMPILER_OBJEXT_REJECT | *.o | *.obj])
422 # We must not AU define them, because autoupdate would then remove
423 # them, which is right, but Automake 1.4 would remove the support for
425 # FIXME: Remove this once Automake fixed.
426 AC_DEFUN([AC_EXEEXT], [])
427 AC_DEFUN([AC_OBJEXT], [])
430 # _AC_COMPILER_EXEEXT_DEFAULT
431 # ---------------------------
432 # Check for the extension used for the default name for executables.
434 # We do this in order to find out what is the extension we must add for
435 # creating executables (see _AC_COMPILER_EXEEXT's comments).
437 # On OpenVMS 7.1 system, the DEC C 5.5 compiler when called through a
438 # GNV (gnv.sourceforge.net) cc wrapper, produces the output file named
440 # b.out is created by i960 compilers.
442 # Start with the most likely output file names, but:
443 # 1) Beware the clever `test -f' on Cygwin, try the DOS-like .exe names
444 # before the counterparts without the extension.
445 # 2) The algorithm is not robust to junk in `.', hence go to wildcards
446 # (conftest.*) only as a last resort.
447 # Beware of `expr' that may return `0' or `'. Since this macro is
448 # the first one in touch with the compiler, it should also check that
449 # it compiles properly.
451 # The IRIX 6 linker writes into existing files which may not be
452 # executable, retaining their permissions. Remove them first so a
453 # subsequent execution test works.
455 m4_define([_AC_COMPILER_EXEEXT_DEFAULT],
456 [# Try to create an executable without -o first, disregard a.out.
457 # It will help us diagnose broken compilers, and finding out an intuition
459 AC_MSG_CHECKING([for _AC_LANG compiler default output file name])
460 ac_link_default=`AS_ECHO(["$ac_link"]) | sed ['s/ -o *conftest[^ ]*//']`
462 # The possible output files:
463 ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
466 for ac_file in $ac_files
469 _AC_COMPILER_EXEEXT_REJECT ) ;;
470 * ) ac_rmfiles="$ac_rmfiles $ac_file";;
475 AS_IF([_AC_DO_VAR(ac_link_default)],
476 [# Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
477 # So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
478 # in a Makefile. We should not override ac_cv_exeext if it was cached,
479 # so that the user can short-circuit this test for compilers unknown to
481 for ac_file in $ac_files ''
483 test -f "$ac_file" || continue
485 _AC_COMPILER_EXEEXT_REJECT )
488 # We found the default executable, but exeext='' is most
492 if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
494 ac_cv_exeext=`expr "$ac_file" : ['[^.]*\(\..*\)']`
496 # We set ac_cv_exeext here because the later test for it is not
497 # safe: cross compilers may not add the suffix if given an `-o'
498 # argument, so we may need to know it at that point already.
499 # Even if this section looks crufty: it has the advantage of
506 test "$ac_cv_exeext" = no && ac_cv_exeext=
509 AC_MSG_RESULT([$ac_file])
510 AS_IF([test -z "$ac_file"],
511 [_AC_MSG_LOG_CONFTEST
512 AC_MSG_FAILURE([_AC_LANG compiler cannot create executables], 77)])
513 ac_exeext=$ac_cv_exeext
514 ])# _AC_COMPILER_EXEEXT_DEFAULT
517 # _AC_COMPILER_EXEEXT_WORKS
518 # -------------------------
519 m4_define([_AC_COMPILER_EXEEXT_WORKS],
520 [# Check that the compiler produces executables we can run. If not, either
521 # the compiler is broken, or we cross compile.
522 AC_MSG_CHECKING([whether the _AC_LANG compiler works])
523 # FIXME: These cross compiler hacks should be removed for Autoconf 3.0
524 # If not cross compiling, check that we can run a simple program.
525 if test "$cross_compiling" != yes; then
526 if _AC_DO_TOKENS([./$ac_file]); then
529 if test "$cross_compiling" = maybe; then
532 AC_MSG_FAILURE([cannot run _AC_LANG compiled programs.
533 If you meant to cross compile, use `--host'.])
538 ])# _AC_COMPILER_EXEEXT_WORKS
541 # _AC_COMPILER_EXEEXT_CROSS
542 # -------------------------
543 m4_define([_AC_COMPILER_EXEEXT_CROSS],
544 [# Check that the compiler produces executables we can run. If not, either
545 # the compiler is broken, or we cross compile.
546 AC_MSG_CHECKING([whether we are cross compiling])
547 AC_MSG_RESULT([$cross_compiling])
548 ])# _AC_COMPILER_EXEEXT_CROSS
551 # _AC_COMPILER_EXEEXT_O
552 # ---------------------
553 # Check for the extension used when `-o foo'. Try to see if ac_cv_exeext,
554 # as computed by _AC_COMPILER_EXEEXT_DEFAULT is OK.
555 m4_define([_AC_COMPILER_EXEEXT_O],
556 [AC_MSG_CHECKING([for suffix of executables])
557 AS_IF([_AC_DO_VAR(ac_link)],
558 [# If both `conftest.exe' and `conftest' are `present' (well, observable)
559 # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will
560 # work properly (i.e., refer to `conftest.exe'), while it won't with
562 for ac_file in conftest.exe conftest conftest.*; do
563 test -f "$ac_file" || continue
565 _AC_COMPILER_EXEEXT_REJECT ) ;;
566 *.* ) ac_cv_exeext=`expr "$ac_file" : ['[^.]*\(\..*\)']`
571 [AC_MSG_FAILURE([cannot compute suffix of executables: cannot compile and link])])
572 rm -f conftest$ac_cv_exeext
573 AC_MSG_RESULT([$ac_cv_exeext])
574 ])# _AC_COMPILER_EXEEXT_O
577 # _AC_COMPILER_EXEEXT
578 # -------------------
579 # Check for the extension used for executables. It compiles a test
580 # executable. If this is called, the executable extensions will be
581 # automatically used by link commands run by the configure script.
583 # Note that some compilers (cross or not), strictly obey to `-o foo' while
584 # the host requires `foo.exe', so we should not depend upon `-o' to
585 # test EXEEXT. But then, be sure not to destroy user files.
587 # Must be run before _AC_COMPILER_OBJEXT because _AC_COMPILER_EXEEXT_DEFAULT
588 # checks whether the compiler works.
589 m4_define([_AC_COMPILER_EXEEXT],
590 [AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
591 ac_clean_files_save=$ac_clean_files
592 ac_clean_files="$ac_clean_files a.out a.exe b.out"
593 _AC_COMPILER_EXEEXT_DEFAULT
594 _AC_COMPILER_EXEEXT_WORKS
595 rm -f a.out a.exe conftest$ac_cv_exeext b.out
596 ac_clean_files=$ac_clean_files_save
597 _AC_COMPILER_EXEEXT_CROSS
598 _AC_COMPILER_EXEEXT_O
599 rm -f conftest.$ac_ext
600 AC_SUBST([EXEEXT], [$ac_cv_exeext])dnl
602 ])# _AC_COMPILER_EXEEXT
605 # _AC_COMPILER_OBJEXT
606 # -------------------
607 # Check the object extension used by the compiler: typically `.o' or
608 # `.obj'. If this is called, some other behavior will change,
609 # determined by ac_objext.
611 # This macro is called by AC_LANG_COMPILER, the latter being required
612 # by the AC_COMPILE_IFELSE macros, so use _AC_COMPILE_IFELSE. And in fact,
613 # don't, since _AC_COMPILE_IFELSE needs to know ac_objext for the `test -s'
614 # it includes. So do it by hand.
615 m4_define([_AC_COMPILER_OBJEXT],
616 [AC_CACHE_CHECK([for suffix of object files], ac_cv_objext,
617 [AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
618 rm -f conftest.o conftest.obj
619 AS_IF([_AC_DO_VAR(ac_compile)],
620 [for ac_file in conftest.o conftest.obj conftest.*; do
621 test -f "$ac_file" || continue;
623 _AC_COMPILER_OBJEXT_REJECT ) ;;
624 *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
628 [_AC_MSG_LOG_CONFTEST
629 AC_MSG_FAILURE([cannot compute suffix of object files: cannot compile])])
630 rm -f conftest.$ac_cv_objext conftest.$ac_ext])
631 AC_SUBST([OBJEXT], [$ac_cv_objext])dnl
633 ])# _AC_COMPILER_OBJEXT
638 ## ------------------------------- ##
639 ## 4. Compilers' characteristics. ##
640 ## ------------------------------- ##
644 # Treat warnings from the current language's preprocessor, compiler, and
645 # linker as fatal errors.
646 AC_DEFUN([AC_LANG_WERROR],
647 [m4_divert_text([DEFAULTS], [ac_[]_AC_LANG_ABBREV[]_werror_flag=])
648 ac_[]_AC_LANG_ABBREV[]_werror_flag=yes])# AC_LANG_WERROR