3 # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 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 m4_include([m4/compat.at])
19 dnl Checks for --enable-coverage and updates CFLAGS and LDFLAGS appropriately.
20 AC_DEFUN([OVS_CHECK_COVERAGE],
21 [AC_REQUIRE([AC_PROG_CC])
24 [AC_HELP_STRING([--enable-coverage],
25 [Enable gcov coverage tool.])],
26 [case "${enableval}" in
27 (yes) coverage=true ;;
28 (no) coverage=false ;;
29 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;;
33 CFLAGS="$CFLAGS -O0 --coverage"
34 LDFLAGS="$LDFLAGS --coverage"
37 dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
38 AC_DEFUN([OVS_CHECK_NDEBUG],
41 [AC_HELP_STRING([--enable-ndebug],
42 [Disable debugging features for max performance])],
43 [case "${enableval}" in
46 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
49 AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
52 AC_DEFUN([OVS_CHECK_ESX],
53 [AC_CHECK_HEADER([vmware.h],
56 AM_CONDITIONAL([ESX], [test "$ESX" = yes])
57 if test "$ESX" = yes; then
58 AC_DEFINE([ESX], [1], [Define to 1 if building on ESX.])
61 dnl Checks for WINDOWS.
62 AC_DEFUN([OVS_CHECK_WIN32],
63 [AC_CHECK_HEADER([windows.h],
66 AM_CONDITIONAL([WIN32], [test "$WIN32" = yes])
67 if test "$WIN32" = yes; then
68 AC_ARG_WITH([pthread],
69 [AS_HELP_STRING([--with-pthread=DIR],
70 [root of the pthread-win32 directory])],
73 "" | y | ye | yes | n | no)
74 AC_MSG_ERROR([Invalid --with-pthread value])
77 PTHREAD_INCLUDES="-I$withval/include"
78 PTHREAD_LDFLAGS="-L$withval/lib/x86"
79 PTHREAD_LIBS="-lpthreadVC2"
80 AC_SUBST([PTHREAD_INCLUDES])
81 AC_SUBST([PTHREAD_LDFLAGS])
82 AC_SUBST([PTHREAD_LIBS])
86 AC_MSG_ERROR([pthread directory not specified])
89 AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
90 AH_BOTTOM([#ifdef WIN32
91 #include "include/windows/windefs.h"
95 dnl Checks for Netlink support.
96 AC_DEFUN([OVS_CHECK_NETLINK],
97 [AC_CHECK_HEADER([linux/netlink.h],
100 [#include <sys/socket.h>
102 AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
103 if test "$HAVE_NETLINK" = yes; then
104 AC_DEFINE([HAVE_NETLINK], [1],
105 [Define to 1 if Netlink protocol is available.])
108 dnl Checks for OpenSSL.
109 AC_DEFUN([OVS_CHECK_OPENSSL],
112 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
113 [case "${enableval}" in
116 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
120 if test "$ssl" != false; then
124 if test "$ssl" = check; then
125 AC_MSG_WARN([Cannot find openssl:
129 OpenFlow connections over SSL will not be supported.
130 (You may use --disable-ssl to suppress this warning.)])
132 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
137 AC_SUBST([HAVE_OPENSSL])
138 AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
139 if test "$HAVE_OPENSSL" = yes; then
140 AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
143 dnl Checks for libraries needed by lib/socket-util.c.
144 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
145 [AC_CHECK_LIB([socket], [connect])
146 AC_SEARCH_LIBS([gethostbyname], [resolv])])
148 dnl Checks for the directory in which to store the PKI.
149 AC_DEFUN([OVS_CHECK_PKIDIR],
152 AC_HELP_STRING([--with-pkidir=DIR],
153 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
155 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
158 dnl Checks for the directory in which to store pidfiles.
159 AC_DEFUN([OVS_CHECK_RUNDIR],
162 AC_HELP_STRING([--with-rundir=DIR],
163 [directory used for pidfiles
164 [[LOCALSTATEDIR/run/openvswitch]]]),
166 [RUNDIR='${localstatedir}/run/openvswitch'])
169 dnl Checks for the directory in which to store logs.
170 AC_DEFUN([OVS_CHECK_LOGDIR],
173 AC_HELP_STRING([--with-logdir=DIR],
174 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
176 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
179 dnl Checks for the directory in which to store the Open vSwitch database.
180 AC_DEFUN([OVS_CHECK_DBDIR],
183 AC_HELP_STRING([--with-dbdir=DIR],
184 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
186 [DBDIR='${sysconfdir}/${PACKAGE}'])
189 dnl Defines HAVE_BACKTRACE if backtrace() is found.
190 AC_DEFUN([OVS_CHECK_BACKTRACE],
191 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
192 [AC_DEFINE([HAVE_BACKTRACE], [1],
193 [Define to 1 if you have backtrace(3).])])])
195 dnl Checks for valgrind/valgrind.h.
196 AC_DEFUN([OVS_CHECK_VALGRIND],
197 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
199 dnl Checks for Python 2.x, x >= 4.
200 AC_DEFUN([OVS_CHECK_PYTHON],
202 [for Python 2.x for x >= 4],
204 [if test -n "$PYTHON"; then
205 ovs_cv_python=$PYTHON
208 for binary in python python2.4 python2.5; do
209 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
212 test -z "$dir" && dir=.
213 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
214 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
218 ovs_cv_python=$dir/$binary
224 AC_SUBST([HAVE_PYTHON])
225 AM_MISSING_PROG([PYTHON], [python])
226 if test $ovs_cv_python != no; then
227 PYTHON=$ovs_cv_python
232 AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
235 AC_DEFUN([OVS_CHECK_DOT],
239 [dnl "dot" writes -V output to stderr:
240 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
245 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
247 dnl Checks whether $PYTHON supports the module given as $1
248 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
249 [AC_REQUIRE([OVS_CHECK_PYTHON])
251 [for $1 Python module],
252 [ovs_cv_py_[]AS_TR_SH([$1])],
253 [ovs_cv_py_[]AS_TR_SH([$1])=no
254 if test $HAVE_PYTHON = yes; then
255 AS_ECHO(["running $PYTHON -c 'import $1
257 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
258 if $PYTHON -c 'import $1
260 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
261 ovs_cv_py_[]AS_TR_SH([$1])=yes
265 dnl Checks for missing python modules at build time
266 AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
267 [OVS_CHECK_PYTHON_MODULE([uuid])
268 if test $ovs_cv_py_uuid = yes; then
269 INCLUDE_PYTHON_COMPAT=no
271 INCLUDE_PYTHON_COMPAT=yes
273 AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
274 AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
275 AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
277 dnl Checks for groff.
278 AC_DEFUN([OVS_CHECK_GROFF],
282 [if (groff -v) >/dev/null 2>&1; then
287 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
289 dnl Checks for thread-local storage support.
291 dnl Checks whether the compiler and linker support the C11
292 dnl thread_local macro from <threads.h>, and if so defines
293 dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
294 dnl support the GCC __thread extension, and if so defines
296 AC_DEFUN([OVS_CHECK_TLS],
298 [whether $CC has <threads.h> that supports thread_local],
299 [ovs_cv_thread_local],
301 [AC_LANG_PROGRAM([#include <threads.h>
302 static thread_local int var;], [return var;])],
303 [ovs_cv_thread_local=yes],
304 [ovs_cv_thread_local=no])])
305 if test $ovs_cv_thread_local = yes; then
306 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
307 [Define to 1 if the C compiler and linker supports the C11
308 thread_local matcro defined in <threads.h>.])
311 [whether $CC supports __thread],
314 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
315 [ovs_cv___thread=yes],
316 [ovs_cv___thread=no])])
317 if test $ovs_cv___thread = yes; then
318 AC_DEFINE([HAVE___THREAD], [1],
319 [Define to 1 if the C compiler and linker supports the
320 GCC __thread extenions.])
324 dnl OVS_CHECK_ATOMIC_LIBS
326 dnl Check to see if -latomic is need for GCC atomic built-ins.
327 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
328 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
330 dnl OVS_CHECK_GCC4_ATOMICS
332 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
333 dnl A compile-time only check is not enough because the compiler defers
334 dnl unimplemented built-ins to libgcc, which sometimes also lacks
336 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
338 [whether $CC supports GCC 4.0+ atomic built-ins],
339 [ovs_cv_gcc4_atomics],
341 [AC_LANG_PROGRAM([[#include <stdlib.h>
343 #define ovs_assert(expr) if (!(expr)) abort();
344 #define TEST_ATOMIC_TYPE(TYPE) \
349 __sync_synchronize(); \
350 ovs_assert(x == 1); \
352 __sync_synchronize(); \
354 __sync_synchronize(); \
355 ovs_assert(x == 3); \
357 orig = __sync_fetch_and_add(&x, 1); \
358 ovs_assert(orig == 3); \
359 __sync_synchronize(); \
360 ovs_assert(x == 4); \
362 orig = __sync_fetch_and_sub(&x, 2); \
363 ovs_assert(orig == 4); \
364 __sync_synchronize(); \
365 ovs_assert(x == 2); \
367 orig = __sync_fetch_and_or(&x, 6); \
368 ovs_assert(orig == 2); \
369 __sync_synchronize(); \
370 ovs_assert(x == 6); \
372 orig = __sync_fetch_and_and(&x, 10); \
373 ovs_assert(orig == 6); \
374 __sync_synchronize(); \
375 ovs_assert(x == 2); \
377 orig = __sync_fetch_and_xor(&x, 10); \
378 ovs_assert(orig == 2); \
379 __sync_synchronize(); \
380 ovs_assert(x == 8); \
382 TEST_ATOMIC_TYPE(char);
383 TEST_ATOMIC_TYPE(unsigned char);
384 TEST_ATOMIC_TYPE(signed char);
385 TEST_ATOMIC_TYPE(short);
386 TEST_ATOMIC_TYPE(unsigned short);
387 TEST_ATOMIC_TYPE(int);
388 TEST_ATOMIC_TYPE(unsigned int);
389 TEST_ATOMIC_TYPE(long int);
390 TEST_ATOMIC_TYPE(unsigned long int);
391 TEST_ATOMIC_TYPE(long long int);
392 TEST_ATOMIC_TYPE(unsigned long long int);
394 [ovs_cv_gcc4_atomics=yes],
395 [ovs_cv_gcc4_atomics=no])])
396 if test $ovs_cv_gcc4_atomics = yes; then
397 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
398 [Define to 1 if the C compiler and linker supports the GCC 4.0+
402 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
404 dnl Checks __atomic_always_lock_free(SIZE, 0)
405 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
407 [value of __atomic_always_lock_free($1)],
408 [ovs_cv_atomic_always_lock_free_$1],
410 [ovs_cv_atomic_always_lock_free_$1],
411 [__atomic_always_lock_free($1, 0)],
413 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
414 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
416 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
417 [$ovs_cv_atomic_always_lock_free_$1],
418 [If the C compiler is GCC 4.7 or later, define to the return value of
419 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
420 an older version of GCC, the value does not matter.])
423 dnl OVS_CHECK_POSIX_AIO
424 AC_DEFUN([OVS_CHECK_POSIX_AIO],
425 [AC_SEARCH_LIBS([aio_write], [rt])
426 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
428 dnl OVS_CHECK_INCLUDE_NEXT
429 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
430 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
431 gl_CHECK_NEXT_HEADERS([$1])])