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])
90 AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
91 AH_BOTTOM([#ifdef WIN32
92 #include "include/windows/windefs.h"
98 dnl Configure Visual Studio solution build
99 AC_DEFUN([OVS_CHECK_VISUAL_STUDIO_DDK], [
100 AC_ARG_WITH([vstudioddk],
101 [AS_HELP_STRING([--with-vstudioddk=version_type],
102 [Visual Studio DDK version type e.g. Win8.1 Release])],
109 *) AC_MSG_ERROR([No good Visual Studio configuration found]) ;;
112 VSTUDIO_CONFIG=$withval
118 AC_SUBST([VSTUDIO_CONFIG])
119 AC_DEFINE([VSTUDIO_DDK], [1], [System uses the Visual Studio DDK version module.])
120 AM_CONDITIONAL([VSTUDIO_DDK], [test -n "$VSTUDIO_CONFIG"])
123 dnl Checks for Netlink support.
124 AC_DEFUN([OVS_CHECK_NETLINK],
125 [AC_CHECK_HEADER([linux/netlink.h],
128 [#include <sys/socket.h>
130 AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
131 if test "$HAVE_NETLINK" = yes; then
132 AC_DEFINE([HAVE_NETLINK], [1],
133 [Define to 1 if Netlink protocol is available.])
136 dnl Checks for OpenSSL.
137 AC_DEFUN([OVS_CHECK_OPENSSL],
140 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
141 [case "${enableval}" in
144 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
148 if test "$ssl" != false; then
152 if test "$ssl" = check; then
153 AC_MSG_WARN([Cannot find openssl:
157 OpenFlow connections over SSL will not be supported.
158 (You may use --disable-ssl to suppress this warning.)])
160 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
165 AC_SUBST([HAVE_OPENSSL])
166 AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
167 if test "$HAVE_OPENSSL" = yes; then
168 AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
171 dnl Checks for libraries needed by lib/socket-util.c.
172 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
173 [AC_CHECK_LIB([socket], [connect])
174 AC_SEARCH_LIBS([gethostbyname], [resolv])])
176 dnl Checks for the directory in which to store the PKI.
177 AC_DEFUN([OVS_CHECK_PKIDIR],
180 AC_HELP_STRING([--with-pkidir=DIR],
181 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
183 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
186 dnl Checks for the directory in which to store pidfiles.
187 AC_DEFUN([OVS_CHECK_RUNDIR],
190 AC_HELP_STRING([--with-rundir=DIR],
191 [directory used for pidfiles
192 [[LOCALSTATEDIR/run/openvswitch]]]),
194 [RUNDIR='${localstatedir}/run/openvswitch'])
197 dnl Checks for the directory in which to store logs.
198 AC_DEFUN([OVS_CHECK_LOGDIR],
201 AC_HELP_STRING([--with-logdir=DIR],
202 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
204 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
207 dnl Checks for the directory in which to store the Open vSwitch database.
208 AC_DEFUN([OVS_CHECK_DBDIR],
211 AC_HELP_STRING([--with-dbdir=DIR],
212 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
214 [DBDIR='${sysconfdir}/${PACKAGE}'])
217 dnl Defines HAVE_BACKTRACE if backtrace() is found.
218 AC_DEFUN([OVS_CHECK_BACKTRACE],
219 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
220 [AC_DEFINE([HAVE_BACKTRACE], [1],
221 [Define to 1 if you have backtrace(3).])])])
223 dnl Checks for valgrind/valgrind.h.
224 AC_DEFUN([OVS_CHECK_VALGRIND],
225 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
227 dnl Checks for Python 2.x, x >= 4.
228 AC_DEFUN([OVS_CHECK_PYTHON],
230 [for Python 2.x for x >= 4],
232 [if test -n "$PYTHON"; then
233 ovs_cv_python=$PYTHON
236 for binary in python python2.4 python2.5; do
237 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
240 test -z "$dir" && dir=.
241 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
242 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
246 ovs_cv_python=$dir/$binary
252 AC_SUBST([HAVE_PYTHON])
253 AM_MISSING_PROG([PYTHON], [python])
254 if test $ovs_cv_python != no; then
255 PYTHON=$ovs_cv_python
260 AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
263 AC_DEFUN([OVS_CHECK_DOT],
267 [dnl "dot" writes -V output to stderr:
268 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
273 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
275 dnl Checks whether $PYTHON supports the module given as $1
276 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
277 [AC_REQUIRE([OVS_CHECK_PYTHON])
279 [for $1 Python module],
280 [ovs_cv_py_[]AS_TR_SH([$1])],
281 [ovs_cv_py_[]AS_TR_SH([$1])=no
282 if test $HAVE_PYTHON = yes; then
283 AS_ECHO(["running $PYTHON -c 'import $1
285 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
286 if $PYTHON -c 'import $1
288 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
289 ovs_cv_py_[]AS_TR_SH([$1])=yes
293 dnl Checks for missing python modules at build time
294 AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
295 [OVS_CHECK_PYTHON_MODULE([uuid])
296 if test $ovs_cv_py_uuid = yes; then
297 INCLUDE_PYTHON_COMPAT=no
299 INCLUDE_PYTHON_COMPAT=yes
301 AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
302 AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
303 AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
305 dnl Checks for groff.
306 AC_DEFUN([OVS_CHECK_GROFF],
310 [if (groff -v) >/dev/null 2>&1; then
315 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
317 dnl Checks for thread-local storage support.
319 dnl Checks whether the compiler and linker support the C11
320 dnl thread_local macro from <threads.h>, and if so defines
321 dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
322 dnl support the GCC __thread extension, and if so defines
324 AC_DEFUN([OVS_CHECK_TLS],
326 [whether $CC has <threads.h> that supports thread_local],
327 [ovs_cv_thread_local],
329 [AC_LANG_PROGRAM([#include <threads.h>
330 static thread_local int var;], [return var;])],
331 [ovs_cv_thread_local=yes],
332 [ovs_cv_thread_local=no])])
333 if test $ovs_cv_thread_local = yes; then
334 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
335 [Define to 1 if the C compiler and linker supports the C11
336 thread_local matcro defined in <threads.h>.])
339 [whether $CC supports __thread],
342 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
343 [ovs_cv___thread=yes],
344 [ovs_cv___thread=no])])
345 if test $ovs_cv___thread = yes; then
346 AC_DEFINE([HAVE___THREAD], [1],
347 [Define to 1 if the C compiler and linker supports the
348 GCC __thread extenions.])
352 dnl OVS_CHECK_ATOMIC_LIBS
354 dnl Check to see if -latomic is need for GCC atomic built-ins.
355 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
356 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
358 dnl OVS_CHECK_GCC4_ATOMICS
360 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
361 dnl A compile-time only check is not enough because the compiler defers
362 dnl unimplemented built-ins to libgcc, which sometimes also lacks
364 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
366 [whether $CC supports GCC 4.0+ atomic built-ins],
367 [ovs_cv_gcc4_atomics],
369 [AC_LANG_PROGRAM([[#include <stdlib.h>
371 #define ovs_assert(expr) if (!(expr)) abort();
372 #define TEST_ATOMIC_TYPE(TYPE) \
377 __sync_synchronize(); \
378 ovs_assert(x == 1); \
380 __sync_synchronize(); \
382 __sync_synchronize(); \
383 ovs_assert(x == 3); \
385 orig = __sync_fetch_and_add(&x, 1); \
386 ovs_assert(orig == 3); \
387 __sync_synchronize(); \
388 ovs_assert(x == 4); \
390 orig = __sync_fetch_and_sub(&x, 2); \
391 ovs_assert(orig == 4); \
392 __sync_synchronize(); \
393 ovs_assert(x == 2); \
395 orig = __sync_fetch_and_or(&x, 6); \
396 ovs_assert(orig == 2); \
397 __sync_synchronize(); \
398 ovs_assert(x == 6); \
400 orig = __sync_fetch_and_and(&x, 10); \
401 ovs_assert(orig == 6); \
402 __sync_synchronize(); \
403 ovs_assert(x == 2); \
405 orig = __sync_fetch_and_xor(&x, 10); \
406 ovs_assert(orig == 2); \
407 __sync_synchronize(); \
408 ovs_assert(x == 8); \
410 TEST_ATOMIC_TYPE(char);
411 TEST_ATOMIC_TYPE(unsigned char);
412 TEST_ATOMIC_TYPE(signed char);
413 TEST_ATOMIC_TYPE(short);
414 TEST_ATOMIC_TYPE(unsigned short);
415 TEST_ATOMIC_TYPE(int);
416 TEST_ATOMIC_TYPE(unsigned int);
417 TEST_ATOMIC_TYPE(long int);
418 TEST_ATOMIC_TYPE(unsigned long int);
419 TEST_ATOMIC_TYPE(long long int);
420 TEST_ATOMIC_TYPE(unsigned long long int);
422 [ovs_cv_gcc4_atomics=yes],
423 [ovs_cv_gcc4_atomics=no])])
424 if test $ovs_cv_gcc4_atomics = yes; then
425 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
426 [Define to 1 if the C compiler and linker supports the GCC 4.0+
430 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
432 dnl Checks __atomic_always_lock_free(SIZE, 0)
433 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
435 [value of __atomic_always_lock_free($1)],
436 [ovs_cv_atomic_always_lock_free_$1],
438 [ovs_cv_atomic_always_lock_free_$1],
439 [__atomic_always_lock_free($1, 0)],
441 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
442 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
444 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
445 [$ovs_cv_atomic_always_lock_free_$1],
446 [If the C compiler is GCC 4.7 or later, define to the return value of
447 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
448 an older version of GCC, the value does not matter.])
451 dnl OVS_CHECK_POSIX_AIO
452 AC_DEFUN([OVS_CHECK_POSIX_AIO],
453 [AC_SEARCH_LIBS([aio_write], [rt])
454 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
456 dnl OVS_CHECK_INCLUDE_NEXT
457 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
458 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
459 gl_CHECK_NEXT_HEADERS([$1])])
461 dnl OVS_CHECK_PRAGMA_MESSAGE
462 AC_DEFUN([OVS_CHECK_PRAGMA_MESSAGE],
463 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
464 [[_Pragma("message(\"Checking for pragma message\")")
466 [AC_DEFINE(HAVE_PRAGMA_MESSAGE,1,[Define if compiler supports #pragma
467 message directive])])