From 46a9248fedd29299ae089da12ae1b4b0d67fc71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 16 Sep 2018 20:35:40 +0200 Subject: Add configure support for detecting clang Also note that both GCC and Clang are GNU --- configure.ac | 7 +++++-- m4/clang.m4 | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 m4/clang.m4 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 + -- cgit v1.2.1