1 # Sanity test a C compiler.
3 # Copyright (C) 2006, 2009-2015, 2018-2021 Free Software Foundation,
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 # Written by Paul Eggert.
21 AC_DEFUN([BISON_TEST_FOR_WORKING_C_COMPILER], [
25 int test_array[CHAR_BIT];]])],
27 [AC_MSG_FAILURE([cannot compile a simple C program])])
28 AC_SUBST([BISON_C_WORKS], [:])
31 # BISON_CHECK_WITH_POSIXLY_CORRECT(CODE)
32 # --------------------------------------
33 # Run the Autoconf CODE with POSIXLY_CORRECT set to 1, and restored to
34 # its initial value afterwards.
35 AC_DEFUN([BISON_CHECK_WITH_POSIXLY_CORRECT],
36 [gl_awk_probe='BEGIN { if ("POSIXLY_CORRECT" in ENVIRON) print "x" }'
37 case ${POSIXLY_CORRECT+x}`$AWK "$gl_awk_probe" </dev/null` in
38 xx) gl_had_POSIXLY_CORRECT=exported ;;
39 x) gl_had_POSIXLY_CORRECT=yes ;;
40 *) gl_had_POSIXLY_CORRECT= ;;
43 export POSIXLY_CORRECT
45 case $gl_had_POSIXLY_CORRECT in
47 yes) AS_UNSET([POSIXLY_CORRECT]); POSIXLY_CORRECT=1 ;;
48 *) AS_UNSET([POSIXLY_CORRECT]) ;;
52 # BISON_LANG_COMPILER_POSIXLY_CORRECT
53 # -----------------------------------
54 # Whether the compiler for the current language supports -g in
55 # POSIXLY_CORRECT mode. clang-2.9 on OS X does not, because
56 # "clang-mp-2.9 -o test -g test.c" launches "/usr/bin/dsymutil test -o
57 # test.dSYM" which fails with "error: unable to open executable '-o'".
59 # Sets <LANG>_COMPILER_POSIXLY_CORRECT to true/false.
60 AC_DEFUN([BISON_LANG_COMPILER_POSIXLY_CORRECT],
61 [AC_CACHE_CHECK([whether $_AC_CC supports POSIXLY_CORRECT=1],
62 [bison_cv_[]_AC_LANG_ABBREV[]_supports_posixly_correct],
63 [BISON_CHECK_WITH_POSIXLY_CORRECT(
64 [AC_LINK_IFELSE([AC_LANG_PROGRAM],
65 [bison_cv_[]_AC_LANG_ABBREV[]_supports_posixly_correct=yes],
66 [bison_cv_[]_AC_LANG_ABBREV[]_supports_posixly_correct=no])])])
67 case $bison_cv_[]_AC_LANG_ABBREV[]_supports_posixly_correct in
68 yes) AC_SUBST(_AC_LANG_PREFIX[_COMPILER_POSIXLY_CORRECT], [true]) ;;
69 no) AC_SUBST(_AC_LANG_PREFIX[_COMPILER_POSIXLY_CORRECT], [false]);;
73 # BISON_C_COMPILER_POSIXLY_CORRECT
74 # --------------------------------
75 # Whether the C compiler supports -g in POSIXLY_CORRECT mode.
76 AC_DEFUN([BISON_C_COMPILER_POSIXLY_CORRECT],
78 BISON_LANG_COMPILER_POSIXLY_CORRECT