+# Detect warning flags supported by the C compiler and append them to
+# WARN_CFLAGS.
+m4_define([WARN_FLAGS_LIST], [ dnl
+ -Wall dnl
+ -Wextra dnl
+ -Wmissing-prototypes dnl
+ -Wmissing-declarations dnl
+ -Wnull-dereference dnl
+ -Wundef dnl
+ -Wshadow dnl
+ -Wjump-misses-init dnl
+ -Wsuggest-attribute=format dnl
+ -Wtautological-constant-out-of-range-compare dnl
+ -Wnested-externs dnl
+ -Wwrite-strings dnl
+ -Wformat=2 dnl
+ -Wstrict-aliasing dnl
+ -Wmissing-noreturn dnl
+ -Winit-self dnl
+ -Wduplicated-cond dnl
+ -Wduplicated-branches dnl
+ -Wlogical-op dnl
+ dnl These would require reworking the tracepoint macros
+ dnl-Wredundant-decls dnl
+ -Wno-sign-compare dnl
+ -Wno-missing-field-initializers dnl
+ -Wno-null-dereference 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_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 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 an optional C++11 compiler without GNU extensions (-std=c++11)
+AX_CXX_COMPILE_STDCXX([11], [noext], [optional])
+
+AS_IF([test "$HAVE_CXX11" = "1"], [
+ # 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_LIST -Wno-undef -Wno-duplicated-branches], [WARN_CXXFLAGS], [-Werror])
+ AC_LANG_POP([C++])
+])
+
+
+## ##
+## Header checks ##
+## ##
+
+AC_HEADER_STDBOOL
+AC_CHECK_HEADERS([ \
+ arpa/inet.h \
+ dlfcn.h \
+ fcntl.h \
+ float.h \
+ limits.h \
+ linux/perf_event.h \
+ locale.h \
+ stddef.h \
+ sys/socket.h \
+ sys/time.h \
+ wchar.h \
+])
+
+# Check for dlinfo() by testing for RTLD_DI_LINKMAP in dlfcn.h
+AS_IF([test "x$ac_cv_header_dlfcn_h" = "xyes"], [
+ AC_CHECK_DECL([RTLD_DI_LINKMAP], [], [], [[#include <dlfcn.h>]])
+])
+
+
+## ##
+## Programs checks ##
+## ##
+
+AM_PROG_AR
+AC_PROG_SED
+AC_PROG_GREP
+AC_PROG_LN_S
+AC_PROG_MKDIR_P
+AC_PROG_MAKE_SET
+AC_CHECK_PROGS([ASCIIDOC], [asciidoc])
+AC_CHECK_PROGS([CMAKE], [cmake])
+AC_CHECK_PROGS([FOLD], [fold])
+AC_CHECK_PROGS([XMLTO], [xmlto])
+
+AM_PATH_PYTHON([2.7], [], [PYTHON=""])
+
+# Initialize and configure libtool
+LT_INIT([disable-static])