Skip to content

Commit

Permalink
Add autoconf support to detect an LLVM-based C compiler
Browse files Browse the repository at this point in the history
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 29, 2011
1 parent ccf0166 commit 21b4765
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions aclocal.m4
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Expand Up @@ -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])
Expand Down
4 changes: 4 additions & 0 deletions includes/ghc.mk
Expand Up @@ -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)" >> $@
Expand Down
3 changes: 3 additions & 0 deletions mk/project.mk.in
Expand Up @@ -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.