+AC_MSG_CHECKING(whether to disable optimizations and build with -g -O0)
+AC_ARG_ENABLE([optimizations],
+ [AS_HELP_STRING(--disable-optimizations,build with -g -O0 [[default=no]])],
+ [case "${enableval}" in
+ no) disable_optimizations=yes;;
+ *) disable_optimizations=no;;
+ esac],
+ [disable_optimizations=no])
+AC_MSG_RESULT(${disable_optimizations})
+
+dnl Set optimization and debugging for all architectures and systems.
+dnl NOTE: Setting the CFLAGS/CXXFLAGS only works before calling AC_PROG_CC/AC_PROG_CXX.
+if test x"$CFLAGS" = "x"; then
+ OPT_CFLAGS="-g"
+else
+ OPT_CFLAGS=$CFLAGS
+fi
+if test x"${disable_optimizations}" = "xyes"; then
+ OPT_CFLAGS="$OPT_CFLAGS -O0"
+else
+ OPT_CFLAGS="$OPT_CFLAGS -O2"
+fi
+OPT_CFLAGS="$OPT_CFLAGS -fno-strict-aliasing"
+
+if test x"$CXXFLAGS" = "x"; then
+ OPT_CXXFLAGS="-g"
+else
+ OPT_CXXFLAGS=$CXXFLAGS
+fi
+if test x"${disable_optimizations}" = "xyes"; then
+ OPT_CXXFLAGS="$OPT_CXXFLAGS -O0"
+else
+ OPT_CXXFLAGS="$OPT_CXXFLAGS -O2"
+fi
+OPT_CXXFLAGS="$OPT_CXXFLAGS -fno-strict-aliasing"
+
+dnl Check for compiler.
+AC_PROG_CC
+AC_PROG_CXX
+
+dnl Check compiler vendor.
+AX_COMPILER_VENDOR
+
+dnl Set compiler flags depending on the compiler vendor.
+case "$ax_cv_c_compiler_vendor" in
+gnu )
+ CC_FLAGS="-std=c99 -pedantic -Wall -Wno-long-long $CC_FLAGS"
+ CXX_FLAGS="-std=c++98 -pedantic -Wall -Wno-long-long $CXX_FLAGS"
+ ;;
+
+sgi )
+ CC_FLAGS="-c99 $CC_FLAGS"
+ CXX_FLAGS="$CXX_FLAGS"
+ ;;
+
+sun )
+ CC_FLAGS="-xc99 $CC_FLAGS"
+ CXX_FLAGS="$CXX_FLAGS"
+ ;;
+
+* )
+ AC_MSG_ERROR([$ax_cv_c_compiler_vendor compilers are currently not supported.])
+ ;;
+esac
+
+dnl Temporary set the CFLAGS for configure tests (e.g. inline keyword)
+dnl we set it properly at the end of this file.