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 OVS_CFLAGS="$OVS_CFLAGS -O0 --coverage"
34 OVS_LDFLAGS="$OVS_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])
90 [AS_HELP_STRING([--with-debug],
91 [Build without compiler optimizations])],
94 AC_SUBST([MSVC_CFLAGS])
97 AC_SUBST([MSVC_CFLAGS])
101 AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
102 AH_BOTTOM([#ifdef WIN32
103 #include "include/windows/windefs.h"
107 dnl OVS_CHECK_WINDOWS
109 dnl Configure Visual Studio solution build
110 AC_DEFUN([OVS_CHECK_VISUAL_STUDIO_DDK], [
111 AC_ARG_WITH([vstudioddk],
112 [AS_HELP_STRING([--with-vstudioddk=version_type],
113 [Visual Studio DDK version type e.g. Win8.1 Release])],
120 *) AC_MSG_ERROR([No good Visual Studio configuration found]) ;;
123 VSTUDIO_CONFIG=$withval
129 AC_SUBST([VSTUDIO_CONFIG])
130 AC_DEFINE([VSTUDIO_DDK], [1], [System uses the Visual Studio DDK version module.])
131 AM_CONDITIONAL([VSTUDIO_DDK], [test -n "$VSTUDIO_CONFIG"])
134 dnl Checks for Netlink support.
135 AC_DEFUN([OVS_CHECK_NETLINK],
136 [AC_CHECK_HEADER([linux/netlink.h],
139 [#include <sys/socket.h>
141 AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
142 if test "$HAVE_NETLINK" = yes; then
143 AC_DEFINE([HAVE_NETLINK], [1],
144 [Define to 1 if Netlink protocol is available.])
147 dnl Checks for OpenSSL.
148 AC_DEFUN([OVS_CHECK_OPENSSL],
151 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
152 [case "${enableval}" in
155 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
159 if test "$ssl" != false; then
163 if test "$ssl" = check; then
164 AC_MSG_WARN([Cannot find openssl:
168 OpenFlow connections over SSL will not be supported.
169 (You may use --disable-ssl to suppress this warning.)])
171 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
176 AC_SUBST([HAVE_OPENSSL])
177 AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
178 if test "$HAVE_OPENSSL" = yes; then
179 AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
182 dnl Checks for libraries needed by lib/socket-util.c.
183 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
184 [AC_CHECK_LIB([socket], [connect])
185 AC_SEARCH_LIBS([gethostbyname], [resolv])])
187 dnl Checks for the directory in which to store the PKI.
188 AC_DEFUN([OVS_CHECK_PKIDIR],
191 AC_HELP_STRING([--with-pkidir=DIR],
192 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
194 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
197 dnl Checks for the directory in which to store pidfiles.
198 AC_DEFUN([OVS_CHECK_RUNDIR],
201 AC_HELP_STRING([--with-rundir=DIR],
202 [directory used for pidfiles
203 [[LOCALSTATEDIR/run/openvswitch]]]),
205 [RUNDIR='${localstatedir}/run/openvswitch'])
208 dnl Checks for the directory in which to store logs.
209 AC_DEFUN([OVS_CHECK_LOGDIR],
212 AC_HELP_STRING([--with-logdir=DIR],
213 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
215 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
218 dnl Checks for the directory in which to store the Open vSwitch database.
219 AC_DEFUN([OVS_CHECK_DBDIR],
222 AC_HELP_STRING([--with-dbdir=DIR],
223 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
225 [DBDIR='${sysconfdir}/${PACKAGE}'])
228 dnl Defines HAVE_BACKTRACE if backtrace() is found.
229 AC_DEFUN([OVS_CHECK_BACKTRACE],
230 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
231 [AC_DEFINE([HAVE_BACKTRACE], [1],
232 [Define to 1 if you have backtrace(3).])])])
234 dnl Checks for valgrind/valgrind.h.
235 AC_DEFUN([OVS_CHECK_VALGRIND],
236 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
238 dnl Checks for Python 2.x, x >= 4.
239 AC_DEFUN([OVS_CHECK_PYTHON],
241 [for Python 2.x for x >= 4],
243 [if test -n "$PYTHON"; then
244 ovs_cv_python=$PYTHON
247 for binary in python python2.4 python2.5 python2.7; do
248 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
251 test -z "$dir" && dir=.
252 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
253 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
257 ovs_cv_python=$dir/$binary
263 AC_SUBST([HAVE_PYTHON])
264 AM_MISSING_PROG([PYTHON], [python])
265 if test $ovs_cv_python != no; then
266 PYTHON=$ovs_cv_python
271 AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
274 AC_DEFUN([OVS_CHECK_DOT],
278 [dnl "dot" writes -V output to stderr:
279 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
284 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
286 dnl Checks whether $PYTHON supports the module given as $1
287 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
288 [AC_REQUIRE([OVS_CHECK_PYTHON])
290 [for $1 Python module],
291 [ovs_cv_py_[]AS_TR_SH([$1])],
292 [ovs_cv_py_[]AS_TR_SH([$1])=no
293 if test $HAVE_PYTHON = yes; then
294 AS_ECHO(["running $PYTHON -c 'import $1
296 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
297 if $PYTHON -c 'import $1
299 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
300 ovs_cv_py_[]AS_TR_SH([$1])=yes
304 dnl Checks for missing python modules at build time
305 AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
306 [OVS_CHECK_PYTHON_MODULE([uuid])
307 if test $ovs_cv_py_uuid = yes; then
308 INCLUDE_PYTHON_COMPAT=no
310 INCLUDE_PYTHON_COMPAT=yes
312 AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
313 AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
314 AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
316 dnl Checks for groff.
317 AC_DEFUN([OVS_CHECK_GROFF],
321 [if (groff -v) >/dev/null 2>&1; then
326 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
328 dnl Checks for thread-local storage support.
330 dnl Checks whether the compiler and linker support the C11
331 dnl thread_local macro from <threads.h>, and if so defines
332 dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
333 dnl support the GCC __thread extension, and if so defines
335 AC_DEFUN([OVS_CHECK_TLS],
337 [whether $CC has <threads.h> that supports thread_local],
338 [ovs_cv_thread_local],
340 [AC_LANG_PROGRAM([#include <threads.h>
341 static thread_local int var;], [return var;])],
342 [ovs_cv_thread_local=yes],
343 [ovs_cv_thread_local=no])])
344 if test $ovs_cv_thread_local = yes; then
345 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
346 [Define to 1 if the C compiler and linker supports the C11
347 thread_local matcro defined in <threads.h>.])
350 [whether $CC supports __thread],
353 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
354 [ovs_cv___thread=yes],
355 [ovs_cv___thread=no])])
356 if test $ovs_cv___thread = yes; then
357 AC_DEFINE([HAVE___THREAD], [1],
358 [Define to 1 if the C compiler and linker supports the
359 GCC __thread extenions.])
363 dnl OVS_CHECK_ATOMIC_LIBS
365 dnl Check to see if -latomic is need for GCC atomic built-ins.
366 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
367 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
369 dnl OVS_CHECK_GCC4_ATOMICS
371 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
372 dnl A compile-time only check is not enough because the compiler defers
373 dnl unimplemented built-ins to libgcc, which sometimes also lacks
375 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
377 [whether $CC supports GCC 4.0+ atomic built-ins],
378 [ovs_cv_gcc4_atomics],
380 [AC_LANG_PROGRAM([[#include <stdlib.h>
382 #define ovs_assert(expr) if (!(expr)) abort();
383 #define TEST_ATOMIC_TYPE(TYPE) \
388 __sync_synchronize(); \
389 ovs_assert(x == 1); \
391 __sync_synchronize(); \
393 __sync_synchronize(); \
394 ovs_assert(x == 3); \
396 orig = __sync_fetch_and_add(&x, 1); \
397 ovs_assert(orig == 3); \
398 __sync_synchronize(); \
399 ovs_assert(x == 4); \
401 orig = __sync_fetch_and_sub(&x, 2); \
402 ovs_assert(orig == 4); \
403 __sync_synchronize(); \
404 ovs_assert(x == 2); \
406 orig = __sync_fetch_and_or(&x, 6); \
407 ovs_assert(orig == 2); \
408 __sync_synchronize(); \
409 ovs_assert(x == 6); \
411 orig = __sync_fetch_and_and(&x, 10); \
412 ovs_assert(orig == 6); \
413 __sync_synchronize(); \
414 ovs_assert(x == 2); \
416 orig = __sync_fetch_and_xor(&x, 10); \
417 ovs_assert(orig == 2); \
418 __sync_synchronize(); \
419 ovs_assert(x == 8); \
421 TEST_ATOMIC_TYPE(char);
422 TEST_ATOMIC_TYPE(unsigned char);
423 TEST_ATOMIC_TYPE(signed char);
424 TEST_ATOMIC_TYPE(short);
425 TEST_ATOMIC_TYPE(unsigned short);
426 TEST_ATOMIC_TYPE(int);
427 TEST_ATOMIC_TYPE(unsigned int);
428 TEST_ATOMIC_TYPE(long int);
429 TEST_ATOMIC_TYPE(unsigned long int);
430 TEST_ATOMIC_TYPE(long long int);
431 TEST_ATOMIC_TYPE(unsigned long long int);
433 [ovs_cv_gcc4_atomics=yes],
434 [ovs_cv_gcc4_atomics=no])])
435 if test $ovs_cv_gcc4_atomics = yes; then
436 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
437 [Define to 1 if the C compiler and linker supports the GCC 4.0+
441 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
443 dnl Checks __atomic_always_lock_free(SIZE, 0)
444 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
446 [value of __atomic_always_lock_free($1)],
447 [ovs_cv_atomic_always_lock_free_$1],
449 [ovs_cv_atomic_always_lock_free_$1],
450 [__atomic_always_lock_free($1, 0)],
452 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
453 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
455 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
456 [$ovs_cv_atomic_always_lock_free_$1],
457 [If the C compiler is GCC 4.7 or later, define to the return value of
458 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
459 an older version of GCC, the value does not matter.])
462 dnl OVS_CHECK_POSIX_AIO
463 AC_DEFUN([OVS_CHECK_POSIX_AIO],
464 [AC_SEARCH_LIBS([aio_write], [rt])
465 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
467 dnl OVS_CHECK_INCLUDE_NEXT
468 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
469 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
470 gl_CHECK_NEXT_HEADERS([$1])])
472 dnl OVS_CHECK_PRAGMA_MESSAGE
473 AC_DEFUN([OVS_CHECK_PRAGMA_MESSAGE],
474 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
475 [[_Pragma("message(\"Checking for pragma message\")")
477 [AC_DEFINE(HAVE_PRAGMA_MESSAGE,1,[Define if compiler supports #pragma
478 message directive])])