]> git.saurik.com Git - bison.git/commitdiff
tests: beware of compilers that do not support POSIXLY_CORRECT
authorAkim Demaille <akim@lrde.epita.fr>
Wed, 7 Nov 2012 16:23:06 +0000 (17:23 +0100)
committerAkim Demaille <akim@lrde.epita.fr>
Wed, 7 Nov 2012 16:23:06 +0000 (17:23 +0100)
Running "maintainer-release-check" on OS X with Clang 2.9 fails,
because "clang-mp-2.9 -o test -g test.c" launches "/usr/bin/dsymutil
test -o test.dSYM" which fails with "error: unable to open executable
'-o'".

* m4/c-working.m4 (BISON_CHECK_WITH_POSIXLY_CORRECT)
(BISON_C_COMPILER_POSIXLY_CORRECT): New.
* configure.ac: Use the latter.
* tests/atlocal.in (POSIXLY_CORRECT_IS_EXPORTED): New.
* tests/local.at (AT_BISON_CHECK_WARNINGS_): Use it instead of computing its
value each time.
(AT_QUELL_VALGRIND): Skip tests that cannot work because of compilers
that do not support POSIXLY_CORRECT.

configure.ac
m4/c-working.m4
tests/atlocal.in
tests/local.at

index 651fa1397eab9c715ae1281b90cdc3a8cd25968d..86783d525578f2dffd1400a9e8218bdd5896624f 100644 (file)
@@ -114,6 +114,7 @@ fi
 
 BISON_TEST_FOR_WORKING_C_COMPILER
 BISON_TEST_FOR_WORKING_CXX_COMPILER
 
 BISON_TEST_FOR_WORKING_C_COMPILER
 BISON_TEST_FOR_WORKING_CXX_COMPILER
+BISON_C_COMPILER_POSIXLY_CORRECT
 
 AC_ARG_ENABLE([yacc],
   [AC_HELP_STRING([--disable-yacc],
 
 AC_ARG_ENABLE([yacc],
   [AC_HELP_STRING([--disable-yacc],
index d563d32b9c9fa9a1c0579c8b9c01dbc175c6b929..0db60f764725b461540896ce320702ebab842adc 100644 (file)
@@ -25,3 +25,47 @@ AC_DEFUN([BISON_TEST_FOR_WORKING_C_COMPILER], [
     [],
     [AC_MSG_FAILURE([cannot compile a simple C program])])
 ])
     [],
     [AC_MSG_FAILURE([cannot compile a simple C program])])
 ])
+
+# BISON_CHECK_WITH_POSIXLY_CORRECT(CODE)
+# --------------------------------------
+# Run the Autoconf CODE with POSIXLY_CORRECT set to 1, and restored to
+# its initial value afterwards.
+AC_DEFUN([BISON_CHECK_WITH_POSIXLY_CORRECT],
+[gl_awk_probe='BEGIN { if ("POSIXLY_CORRECT" in ENVIRON) print "x" }'
+case ${POSIXLY_CORRECT+x}`$AWK "$gl_awk_probe" </dev/null` in
+  xx) gl_had_POSIXLY_CORRECT=exported ;;
+  x)  gl_had_POSIXLY_CORRECT=yes      ;;
+  *)  gl_had_POSIXLY_CORRECT=         ;;
+esac
+POSIXLY_CORRECT=1
+export POSIXLY_CORRECT
+$1
+case $gl_had_POSIXLY_CORRECT in
+  exported) ;;
+  yes) AS_UNSET([POSIXLY_CORRECT]); POSIXLY_CORRECT=1 ;;
+  *) AS_UNSET([POSIXLY_CORRECT]) ;;
+esac
+])
+
+# BISON_C_COMPILER_POSIXLY_CORRECT
+# --------------------------------
+# Whether the compiler supports -g in POSIXLY_CORRECT mode.  clang-2.9
+# on OS X does not, because "clang-mp-2.9 -o test -g test.c" launches
+# "/usr/bin/dsymutil test -o test.dSYM" which fails with "error:
+# unable to open executable '-o'".
+#
+# Sets C_COMPILER_POSIXLY_CORRECT to true/false.
+AC_DEFUN([BISON_C_COMPILER_POSIXLY_CORRECT],
+[AC_CACHE_CHECK([whether $CC supports POSIXLY_CORRECT=1],
+                [bison_cv_cc_supports_posixly_correct],
+[BISON_CHECK_WITH_POSIXLY_CORRECT(
+[AC_LANG_PUSH([C])
+AC_LINK_IFELSE([AC_LANG_PROGRAM],
+                [bison_cv_cc_supports_posixly_correct=yes],
+                [bison_cv_cc_supports_posixly_correct=no])
+AC_LANG_POP([C])])])
+case $bison_cv_cc_supports_posixly_correct in
+  yes) AC_SUBST([C_COMPILER_POSIXLY_CORRECT], [true]) ;;
+  no)  AC_SUBST([C_COMPILER_POSIXLY_CORRECT], [false]);;
+esac
+])
index 2f68259288179815590bdc989037ad8a06bc902e..5e3cb723a48837d92e3782cc56616ab3b4b82587 100644 (file)
@@ -79,3 +79,13 @@ LIBS="$abs_top_builddir/lib/libbison.a @LIBS@ @INTLLIBS@"
 : ${XSLTPROC='@XSLTPROC@'}
 
 : ${PERL='@PERL@'}
 : ${XSLTPROC='@XSLTPROC@'}
 
 : ${PERL='@PERL@'}
+
+# Don't just check if $POSIXLY_CORRECT is set, as Bash, when launched
+# as /bin/sh, sets the shell variable POSIXLY_CORRECT to y, but not
+# the environment variable.
+: ${C_COMPILER_POSIXLY_CORRECT='@C_COMPILER_POSIXLY_CORRECT@'}
+if env | grep '^POSIXLY_CORRECT=' >/dev/null; then
+  POSIXLY_CORRECT_IS_EXPORTED=true
+else
+  POSIXLY_CORRECT_IS_EXPORTED=false
+fi
index 88825210e7c0b5d39bed4b291a899eead3cd401f..e803e57ffc1491b68aa804b3567b4c57b4f2db8b 100644 (file)
@@ -468,11 +468,7 @@ m4_define([AT_BISON_CHECK_WARNINGS_],
 [[# Defining POSIXLY_CORRECT causes bison to complain if options are
 # added after the grammar file name, so skip these checks in that
 # case.
 [[# Defining POSIXLY_CORRECT causes bison to complain if options are
 # added after the grammar file name, so skip these checks in that
 # case.
-#
-# Don't just check if $POSIXLY_CORRECT is set, as Bash, when launched
-# as /bin/sh, sets the shell variable POSIXLY_CORRECT to y, but not
-# the environment variable.
-if env | grep '^POSIXLY_CORRECT=' >/dev/null; then :; else
+if test "$POSIXLY_CORRECT_IS_EXPORTED" = false; then
   ]AT_SAVE_SPECIAL_FILES[
 
   # To avoid expanding it repeatedly, store specified stdout.
   ]AT_SAVE_SPECIAL_FILES[
 
   # To avoid expanding it repeatedly, store specified stdout.
@@ -597,7 +593,10 @@ m4_define([AT_QUELL_VALGRIND],
 # otherwise pass "-c"; this is a hack.  The default SOURCES is OUTPUT
 # with trailing .o removed, and ".c" appended.
 m4_define([AT_COMPILE],
 # otherwise pass "-c"; this is a hack.  The default SOURCES is OUTPUT
 # with trailing .o removed, and ".c" appended.
 m4_define([AT_COMPILE],
-[AT_CHECK(m4_join([ ],
+[AT_CHECK([case $POSIXLY_CORRECT_IS_EXPORTED:$C_COMPILER_POSIXLY_CORRECT in
+  true:false) echo 'cannot compile properly with POSIXLY_CORRECT' && exit 77;;
+esac])
+AT_CHECK(m4_join([ ],
                   [$CC $CFLAGS $CPPFLAGS],
                   [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
                   [-o $1],
                   [$CC $CFLAGS $CPPFLAGS],
                   [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
                   [-o $1],