3 # Copyright (c) 2008-2016, 2019 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.m4])
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])])
63 dnl Checks for MSVC x64 compiler.
64 AC_DEFUN([OVS_CHECK_WIN64],
66 [for MSVC x64 compiler],
68 [dnl "cl" writes x64 output to stdin:
69 if (cl) 2>&1 | grep 'x64' >/dev/null 2>&1; then
71 MSVC64_LDFLAGS=" /MACHINE:X64 "
78 AC_SUBST([MSVC64_LDFLAGS])
79 AC_SUBST([MSVC_PLATFORM])
82 dnl Checks for WINDOWS.
83 AC_DEFUN([OVS_CHECK_WIN32],
84 [AC_CHECK_HEADER([windows.h],
87 AM_CONDITIONAL([WIN32], [test "$WIN32" = yes])
88 if test "$WIN32" = yes; then
89 AC_ARG_WITH([pthread],
90 [AS_HELP_STRING([--with-pthread=DIR],
91 [root of the pthread-win32 directory])],
94 "" | y | ye | yes | n | no)
95 AC_MSG_ERROR([Invalid --with-pthread value])
98 if (cl) 2>&1 | grep 'x64' >/dev/null 2>&1; then
103 if test "$cl_cv_x64" = yes; then
104 PTHREAD_WIN32_DIR=$withval/lib/x64
105 PTHREAD_WIN32_DIR_DLL=/$(echo ${withval} | ${SED} -e 's/://')/dll/x64
106 PTHREAD_WIN32_DIR_DLL_WIN_FORM=$withval/dll/x64
108 PTHREAD_WIN32_DIR=$withval/lib/x86
109 PTHREAD_WIN32_DIR_DLL=/$(echo ${withval} | ${SED} -e 's/://')/dll/x86
110 PTHREAD_WIN32_DIR_DLL_WIN_FORM=$withval/dll/x86
112 PTHREAD_INCLUDES=-I$withval/include
113 PTHREAD_LDFLAGS=-L$PTHREAD_WIN32_DIR
114 PTHREAD_LIBS="-lpthreadVC2"
115 AC_SUBST([PTHREAD_WIN32_DIR_DLL_WIN_FORM])
116 AC_SUBST([PTHREAD_WIN32_DIR_DLL])
117 AC_SUBST([PTHREAD_INCLUDES])
118 AC_SUBST([PTHREAD_LDFLAGS])
119 AC_SUBST([PTHREAD_LIBS])
123 AC_MSG_ERROR([pthread directory not specified])
127 [AS_HELP_STRING([--with-debug],
128 [Build without compiler optimizations])],
131 AC_SUBST([MSVC_CFLAGS])
134 AC_SUBST([MSVC_CFLAGS])
138 AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
139 AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
140 AH_BOTTOM([#ifdef WIN32
141 #include "include/windows/windefs.h"
145 dnl OVS_CHECK_WINDOWS
147 dnl Configure Visual Studio solution build
148 AC_DEFUN([OVS_CHECK_VISUAL_STUDIO_DDK], [
149 AC_ARG_WITH([vstudiotarget],
150 [AS_HELP_STRING([--with-vstudiotarget=target_type],
151 [Target type: Debug/Release])],
156 *) AC_MSG_ERROR([No valid Visual Studio configuration found]) ;;
159 VSTUDIO_CONFIG=$withval
165 AC_SUBST([VSTUDIO_CONFIG])
167 AC_ARG_WITH([vstudiotargetver],
168 [AS_HELP_STRING([--with-vstudiotargetver=target_ver1,target_ver2],
169 [Target versions: Win8,Win8.1,Win10])],
171 targetver=`echo "$withval" | tr -s , ' ' `
172 for ver in $targetver; do
174 "Win8") VSTUDIO_WIN8=true ;;
175 "Win8.1") VSTUDIO_WIN8_1=true ;;
176 "Win10") VSTUDIO_WIN10=true ;;
177 *) AC_MSG_ERROR([No valid Visual Studio target version found]) ;;
188 AM_CONDITIONAL([VSTUDIO_WIN8], [test -n "$VSTUDIO_WIN8"])
189 AM_CONDITIONAL([VSTUDIO_WIN8_1], [test -n "$VSTUDIO_WIN8_1"])
190 AM_CONDITIONAL([VSTUDIO_WIN10], [test -n "$VSTUDIO_WIN10"])
192 AC_DEFINE([VSTUDIO_DDK], [1], [System uses the Visual Studio build target.])
193 AM_CONDITIONAL([VSTUDIO_DDK], [test -n "$VSTUDIO_CONFIG"])
196 dnl Checks for Netlink support.
197 AC_DEFUN([OVS_CHECK_NETLINK],
198 [AC_CHECK_HEADER([linux/netlink.h],
201 [#include <sys/socket.h>
203 AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
204 if test "$HAVE_NETLINK" = yes; then
205 AC_DEFINE([HAVE_NETLINK], [1],
206 [Define to 1 if Netlink protocol is available.])
209 dnl Checks for libcap-ng.
210 AC_DEFUN([OVS_CHECK_LIBCAPNG],
213 [AC_HELP_STRING([--disable-libcapng], [Disable Linux capability support])],
214 [case "${enableval}" in
215 (yes) libcapng=true ;;
216 (no) libcapng=false ;;
217 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-libcapng]) ;;
221 if test "$libcapng" != false; then
222 AC_CHECK_LIB([cap-ng], [capng_clear], [HAVE_LIBCAPNG=yes])
224 if test "$HAVE_LIBCAPNG" != yes; then
225 if test "$libcapng" = true ; then
226 AC_MSG_ERROR([libcap-ng support requested, but not found])
228 if test "$libcapng" = check ; then
229 AC_MSG_WARN([cannot find libcap-ng.
230 --user option will not be supported on Linux.
231 (you may use --disable-libcapng to suppress this warning). ])
236 AC_SUBST([HAVE_LIBCAPNG])
237 AM_CONDITIONAL([HAVE_LIBCAPNG], [test "$HAVE_LIBCAPNG" = yes])
238 if test "$HAVE_LIBCAPNG" = yes; then
239 AC_DEFINE([HAVE_LIBCAPNG], [1],
240 [Define to 1 if libcap-ng is available.])
241 CAPNG_LDADD="-lcap-ng"
242 AC_SUBST([CAPNG_LDADD])
245 dnl Checks for OpenSSL.
246 AC_DEFUN([OVS_CHECK_OPENSSL],
249 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
250 [case "${enableval}" in
253 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
257 if test "$ssl" != false; then
261 if test "$ssl" = check; then
262 AC_MSG_WARN([Cannot find openssl:
266 OpenFlow connections over SSL will not be supported.
267 (You may use --disable-ssl to suppress this warning.)])
269 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
274 AC_SUBST([HAVE_OPENSSL])
275 AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
276 if test "$HAVE_OPENSSL" = yes; then
277 AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
280 OPENSSL_SUPPORTS_SNI=no
281 if test $HAVE_OPENSSL = yes; then
282 save_CPPFLAGS=$CPPFLAGS
283 CPPFLAGS="$CPPFLAGS $SSL_INCLUDES"
284 AC_CHECK_DECL([SSL_set_tlsext_host_name], [OPENSSL_SUPPORTS_SNI=yes],
285 [], [#include <openssl/ssl.h>
287 if test $OPENSSL_SUPPORTS_SNI = yes; then
289 [OPENSSL_SUPPORTS_SNI], [1],
290 [Define to 1 if OpenSSL supports Server Name Indication (SNI).])
292 CPPFLAGS=$save_CPPFLAGS
294 AC_SUBST([OPENSSL_SUPPORTS_SNI])
297 dnl Checks for libraries needed by lib/socket-util.c.
298 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
299 [AC_CHECK_LIB([socket], [connect])
300 AC_SEARCH_LIBS([gethostbyname], [resolv])])
302 dnl Checks for the directory in which to store the PKI.
303 AC_DEFUN([OVS_CHECK_PKIDIR],
306 AC_HELP_STRING([--with-pkidir=DIR],
307 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
309 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
312 dnl Checks for the directory in which to store pidfiles.
313 AC_DEFUN([OVS_CHECK_RUNDIR],
316 AC_HELP_STRING([--with-rundir=DIR],
317 [directory used for pidfiles
318 [[LOCALSTATEDIR/run/openvswitch]]]),
320 [RUNDIR='${localstatedir}/run/openvswitch'])
323 dnl Checks for the directory in which to store logs.
324 AC_DEFUN([OVS_CHECK_LOGDIR],
327 AC_HELP_STRING([--with-logdir=DIR],
328 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
330 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
333 dnl Checks for the directory in which to store the Open vSwitch database.
334 AC_DEFUN([OVS_CHECK_DBDIR],
337 AC_HELP_STRING([--with-dbdir=DIR],
338 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
340 [DBDIR='${sysconfdir}/${PACKAGE}'])
343 dnl Defines HAVE_BACKTRACE if backtrace() is found.
344 AC_DEFUN([OVS_CHECK_BACKTRACE],
345 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
346 [AC_DEFINE([HAVE_BACKTRACE], [1],
347 [Define to 1 if you have backtrace(3).])])])
349 dnl Defines HAVE_PERF_EVENT if linux/perf_event.h is found.
350 AC_DEFUN([OVS_CHECK_PERF_EVENT],
351 [AC_CHECK_HEADERS([linux/perf_event.h])])
353 dnl Checks for valgrind/valgrind.h.
354 AC_DEFUN([OVS_CHECK_VALGRIND],
355 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
357 dnl Checks for Python 3.4 or later.
358 AC_DEFUN([OVS_CHECK_PYTHON3],
360 [for Python 3 (version 3.4 or later)],
362 [if test -n "$PYTHON3"; then
363 ovs_cv_python3=$PYTHON3
366 for binary in python3 python3.4 python3.5 python3.6 python3.7; do
367 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
370 test -z "$dir" && dir=.
371 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
372 if sys.hexversion >= 0x03040000 and sys.hexversion < 0x04000000:
376 ovs_cv_python3=$dir/$binary
382 if test "$ovs_cv_python3" = no; then
383 AC_MSG_ERROR([Python 3.4 or later is required but not found in $PATH, please install it or set $PYTHON3 to point to it])
385 AC_ARG_VAR([PYTHON3])
386 PYTHON3=$ovs_cv_python3])
388 dnl Checks for python six library.
389 AC_DEFUN([OVS_CHECK_SIX],
390 [AC_REQUIRE([OVS_CHECK_PYTHON3])
392 [where Python six library is available],
394 [if $PYTHON3 -c 'import six' >/dev/null 2>&1; then
397 AC_MSG_ERROR([Missing Python six library.])
400 dnl Checks for flake8.
401 AC_DEFUN([OVS_CHECK_FLAKE8],
405 [if flake8 --version >/dev/null 2>&1; then
410 AM_CONDITIONAL([HAVE_FLAKE8], [test "$ovs_cv_flake8" = yes])])
412 dnl Checks for sphinx.
413 AC_DEFUN([OVS_CHECK_SPHINX],
415 [SPHINXBUILD], [sphinx-build-3 sphinx-build-2 sphinx-build], [none])
416 AC_ARG_VAR([SPHINXBUILD])
417 AM_CONDITIONAL([HAVE_SPHINX], [test "$SPHINXBUILD" != none])])
420 AC_DEFUN([OVS_CHECK_DOT],
424 [dnl "dot" writes -V output to stderr:
425 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
430 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
432 dnl Checks for groff.
433 AC_DEFUN([OVS_CHECK_GROFF],
437 [if (groff -v) >/dev/null 2>&1; then
442 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
444 dnl Checks for thread-local storage support.
446 dnl Checks whether the compiler and linker support the C11
447 dnl thread_local macro from <threads.h>, and if so defines
448 dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
449 dnl support the GCC __thread extension, and if so defines
451 AC_DEFUN([OVS_CHECK_TLS],
453 [whether $CC has <threads.h> that supports thread_local],
454 [ovs_cv_thread_local],
456 [AC_LANG_PROGRAM([#include <threads.h>
457 static thread_local int var;], [return var;])],
458 [ovs_cv_thread_local=yes],
459 [ovs_cv_thread_local=no])])
460 if test $ovs_cv_thread_local = yes; then
461 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
462 [Define to 1 if the C compiler and linker supports the C11
463 thread_local matcro defined in <threads.h>.])
466 [whether $CC supports __thread],
469 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
470 [ovs_cv___thread=yes],
471 [ovs_cv___thread=no])])
472 if test $ovs_cv___thread = yes; then
473 AC_DEFINE([HAVE___THREAD], [1],
474 [Define to 1 if the C compiler and linker supports the
475 GCC __thread extenions.])
479 dnl OVS_CHECK_ATOMIC_LIBS
481 dnl Check to see if -latomic is need for GCC atomic built-ins.
482 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
483 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
485 dnl OVS_CHECK_GCC4_ATOMICS
487 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
488 dnl A compile-time only check is not enough because the compiler defers
489 dnl unimplemented built-ins to libgcc, which sometimes also lacks
491 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
493 [whether $CC supports GCC 4.0+ atomic built-ins],
494 [ovs_cv_gcc4_atomics],
496 [AC_LANG_PROGRAM([[#include <stdlib.h>
498 #define ovs_assert(expr) if (!(expr)) abort();
499 #define TEST_ATOMIC_TYPE(TYPE) \
504 __sync_synchronize(); \
505 ovs_assert(x == 1); \
507 __sync_synchronize(); \
509 __sync_synchronize(); \
510 ovs_assert(x == 3); \
512 orig = __sync_fetch_and_add(&x, 1); \
513 ovs_assert(orig == 3); \
514 __sync_synchronize(); \
515 ovs_assert(x == 4); \
517 orig = __sync_fetch_and_sub(&x, 2); \
518 ovs_assert(orig == 4); \
519 __sync_synchronize(); \
520 ovs_assert(x == 2); \
522 orig = __sync_fetch_and_or(&x, 6); \
523 ovs_assert(orig == 2); \
524 __sync_synchronize(); \
525 ovs_assert(x == 6); \
527 orig = __sync_fetch_and_and(&x, 10); \
528 ovs_assert(orig == 6); \
529 __sync_synchronize(); \
530 ovs_assert(x == 2); \
532 orig = __sync_fetch_and_xor(&x, 10); \
533 ovs_assert(orig == 2); \
534 __sync_synchronize(); \
535 ovs_assert(x == 8); \
537 TEST_ATOMIC_TYPE(char);
538 TEST_ATOMIC_TYPE(unsigned char);
539 TEST_ATOMIC_TYPE(signed char);
540 TEST_ATOMIC_TYPE(short);
541 TEST_ATOMIC_TYPE(unsigned short);
542 TEST_ATOMIC_TYPE(int);
543 TEST_ATOMIC_TYPE(unsigned int);
544 TEST_ATOMIC_TYPE(long int);
545 TEST_ATOMIC_TYPE(unsigned long int);
546 TEST_ATOMIC_TYPE(long long int);
547 TEST_ATOMIC_TYPE(unsigned long long int);
549 [ovs_cv_gcc4_atomics=yes],
550 [ovs_cv_gcc4_atomics=no])])
551 if test $ovs_cv_gcc4_atomics = yes; then
552 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
553 [Define to 1 if the C compiler and linker supports the GCC 4.0+
557 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
559 dnl Checks __atomic_always_lock_free(SIZE, 0)
560 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
562 [value of __atomic_always_lock_free($1)],
563 [ovs_cv_atomic_always_lock_free_$1],
565 [ovs_cv_atomic_always_lock_free_$1],
566 [__atomic_always_lock_free($1, 0)],
568 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
569 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
571 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
572 [$ovs_cv_atomic_always_lock_free_$1],
573 [If the C compiler is GCC 4.7 or later, define to the return value of
574 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
575 an older version of GCC, the value does not matter.])
578 dnl OVS_CHECK_POSIX_AIO
579 AC_DEFUN([OVS_CHECK_POSIX_AIO],
580 [AC_SEARCH_LIBS([aio_write], [rt])
581 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
583 dnl OVS_CHECK_INCLUDE_NEXT
584 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
585 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
586 gl_CHECK_NEXT_HEADERS([$1])])
588 dnl OVS_CHECK_PRAGMA_MESSAGE
589 AC_DEFUN([OVS_CHECK_PRAGMA_MESSAGE],
590 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
591 [[_Pragma("message(\"Checking for pragma message\")")
593 [AC_DEFINE(HAVE_PRAGMA_MESSAGE,1,[Define if compiler supports #pragma
594 message directive])])
597 dnl OVS_LIBTOOL_VERSIONS sets the major, minor, micro version information for
598 dnl OVS_LTINFO variable. This variable locks libtool information for shared
599 dnl objects, allowing multiple versions with different ABIs to coexist.
600 AC_DEFUN([OVS_LIBTOOL_VERSIONS],
601 [AC_MSG_CHECKING(linker output version information)
602 OVS_MAJOR=`echo "$PACKAGE_VERSION" | sed -e 's/[[.]].*//'`
603 OVS_MINOR=`echo "$PACKAGE_VERSION" | sed -e "s/^$OVS_MAJOR//" -e 's/^.//' -e 's/[[.]].*//'`
604 OVS_MICRO=`echo "$PACKAGE_VERSION" | sed -e "s/^$OVS_MAJOR.$OVS_MINOR//" -e 's/^.//' -e 's/[[^0-9]].*//'`
605 OVS_LT_RELINFO="-release $OVS_MAJOR.$OVS_MINOR"
606 OVS_LT_VERINFO="-version-info $LT_CURRENT:$OVS_MICRO"
607 OVS_LTINFO="$OVS_LT_RELINFO $OVS_LT_VERINFO"
608 AC_MSG_RESULT([libX-$OVS_MAJOR.$OVS_MINOR.so.$LT_CURRENT.0.$OVS_MICRO)])
612 dnl OVS does not use C++ itself, but it provides public header files
613 dnl that a C++ compiler should accept, so when --enable-Werror is in
614 dnl effect and a C++ compiler is available, we enable building a C++
615 dnl source file that #includes all the public headers, as a way to
616 dnl ensure that they are acceptable as C++.
617 AC_DEFUN([OVS_CHECK_CXX],
618 [AC_REQUIRE([AC_PROG_CXX])
619 AC_REQUIRE([OVS_ENABLE_WERROR])
620 AX_CXX_COMPILE_STDCXX([11], [], [optional])
621 if test $enable_Werror = yes && test $HAVE_CXX11 = 1; then
624 AC_CHECK_HEADERS([atomic])
629 AM_CONDITIONAL([HAVE_CXX], [$enable_cxx])])
631 dnl Checks for unbound library.
632 AC_DEFUN([OVS_CHECK_UNBOUND],
633 [AC_CHECK_LIB(unbound, ub_ctx_create, [HAVE_UNBOUND=yes], [HAVE_UNBOUND=no])
634 if test "$HAVE_UNBOUND" = yes; then
635 AC_DEFINE([HAVE_UNBOUND], [1], [Define to 1 if unbound is detected.])
636 LIBS="$LIBS -lunbound"
638 AM_CONDITIONAL([HAVE_UNBOUND], [test "$HAVE_UNBOUND" = yes])
639 AC_SUBST([HAVE_UNBOUND])])