ovs-thread: Add per-thread data support.
[sliver-openvswitch.git] / m4 / openvswitch.m4
index 7469011..57c71e0 100644 (file)
@@ -1,6 +1,6 @@
 # -*- autoconf -*-
 
-# Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+# Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -99,8 +99,7 @@ AC_DEFUN([OVS_CHECK_OPENSSL],
      [ssl=check])
 
    if test "$ssl" != false; then
-       m4_ifndef([PKG_CHECK_MODULES], [m4_fatal([Please install pkg-config.])])
-       PKG_CHECK_MODULES([SSL], [openssl],
+       AX_CHECK_OPENSSL(
          [HAVE_OPENSSL=yes],
          [HAVE_OPENSSL=no
           if test "$ssl" = check; then
@@ -168,10 +167,11 @@ AC_DEFUN([OVS_CHECK_DBDIR],
      [DBDIR='${sysconfdir}/${PACKAGE}'])
    AC_SUBST([DBDIR])])
 
-dnl Defines HAVE_BACKTRACE if backtrace() is declared in <execinfo.h>
-dnl and exists in libc.
+dnl Defines HAVE_BACKTRACE if backtrace() is found.
 AC_DEFUN([OVS_CHECK_BACKTRACE],
-  [AC_CHECK_HEADER([execinfo.h], [AC_CHECK_FUNCS([backtrace])])])
+  [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
+                  [AC_DEFINE([HAVE_BACKTRACE], [1],
+                             [Define to 1 if you have backtrace(3).])])])
 
 dnl Checks for __malloc_hook, etc., supported by glibc.
 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
@@ -391,22 +391,37 @@ AC_DEFUN([OVS_CHECK_GROFF],
      fi])
    AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
 
-dnl Checks for --disable-brcompat and undefines BUILD_BRCOMPAT if it is specified.
-AC_DEFUN([OVS_CHECK_BRCOMPAT],
-  [AC_ARG_ENABLE(
-     [brcompat],
-     [AC_HELP_STRING([--disable-brcompat],
-                     [Disable building brcompat])],
-     [case "${enableval}" in
-        (yes) brcompat=true ;;
-        (no)  brcompat=false ;;
-        (*) AC_MSG_ERROR([bad value ${enableval} for --enable-brcompat]) ;;
-      esac],
-     [brcompat=true])
-   if test x$brcompat = xtrue; then
-      BUILD_BRCOMPAT=yes
+dnl Checks for thread-local storage support.
+dnl
+dnl Checks whether the compiler and linker support the C11
+dnl thread_local macro from <threads.h>, and if so defines
+dnl HAVE_THREAD_LOCAL.  If not, checks whether the compiler and linker
+dnl support the GCC __thread extension, and if so defines
+dnl HAVE___THREAD.
+AC_DEFUN([OVS_CHECK_TLS],
+  [AC_CACHE_CHECK(
+     [whether $CC has <threads.h> that supports thread_local],
+     [ovs_cv_thread_local],
+     [AC_LINK_IFELSE(
+        [AC_LANG_PROGRAM([#include <threads.h>
+static thread_local int var;], [return var;])],
+        [ovs_cv_thread_local=yes],
+        [ovs_cv_thread_local=no])])
+   if test $ovs_cv_thread_local = yes; then
+     AC_DEFINE([HAVE_THREAD_LOCAL], [1],
+               [Define to 1 if the C compiler and linker supports the C11
+                thread_local matcro defined in <threads.h>.])
    else
-      BUILD_BRCOMPAT=""
-   fi
-   AC_SUBST([BUILD_BRCOMPAT])
-   AM_CONDITIONAL([BUILD_BRCOMPAT], [test x$brcompat = xtrue])])
+     AC_CACHE_CHECK(
+       [whether $CC supports __thread],
+       [ovs_cv___thread],
+       [AC_LINK_IFELSE(
+          [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
+          [ovs_cv___thread=yes],
+          [ovs_cv___thread=no])])
+     if test $ovs_cv___thread = yes; then
+       AC_DEFINE([HAVE___THREAD], [1],
+                 [Define to 1 if the C compiler and linker supports the
+                  GCC __thread extenions.])
+     fi
+   fi])