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