summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders F Björklund <anders.f.bjorklund@gmail.com>2018-09-16 20:35:40 +0200
committerAnders F Björklund <anders.f.bjorklund@gmail.com>2018-09-16 20:40:25 +0200
commit46a9248fedd29299ae089da12ae1b4b0d67fc71a (patch)
tree83261c8dafdae94dbe6595fe2e54ee8a9e492c16
parentc46da15589b971981435e11be31f9f2ccae1bb77 (diff)
downloadccache-46a9248fedd29299ae089da12ae1b4b0d67fc71a.tar.gz
Add configure support for detecting clang
Also note that both GCC and Clang are GNU
-rw-r--r--configure.ac7
-rw-r--r--m4/clang.m419
2 files changed, 24 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 9a65f85d..345a5617 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,8 +23,11 @@ AC_SUBST(test_suites)
AC_SUBST(disable_man)
m4_include(m4/feature_macros.m4)
+m4_include(m4/clang.m4)
dnl Checks for programs.
+AC_PROG_CC
+_AC_LANG_COMPILER_CLANG
AC_PROG_CC_C99
if test "$ac_cv_prog_cc_c99" = no; then
AC_MSG_ERROR(cannot find a C99-compatible compiler)
@@ -41,8 +44,8 @@ fi
# Prefer bash, needed for test.sh
AC_PATH_TOOL(BASH, bash, "/bin/bash")
-# If GCC, turn on warnings.
-if test "x$GCC" = "xyes"; then
+# If GCC (or clang), turn on warnings.
+if test "$ac_compiler_gnu" = yes; then
CFLAGS="$CFLAGS -Wall -W"
else
CFLAGS="$CFLAGS -O"
diff --git a/m4/clang.m4 b/m4/clang.m4
new file mode 100644
index 00000000..11911ce2
--- /dev/null
+++ b/m4/clang.m4
@@ -0,0 +1,19 @@
+# _AC_LANG_COMPILER_CLANG
+# ---------------------
+# Check whether the compiler for the current language is clang.
+# Adapted from standard autoconf function: _AC_LANG_COMPILER_GNU
+#
+# Note: clang also identifies itself as a GNU compiler (gcc 4.2.1)
+# for compatibility reasons, so that cannot be used to determine
+m4_define([_AC_LANG_COMPILER_CLANG],
+[AC_CACHE_CHECK([whether we are using the clang _AC_LANG compiler],
+ [ac_cv_[]_AC_LANG_ABBREV[]_compiler_clang],
+[_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __clang__
+ choke me
+#endif
+]])],
+ [ac_compiler_clang=yes],
+ [ac_compiler_clang=no])
+ac_cv_[]_AC_LANG_ABBREV[]_compiler_clang=$ac_compiler_clang
+])])# _AC_LANG_COMPILER_CLANG
+