ovsdbmonitor: Remove.
[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_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
67       AH_BOTTOM([#ifdef WIN32
68 #include "include/windows/windefs.h"
69 #endif])
70    fi])
71
72 dnl Checks for Netlink support.
73 AC_DEFUN([OVS_CHECK_NETLINK],
74   [AC_CHECK_HEADER([linux/netlink.h],
75                    [HAVE_NETLINK=yes],
76                    [HAVE_NETLINK=no],
77                    [#include <sys/socket.h>
78    #include <linux/types.h>
79    ])
80    AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
81    if test "$HAVE_NETLINK" = yes; then
82       AC_DEFINE([HAVE_NETLINK], [1],
83                 [Define to 1 if Netlink protocol is available.])
84    fi])
85
86 dnl Checks for OpenSSL.
87 AC_DEFUN([OVS_CHECK_OPENSSL],
88   [AC_ARG_ENABLE(
89      [ssl],
90      [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
91      [case "${enableval}" in
92         (yes) ssl=true ;;
93         (no)  ssl=false ;;
94         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
95       esac],
96      [ssl=check])
97
98    if test "$ssl" != false; then
99        AX_CHECK_OPENSSL(
100          [HAVE_OPENSSL=yes],
101          [HAVE_OPENSSL=no
102           if test "$ssl" = check; then
103             AC_MSG_WARN([Cannot find openssl:
104
105 $SSL_PKG_ERRORS
106
107 OpenFlow connections over SSL will not be supported.
108 (You may use --disable-ssl to suppress this warning.)])
109           else
110             AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
111           fi])
112    else
113        HAVE_OPENSSL=no
114    fi
115    AC_SUBST([HAVE_OPENSSL])
116    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
117    if test "$HAVE_OPENSSL" = yes; then
118       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
119    fi])
120
121 dnl Checks for libraries needed by lib/socket-util.c.
122 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
123   [AC_CHECK_LIB([socket], [connect])
124    AC_SEARCH_LIBS([gethostbyname], [resolv])])
125
126 dnl Checks for the directory in which to store the PKI.
127 AC_DEFUN([OVS_CHECK_PKIDIR],
128   [AC_ARG_WITH(
129      [pkidir],
130      AC_HELP_STRING([--with-pkidir=DIR],
131                     [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
132      [PKIDIR=$withval],
133      [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
134    AC_SUBST([PKIDIR])])
135
136 dnl Checks for the directory in which to store pidfiles.
137 AC_DEFUN([OVS_CHECK_RUNDIR],
138   [AC_ARG_WITH(
139      [rundir],
140      AC_HELP_STRING([--with-rundir=DIR],
141                     [directory used for pidfiles
142                     [[LOCALSTATEDIR/run/openvswitch]]]),
143      [RUNDIR=$withval],
144      [RUNDIR='${localstatedir}/run/openvswitch'])
145    AC_SUBST([RUNDIR])])
146
147 dnl Checks for the directory in which to store logs.
148 AC_DEFUN([OVS_CHECK_LOGDIR],
149   [AC_ARG_WITH(
150      [logdir],
151      AC_HELP_STRING([--with-logdir=DIR],
152                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
153      [LOGDIR=$withval],
154      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
155    AC_SUBST([LOGDIR])])
156
157 dnl Checks for the directory in which to store the Open vSwitch database.
158 AC_DEFUN([OVS_CHECK_DBDIR],
159   [AC_ARG_WITH(
160      [dbdir],
161      AC_HELP_STRING([--with-dbdir=DIR],
162                     [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
163      [DBDIR=$withval],
164      [DBDIR='${sysconfdir}/${PACKAGE}'])
165    AC_SUBST([DBDIR])])
166
167 dnl Defines HAVE_BACKTRACE if backtrace() is found.
168 AC_DEFUN([OVS_CHECK_BACKTRACE],
169   [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
170                   [AC_DEFINE([HAVE_BACKTRACE], [1],
171                              [Define to 1 if you have backtrace(3).])])])
172
173 dnl Checks for __malloc_hook, etc., supported by glibc.
174 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
175   [AC_CACHE_CHECK(
176     [whether libc supports hooks for malloc and related functions],
177     [ovs_cv_malloc_hooks],
178     [AC_COMPILE_IFELSE(
179       [AC_LANG_PROGRAM(
180          [#include <malloc.h>
181          ],
182          [(void) __malloc_hook;
183           (void) __realloc_hook;
184           (void) __free_hook;])],
185       [ovs_cv_malloc_hooks=yes],
186       [ovs_cv_malloc_hooks=no])])
187    if test $ovs_cv_malloc_hooks = yes; then
188      AC_DEFINE([HAVE_MALLOC_HOOKS], [1],
189                [Define to 1 if you have __malloc_hook, __realloc_hook, and
190                 __free_hook in <malloc.h>.])
191    fi])
192
193 dnl Checks for valgrind/valgrind.h.
194 AC_DEFUN([OVS_CHECK_VALGRIND],
195   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
196
197 dnl Checks for Python 2.x, x >= 4.
198 AC_DEFUN([OVS_CHECK_PYTHON],
199   [AC_CACHE_CHECK(
200      [for Python 2.x for x >= 4],
201      [ovs_cv_python],
202      [if test -n "$PYTHON"; then
203         ovs_cv_python=$PYTHON
204       else
205         ovs_cv_python=no
206         for binary in python python2.4 python2.5; do
207           ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
208           for dir in $PATH; do
209             IFS=$ovs_save_IFS
210             test -z "$dir" && dir=.
211             if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
212 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
213     sys.exit(0)
214 else:
215     sys.exit(1)'; then
216               ovs_cv_python=$dir/$binary
217               break 2
218             fi
219           done
220         done
221       fi])
222    AC_SUBST([HAVE_PYTHON])
223    AM_MISSING_PROG([PYTHON], [python])
224    if test $ovs_cv_python != no; then
225      PYTHON=$ovs_cv_python
226      HAVE_PYTHON=yes
227    else
228      HAVE_PYTHON=no
229    fi
230    AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
231
232 dnl Checks for dot.
233 AC_DEFUN([OVS_CHECK_DOT],
234   [AC_CACHE_CHECK(
235     [for dot],
236     [ovs_cv_dot],
237     [dnl "dot" writes -V output to stderr:
238      if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
239        ovs_cv_dot=yes
240      else
241        ovs_cv_dot=no
242      fi])
243    AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
244
245 dnl Checks whether $PYTHON supports the module given as $1
246 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
247   [AC_REQUIRE([OVS_CHECK_PYTHON])
248    AC_CACHE_CHECK(
249      [for $1 Python module],
250      [ovs_cv_py_[]AS_TR_SH([$1])],
251      [ovs_cv_py_[]AS_TR_SH([$1])=no
252       if test $HAVE_PYTHON = yes; then
253         AS_ECHO(["running $PYTHON -c 'import $1
254 import sys
255 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
256         if $PYTHON -c 'import $1
257 import sys
258 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
259           ovs_cv_py_[]AS_TR_SH([$1])=yes
260         fi
261       fi])])
262
263 dnl Checks for missing python modules at build time
264 AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
265   [OVS_CHECK_PYTHON_MODULE([uuid])
266    if test $ovs_cv_py_uuid = yes; then
267      INCLUDE_PYTHON_COMPAT=no
268    else
269      INCLUDE_PYTHON_COMPAT=yes
270    fi
271    AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
272    AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
273    AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
274
275 dnl Checks for groff.
276 AC_DEFUN([OVS_CHECK_GROFF],
277   [AC_CACHE_CHECK(
278     [for groff],
279     [ovs_cv_groff],
280     [if (groff -v) >/dev/null 2>&1; then
281        ovs_cv_groff=yes
282      else
283        ovs_cv_groff=no
284      fi])
285    AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
286
287 dnl Checks for thread-local storage support.
288 dnl
289 dnl Checks whether the compiler and linker support the C11
290 dnl thread_local macro from <threads.h>, and if so defines
291 dnl HAVE_THREAD_LOCAL.  If not, checks whether the compiler and linker
292 dnl support the GCC __thread extension, and if so defines
293 dnl HAVE___THREAD.
294 AC_DEFUN([OVS_CHECK_TLS],
295   [AC_CACHE_CHECK(
296      [whether $CC has <threads.h> that supports thread_local],
297      [ovs_cv_thread_local],
298      [AC_LINK_IFELSE(
299         [AC_LANG_PROGRAM([#include <threads.h>
300 static thread_local int var;], [return var;])],
301         [ovs_cv_thread_local=yes],
302         [ovs_cv_thread_local=no])])
303    if test $ovs_cv_thread_local = yes; then
304      AC_DEFINE([HAVE_THREAD_LOCAL], [1],
305                [Define to 1 if the C compiler and linker supports the C11
306                 thread_local matcro defined in <threads.h>.])
307    else
308      AC_CACHE_CHECK(
309        [whether $CC supports __thread],
310        [ovs_cv___thread],
311        [AC_LINK_IFELSE(
312           [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
313           [ovs_cv___thread=yes],
314           [ovs_cv___thread=no])])
315      if test $ovs_cv___thread = yes; then
316        AC_DEFINE([HAVE___THREAD], [1],
317                  [Define to 1 if the C compiler and linker supports the
318                   GCC __thread extenions.])
319      fi
320    fi])
321
322 dnl OVS_CHECK_ATOMIC_LIBS
323 dnl
324 dnl Check to see if -latomic is need for GCC atomic built-ins.
325 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
326    [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
327
328 dnl OVS_CHECK_GCC4_ATOMICS
329 dnl
330 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
331 dnl A compile-time only check is not enough because the compiler defers
332 dnl unimplemented built-ins to libgcc, which sometimes also lacks
333 dnl implementations.
334 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
335   [AC_CACHE_CHECK(
336      [whether $CC supports GCC 4.0+ atomic built-ins],
337      [ovs_cv_gcc4_atomics],
338      [AC_LINK_IFELSE(
339         [AC_LANG_PROGRAM([[#include <stdlib.h>
340
341 #define ovs_assert(expr) if (!(expr)) abort();
342 #define TEST_ATOMIC_TYPE(TYPE)                  \
343     {                                           \
344         TYPE x = 1;                             \
345         TYPE orig;                              \
346                                                 \
347         __sync_synchronize();                   \
348         ovs_assert(x == 1);                     \
349                                                 \
350         __sync_synchronize();                   \
351         x = 3;                                  \
352         __sync_synchronize();                   \
353         ovs_assert(x == 3);                     \
354                                                 \
355         orig = __sync_fetch_and_add(&x, 1);     \
356         ovs_assert(orig == 3);                  \
357         __sync_synchronize();                   \
358         ovs_assert(x == 4);                     \
359                                                 \
360         orig = __sync_fetch_and_sub(&x, 2);     \
361         ovs_assert(orig == 4);                  \
362         __sync_synchronize();                   \
363         ovs_assert(x == 2);                     \
364                                                 \
365         orig = __sync_fetch_and_or(&x, 6);      \
366         ovs_assert(orig == 2);                  \
367         __sync_synchronize();                   \
368         ovs_assert(x == 6);                     \
369                                                 \
370         orig = __sync_fetch_and_and(&x, 10);    \
371         ovs_assert(orig == 6);                  \
372         __sync_synchronize();                   \
373         ovs_assert(x == 2);                     \
374                                                 \
375         orig = __sync_fetch_and_xor(&x, 10);    \
376         ovs_assert(orig == 2);                  \
377         __sync_synchronize();                   \
378         ovs_assert(x == 8);                     \
379     }]], [dnl
380 TEST_ATOMIC_TYPE(char);
381 TEST_ATOMIC_TYPE(unsigned char);
382 TEST_ATOMIC_TYPE(signed char);
383 TEST_ATOMIC_TYPE(short);
384 TEST_ATOMIC_TYPE(unsigned short);
385 TEST_ATOMIC_TYPE(int);
386 TEST_ATOMIC_TYPE(unsigned int);
387 TEST_ATOMIC_TYPE(long int);
388 TEST_ATOMIC_TYPE(unsigned long int);
389 TEST_ATOMIC_TYPE(long long int);
390 TEST_ATOMIC_TYPE(unsigned long long int);
391 ])],
392         [ovs_cv_gcc4_atomics=yes],
393         [ovs_cv_gcc4_atomics=no])])
394    if test $ovs_cv_gcc4_atomics = yes; then
395      AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
396                [Define to 1 if the C compiler and linker supports the GCC 4.0+
397                 atomic built-ins.])
398    fi])
399
400 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
401 dnl
402 dnl Checks __atomic_always_lock_free(SIZE, 0)
403 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE], 
404   [AC_CACHE_CHECK(
405     [value of __atomic_always_lock_free($1)],
406     [ovs_cv_atomic_always_lock_free_$1],
407     [AC_COMPUTE_INT(
408         [ovs_cv_atomic_always_lock_free_$1],
409         [__atomic_always_lock_free($1, 0)],
410         [],
411         [ovs_cv_atomic_always_lock_free_$1=unsupported])])
412    if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
413      AC_DEFINE_UNQUOTED(
414        [ATOMIC_ALWAYS_LOCK_FREE_$1B],
415        [$ovs_cv_atomic_always_lock_free_$1],
416        [If the C compiler is GCC 4.7 or later, define to the return value of
417         __atomic_always_lock_free($1, 0).  If the C compiler is not GCC or is
418         an older version of GCC, the value does not matter.])
419    fi])
420
421 dnl OVS_CHECK_POSIX_AIO
422 AC_DEFUN([OVS_CHECK_POSIX_AIO],
423   [AC_SEARCH_LIBS([aio_write], [rt])
424    AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
425
426 dnl OVS_CHECK_INCLUDE_NEXT
427 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
428   [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
429    gl_CHECK_NEXT_HEADERS([$1])])