1 # Sanity test a C compiler.
3 # Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Written by Paul Eggert.
20 AC_DEFUN([BISON_TEST_FOR_WORKING_C_COMPILER], [
24 int test_array[CHAR_BIT];]])],
26 [AC_MSG_FAILURE([cannot compile a simple C program])])
29 # BISON_CHECK_WITH_POSIXLY_CORRECT(CODE)
30 # --------------------------------------
31 # Run the Autoconf CODE with POSIXLY_CORRECT set to 1, and restored to
32 # its initial value afterwards.
33 AC_DEFUN([BISON_CHECK_WITH_POSIXLY_CORRECT],
34 [gl_awk_probe='BEGIN { if ("POSIXLY_CORRECT" in ENVIRON) print "x" }'
35 case ${POSIXLY_CORRECT+x}`$AWK "$gl_awk_probe" </dev/null` in
36 xx) gl_had_POSIXLY_CORRECT=exported ;;
37 x) gl_had_POSIXLY_CORRECT=yes ;;
38 *) gl_had_POSIXLY_CORRECT= ;;
41 export POSIXLY_CORRECT
43 case $gl_had_POSIXLY_CORRECT in
45 yes) AS_UNSET([POSIXLY_CORRECT]); POSIXLY_CORRECT=1 ;;
46 *) AS_UNSET([POSIXLY_CORRECT]) ;;
50 # BISON_C_COMPILER_POSIXLY_CORRECT
51 # --------------------------------
52 # Whether the compiler supports -g in POSIXLY_CORRECT mode. clang-2.9
53 # on OS X does not, because "clang-mp-2.9 -o test -g test.c" launches
54 # "/usr/bin/dsymutil test -o test.dSYM" which fails with "error:
55 # unable to open executable '-o'".
57 # Sets C_COMPILER_POSIXLY_CORRECT to true/false.
58 AC_DEFUN([BISON_C_COMPILER_POSIXLY_CORRECT],
59 [AC_CACHE_CHECK([whether $CC supports POSIXLY_CORRECT=1],
60 [bison_cv_cc_supports_posixly_correct],
61 [BISON_CHECK_WITH_POSIXLY_CORRECT(
63 AC_LINK_IFELSE([AC_LANG_PROGRAM],
64 [bison_cv_cc_supports_posixly_correct=yes],
65 [bison_cv_cc_supports_posixly_correct=no])
67 case $bison_cv_cc_supports_posixly_correct in
68 yes) AC_SUBST([C_COMPILER_POSIXLY_CORRECT], [true]) ;;
69 no) AC_SUBST([C_COMPILER_POSIXLY_CORRECT], [false]);;