]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add configure support for detecting clang
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 16 Sep 2018 18:35:40 +0000 (20:35 +0200)
committerAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 16 Sep 2018 18:40:25 +0000 (20:40 +0200)
Also note that both GCC and Clang are GNU

configure.ac
m4/clang.m4 [new file with mode: 0644]

index 9a65f85d49c161f67cb1f7e34645f5922926a9db..345a5617186af8c95c59d8436ec9368d69be9e5d 100644 (file)
@@ -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 (file)
index 0000000..11911ce
--- /dev/null
@@ -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
+