+# Detect warning flags supported by the C and C++ compilers and append them to
+# WARN_CFLAGS and WARN_CXXFLAGS.
+m4_define([WARN_FLAGS_COMMON_LIST], [ dnl
+ -Wall dnl
+ -Wextra dnl
+ -Wmissing-declarations dnl
+ -Wnull-dereference dnl
+ -Wundef dnl
+ -Wredundant-decls dnl
+ -Wshadow dnl
+ -Wsuggest-attribute=format dnl
+ -Wtautological-constant-out-of-range-compare dnl Clang specific
+ -Wwrite-strings dnl
+ -Wformat=2 dnl
+ -Wstrict-aliasing dnl
+ -Wmissing-noreturn dnl
+ -Wduplicated-cond dnl
+ -Wduplicated-branches dnl
+ -Wlogical-op dnl
+ -Winit-self dnl
+ dnl We currently get this warning when building with Clang:
+ dnl
+ dnl /usr/include/setjmp.h:54:12: error: declaration of built-in function '__sigsetjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header <setjmp.h>. [-Werror,-Wincomplete-setjmp-declaration]
+ dnl extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
+ dnl ^
+ -Wno-incomplete-setjmp-declaration dnl
+ -Wno-gnu-folding-constant dnl Clang specific
+])
+
+# Detect warning flags specific to the C compiler and append them to
+# WARN_CFLAGS.
+m4_define([WARN_FLAGS_C_LIST], [ dnl
+ -Wdiscarded-qualifiers dnl
+ -Wmissing-prototypes dnl
+ -Wmissing-parameter-type dnl
+ -Wjump-misses-init dnl
+ -Wnested-externs dnl
+])
+
+# Pass -Werror as an extra flag during the test: this is needed to make the
+# -Wunknown-warning-option diagnostic fatal with clang.
+AC_LANG_PUSH([C])
+AX_APPEND_COMPILE_FLAGS([WARN_FLAGS_COMMON_LIST WARN_FLAGS_C_LIST], [WARN_CFLAGS], [-Werror])
+AC_LANG_POP([C])
+
+# The test used in AX_APPEND_COMPILE_FLAGS, generated using AC_LANG_PROGRAM, is
+# written in such a way that it triggers warnings with the following warning
+# flags. So they would always end up disabled if we put them there, because
+# the test program would not build.
+#
+# Enable them here unconditionally. They are supported by GCC >= 4.8 and by
+# Clang >= 3.3 (required by the project) and are only valid for C code.
+WARN_CFLAGS="${WARN_CFLAGS} -Wold-style-definition -Wstrict-prototypes"
+
+# Disable 'strict aliasing' if the C compiler supports it.
+AC_LANG_PUSH([C])
+AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing], [OPT_CFLAGS], [-Werror])
+AC_LANG_POP([C])
+
+
+## ##
+## C++ compiler checks ##
+## ##
+
+# Find a C++11 compiler with GNU extensions (-std=gnu++11)
+AX_CXX_COMPILE_STDCXX([11], [ext], [mandatory])
+
+# Detect warning flags specific to the C++ compiler and append them to
+# WARN_CXXFLAGS.
+m4_define([WARN_FLAGS_CXX_LIST], [ dnl
+ dnl GCC enables this with -Wall in C++, and that generates a
+ dnl lot of warnings that have on average a low value to fix.
+ -Wno-sign-compare dnl
+])
+
+# Pass -Werror as an extra flag during the test: this is needed to make the
+# -Wunknown-warning-option diagnostic fatal with clang.
+AC_LANG_PUSH([C++])
+AX_APPEND_COMPILE_FLAGS([WARN_FLAGS_COMMON_LIST WARN_FLAGS_CXX_LIST], [WARN_CXXFLAGS], [-Werror])
+AC_LANG_POP([C++])
+
+# Disable 'strict aliasing' if the C++ compiler supports it.
+AC_LANG_PUSH([C++])
+AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing], [OPT_CXXFLAGS], [-Werror])
+AC_LANG_POP([C++])
+
+
+# When given, add -Werror to WARN_CFLAGS and WARN_CXXFLAGS.
+AC_ARG_ENABLE([Werror],[
+ AS_HELP_STRING([--enable-Werror], [Treat compiler warnings as errors.])
+])
+
+AS_IF([test "x$enable_Werror" = "xyes"], [
+ WARN_CFLAGS="${WARN_CFLAGS} -Werror"
+ WARN_CXXFLAGS="${WARN_CXXFLAGS} -Werror"
+])
+
+# Checks for programs.
+AC_PROG_GREP
+AC_PROG_MAKE_SET
+AC_PROG_SED
+AC_PATH_PROG([report_fold], [fold])
+LT_INIT
+
+# Check for objcopy, required by the base address statedump and dynamic linker tests
+AC_CHECK_TOOL([OBJCOPY], [objcopy], [no])
+AS_IF([test "x$OBJCOPY" = "xno"],
+ [AC_MSG_WARN([Cannot find objcopy. The base address statedump and dynamic linker tests will be disabled. Install the binutils package to remediate this.])]
+)
+AM_CONDITIONAL([HAVE_OBJCOPY], [test "x$OBJCOPY" != xno])
+
+# check for pgrep
+AC_PATH_PROG([PGREP], [pgrep], [no])
+AM_CONDITIONAL([HAVE_PGREP], [test "x$PGREP" != "xno"])
+
+# set $IN_GIT_REPO if we're in the Git repository; the `bootstrap` file
+# is not distributed in tarballs
+AS_IF([test -f "$srcdir/bootstrap"], [in_git_repo=yes], [in_git_repo=no])
+AM_CONDITIONAL([IN_GIT_REPO], [test "x$in_git_repo" = "xyes"])