Skip to content

Commit

Permalink
Configure: if we compile with clang, check that it is not broken
Browse files Browse the repository at this point in the history
Some linux distibutions (for example, Mageia 2, Fedora 17) ship Clang that is
essentially broken for the end user.  Clang can not find or compile libstdc++
headers.

The issue is that our configure prefers clang over gcc, thus selecting a broken
Clang when a working GCC is available.

Now we detect this issue by compiling a simple program.  If it does not
compile, configure stops with an error suggesting the user to select a
different compiler.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171975 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
gribozavr committed Jan 9, 2013
1 parent 7bf2e1b commit a730336
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 2 deletions.
26 changes: 26 additions & 0 deletions autoconf/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ AC_PROG_CC(clang llvm-gcc gcc)
AC_PROG_CXX(clang++ llvm-g++ g++)
AC_PROG_CPP

dnl If CXX is Clang, check that it can find and parse C++ standard library
dnl headers.
if test "$CXX" = "clang++" ; then
AC_MSG_CHECKING([whether clang works])
AC_LANG_PUSH([C++])
dnl Note that space between 'include' and '(' is required. There's a broken
dnl regex in aclocal that otherwise will think that we call m4's include
dnl builtin.
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <limits>
#if __has_include (<cxxabi.h>)
#include <cxxabi.h>
#endif
#if __has_include (<unwind.h>)
#include <unwind.h>
#endif
]])],
[
AC_MSG_RESULT([yes])
],
[
AC_MSG_RESULT([no])
AC_MSG_ERROR([Selected compiler could not find or parse C++ standard library headers. Rerun with CC=c-compiler CXX=c++-compiler ./configure ...])
])
AC_LANG_POP([C++])
fi

dnl Configure all of the projects present in our source tree. While we could
dnl just AC_CONFIG_SUBDIRS on the set of directories in projects that have a
dnl configure script, that usage of the AC_CONFIG_SUBDIRS macro is deprecated.
Expand Down
95 changes: 93 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -3471,6 +3471,98 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu


if test "$CXX" = "clang++" ; then
{ echo "$as_me:$LINENO: checking whether clang works" >&5
echo $ECHO_N "checking whether clang works... $ECHO_C" >&6; }
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu


cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <limits>
#if __has_include (<cxxabi.h>)
#include <cxxabi.h>
#endif
#if __has_include (<unwind.h>)
#include <unwind.h>
#endif

int
main ()
{

;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext
if { (ac_try="$ac_compile"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_compile") 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err'
{ (case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_try") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest.$ac_objext'
{ (case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_try") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then

{ echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6; }

else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5


{ echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6; }
{ { echo "$as_me:$LINENO: error: Selected compiler could not find or parse C++ standard library headers. Rerun with CC=c-compiler CXX=c++-compiler ./configure ..." >&5
echo "$as_me: error: Selected compiler could not find or parse C++ standard library headers. Rerun with CC=c-compiler CXX=c++-compiler ./configure ..." >&2;}
{ (exit 1); exit 1; }; }

fi

rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu

fi



if test -d ${srcdir}/projects/llvm-gcc ; then
Expand Down Expand Up @@ -10393,7 +10485,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
#line 10396 "configure"
#line 10488 "configure"
#include "confdefs.h"

#if HAVE_DLFCN_H
Expand Down Expand Up @@ -16330,7 +16422,6 @@ rm -f core conftest.err conftest.$ac_objext \




{ echo "$as_me:$LINENO: checking for HUGE_VAL sanity" >&5
echo $ECHO_N "checking for HUGE_VAL sanity... $ECHO_C" >&6; }
if test "${ac_cv_huge_val_sanity+set}" = set; then
Expand Down

0 comments on commit a730336

Please sign in to comment.