3 # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 # Autoconf by default puts "-g -O2" in CFLAGS. We need to remove the -O2
34 # option for coverage to be useful. This does it without otherwise
35 # interfering with anything that the user might have put there.
38 for option in $old_CFLAGS; do
41 (*) CFLAGS="$CFLAGS $option" ;;
45 OVS_CFLAGS="$OVS_CFLAGS --coverage"
46 OVS_LDFLAGS="$OVS_LDFLAGS --coverage"
49 dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
50 AC_DEFUN([OVS_CHECK_NDEBUG],
53 [AC_HELP_STRING([--enable-ndebug],
54 [Disable debugging features for max performance])],
55 [case "${enableval}" in
58 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
61 AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
64 AC_DEFUN([OVS_CHECK_ESX],
65 [AC_CHECK_HEADER([vmware.h],
68 AM_CONDITIONAL([ESX], [test "$ESX" = yes])
69 if test "$ESX" = yes; then
70 AC_DEFINE([ESX], [1], [Define to 1 if building on ESX.])
73 dnl Checks for WINDOWS.
74 AC_DEFUN([OVS_CHECK_WIN32],
75 [AC_CHECK_HEADER([windows.h],
78 AM_CONDITIONAL([WIN32], [test "$WIN32" = yes])
79 if test "$WIN32" = yes; then
80 AC_ARG_WITH([pthread],
81 [AS_HELP_STRING([--with-pthread=DIR],
82 [root of the pthread-win32 directory])],
85 "" | y | ye | yes | n | no)
86 AC_MSG_ERROR([Invalid --with-pthread value])
89 PTHREAD_INCLUDES="-I$withval/include"
90 PTHREAD_LDFLAGS="-L$withval/lib/x86"
91 PTHREAD_LIBS="-lpthreadVC2"
92 AC_SUBST([PTHREAD_INCLUDES])
93 AC_SUBST([PTHREAD_LDFLAGS])
94 AC_SUBST([PTHREAD_LIBS])
98 AC_MSG_ERROR([pthread directory not specified])
102 [AS_HELP_STRING([--with-debug],
103 [Build without compiler optimizations])],
106 AC_SUBST([MSVC_CFLAGS])
109 AC_SUBST([MSVC_CFLAGS])
113 AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
114 AH_BOTTOM([#ifdef WIN32
115 #include "include/windows/windefs.h"
119 dnl OVS_CHECK_WINDOWS
121 dnl Configure Visual Studio solution build
122 AC_DEFUN([OVS_CHECK_VISUAL_STUDIO_DDK], [
123 AC_ARG_WITH([vstudioddk],
124 [AS_HELP_STRING([--with-vstudioddk=version_type],
125 [Visual Studio DDK version type e.g. Win8.1 Release])],
132 *) AC_MSG_ERROR([No good Visual Studio configuration found]) ;;
135 VSTUDIO_CONFIG=$withval
141 AC_SUBST([VSTUDIO_CONFIG])
142 AC_DEFINE([VSTUDIO_DDK], [1], [System uses the Visual Studio DDK version module.])
143 AM_CONDITIONAL([VSTUDIO_DDK], [test -n "$VSTUDIO_CONFIG"])
146 dnl Checks for Netlink support.
147 AC_DEFUN([OVS_CHECK_NETLINK],
148 [AC_CHECK_HEADER([linux/netlink.h],
151 [#include <sys/socket.h>
153 AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
154 if test "$HAVE_NETLINK" = yes; then
155 AC_DEFINE([HAVE_NETLINK], [1],
156 [Define to 1 if Netlink protocol is available.])
159 dnl Checks for OpenSSL.
160 AC_DEFUN([OVS_CHECK_OPENSSL],
163 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
164 [case "${enableval}" in
167 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
171 if test "$ssl" != false; then
175 if test "$ssl" = check; then
176 AC_MSG_WARN([Cannot find openssl:
180 OpenFlow connections over SSL will not be supported.
181 (You may use --disable-ssl to suppress this warning.)])
183 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
188 AC_SUBST([HAVE_OPENSSL])
189 AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
190 if test "$HAVE_OPENSSL" = yes; then
191 AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
194 dnl Checks for libraries needed by lib/socket-util.c.
195 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
196 [AC_CHECK_LIB([socket], [connect])
197 AC_SEARCH_LIBS([gethostbyname], [resolv])])
199 dnl Checks for the directory in which to store the PKI.
200 AC_DEFUN([OVS_CHECK_PKIDIR],
203 AC_HELP_STRING([--with-pkidir=DIR],
204 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
206 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
209 dnl Checks for the directory in which to store pidfiles.
210 AC_DEFUN([OVS_CHECK_RUNDIR],
213 AC_HELP_STRING([--with-rundir=DIR],
214 [directory used for pidfiles
215 [[LOCALSTATEDIR/run/openvswitch]]]),
217 [RUNDIR='${localstatedir}/run/openvswitch'])
220 dnl Checks for the directory in which to store logs.
221 AC_DEFUN([OVS_CHECK_LOGDIR],
224 AC_HELP_STRING([--with-logdir=DIR],
225 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
227 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
230 dnl Checks for the directory in which to store the Open vSwitch database.
231 AC_DEFUN([OVS_CHECK_DBDIR],
234 AC_HELP_STRING([--with-dbdir=DIR],
235 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
237 [DBDIR='${sysconfdir}/${PACKAGE}'])
240 dnl Defines HAVE_BACKTRACE if backtrace() is found.
241 AC_DEFUN([OVS_CHECK_BACKTRACE],
242 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
243 [AC_DEFINE([HAVE_BACKTRACE], [1],
244 [Define to 1 if you have backtrace(3).])])])
246 dnl Defines HAVE_PERF_EVENT if linux/perf_event.h is found.
247 AC_DEFUN([OVS_CHECK_PERF_EVENT],
248 [AC_CHECK_HEADERS([linux/perf_event.h])])
250 dnl Checks for valgrind/valgrind.h.
251 AC_DEFUN([OVS_CHECK_VALGRIND],
252 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
254 dnl Checks for Python 2.x, x >= 4.
255 AC_DEFUN([OVS_CHECK_PYTHON],
257 [for Python 2.x for x >= 4],
259 [if test -n "$PYTHON"; then
260 ovs_cv_python=$PYTHON
263 for binary in python python2.4 python2.5 python2.7; do
264 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
267 test -z "$dir" && dir=.
268 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
269 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
273 ovs_cv_python=$dir/$binary
279 AC_SUBST([HAVE_PYTHON])
280 AM_MISSING_PROG([PYTHON], [python])
281 if test $ovs_cv_python != no; then
282 PYTHON=$ovs_cv_python
287 AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
290 AC_DEFUN([OVS_CHECK_DOT],
294 [dnl "dot" writes -V output to stderr:
295 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
300 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
302 dnl Checks whether $PYTHON supports the module given as $1
303 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
304 [AC_REQUIRE([OVS_CHECK_PYTHON])
306 [for $1 Python module],
307 [ovs_cv_py_[]AS_TR_SH([$1])],
308 [ovs_cv_py_[]AS_TR_SH([$1])=no
309 if test $HAVE_PYTHON = yes; then
310 AS_ECHO(["running $PYTHON -c 'import $1
312 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
313 if $PYTHON -c 'import $1
315 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
316 ovs_cv_py_[]AS_TR_SH([$1])=yes
320 dnl Checks for missing python modules at build time
321 AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
322 [OVS_CHECK_PYTHON_MODULE([uuid])
323 if test $ovs_cv_py_uuid = yes; then
324 INCLUDE_PYTHON_COMPAT=no
326 INCLUDE_PYTHON_COMPAT=yes
328 AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
329 AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
330 AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
332 dnl Checks for groff.
333 AC_DEFUN([OVS_CHECK_GROFF],
337 [if (groff -v) >/dev/null 2>&1; then
342 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
344 dnl Checks for thread-local storage support.
346 dnl Checks whether the compiler and linker support the C11
347 dnl thread_local macro from <threads.h>, and if so defines
348 dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
349 dnl support the GCC __thread extension, and if so defines
351 AC_DEFUN([OVS_CHECK_TLS],
353 [whether $CC has <threads.h> that supports thread_local],
354 [ovs_cv_thread_local],
356 [AC_LANG_PROGRAM([#include <threads.h>
357 static thread_local int var;], [return var;])],
358 [ovs_cv_thread_local=yes],
359 [ovs_cv_thread_local=no])])
360 if test $ovs_cv_thread_local = yes; then
361 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
362 [Define to 1 if the C compiler and linker supports the C11
363 thread_local matcro defined in <threads.h>.])
366 [whether $CC supports __thread],
369 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
370 [ovs_cv___thread=yes],
371 [ovs_cv___thread=no])])
372 if test $ovs_cv___thread = yes; then
373 AC_DEFINE([HAVE___THREAD], [1],
374 [Define to 1 if the C compiler and linker supports the
375 GCC __thread extenions.])
379 dnl OVS_CHECK_ATOMIC_LIBS
381 dnl Check to see if -latomic is need for GCC atomic built-ins.
382 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
383 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
385 dnl OVS_CHECK_GCC4_ATOMICS
387 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
388 dnl A compile-time only check is not enough because the compiler defers
389 dnl unimplemented built-ins to libgcc, which sometimes also lacks
391 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
393 [whether $CC supports GCC 4.0+ atomic built-ins],
394 [ovs_cv_gcc4_atomics],
396 [AC_LANG_PROGRAM([[#include <stdlib.h>
398 #define ovs_assert(expr) if (!(expr)) abort();
399 #define TEST_ATOMIC_TYPE(TYPE) \
404 __sync_synchronize(); \
405 ovs_assert(x == 1); \
407 __sync_synchronize(); \
409 __sync_synchronize(); \
410 ovs_assert(x == 3); \
412 orig = __sync_fetch_and_add(&x, 1); \
413 ovs_assert(orig == 3); \
414 __sync_synchronize(); \
415 ovs_assert(x == 4); \
417 orig = __sync_fetch_and_sub(&x, 2); \
418 ovs_assert(orig == 4); \
419 __sync_synchronize(); \
420 ovs_assert(x == 2); \
422 orig = __sync_fetch_and_or(&x, 6); \
423 ovs_assert(orig == 2); \
424 __sync_synchronize(); \
425 ovs_assert(x == 6); \
427 orig = __sync_fetch_and_and(&x, 10); \
428 ovs_assert(orig == 6); \
429 __sync_synchronize(); \
430 ovs_assert(x == 2); \
432 orig = __sync_fetch_and_xor(&x, 10); \
433 ovs_assert(orig == 2); \
434 __sync_synchronize(); \
435 ovs_assert(x == 8); \
437 TEST_ATOMIC_TYPE(char);
438 TEST_ATOMIC_TYPE(unsigned char);
439 TEST_ATOMIC_TYPE(signed char);
440 TEST_ATOMIC_TYPE(short);
441 TEST_ATOMIC_TYPE(unsigned short);
442 TEST_ATOMIC_TYPE(int);
443 TEST_ATOMIC_TYPE(unsigned int);
444 TEST_ATOMIC_TYPE(long int);
445 TEST_ATOMIC_TYPE(unsigned long int);
446 TEST_ATOMIC_TYPE(long long int);
447 TEST_ATOMIC_TYPE(unsigned long long int);
449 [ovs_cv_gcc4_atomics=yes],
450 [ovs_cv_gcc4_atomics=no])])
451 if test $ovs_cv_gcc4_atomics = yes; then
452 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
453 [Define to 1 if the C compiler and linker supports the GCC 4.0+
457 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
459 dnl Checks __atomic_always_lock_free(SIZE, 0)
460 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
462 [value of __atomic_always_lock_free($1)],
463 [ovs_cv_atomic_always_lock_free_$1],
465 [ovs_cv_atomic_always_lock_free_$1],
466 [__atomic_always_lock_free($1, 0)],
468 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
469 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
471 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
472 [$ovs_cv_atomic_always_lock_free_$1],
473 [If the C compiler is GCC 4.7 or later, define to the return value of
474 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
475 an older version of GCC, the value does not matter.])
478 dnl OVS_CHECK_POSIX_AIO
479 AC_DEFUN([OVS_CHECK_POSIX_AIO],
480 [AC_SEARCH_LIBS([aio_write], [rt])
481 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
483 dnl OVS_CHECK_INCLUDE_NEXT
484 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
485 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
486 gl_CHECK_NEXT_HEADERS([$1])])
488 dnl OVS_CHECK_PRAGMA_MESSAGE
489 AC_DEFUN([OVS_CHECK_PRAGMA_MESSAGE],
490 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
491 [[_Pragma("message(\"Checking for pragma message\")")
493 [AC_DEFINE(HAVE_PRAGMA_MESSAGE,1,[Define if compiler supports #pragma
494 message directive])])