Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / m4 / openvswitch.m4
1 # -*- autoconf -*-
2
3 # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 dnl Checks for --enable-coverage and updates CFLAGS and LDFLAGS appropriately.
18 AC_DEFUN([OVS_CHECK_COVERAGE],
19   [AC_REQUIRE([AC_PROG_CC])
20    AC_ARG_ENABLE(
21      [coverage],
22      [AC_HELP_STRING([--enable-coverage],
23                      [Enable gcov coverage tool.])],
24      [case "${enableval}" in
25         (yes) coverage=true ;;
26         (no)  coverage=false ;;
27         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;;
28       esac],
29      [coverage=false])
30    if $coverage; then
31      CFLAGS="$CFLAGS -O0 --coverage"
32      LDFLAGS="$LDFLAGS --coverage"
33    fi])
34
35 dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
36 AC_DEFUN([OVS_CHECK_NDEBUG],
37   [AC_ARG_ENABLE(
38      [ndebug],
39      [AC_HELP_STRING([--enable-ndebug],
40                      [Disable debugging features for max performance])],
41      [case "${enableval}" in
42         (yes) ndebug=true ;;
43         (no)  ndebug=false ;;
44         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
45       esac],
46      [ndebug=false])
47    AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
48
49 dnl Checks for ESX.
50 AC_DEFUN([OVS_CHECK_ESX],
51   [AC_CHECK_HEADER([vmware.h],
52                    [ESX=yes],
53                    [ESX=no])
54    AM_CONDITIONAL([ESX], [test "$ESX" = yes])
55    if test "$ESX" = yes; then
56       AC_DEFINE([ESX], [1], [Define to 1 if building on ESX.])
57    fi])
58
59 dnl Checks for WINDOWS.
60 AC_DEFUN([OVS_CHECK_WIN32],
61   [AC_CHECK_HEADER([windows.h],
62                    [WIN32=yes],
63                    [WIN32=no])
64    AM_CONDITIONAL([WIN32], [test "$WIN32" = yes])
65    if test "$WIN32" = yes; then
66       AC_ARG_WITH([pthread],
67          [AS_HELP_STRING([--with-pthread=DIR],
68             [root of the pthread-win32 directory])],
69          [
70             case "$withval" in
71             "" | y | ye | yes | n | no)
72             AC_MSG_ERROR([Invalid --with-pthread value])
73               ;;
74             *)
75             PTHREAD_INCLUDES="-I$withval/include"
76             PTHREAD_LDFLAGS="-L$withval/lib/x86"
77             PTHREAD_LIBS="-lpthreadVC2"
78             AC_SUBST([PTHREAD_INCLUDES])
79             AC_SUBST([PTHREAD_LDFLAGS])
80             AC_SUBST([PTHREAD_LIBS])
81               ;;
82             esac
83          ], [
84             AC_MSG_ERROR([pthread directory not specified])
85          ]
86       )
87       AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
88       AH_BOTTOM([#ifdef WIN32
89 #include "include/windows/windefs.h"
90 #endif])
91    fi])
92
93 dnl Checks for Netlink support.
94 AC_DEFUN([OVS_CHECK_NETLINK],
95   [AC_CHECK_HEADER([linux/netlink.h],
96                    [HAVE_NETLINK=yes],
97                    [HAVE_NETLINK=no],
98                    [#include <sys/socket.h>
99    ])
100    AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
101    if test "$HAVE_NETLINK" = yes; then
102       AC_DEFINE([HAVE_NETLINK], [1],
103                 [Define to 1 if Netlink protocol is available.])
104    fi])
105
106 dnl Checks for OpenSSL.
107 AC_DEFUN([OVS_CHECK_OPENSSL],
108   [AC_ARG_ENABLE(
109      [ssl],
110      [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
111      [case "${enableval}" in
112         (yes) ssl=true ;;
113         (no)  ssl=false ;;
114         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
115       esac],
116      [ssl=check])
117
118    if test "$ssl" != false; then
119        AX_CHECK_OPENSSL(
120          [HAVE_OPENSSL=yes],
121          [HAVE_OPENSSL=no
122           if test "$ssl" = check; then
123             AC_MSG_WARN([Cannot find openssl:
124
125 $SSL_PKG_ERRORS
126
127 OpenFlow connections over SSL will not be supported.
128 (You may use --disable-ssl to suppress this warning.)])
129           else
130             AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
131           fi])
132    else
133        HAVE_OPENSSL=no
134    fi
135    AC_SUBST([HAVE_OPENSSL])
136    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
137    if test "$HAVE_OPENSSL" = yes; then
138       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
139    fi])
140
141 dnl Checks for libraries needed by lib/socket-util.c.
142 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
143   [AC_CHECK_LIB([socket], [connect])
144    AC_SEARCH_LIBS([gethostbyname], [resolv])])
145
146 dnl Checks for the directory in which to store the PKI.
147 AC_DEFUN([OVS_CHECK_PKIDIR],
148   [AC_ARG_WITH(
149      [pkidir],
150      AC_HELP_STRING([--with-pkidir=DIR],
151                     [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
152      [PKIDIR=$withval],
153      [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
154    AC_SUBST([PKIDIR])])
155
156 dnl Checks for the directory in which to store pidfiles.
157 AC_DEFUN([OVS_CHECK_RUNDIR],
158   [AC_ARG_WITH(
159      [rundir],
160      AC_HELP_STRING([--with-rundir=DIR],
161                     [directory used for pidfiles
162                     [[LOCALSTATEDIR/run/openvswitch]]]),
163      [RUNDIR=$withval],
164      [RUNDIR='${localstatedir}/run/openvswitch'])
165    AC_SUBST([RUNDIR])])
166
167 dnl Checks for the directory in which to store logs.
168 AC_DEFUN([OVS_CHECK_LOGDIR],
169   [AC_ARG_WITH(
170      [logdir],
171      AC_HELP_STRING([--with-logdir=DIR],
172                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
173      [LOGDIR=$withval],
174      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
175    AC_SUBST([LOGDIR])])
176
177 dnl Checks for the directory in which to store the Open vSwitch database.
178 AC_DEFUN([OVS_CHECK_DBDIR],
179   [AC_ARG_WITH(
180      [dbdir],
181      AC_HELP_STRING([--with-dbdir=DIR],
182                     [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
183      [DBDIR=$withval],
184      [DBDIR='${sysconfdir}/${PACKAGE}'])
185    AC_SUBST([DBDIR])])
186
187 dnl Defines HAVE_BACKTRACE if backtrace() is found.
188 AC_DEFUN([OVS_CHECK_BACKTRACE],
189   [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
190                   [AC_DEFINE([HAVE_BACKTRACE], [1],
191                              [Define to 1 if you have backtrace(3).])])])
192
193 dnl Checks for __malloc_hook, etc., supported by glibc.
194 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
195   [AC_CACHE_CHECK(
196     [whether libc supports hooks for malloc and related functions],
197     [ovs_cv_malloc_hooks],
198     [AC_COMPILE_IFELSE(
199       [AC_LANG_PROGRAM(
200          [#include <malloc.h>
201          ],
202          [(void) __malloc_hook;
203           (void) __realloc_hook;
204           (void) __free_hook;])],
205       [ovs_cv_malloc_hooks=yes],
206       [ovs_cv_malloc_hooks=no])])
207    if test $ovs_cv_malloc_hooks = yes; then
208      AC_DEFINE([HAVE_MALLOC_HOOKS], [1],
209                [Define to 1 if you have __malloc_hook, __realloc_hook, and
210                 __free_hook in <malloc.h>.])
211    fi])
212
213 dnl Checks for valgrind/valgrind.h.
214 AC_DEFUN([OVS_CHECK_VALGRIND],
215   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
216
217 dnl Checks for Python 2.x, x >= 4.
218 AC_DEFUN([OVS_CHECK_PYTHON],
219   [AC_CACHE_CHECK(
220      [for Python 2.x for x >= 4],
221      [ovs_cv_python],
222      [if test -n "$PYTHON"; then
223         ovs_cv_python=$PYTHON
224       else
225         ovs_cv_python=no
226         for binary in python python2.4 python2.5; do
227           ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
228           for dir in $PATH; do
229             IFS=$ovs_save_IFS
230             test -z "$dir" && dir=.
231             if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
232 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
233     sys.exit(0)
234 else:
235     sys.exit(1)'; then
236               ovs_cv_python=$dir/$binary
237               break 2
238             fi
239           done
240         done
241       fi])
242    AC_SUBST([HAVE_PYTHON])
243    AM_MISSING_PROG([PYTHON], [python])
244    if test $ovs_cv_python != no; then
245      PYTHON=$ovs_cv_python
246      HAVE_PYTHON=yes
247    else
248      HAVE_PYTHON=no
249    fi
250    AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
251
252 dnl Checks for dot.
253 AC_DEFUN([OVS_CHECK_DOT],
254   [AC_CACHE_CHECK(
255     [for dot],
256     [ovs_cv_dot],
257     [dnl "dot" writes -V output to stderr:
258      if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
259        ovs_cv_dot=yes
260      else
261        ovs_cv_dot=no
262      fi])
263    AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
264
265 dnl Checks whether $PYTHON supports the module given as $1
266 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
267   [AC_REQUIRE([OVS_CHECK_PYTHON])
268    AC_CACHE_CHECK(
269      [for $1 Python module],
270      [ovs_cv_py_[]AS_TR_SH([$1])],
271      [ovs_cv_py_[]AS_TR_SH([$1])=no
272       if test $HAVE_PYTHON = yes; then
273         AS_ECHO(["running $PYTHON -c 'import $1
274 import sys
275 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
276         if $PYTHON -c 'import $1
277 import sys
278 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
279           ovs_cv_py_[]AS_TR_SH([$1])=yes
280         fi
281       fi])])
282
283 dnl Checks for missing python modules at build time
284 AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
285   [OVS_CHECK_PYTHON_MODULE([uuid])
286    if test $ovs_cv_py_uuid = yes; then
287      INCLUDE_PYTHON_COMPAT=no
288    else
289      INCLUDE_PYTHON_COMPAT=yes
290    fi
291    AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
292    AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
293    AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
294
295 dnl Checks for groff.
296 AC_DEFUN([OVS_CHECK_GROFF],
297   [AC_CACHE_CHECK(
298     [for groff],
299     [ovs_cv_groff],
300     [if (groff -v) >/dev/null 2>&1; then
301        ovs_cv_groff=yes
302      else
303        ovs_cv_groff=no
304      fi])
305    AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
306
307 dnl Checks for thread-local storage support.
308 dnl
309 dnl Checks whether the compiler and linker support the C11
310 dnl thread_local macro from <threads.h>, and if so defines
311 dnl HAVE_THREAD_LOCAL.  If not, checks whether the compiler and linker
312 dnl support the GCC __thread extension, and if so defines
313 dnl HAVE___THREAD.
314 AC_DEFUN([OVS_CHECK_TLS],
315   [AC_CACHE_CHECK(
316      [whether $CC has <threads.h> that supports thread_local],
317      [ovs_cv_thread_local],
318      [AC_LINK_IFELSE(
319         [AC_LANG_PROGRAM([#include <threads.h>
320 static thread_local int var;], [return var;])],
321         [ovs_cv_thread_local=yes],
322         [ovs_cv_thread_local=no])])
323    if test $ovs_cv_thread_local = yes; then
324      AC_DEFINE([HAVE_THREAD_LOCAL], [1],
325                [Define to 1 if the C compiler and linker supports the C11
326                 thread_local matcro defined in <threads.h>.])
327    else
328      AC_CACHE_CHECK(
329        [whether $CC supports __thread],
330        [ovs_cv___thread],
331        [AC_LINK_IFELSE(
332           [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
333           [ovs_cv___thread=yes],
334           [ovs_cv___thread=no])])
335      if test $ovs_cv___thread = yes; then
336        AC_DEFINE([HAVE___THREAD], [1],
337                  [Define to 1 if the C compiler and linker supports the
338                   GCC __thread extenions.])
339      fi
340    fi])
341
342 dnl OVS_CHECK_ATOMIC_LIBS
343 dnl
344 dnl Check to see if -latomic is need for GCC atomic built-ins.
345 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
346    [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
347
348 dnl OVS_CHECK_GCC4_ATOMICS
349 dnl
350 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
351 dnl A compile-time only check is not enough because the compiler defers
352 dnl unimplemented built-ins to libgcc, which sometimes also lacks
353 dnl implementations.
354 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
355   [AC_CACHE_CHECK(
356      [whether $CC supports GCC 4.0+ atomic built-ins],
357      [ovs_cv_gcc4_atomics],
358      [AC_LINK_IFELSE(
359         [AC_LANG_PROGRAM([[#include <stdlib.h>
360
361 #define ovs_assert(expr) if (!(expr)) abort();
362 #define TEST_ATOMIC_TYPE(TYPE)                  \
363     {                                           \
364         TYPE x = 1;                             \
365         TYPE orig;                              \
366                                                 \
367         __sync_synchronize();                   \
368         ovs_assert(x == 1);                     \
369                                                 \
370         __sync_synchronize();                   \
371         x = 3;                                  \
372         __sync_synchronize();                   \
373         ovs_assert(x == 3);                     \
374                                                 \
375         orig = __sync_fetch_and_add(&x, 1);     \
376         ovs_assert(orig == 3);                  \
377         __sync_synchronize();                   \
378         ovs_assert(x == 4);                     \
379                                                 \
380         orig = __sync_fetch_and_sub(&x, 2);     \
381         ovs_assert(orig == 4);                  \
382         __sync_synchronize();                   \
383         ovs_assert(x == 2);                     \
384                                                 \
385         orig = __sync_fetch_and_or(&x, 6);      \
386         ovs_assert(orig == 2);                  \
387         __sync_synchronize();                   \
388         ovs_assert(x == 6);                     \
389                                                 \
390         orig = __sync_fetch_and_and(&x, 10);    \
391         ovs_assert(orig == 6);                  \
392         __sync_synchronize();                   \
393         ovs_assert(x == 2);                     \
394                                                 \
395         orig = __sync_fetch_and_xor(&x, 10);    \
396         ovs_assert(orig == 2);                  \
397         __sync_synchronize();                   \
398         ovs_assert(x == 8);                     \
399     }]], [dnl
400 TEST_ATOMIC_TYPE(char);
401 TEST_ATOMIC_TYPE(unsigned char);
402 TEST_ATOMIC_TYPE(signed char);
403 TEST_ATOMIC_TYPE(short);
404 TEST_ATOMIC_TYPE(unsigned short);
405 TEST_ATOMIC_TYPE(int);
406 TEST_ATOMIC_TYPE(unsigned int);
407 TEST_ATOMIC_TYPE(long int);
408 TEST_ATOMIC_TYPE(unsigned long int);
409 TEST_ATOMIC_TYPE(long long int);
410 TEST_ATOMIC_TYPE(unsigned long long int);
411 ])],
412         [ovs_cv_gcc4_atomics=yes],
413         [ovs_cv_gcc4_atomics=no])])
414    if test $ovs_cv_gcc4_atomics = yes; then
415      AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
416                [Define to 1 if the C compiler and linker supports the GCC 4.0+
417                 atomic built-ins.])
418    fi])
419
420 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
421 dnl
422 dnl Checks __atomic_always_lock_free(SIZE, 0)
423 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE], 
424   [AC_CACHE_CHECK(
425     [value of __atomic_always_lock_free($1)],
426     [ovs_cv_atomic_always_lock_free_$1],
427     [AC_COMPUTE_INT(
428         [ovs_cv_atomic_always_lock_free_$1],
429         [__atomic_always_lock_free($1, 0)],
430         [],
431         [ovs_cv_atomic_always_lock_free_$1=unsupported])])
432    if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
433      AC_DEFINE_UNQUOTED(
434        [ATOMIC_ALWAYS_LOCK_FREE_$1B],
435        [$ovs_cv_atomic_always_lock_free_$1],
436        [If the C compiler is GCC 4.7 or later, define to the return value of
437         __atomic_always_lock_free($1, 0).  If the C compiler is not GCC or is
438         an older version of GCC, the value does not matter.])
439    fi])
440
441 dnl OVS_CHECK_POSIX_AIO
442 AC_DEFUN([OVS_CHECK_POSIX_AIO],
443   [AC_SEARCH_LIBS([aio_write], [rt])
444    AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
445
446 dnl OVS_CHECK_INCLUDE_NEXT
447 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
448   [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
449    gl_CHECK_NEXT_HEADERS([$1])])