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 MSVC x64 compiler.
74 AC_DEFUN([OVS_CHECK_WIN64],
76 [for MSVC x64 compiler],
78 [dnl "cl" writes x64 output to stdin:
79 if (cl) 2>&1 | grep 'x64' >/dev/null 2>&1; then
81 MSVC64_LDFLAGS=" /MACHINE:X64 "
86 AC_SUBST([MSVC64_LDFLAGS])
89 dnl Checks for WINDOWS.
90 AC_DEFUN([OVS_CHECK_WIN32],
91 [AC_CHECK_HEADER([windows.h],
94 AM_CONDITIONAL([WIN32], [test "$WIN32" = yes])
95 if test "$WIN32" = yes; then
96 AC_ARG_WITH([pthread],
97 [AS_HELP_STRING([--with-pthread=DIR],
98 [root of the pthread-win32 directory])],
101 "" | y | ye | yes | n | no)
102 AC_MSG_ERROR([Invalid --with-pthread value])
105 if (cl) 2>&1 | grep 'x64' >/dev/null 2>&1; then
110 if test "$cl_cv_x64" = yes; then
111 PTHREAD_WIN32_DIR=$withval/lib/x64
112 PTHREAD_WIN32_DIR_DLL=/$(echo ${withval} | ${SED} -e 's/://')/dll/x64
113 PTHREAD_WIN32_DIR_DLL_WIN_FORM=$withval/dll/x64
115 PTHREAD_WIN32_DIR=$withval/lib/x86
116 PTHREAD_WIN32_DIR_DLL=/$(echo ${withval} | ${SED} -e 's/://')/dll/x86
117 PTHREAD_WIN32_DIR_DLL_WIN_FORM=$withval/dll/x86
119 PTHREAD_INCLUDES=-I$withval/include
120 PTHREAD_LDFLAGS=-L$PTHREAD_WIN32_DIR
121 PTHREAD_LIBS="-lpthreadVC2"
122 AC_SUBST([PTHREAD_WIN32_DIR_DLL_WIN_FORM])
123 AC_SUBST([PTHREAD_WIN32_DIR_DLL])
124 AC_SUBST([PTHREAD_INCLUDES])
125 AC_SUBST([PTHREAD_LDFLAGS])
126 AC_SUBST([PTHREAD_LIBS])
130 AC_MSG_ERROR([pthread directory not specified])
134 [AS_HELP_STRING([--with-debug],
135 [Build without compiler optimizations])],
138 AC_SUBST([MSVC_CFLAGS])
141 AC_SUBST([MSVC_CFLAGS])
145 AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
146 AH_BOTTOM([#ifdef WIN32
147 #include "include/windows/windefs.h"
151 dnl OVS_CHECK_WINDOWS
153 dnl Configure Visual Studio solution build
154 AC_DEFUN([OVS_CHECK_VISUAL_STUDIO_DDK], [
155 AC_ARG_WITH([vstudiotarget],
156 [AS_HELP_STRING([--with-vstudiotarget=target_type],
157 [Target type: Debug/Release])],
162 *) AC_MSG_ERROR([No valid Visual Studio configuration found]) ;;
165 VSTUDIO_CONFIG=$withval
171 AC_SUBST([VSTUDIO_CONFIG])
172 AC_DEFINE([VSTUDIO_DDK], [1], [System uses the Visual Studio build target.])
173 AM_CONDITIONAL([VSTUDIO_DDK], [test -n "$VSTUDIO_CONFIG"])
176 dnl Checks for Netlink support.
177 AC_DEFUN([OVS_CHECK_NETLINK],
178 [AC_CHECK_HEADER([linux/netlink.h],
181 [#include <sys/socket.h>
183 AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
184 if test "$HAVE_NETLINK" = yes; then
185 AC_DEFINE([HAVE_NETLINK], [1],
186 [Define to 1 if Netlink protocol is available.])
189 dnl Checks for libcap-ng.
190 AC_DEFUN([OVS_CHECK_LIBCAPNG],
193 [AC_HELP_STRING([--disable-libcapng], [Disable Linux capability support])],
194 [case "${enableval}" in
195 (yes) libcapng=true ;;
196 (no) libcapng=false ;;
197 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-libcapng]) ;;
201 if test "$libcapng" != false; then
202 AC_CHECK_LIB([cap-ng], [capng_clear], [HAVE_LIBCAPNG=yes])
204 if test "$HAVE_LIBCAPNG" != yes; then
205 if test "$libcapng" = true ; then
206 AC_MSG_ERROR([libcap-ng support requested, but not found])
208 if test "$libcapng" = check ; then
209 AC_MSG_WARN([cannot find libcap-ng.
210 --user option will not be supported on Linux.
211 (you may use --disable-libcapng to suppress this warning). ])
216 AC_SUBST([HAVE_LIBCAPNG])
217 AM_CONDITIONAL([HAVE_LIBCAPNG], [test "$HAVE_LIBCAPNG" = yes])
218 if test "$HAVE_LIBCAPNG" = yes; then
219 AC_DEFINE([HAVE_LIBCAPNG], [1],
220 [Define to 1 if libcap-ng is available.])
221 CAPNG_LDADD="-lcap-ng"
222 AC_SUBST([CAPNG_LDADD])
225 dnl Checks for OpenSSL.
226 AC_DEFUN([OVS_CHECK_OPENSSL],
229 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
230 [case "${enableval}" in
233 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
237 if test "$ssl" != false; then
241 if test "$ssl" = check; then
242 AC_MSG_WARN([Cannot find openssl:
246 OpenFlow connections over SSL will not be supported.
247 (You may use --disable-ssl to suppress this warning.)])
249 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
254 AC_SUBST([HAVE_OPENSSL])
255 AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
256 if test "$HAVE_OPENSSL" = yes; then
257 AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
260 dnl Checks for libraries needed by lib/socket-util.c.
261 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
262 [AC_CHECK_LIB([socket], [connect])
263 AC_SEARCH_LIBS([gethostbyname], [resolv])])
265 dnl Checks for the directory in which to store the PKI.
266 AC_DEFUN([OVS_CHECK_PKIDIR],
269 AC_HELP_STRING([--with-pkidir=DIR],
270 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
272 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
275 dnl Checks for the directory in which to store pidfiles.
276 AC_DEFUN([OVS_CHECK_RUNDIR],
279 AC_HELP_STRING([--with-rundir=DIR],
280 [directory used for pidfiles
281 [[LOCALSTATEDIR/run/openvswitch]]]),
283 [RUNDIR='${localstatedir}/run/openvswitch'])
286 dnl Checks for the directory in which to store logs.
287 AC_DEFUN([OVS_CHECK_LOGDIR],
290 AC_HELP_STRING([--with-logdir=DIR],
291 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
293 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
296 dnl Checks for the directory in which to store the Open vSwitch database.
297 AC_DEFUN([OVS_CHECK_DBDIR],
300 AC_HELP_STRING([--with-dbdir=DIR],
301 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
303 [DBDIR='${sysconfdir}/${PACKAGE}'])
306 dnl Defines HAVE_BACKTRACE if backtrace() is found.
307 AC_DEFUN([OVS_CHECK_BACKTRACE],
308 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
309 [AC_DEFINE([HAVE_BACKTRACE], [1],
310 [Define to 1 if you have backtrace(3).])])])
312 dnl Defines HAVE_PERF_EVENT if linux/perf_event.h is found.
313 AC_DEFUN([OVS_CHECK_PERF_EVENT],
314 [AC_CHECK_HEADERS([linux/perf_event.h])])
316 dnl Checks for valgrind/valgrind.h.
317 AC_DEFUN([OVS_CHECK_VALGRIND],
318 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
320 dnl Checks for Python 2.x, x >= 7.
321 AC_DEFUN([OVS_CHECK_PYTHON],
323 [for Python 2.x for x >= 7],
325 [if test -n "$PYTHON"; then
326 ovs_cv_python=$PYTHON
329 for binary in python python2.7; do
330 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
333 test -z "$dir" && dir=.
334 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
335 if sys.hexversion >= 0x02070000 and sys.hexversion < 0x03000000:
339 ovs_cv_python=$dir/$binary
345 AC_SUBST([HAVE_PYTHON])
346 AM_MISSING_PROG([PYTHON], [python])
347 if test $ovs_cv_python != no; then
348 PYTHON=$ovs_cv_python
353 AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
356 AC_DEFUN([OVS_CHECK_FLAKE8],
360 [if flake8 --version >/dev/null 2>&1; then
365 AM_CONDITIONAL([HAVE_FLAKE8], [test "$ovs_cv_flake8" = yes])])
368 AC_DEFUN([OVS_CHECK_DOT],
372 [dnl "dot" writes -V output to stderr:
373 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
378 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
380 dnl Checks for groff.
381 AC_DEFUN([OVS_CHECK_GROFF],
385 [if (groff -v) >/dev/null 2>&1; then
390 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
392 dnl Checks for thread-local storage support.
394 dnl Checks whether the compiler and linker support the C11
395 dnl thread_local macro from <threads.h>, and if so defines
396 dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
397 dnl support the GCC __thread extension, and if so defines
399 AC_DEFUN([OVS_CHECK_TLS],
401 [whether $CC has <threads.h> that supports thread_local],
402 [ovs_cv_thread_local],
404 [AC_LANG_PROGRAM([#include <threads.h>
405 static thread_local int var;], [return var;])],
406 [ovs_cv_thread_local=yes],
407 [ovs_cv_thread_local=no])])
408 if test $ovs_cv_thread_local = yes; then
409 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
410 [Define to 1 if the C compiler and linker supports the C11
411 thread_local matcro defined in <threads.h>.])
414 [whether $CC supports __thread],
417 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
418 [ovs_cv___thread=yes],
419 [ovs_cv___thread=no])])
420 if test $ovs_cv___thread = yes; then
421 AC_DEFINE([HAVE___THREAD], [1],
422 [Define to 1 if the C compiler and linker supports the
423 GCC __thread extenions.])
427 dnl OVS_CHECK_ATOMIC_LIBS
429 dnl Check to see if -latomic is need for GCC atomic built-ins.
430 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
431 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
433 dnl OVS_CHECK_GCC4_ATOMICS
435 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
436 dnl A compile-time only check is not enough because the compiler defers
437 dnl unimplemented built-ins to libgcc, which sometimes also lacks
439 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
441 [whether $CC supports GCC 4.0+ atomic built-ins],
442 [ovs_cv_gcc4_atomics],
444 [AC_LANG_PROGRAM([[#include <stdlib.h>
446 #define ovs_assert(expr) if (!(expr)) abort();
447 #define TEST_ATOMIC_TYPE(TYPE) \
452 __sync_synchronize(); \
453 ovs_assert(x == 1); \
455 __sync_synchronize(); \
457 __sync_synchronize(); \
458 ovs_assert(x == 3); \
460 orig = __sync_fetch_and_add(&x, 1); \
461 ovs_assert(orig == 3); \
462 __sync_synchronize(); \
463 ovs_assert(x == 4); \
465 orig = __sync_fetch_and_sub(&x, 2); \
466 ovs_assert(orig == 4); \
467 __sync_synchronize(); \
468 ovs_assert(x == 2); \
470 orig = __sync_fetch_and_or(&x, 6); \
471 ovs_assert(orig == 2); \
472 __sync_synchronize(); \
473 ovs_assert(x == 6); \
475 orig = __sync_fetch_and_and(&x, 10); \
476 ovs_assert(orig == 6); \
477 __sync_synchronize(); \
478 ovs_assert(x == 2); \
480 orig = __sync_fetch_and_xor(&x, 10); \
481 ovs_assert(orig == 2); \
482 __sync_synchronize(); \
483 ovs_assert(x == 8); \
485 TEST_ATOMIC_TYPE(char);
486 TEST_ATOMIC_TYPE(unsigned char);
487 TEST_ATOMIC_TYPE(signed char);
488 TEST_ATOMIC_TYPE(short);
489 TEST_ATOMIC_TYPE(unsigned short);
490 TEST_ATOMIC_TYPE(int);
491 TEST_ATOMIC_TYPE(unsigned int);
492 TEST_ATOMIC_TYPE(long int);
493 TEST_ATOMIC_TYPE(unsigned long int);
494 TEST_ATOMIC_TYPE(long long int);
495 TEST_ATOMIC_TYPE(unsigned long long int);
497 [ovs_cv_gcc4_atomics=yes],
498 [ovs_cv_gcc4_atomics=no])])
499 if test $ovs_cv_gcc4_atomics = yes; then
500 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
501 [Define to 1 if the C compiler and linker supports the GCC 4.0+
505 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
507 dnl Checks __atomic_always_lock_free(SIZE, 0)
508 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
510 [value of __atomic_always_lock_free($1)],
511 [ovs_cv_atomic_always_lock_free_$1],
513 [ovs_cv_atomic_always_lock_free_$1],
514 [__atomic_always_lock_free($1, 0)],
516 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
517 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
519 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
520 [$ovs_cv_atomic_always_lock_free_$1],
521 [If the C compiler is GCC 4.7 or later, define to the return value of
522 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
523 an older version of GCC, the value does not matter.])
526 dnl OVS_CHECK_POSIX_AIO
527 AC_DEFUN([OVS_CHECK_POSIX_AIO],
528 [AC_SEARCH_LIBS([aio_write], [rt])
529 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
531 dnl OVS_CHECK_INCLUDE_NEXT
532 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
533 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
534 gl_CHECK_NEXT_HEADERS([$1])])
536 dnl OVS_CHECK_PRAGMA_MESSAGE
537 AC_DEFUN([OVS_CHECK_PRAGMA_MESSAGE],
538 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
539 [[_Pragma("message(\"Checking for pragma message\")")
541 [AC_DEFINE(HAVE_PRAGMA_MESSAGE,1,[Define if compiler supports #pragma
542 message directive])])