3 # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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:
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 dnl Checks for --enable-coverage and updates CFLAGS and LDFLAGS appropriately.
18 AC_DEFUN([OVS_CHECK_COVERAGE],
19 [AC_REQUIRE([AC_PROG_CC])
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]) ;;
31 CFLAGS="$CFLAGS -O0 --coverage"
32 LDFLAGS="$LDFLAGS --coverage"
35 dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
36 AC_DEFUN([OVS_CHECK_NDEBUG],
39 [AC_HELP_STRING([--enable-ndebug],
40 [Disable debugging features for max performance])],
41 [case "${enableval}" in
44 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
47 AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
50 AC_DEFUN([OVS_CHECK_ESX],
51 [AC_CHECK_HEADER([vmware.h],
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.])
59 dnl Checks for WINDOWS.
60 AC_DEFUN([OVS_CHECK_WIN32],
61 [AC_CHECK_HEADER([windows.h],
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.])
69 dnl Checks for Netlink support.
70 AC_DEFUN([OVS_CHECK_NETLINK],
71 [AC_CHECK_HEADER([linux/netlink.h],
74 [#include <sys/socket.h>
75 #include <linux/types.h>
77 AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
78 if test "$HAVE_NETLINK" = yes; then
79 AC_DEFINE([HAVE_NETLINK], [1],
80 [Define to 1 if Netlink protocol is available.])
83 dnl Checks for OpenSSL.
84 AC_DEFUN([OVS_CHECK_OPENSSL],
87 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
88 [case "${enableval}" in
91 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
95 if test "$ssl" != false; then
99 if test "$ssl" = check; then
100 AC_MSG_WARN([Cannot find openssl:
104 OpenFlow connections over SSL will not be supported.
105 (You may use --disable-ssl to suppress this warning.)])
107 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
112 AC_SUBST([HAVE_OPENSSL])
113 AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
114 if test "$HAVE_OPENSSL" = yes; then
115 AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
118 dnl Checks for libraries needed by lib/socket-util.c.
119 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
120 [AC_CHECK_LIB([socket], [connect])
121 AC_SEARCH_LIBS([gethostbyname], [resolv])])
123 dnl Checks for the directory in which to store the PKI.
124 AC_DEFUN([OVS_CHECK_PKIDIR],
127 AC_HELP_STRING([--with-pkidir=DIR],
128 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
130 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
133 dnl Checks for the directory in which to store pidfiles.
134 AC_DEFUN([OVS_CHECK_RUNDIR],
137 AC_HELP_STRING([--with-rundir=DIR],
138 [directory used for pidfiles
139 [[LOCALSTATEDIR/run/openvswitch]]]),
141 [RUNDIR='${localstatedir}/run/openvswitch'])
144 dnl Checks for the directory in which to store logs.
145 AC_DEFUN([OVS_CHECK_LOGDIR],
148 AC_HELP_STRING([--with-logdir=DIR],
149 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
151 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
154 dnl Checks for the directory in which to store the Open vSwitch database.
155 AC_DEFUN([OVS_CHECK_DBDIR],
158 AC_HELP_STRING([--with-dbdir=DIR],
159 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
161 [DBDIR='${sysconfdir}/${PACKAGE}'])
164 dnl Defines HAVE_BACKTRACE if backtrace() is found.
165 AC_DEFUN([OVS_CHECK_BACKTRACE],
166 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
167 [AC_DEFINE([HAVE_BACKTRACE], [1],
168 [Define to 1 if you have backtrace(3).])])])
170 dnl Checks for __malloc_hook, etc., supported by glibc.
171 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
173 [whether libc supports hooks for malloc and related functions],
174 [ovs_cv_malloc_hooks],
179 [(void) __malloc_hook;
180 (void) __realloc_hook;
181 (void) __free_hook;])],
182 [ovs_cv_malloc_hooks=yes],
183 [ovs_cv_malloc_hooks=no])])
184 if test $ovs_cv_malloc_hooks = yes; then
185 AC_DEFINE([HAVE_MALLOC_HOOKS], [1],
186 [Define to 1 if you have __malloc_hook, __realloc_hook, and
187 __free_hook in <malloc.h>.])
190 dnl Checks for valgrind/valgrind.h.
191 AC_DEFUN([OVS_CHECK_VALGRIND],
192 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
194 dnl Checks for Python 2.x, x >= 4.
195 AC_DEFUN([OVS_CHECK_PYTHON],
197 [for Python 2.x for x >= 4],
199 [if test -n "$PYTHON"; then
200 ovs_cv_python=$PYTHON
203 for binary in python python2.4 python2.5; do
204 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
207 test -z "$dir" && dir=.
208 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
209 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
213 ovs_cv_python=$dir/$binary
219 AC_SUBST([HAVE_PYTHON])
220 AM_MISSING_PROG([PYTHON], [python])
221 if test $ovs_cv_python != no; then
222 PYTHON=$ovs_cv_python
227 AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
230 AC_DEFUN([OVS_CHECK_DOT],
234 [dnl "dot" writes -V output to stderr:
235 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
240 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
242 dnl Checks for pyuic4.
243 AC_DEFUN([OVS_CHECK_PYUIC4],
247 [if (pyuic4 --version) >/dev/null 2>&1; then
252 AM_MISSING_PROG([PYUIC4], [pyuic4])
253 if test $ovs_cv_pyuic4 != no; then
254 PYUIC4=$ovs_cv_pyuic4
257 dnl Checks whether $PYTHON supports the module given as $1
258 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
259 [AC_REQUIRE([OVS_CHECK_PYTHON])
261 [for $1 Python module],
262 [ovs_cv_py_[]AS_TR_SH([$1])],
263 [ovs_cv_py_[]AS_TR_SH([$1])=no
264 if test $HAVE_PYTHON = yes; then
265 AS_ECHO(["running $PYTHON -c 'import $1
267 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
268 if $PYTHON -c 'import $1
270 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
271 ovs_cv_py_[]AS_TR_SH([$1])=yes
275 dnl Checks for Python modules needed by ovsdbmonitor.
276 AC_DEFUN([OVS_CHECK_OVSDBMONITOR],
277 [OVS_CHECK_PYTHON_MODULE([PySide.QtCore])
278 OVS_CHECK_PYTHON_MODULE([PyQt4.QtCore])
279 OVS_CHECK_PYTHON_MODULE([twisted.conch.ssh])
280 OVS_CHECK_PYTHON_MODULE([twisted.internet])
281 OVS_CHECK_PYTHON_MODULE([twisted.application])
282 OVS_CHECK_PYTHON_MODULE([json])
283 OVS_CHECK_PYTHON_MODULE([zope.interface])
284 if (test $ovs_cv_py_PySide_QtCore = yes \
285 || test $ovs_cv_py_PyQt4_QtCore = yes) \
286 && test $ovs_cv_py_twisted_conch_ssh = yes \
287 && test $ovs_cv_py_twisted_internet = yes \
288 && test $ovs_cv_py_twisted_application = yes \
289 && test $ovs_cv_py_json = yes \
290 && test $ovs_cv_py_zope_interface = yes; then
291 BUILD_OVSDBMONITOR=yes
293 BUILD_OVSDBMONITOR=no
295 AC_MSG_CHECKING([whether to build ovsdbmonitor])
296 AC_MSG_RESULT([$BUILD_OVSDBMONITOR])
297 AM_CONDITIONAL([BUILD_OVSDBMONITOR], [test $BUILD_OVSDBMONITOR = yes])])
299 dnl Checks for missing python modules at build time
300 AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
301 [OVS_CHECK_PYTHON_MODULE([uuid])
302 if test $ovs_cv_py_uuid = yes; then
303 INCLUDE_PYTHON_COMPAT=no
305 INCLUDE_PYTHON_COMPAT=yes
307 AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
308 AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
309 AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
311 dnl Checks for groff.
312 AC_DEFUN([OVS_CHECK_GROFF],
316 [if (groff -v) >/dev/null 2>&1; then
321 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
323 dnl Checks for thread-local storage support.
325 dnl Checks whether the compiler and linker support the C11
326 dnl thread_local macro from <threads.h>, and if so defines
327 dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
328 dnl support the GCC __thread extension, and if so defines
330 AC_DEFUN([OVS_CHECK_TLS],
332 [whether $CC has <threads.h> that supports thread_local],
333 [ovs_cv_thread_local],
335 [AC_LANG_PROGRAM([#include <threads.h>
336 static thread_local int var;], [return var;])],
337 [ovs_cv_thread_local=yes],
338 [ovs_cv_thread_local=no])])
339 if test $ovs_cv_thread_local = yes; then
340 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
341 [Define to 1 if the C compiler and linker supports the C11
342 thread_local matcro defined in <threads.h>.])
345 [whether $CC supports __thread],
348 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
349 [ovs_cv___thread=yes],
350 [ovs_cv___thread=no])])
351 if test $ovs_cv___thread = yes; then
352 AC_DEFINE([HAVE___THREAD], [1],
353 [Define to 1 if the C compiler and linker supports the
354 GCC __thread extenions.])
358 dnl OVS_CHECK_ATOMIC_LIBS
360 dnl Check to see if -latomic is need for GCC atomic built-ins.
361 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
362 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
364 dnl OVS_CHECK_GCC4_ATOMICS
366 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
367 dnl A compile-time only check is not enough because the compiler defers
368 dnl unimplemented built-ins to libgcc, which sometimes also lacks
370 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
372 [whether $CC supports GCC 4.0+ atomic built-ins],
373 [ovs_cv_gcc4_atomics],
375 [AC_LANG_PROGRAM([[#include <stdlib.h>
377 #define ovs_assert(expr) if (!(expr)) abort();
378 #define TEST_ATOMIC_TYPE(TYPE) \
383 __sync_synchronize(); \
384 ovs_assert(x == 1); \
386 __sync_synchronize(); \
388 __sync_synchronize(); \
389 ovs_assert(x == 3); \
391 orig = __sync_fetch_and_add(&x, 1); \
392 ovs_assert(orig == 3); \
393 __sync_synchronize(); \
394 ovs_assert(x == 4); \
396 orig = __sync_fetch_and_sub(&x, 2); \
397 ovs_assert(orig == 4); \
398 __sync_synchronize(); \
399 ovs_assert(x == 2); \
401 orig = __sync_fetch_and_or(&x, 6); \
402 ovs_assert(orig == 2); \
403 __sync_synchronize(); \
404 ovs_assert(x == 6); \
406 orig = __sync_fetch_and_and(&x, 10); \
407 ovs_assert(orig == 6); \
408 __sync_synchronize(); \
409 ovs_assert(x == 2); \
411 orig = __sync_fetch_and_xor(&x, 10); \
412 ovs_assert(orig == 2); \
413 __sync_synchronize(); \
414 ovs_assert(x == 8); \
416 TEST_ATOMIC_TYPE(char);
417 TEST_ATOMIC_TYPE(unsigned char);
418 TEST_ATOMIC_TYPE(signed char);
419 TEST_ATOMIC_TYPE(short);
420 TEST_ATOMIC_TYPE(unsigned short);
421 TEST_ATOMIC_TYPE(int);
422 TEST_ATOMIC_TYPE(unsigned int);
423 TEST_ATOMIC_TYPE(long int);
424 TEST_ATOMIC_TYPE(unsigned long int);
425 TEST_ATOMIC_TYPE(long long int);
426 TEST_ATOMIC_TYPE(unsigned long long int);
428 [ovs_cv_gcc4_atomics=yes],
429 [ovs_cv_gcc4_atomics=no])])
430 if test $ovs_cv_gcc4_atomics = yes; then
431 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
432 [Define to 1 if the C compiler and linker supports the GCC 4.0+
436 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
438 dnl Checks __atomic_always_lock_free(SIZE, 0)
439 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
441 [value of __atomic_always_lock_free($1)],
442 [ovs_cv_atomic_always_lock_free_$1],
444 [ovs_cv_atomic_always_lock_free_$1],
445 [__atomic_always_lock_free($1, 0)],
447 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
448 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
450 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
451 [$ovs_cv_atomic_always_lock_free_$1],
452 [If the C compiler is GCC 4.7 or later, define to the return value of
453 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
454 an older version of GCC, the value does not matter.])
457 dnl OVS_CHECK_POSIX_AIO
458 AC_DEFUN([OVS_CHECK_POSIX_AIO],
459 [AC_SEARCH_LIBS([aio_write], [rt])
460 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
462 dnl OVS_CHECK_INCLUDE_NEXT
463 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
464 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
465 gl_CHECK_NEXT_HEADERS([$1])])