@@ -41,6 +41,8 @@ MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
+AC_LANG(C++)
+
dnl Enabled by default
AC_MSG_CHECKING([whether to build C++ tools])
AC_ARG_ENABLE(c++-tools,
@@ -67,6 +69,35 @@ AC_MSG_RESULT([$maintainer_mode])
test "$maintainer_mode" = yes && MAINTAINER=yes
AC_SUBST(MAINTAINER)
+# Handle configuration of checking; for the tools in this directory we
+# default to release checking and stricter checks do not change this.
+
+AC_ARG_ENABLE(checking,
+[AS_HELP_STRING([[--enable-checking[=LIST]]],
+ [enable expensive run-time checks. With LIST,
+ enable only specific categories of checks.
+ Categories are: yes,no,all,none,release.])],
+[ac_checking_flags="${enableval}"],[
+# Default to checking.
+ac_checking_flags=yes
+])
+IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="$IFS,"
+for check in release $ac_checking_flags
+do
+ case $check in
+ # these set all the flags to specific states
+ yes|all|release|assert) ac_assert_checking=1 ; ;;
+ no|none) ac_assert_checking= ; ;;
+ *) ;;
+ esac
+done
+IFS="$ac_save_IFS"
+
+if test x$ac_assert_checking != x ; then
+ AC_DEFINE(ENABLE_ASSERT_CHECKING, 1,
+[Define if you want assertions enabled. This is a cheap check.])
+fi
+
# Check whether --enable-default-pie was given.
AC_ARG_ENABLE(default-pie,
[AS_HELP_STRING([--enable-default-pie],
@@ -61,6 +61,10 @@ along with GCC; see the file COPYING3. If not see
# define gai_strerror(X) ""
#endif
+#ifndef AI_NUMERICSERV
+#define AI_NUMERICSERV 0
+#endif
+
#include <getopt.h>
// Select or epoll
@@ -92,6 +96,28 @@ along with GCC; see the file COPYING3. If not see
#define DIR_SEPARATOR '/'
#endif
+/* Imported from libcpp/system.h
+ Use gcc_assert(EXPR) to test invariants. */
+#if ENABLE_ASSERT_CHECKING
+#define gcc_assert(EXPR) \
+ ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0))
+#elif (GCC_VERSION >= 4005)
+#define gcc_assert(EXPR) \
+ ((void)(__builtin_expect (!(EXPR), 0) ? __builtin_unreachable (), 0 : 0))
+#else
+/* Include EXPR, so that unused variable warnings do not occur. */
+#define gcc_assert(EXPR) ((void)(0 && (EXPR)))
+#endif
+
+/* Use gcc_unreachable() to mark unreachable locations (like an
+ unreachable default case of a switch. Do not use gcc_assert(0). */
+#if (GCC_VERSION >= 4005) && !ENABLE_ASSERT_CHECKING
+#define gcc_unreachable() __builtin_unreachable ()
+#else
+#define gcc_unreachable() (fancy_abort (__FILE__, __LINE__, __FUNCTION__))
+#endif
+
+
#if NETWORKING
struct netmask {
in6_addr addr;
@@ -202,11 +228,13 @@ internal_error (const char *fmt, ...)
/* Hooked to from gcc_assert & gcc_unreachable. */
+#if ENABLE_ASSERT_CHECKING
void ATTRIBUTE_NORETURN ATTRIBUTE_COLD
fancy_abort (const char *file, int line, const char *func)
{
internal_error ("in %s, at %s:%d", func, trim_src_file (file), line);
}
+#endif
/* Exploded on a signal. */