+
+dnl Check for too-old XenServer.
+AC_DEFUN([OVS_CHECK_XENSERVER_VERSION],
+ [AC_CACHE_CHECK([XenServer release], [ovs_cv_xsversion],
+ [if test -e /etc/redhat-release; then
+ ovs_cv_xsversion=`sed -n 's/^XenServer DDK release \([[^-]]*\)-.*/\1/p' /etc/redhat-release`
+ fi
+ if test -z "$ovs_cv_xsversion"; then
+ ovs_cv_xsversion=none
+ fi])
+ case $ovs_cv_xsversion in
+ none)
+ ;;
+
+ [[1-9]][[0-9]]* | dnl XenServer 10 or later
+ [[6-9]]* | dnl XenServer 6 or later
+ 5.[[7-9]]* | dnl XenServer 5.7 or later
+ 5.6.[[1-9]][[0-9]][[0-9]][[0-9]]* | dnl XenServer 5.6.1000 or later
+ 5.6.[[2-9]][[0-9]][[0-9]]* | dnl XenServer 5.6.200 or later
+ 5.6.1[[0-9]][[0-9]]) dnl Xenserver 5.6.100 or later
+ ;;
+
+ *)
+ AC_MSG_ERROR([This appears to be XenServer $ovs_cv_xsversion, but only XenServer 5.6.100 or later is supported. (If you are really using a supported version of XenServer, you may override this error message by specifying 'ovs_cv_xsversion=5.6.100' on the "configure" command line.)])
+ ;;
+ esac])
+
+dnl OVS_MAKE_HAS_IF([if-true], [if-false])
+dnl
+dnl Checks whether make has the GNU make $(if condition,then,else) extension.
+dnl Runs 'if-true' if so, 'if-false' otherwise.
+AC_DEFUN([OVS_CHECK_MAKE_IF],
+ [AC_CACHE_CHECK(
+ [whether ${MAKE-make} has GNU make \$(if) extension],
+ [ovs_cv_gnu_make_if],
+ [cat <<'EOF' > conftest.mk
+conftest.out:
+ echo $(if x,y,z) > conftest.out
+.PHONY: all
+EOF
+ rm -f conftest.out
+ AS_ECHO(["$as_me:$LINENO: invoking ${MAKE-make} -f conftest.mk all:"]) >&AS_MESSAGE_LOG_FD 2>&1
+ ${MAKE-make} -f conftest.mk conftest.out >&AS_MESSAGE_LOG_FD 2>&1
+ AS_ECHO(["$as_me:$LINENO: conftest.out contains:"]) >&AS_MESSAGE_LOG_FD 2>&1
+ cat conftest.out >&AS_MESSAGE_LOG_FD 2>&1
+ result=`cat conftest.out`
+ rm -f conftest.mk conftest.out
+ if test "X$result" = "Xy"; then
+ ovs_cv_gnu_make_if=yes
+ else
+ ovs_cv_gnu_make_if=no
+ fi])])
+
+dnl OVS_CHECK_GNU_MAKE
+dnl
+dnl Checks whether make is GNU make (because Linux kernel Makefiles
+dnl only work with GNU make).
+AC_DEFUN([OVS_CHECK_GNU_MAKE],
+ [AC_CACHE_CHECK(
+ [whether ${MAKE-make} is GNU make],
+ [ovs_cv_gnu_make],
+ [rm -f conftest.out
+ AS_ECHO(["$as_me:$LINENO: invoking ${MAKE-make} --version:"]) >&AS_MESSAGE_LOG_FD 2>&1
+ ${MAKE-make} --version >conftest.out 2>&1
+ cat conftest.out >&AS_MESSAGE_LOG_FD 2>&1
+ result=`cat conftest.out`
+ rm -f conftest.mk conftest.out
+
+ case $result in # (
+ GNU*) ovs_cv_gnu_make=yes ;; # (
+ *) ovs_cv_gnu_make=no ;;
+ esac])
+ AM_CONDITIONAL([GNU_MAKE], [test $ovs_cv_gnu_make = yes])])
+
+dnl OVS_CHECK_SPARSE_TARGET
+dnl
+dnl The "cgcc" script from "sparse" isn't very good at detecting the
+dnl target for which the code is being built. This helps it out.
+AC_DEFUN([OVS_CHECK_SPARSE_TARGET],
+ [AC_CACHE_CHECK(
+ [target hint for cgcc],
+ [ac_cv_sparse_target],
+ [AS_CASE([`$CC -dumpmachine 2>/dev/null`],
+ [i?86-* | athlon-*], [ac_cv_sparse_target=x86],
+ [x86_64-*], [ac_cv_sparse_target=x86_64],
+ [ac_cv_sparse_target=other])])
+ AS_CASE([$ac_cv_sparse_target],
+ [x86], [SPARSEFLAGS= CGCCFLAGS=-target=i86],
+ [x86_64], [SPARSEFLAGS=-m64 CGCCFLAGS=-target=x86_64],
+ [SPARSEFLAGS= CGCCFLAGS=])
+ AC_SUBST([SPARSEFLAGS])
+ AC_SUBST([CGCCFLAGS])])
+
+dnl OVS_SPARSE_EXTRA_INCLUDES
+dnl
+dnl The cgcc script from "sparse" does not search gcc's default
+dnl search path. Get the default search path from GCC and pass
+dnl them to sparse.
+AC_DEFUN([OVS_SPARSE_EXTRA_INCLUDES],
+ AC_SUBST([SPARSE_EXTRA_INCLUDES],
+ [`$CC -v -E - </dev/null 2>&1 >/dev/null | sed -n -e '/^#include.*search.*starts.*here:/,/^End.*of.*search.*list\./s/^ \(.*\)/-I \1/p' |grep -v /usr/lib | grep -x -v '\-I /usr/include' | tr \\\n ' ' `] ))
+
+dnl OVS_ENABLE_SPARSE
+AC_DEFUN([OVS_ENABLE_SPARSE],
+ [AC_REQUIRE([OVS_CHECK_SPARSE_TARGET])
+ AC_REQUIRE([OVS_CHECK_MAKE_IF])
+ AC_REQUIRE([OVS_SPARSE_EXTRA_INCLUDES])
+ : ${SPARSE=sparse}
+ AC_SUBST([SPARSE])
+ AC_CONFIG_COMMANDS_PRE(
+ [if test $ovs_cv_gnu_make_if = yes; then
+ CC='$(if $(C),env REAL_CC="'"$CC"'" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse $(SPARSEFLAGS) $(SPARSE_EXTRA_INCLUDES) " cgcc $(CGCCFLAGS),'"$CC"')'
+ fi])])
+
+dnl OVS_PTHREAD_SET_NAME
+dnl
+dnl This checks for three known variants of pthreads functions for setting
+dnl the name of the current thread:
+dnl
+dnl glibc: int pthread_setname_np(pthread_t, const char *name);
+dnl NetBSD: int pthread_setname_np(pthread_t, const char *format, void *arg);
+dnl FreeBSD: int pthread_set_name_np(pthread_t, const char *name);
+dnl
+dnl For glibc and FreeBSD, the arguments are just a thread and its name. For
+dnl NetBSD, 'format' is a printf() format string and 'arg' is an argument to
+dnl provide to it.
+dnl
+dnl This macro defines:
+dnl
+dnl glibc: HAVE_GLIBC_PTHREAD_SETNAME_NP
+dnl NetBSD: HAVE_NETBSD_PTHREAD_SETNAME_NP
+dnl FreeBSD: HAVE_PTHREAD_SET_NAME_NP
+AC_DEFUN([OVS_CHECK_PTHREAD_SET_NAME],
+ [AC_CHECK_FUNCS([pthread_set_name_np])
+ if test $ac_cv_func_pthread_set_name_np != yes; then
+ AC_CACHE_CHECK(
+ [for pthread_setname_np() variant],
+ [ovs_cv_pthread_setname_np],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([#include <pthread.h>
+ ], [pthread_setname_np(pthread_self(), "name");])],
+ [ovs_cv_pthread_setname_np=glibc],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([#include <pthread.h>
+], [pthread_setname_np(pthread_self(), "%s", "name");])],
+ [ovs_cv_pthread_setname_np=netbsd],
+ [ovs_cv_pthread_setname_np=none])])])
+ case $ovs_cv_pthread_setname_np in # (
+ glibc)
+ AC_DEFINE(
+ [HAVE_GLIBC_PTHREAD_SETNAME_NP], [1],
+ [Define to 1 if pthread_setname_np() is available and takes 2 parameters (like glibc).])
+ ;; # (
+ netbsd)
+ AC_DEFINE(
+ [HAVE_NETBSD_PTHREAD_SETNAME_NP], [1],
+ [Define to 1 if pthread_setname_np() is available and takes 3 parameters (like NetBSD).])
+ ;;
+ esac
+ fi])