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