Permalink
Browse files

Add autoconf support to detect an LLVM-based C compiler

This patch adds support to the autoconf scripts to detect
when we are using a C compiler that uses an LLVM back end.
An LLVM back end does not support all of the extensions use
by GCC, so we need to perform some conditional compilation
in the runtime, particularly for handling thread local
storage and global register variables.

The changes here will set the CC_LLVM_BACKEND in the
autoconf scripts if we detect an llvm-based compiler. We use
this variable to define the llvm_CC_FLAVOR variable that we
can use in the runtime code to conditionally compile for
LLVM.
  • Loading branch information...
dmpots committed Jun 28, 2011
1 parent ccf0166 commit 21b476597dcf199801f8dff4358632b141920d1d
Showing with 27 additions and 0 deletions.
  1. +16 −0 aclocal.m4
  2. +4 −0 configure.ac
  3. +4 −0 includes/ghc.mk
  4. +3 −0 mk/project.mk.in
View
@@ -760,6 +760,22 @@ AC_SUBST(GccLT34)
AC_SUBST(GccLT46)
])# FP_GCC_VERSION
+dnl Check to see if the C compiler uses an LLVM back end
+dnl
+AC_DEFUN([FP_CC_LLVM_BACKEND],
+[AC_REQUIRE([AC_PROG_CC])
+AC_MSG_CHECKING([whether C compiler has an LLVM back end])
+$CC -x c /dev/null -dM -E > conftest.txt 2>&1
+if grep "__llvm__" conftest.txt >/dev/null 2>&1; then
+ AC_SUBST([CC_LLVM_BACKEND], [1])
+ AC_MSG_RESULT([yes])
+else
+ AC_SUBST([CC_LLVM_BACKEND], [0])
+ AC_MSG_RESULT([no])
+fi
+rm -f conftest.txt
+])
+
dnl Small feature test for perl version. Assumes PerlCmd
dnl contains path to perl binary.
dnl
View
@@ -526,6 +526,10 @@ dnl If gcc, make sure it's at least 2.1
dnl
FP_GCC_VERSION
+dnl ** look to see if we have a C compiler using an llvm back end.
+dnl
+FP_CC_LLVM_BACKEND
+
FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
FPTOOLS_SET_C_LD_FLAGS([build],[CONF_CC_OPTS_STAGE0],[CONF_GCC_LINKER_OPTS_STAGE0],[CONF_LD_LINKER_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAGE1],[CONF_LD_LINKER_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
View
@@ -104,6 +104,10 @@ endif
@echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
@echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
@echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
+ifeq "$(CC_LLVM_BACKEND)" "1"
+ @echo >> $@
+ @echo "#define llvm_CC_FLAVOR 1" >> $@
+endif
@echo >> $@
@echo "/* These TARGET macros are for backwards compatibily... DO NOT USE! */" >> $@
@echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
View
@@ -143,3 +143,6 @@ OSTYPE=@OSTYPE@
# In case of Solaris OS, does it provide broken shared libs
# linker or not?
SOLARIS_BROKEN_SHLD=@SOLARIS_BROKEN_SHLD@
+
+# Do we have a C compiler using an LLVM back end?
+CC_LLVM_BACKEND = @CC_LLVM_BACKEND@

0 comments on commit 21b4765

Please sign in to comment.