]> git.proxmox.com Git - ovs.git/blame - m4/openvswitch.m4
Remove dependency on python3-six
[ovs.git] / m4 / openvswitch.m4
CommitLineData
064af421
BP
1# -*- autoconf -*-
2
b291eb69 3# Copyright (c) 2008-2016, 2019 Nicira, Inc.
064af421 4#
a14bc59f
BP
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:
064af421 8#
a14bc59f
BP
9# http://www.apache.org/licenses/LICENSE-2.0
10#
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.
0877a018 16#
12878bc4 17m4_include([m4/compat.m4])
064af421 18
c2b07021
BP
19dnl Checks for --enable-coverage and updates CFLAGS and LDFLAGS appropriately.
20AC_DEFUN([OVS_CHECK_COVERAGE],
21 [AC_REQUIRE([AC_PROG_CC])
22 AC_ARG_ENABLE(
23 [coverage],
2e22e1c7 24 [AC_HELP_STRING([--enable-coverage],
c2b07021
BP
25 [Enable gcov coverage tool.])],
26 [case "${enableval}" in
8faa5a21 27 (yes) coverage=true ;;
7c126fbb 28 (no) coverage=false ;;
c2b07021
BP
29 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;;
30 esac],
7c126fbb 31 [coverage=false])
c2b07021 32 if $coverage; then
27a79a44
BP
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.
36 old_CFLAGS=$CFLAGS
37 CFLAGS=
38 for option in $old_CFLAGS; do
39 case $option in
40 (-O2) ;;
41 (*) CFLAGS="$CFLAGS $option" ;;
42 esac
43 done
44
45 OVS_CFLAGS="$OVS_CFLAGS --coverage"
95626395 46 OVS_LDFLAGS="$OVS_LDFLAGS --coverage"
7c126fbb 47 fi])
c2b07021 48
064af421
BP
49dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
50AC_DEFUN([OVS_CHECK_NDEBUG],
51 [AC_ARG_ENABLE(
52 [ndebug],
2e22e1c7 53 [AC_HELP_STRING([--enable-ndebug],
064af421
BP
54 [Disable debugging features for max performance])],
55 [case "${enableval}" in
56 (yes) ndebug=true ;;
57 (no) ndebug=false ;;
58 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
59 esac],
60 [ndebug=false])
61 AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
62
1cb3649c
AS
63dnl Checks for MSVC x64 compiler.
64AC_DEFUN([OVS_CHECK_WIN64],
65 [AC_CACHE_CHECK(
66 [for MSVC x64 compiler],
67 [cl_cv_x64],
68 [dnl "cl" writes x64 output to stdin:
69 if (cl) 2>&1 | grep 'x64' >/dev/null 2>&1; then
70 cl_cv_x64=yes
71 MSVC64_LDFLAGS=" /MACHINE:X64 "
b0bf5ef2 72 MSVC_PLATFORM="x64"
1cb3649c
AS
73 else
74 cl_cv_x64=no
75 MSVC64_LDFLAGS=""
b0bf5ef2 76 MSVC_PLATFORM="x86"
1cb3649c
AS
77 fi])
78 AC_SUBST([MSVC64_LDFLAGS])
b0bf5ef2 79 AC_SUBST([MSVC_PLATFORM])
1cb3649c
AS
80])
81
db6964bb
GS
82dnl Checks for WINDOWS.
83AC_DEFUN([OVS_CHECK_WIN32],
84 [AC_CHECK_HEADER([windows.h],
85 [WIN32=yes],
86 [WIN32=no])
87 AM_CONDITIONAL([WIN32], [test "$WIN32" = yes])
88 if test "$WIN32" = yes; then
94887cf4
GS
89 AC_ARG_WITH([pthread],
90 [AS_HELP_STRING([--with-pthread=DIR],
91 [root of the pthread-win32 directory])],
92 [
93 case "$withval" in
94 "" | y | ye | yes | n | no)
95 AC_MSG_ERROR([Invalid --with-pthread value])
96 ;;
97 *)
1cb3649c
AS
98 if (cl) 2>&1 | grep 'x64' >/dev/null 2>&1; then
99 cl_cv_x64=yes
100 else
101 cl_cv_x64=no
102 fi
103 if test "$cl_cv_x64" = yes; then
104 PTHREAD_WIN32_DIR=$withval/lib/x64
aca8be36 105 PTHREAD_WIN32_DIR_DLL=/$(echo ${withval} | ${SED} -e 's/://')/dll/x64
1cb3649c
AS
106 PTHREAD_WIN32_DIR_DLL_WIN_FORM=$withval/dll/x64
107 else
108 PTHREAD_WIN32_DIR=$withval/lib/x86
aca8be36 109 PTHREAD_WIN32_DIR_DLL=/$(echo ${withval} | ${SED} -e 's/://')/dll/x86
1cb3649c
AS
110 PTHREAD_WIN32_DIR_DLL_WIN_FORM=$withval/dll/x86
111 fi
3e2e7588
AS
112 PTHREAD_INCLUDES=-I$withval/include
113 PTHREAD_LDFLAGS=-L$PTHREAD_WIN32_DIR
94887cf4 114 PTHREAD_LIBS="-lpthreadVC2"
1cb3649c 115 AC_SUBST([PTHREAD_WIN32_DIR_DLL_WIN_FORM])
3e2e7588 116 AC_SUBST([PTHREAD_WIN32_DIR_DLL])
94887cf4
GS
117 AC_SUBST([PTHREAD_INCLUDES])
118 AC_SUBST([PTHREAD_LDFLAGS])
119 AC_SUBST([PTHREAD_LIBS])
120 ;;
121 esac
122 ], [
123 AC_MSG_ERROR([pthread directory not specified])
124 ]
125 )
b0e1bce5
GS
126 AC_ARG_WITH([debug],
127 [AS_HELP_STRING([--with-debug],
128 [Build without compiler optimizations])],
129 [
130 MSVC_CFLAGS="-O0"
131 AC_SUBST([MSVC_CFLAGS])
132 ], [
133 MSVC_CFLAGS="-O2"
134 AC_SUBST([MSVC_CFLAGS])
135 ]
136 )
bd9d7025 137
db6964bb 138 AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
2b3f8b6e 139 AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
e42dfc72
AS
140 AH_BOTTOM([#ifdef WIN32
141#include "include/windows/windefs.h"
142#endif])
db6964bb
GS
143 fi])
144
bd9d7025
AS
145dnl OVS_CHECK_WINDOWS
146dnl
147dnl Configure Visual Studio solution build
148AC_DEFUN([OVS_CHECK_VISUAL_STUDIO_DDK], [
d183efc2
AS
149AC_ARG_WITH([vstudiotarget],
150 [AS_HELP_STRING([--with-vstudiotarget=target_type],
151 [Target type: Debug/Release])],
bd9d7025
AS
152 [
153 case "$withval" in
d183efc2
AS
154 "Release") ;;
155 "Debug") ;;
156 *) AC_MSG_ERROR([No valid Visual Studio configuration found]) ;;
bd9d7025
AS
157 esac
158
159 VSTUDIO_CONFIG=$withval
160 ], [
161 VSTUDIO_CONFIG=
162 ]
163 )
164
165 AC_SUBST([VSTUDIO_CONFIG])
b1db9dd6
SR
166
167AC_ARG_WITH([vstudiotargetver],
168 [AS_HELP_STRING([--with-vstudiotargetver=target_ver1,target_ver2],
169 [Target versions: Win8,Win8.1,Win10])],
170 [
171 targetver=`echo "$withval" | tr -s , ' ' `
172 for ver in $targetver; do
173 case "$ver" in
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]) ;;
178 esac
179 done
180
181 ], [
182 VSTUDIO_WIN8=true
183 VSTUDIO_WIN8_1=true
184 VSTUDIO_WIN10=true
185 ]
186 )
187
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"])
191
d183efc2 192 AC_DEFINE([VSTUDIO_DDK], [1], [System uses the Visual Studio build target.])
bd9d7025
AS
193 AM_CONDITIONAL([VSTUDIO_DDK], [test -n "$VSTUDIO_CONFIG"])
194])
195
064af421
BP
196dnl Checks for Netlink support.
197AC_DEFUN([OVS_CHECK_NETLINK],
198 [AC_CHECK_HEADER([linux/netlink.h],
199 [HAVE_NETLINK=yes],
200 [HAVE_NETLINK=no],
201 [#include <sys/socket.h>
064af421
BP
202 ])
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.])
207 fi])
208
1bbebfb7
AZ
209dnl Checks for libcap-ng.
210AC_DEFUN([OVS_CHECK_LIBCAPNG],
211 [AC_ARG_ENABLE(
212 [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]) ;;
218 esac],
219 [libcapng=check])
220
221 if test "$libcapng" != false; then
222 AC_CHECK_LIB([cap-ng], [capng_clear], [HAVE_LIBCAPNG=yes])
223
224 if test "$HAVE_LIBCAPNG" != yes; then
225 if test "$libcapng" = true ; then
226 AC_MSG_ERROR([libcap-ng support requested, but not found])
227 fi
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). ])
232 fi
233 fi
234 fi
235
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])
243 fi])
244
f272ec73 245dnl Checks for OpenSSL.
064af421
BP
246AC_DEFUN([OVS_CHECK_OPENSSL],
247 [AC_ARG_ENABLE(
248 [ssl],
f272ec73 249 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
064af421
BP
250 [case "${enableval}" in
251 (yes) ssl=true ;;
252 (no) ssl=false ;;
253 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
254 esac],
f272ec73 255 [ssl=check])
064af421 256
f272ec73 257 if test "$ssl" != false; then
0f31bef5 258 AX_CHECK_OPENSSL(
48b9616a
BP
259 [HAVE_OPENSSL=yes],
260 [HAVE_OPENSSL=no
f272ec73 261 if test "$ssl" = check; then
924c2434 262 AC_MSG_WARN([Cannot find openssl:
064af421 263
48b9616a 264$SSL_PKG_ERRORS
064af421 265
f272ec73
BP
266OpenFlow connections over SSL will not be supported.
267(You may use --disable-ssl to suppress this warning.)])
268 else
924c2434 269 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
f272ec73 270 fi])
869decd4
BP
271 else
272 HAVE_OPENSSL=no
064af421 273 fi
d27ce529 274 AC_SUBST([HAVE_OPENSSL])
064af421
BP
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.])
b291eb69
BP
278 fi
279
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>
286])
287 if test $OPENSSL_SUPPORTS_SNI = yes; then
288 AC_DEFINE(
289 [OPENSSL_SUPPORTS_SNI], [1],
290 [Define to 1 if OpenSSL supports Server Name Indication (SNI).])
291 fi
292 CPPFLAGS=$save_CPPFLAGS
293 fi
294 AC_SUBST([OPENSSL_SUPPORTS_SNI])
295])
064af421 296
064af421
BP
297dnl Checks for libraries needed by lib/socket-util.c.
298AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
299 [AC_CHECK_LIB([socket], [connect])
c6e02a5c 300 AC_SEARCH_LIBS([gethostbyname], [resolv])])
064af421
BP
301
302dnl Checks for the directory in which to store the PKI.
303AC_DEFUN([OVS_CHECK_PKIDIR],
304 [AC_ARG_WITH(
2e22e1c7
EJ
305 [pkidir],
306 AC_HELP_STRING([--with-pkidir=DIR],
14bd2d51 307 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
064af421 308 [PKIDIR=$withval],
14bd2d51 309 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
064af421
BP
310 AC_SUBST([PKIDIR])])
311
312dnl Checks for the directory in which to store pidfiles.
313AC_DEFUN([OVS_CHECK_RUNDIR],
314 [AC_ARG_WITH(
2e22e1c7
EJ
315 [rundir],
316 AC_HELP_STRING([--with-rundir=DIR],
bc391960
JP
317 [directory used for pidfiles
318 [[LOCALSTATEDIR/run/openvswitch]]]),
064af421 319 [RUNDIR=$withval],
bc391960 320 [RUNDIR='${localstatedir}/run/openvswitch'])
064af421
BP
321 AC_SUBST([RUNDIR])])
322
323dnl Checks for the directory in which to store logs.
324AC_DEFUN([OVS_CHECK_LOGDIR],
325 [AC_ARG_WITH(
2e22e1c7
EJ
326 [logdir],
327 AC_HELP_STRING([--with-logdir=DIR],
064af421
BP
328 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
329 [LOGDIR=$withval],
330 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
331 AC_SUBST([LOGDIR])])
332
f973f2af
BP
333dnl Checks for the directory in which to store the Open vSwitch database.
334AC_DEFUN([OVS_CHECK_DBDIR],
335 [AC_ARG_WITH(
336 [dbdir],
337 AC_HELP_STRING([--with-dbdir=DIR],
338 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
339 [DBDIR=$withval],
340 [DBDIR='${sysconfdir}/${PACKAGE}'])
341 AC_SUBST([DBDIR])])
342
92f75e60 343dnl Defines HAVE_BACKTRACE if backtrace() is found.
0e6644c3 344AC_DEFUN([OVS_CHECK_BACKTRACE],
3453ed24
YT
345 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
346 [AC_DEFINE([HAVE_BACKTRACE], [1],
347 [Define to 1 if you have backtrace(3).])])])
0e6644c3 348
9a6156bb
AZ
349dnl Defines HAVE_PERF_EVENT if linux/perf_event.h is found.
350AC_DEFUN([OVS_CHECK_PERF_EVENT],
351 [AC_CHECK_HEADERS([linux/perf_event.h])])
352
064af421 353dnl Checks for valgrind/valgrind.h.
2e22e1c7 354AC_DEFUN([OVS_CHECK_VALGRIND],
064af421
BP
355 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
356
1ca0323e 357dnl Checks for Python 3.4 or later.
8fb7d026
RB
358AC_DEFUN([OVS_CHECK_PYTHON3],
359 [AC_CACHE_CHECK(
1ca0323e 360 [for Python 3 (version 3.4 or later)],
8fb7d026
RB
361 [ovs_cv_python3],
362 [if test -n "$PYTHON3"; then
363 ovs_cv_python3=$PYTHON3
364 else
365 ovs_cv_python3=no
1ca0323e 366 for binary in python3 python3.4 python3.5 python3.6 python3.7; do
8fb7d026
RB
367 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
368 for dir in $PATH; do
369 IFS=$ovs_save_IFS
370 test -z "$dir" && dir=.
371 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
372if sys.hexversion >= 0x03040000 and sys.hexversion < 0x04000000:
373 sys.exit(0)
374else:
375 sys.exit(1)'; then
376 ovs_cv_python3=$dir/$binary
377 break 2
378 fi
379 done
380 done
8fb7d026 381 fi])
1ca0323e
BP
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])
8fb7d026 384 fi
1ca0323e
BP
385 AC_ARG_VAR([PYTHON3])
386 PYTHON3=$ovs_cv_python3])
387
d84bdc82 388dnl Checks for flake8.
115d8719
RB
389AC_DEFUN([OVS_CHECK_FLAKE8],
390 [AC_CACHE_CHECK(
391 [for flake8],
392 [ovs_cv_flake8],
393 [if flake8 --version >/dev/null 2>&1; then
394 ovs_cv_flake8=yes
395 else
396 ovs_cv_flake8=no
397 fi])
398 AM_CONDITIONAL([HAVE_FLAKE8], [test "$ovs_cv_flake8" = yes])])
399
d84bdc82
SF
400dnl Checks for sphinx.
401AC_DEFUN([OVS_CHECK_SPHINX],
2a97891e
BP
402 [AC_CHECK_PROGS(
403 [SPHINXBUILD], [sphinx-build-3 sphinx-build-2 sphinx-build], [none])
404 AC_ARG_VAR([SPHINXBUILD])
40053bd4 405 AM_CONDITIONAL([HAVE_SPHINX], [test "$SPHINXBUILD" != none])])
d84bdc82 406
f8d739a9
BP
407dnl Checks for dot.
408AC_DEFUN([OVS_CHECK_DOT],
409 [AC_CACHE_CHECK(
410 [for dot],
411 [ovs_cv_dot],
412 [dnl "dot" writes -V output to stderr:
a5eef57e 413 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
f8d739a9
BP
414 ovs_cv_dot=yes
415 else
416 ovs_cv_dot=no
f8d739a9 417 fi])
7c9b0073 418 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
f8d739a9 419
0027492d
BP
420dnl Checks for groff.
421AC_DEFUN([OVS_CHECK_GROFF],
422 [AC_CACHE_CHECK(
423 [for groff],
424 [ovs_cv_groff],
425 [if (groff -v) >/dev/null 2>&1; then
426 ovs_cv_groff=yes
427 else
428 ovs_cv_groff=no
429 fi])
430 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
c22095a5
BP
431
432dnl Checks for thread-local storage support.
433dnl
434dnl Checks whether the compiler and linker support the C11
435dnl thread_local macro from <threads.h>, and if so defines
436dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
437dnl support the GCC __thread extension, and if so defines
438dnl HAVE___THREAD.
439AC_DEFUN([OVS_CHECK_TLS],
440 [AC_CACHE_CHECK(
441 [whether $CC has <threads.h> that supports thread_local],
442 [ovs_cv_thread_local],
443 [AC_LINK_IFELSE(
444 [AC_LANG_PROGRAM([#include <threads.h>
445static thread_local int var;], [return var;])],
446 [ovs_cv_thread_local=yes],
447 [ovs_cv_thread_local=no])])
448 if test $ovs_cv_thread_local = yes; then
449 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
450 [Define to 1 if the C compiler and linker supports the C11
451 thread_local matcro defined in <threads.h>.])
452 else
453 AC_CACHE_CHECK(
454 [whether $CC supports __thread],
455 [ovs_cv___thread],
456 [AC_LINK_IFELSE(
457 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
458 [ovs_cv___thread=yes],
459 [ovs_cv___thread=no])])
460 if test $ovs_cv___thread = yes; then
461 AC_DEFINE([HAVE___THREAD], [1],
462 [Define to 1 if the C compiler and linker supports the
463 GCC __thread extenions.])
464 fi
465 fi])
31a3fc6e 466
fd2e50cd
JP
467dnl OVS_CHECK_ATOMIC_LIBS
468dnl
469dnl Check to see if -latomic is need for GCC atomic built-ins.
470AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
471 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
472
15248032
BP
473dnl OVS_CHECK_GCC4_ATOMICS
474dnl
475dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
476dnl A compile-time only check is not enough because the compiler defers
477dnl unimplemented built-ins to libgcc, which sometimes also lacks
478dnl implementations.
479AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
480 [AC_CACHE_CHECK(
481 [whether $CC supports GCC 4.0+ atomic built-ins],
482 [ovs_cv_gcc4_atomics],
483 [AC_LINK_IFELSE(
484 [AC_LANG_PROGRAM([[#include <stdlib.h>
485
486#define ovs_assert(expr) if (!(expr)) abort();
487#define TEST_ATOMIC_TYPE(TYPE) \
488 { \
489 TYPE x = 1; \
490 TYPE orig; \
491 \
492 __sync_synchronize(); \
493 ovs_assert(x == 1); \
494 \
495 __sync_synchronize(); \
496 x = 3; \
497 __sync_synchronize(); \
498 ovs_assert(x == 3); \
499 \
500 orig = __sync_fetch_and_add(&x, 1); \
501 ovs_assert(orig == 3); \
502 __sync_synchronize(); \
503 ovs_assert(x == 4); \
504 \
505 orig = __sync_fetch_and_sub(&x, 2); \
506 ovs_assert(orig == 4); \
507 __sync_synchronize(); \
508 ovs_assert(x == 2); \
509 \
510 orig = __sync_fetch_and_or(&x, 6); \
511 ovs_assert(orig == 2); \
512 __sync_synchronize(); \
513 ovs_assert(x == 6); \
514 \
515 orig = __sync_fetch_and_and(&x, 10); \
516 ovs_assert(orig == 6); \
517 __sync_synchronize(); \
518 ovs_assert(x == 2); \
519 \
520 orig = __sync_fetch_and_xor(&x, 10); \
521 ovs_assert(orig == 2); \
522 __sync_synchronize(); \
523 ovs_assert(x == 8); \
524 }]], [dnl
525TEST_ATOMIC_TYPE(char);
526TEST_ATOMIC_TYPE(unsigned char);
527TEST_ATOMIC_TYPE(signed char);
528TEST_ATOMIC_TYPE(short);
529TEST_ATOMIC_TYPE(unsigned short);
530TEST_ATOMIC_TYPE(int);
531TEST_ATOMIC_TYPE(unsigned int);
532TEST_ATOMIC_TYPE(long int);
533TEST_ATOMIC_TYPE(unsigned long int);
534TEST_ATOMIC_TYPE(long long int);
535TEST_ATOMIC_TYPE(unsigned long long int);
536])],
537 [ovs_cv_gcc4_atomics=yes],
538 [ovs_cv_gcc4_atomics=no])])
539 if test $ovs_cv_gcc4_atomics = yes; then
540 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
541 [Define to 1 if the C compiler and linker supports the GCC 4.0+
542 atomic built-ins.])
543 fi])
544
31a3fc6e
BP
545dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
546dnl
547dnl Checks __atomic_always_lock_free(SIZE, 0)
b1db9dd6 548AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
31a3fc6e
BP
549 [AC_CACHE_CHECK(
550 [value of __atomic_always_lock_free($1)],
551 [ovs_cv_atomic_always_lock_free_$1],
552 [AC_COMPUTE_INT(
553 [ovs_cv_atomic_always_lock_free_$1],
554 [__atomic_always_lock_free($1, 0)],
555 [],
556 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
557 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
558 AC_DEFINE_UNQUOTED(
559 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
560 [$ovs_cv_atomic_always_lock_free_$1],
561 [If the C compiler is GCC 4.7 or later, define to the return value of
562 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
563 an older version of GCC, the value does not matter.])
564 fi])
97eba8fc
BP
565
566dnl OVS_CHECK_POSIX_AIO
567AC_DEFUN([OVS_CHECK_POSIX_AIO],
568 [AC_SEARCH_LIBS([aio_write], [rt])
569 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
ed1be787
BP
570
571dnl OVS_CHECK_INCLUDE_NEXT
572AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
573 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
574 gl_CHECK_NEXT_HEADERS([$1])])
aa8ea223
DDP
575
576dnl OVS_CHECK_PRAGMA_MESSAGE
577AC_DEFUN([OVS_CHECK_PRAGMA_MESSAGE],
578 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
579 [[_Pragma("message(\"Checking for pragma message\")")
580 ]])],
581 [AC_DEFINE(HAVE_PRAGMA_MESSAGE,1,[Define if compiler supports #pragma
582 message directive])])
583 ])
cb991590
AC
584
585dnl OVS_LIBTOOL_VERSIONS sets the major, minor, micro version information for
586dnl OVS_LTINFO variable. This variable locks libtool information for shared
587dnl objects, allowing multiple versions with different ABIs to coexist.
588AC_DEFUN([OVS_LIBTOOL_VERSIONS],
589 [AC_MSG_CHECKING(linker output version information)
590 OVS_MAJOR=`echo "$PACKAGE_VERSION" | sed -e 's/[[.]].*//'`
591 OVS_MINOR=`echo "$PACKAGE_VERSION" | sed -e "s/^$OVS_MAJOR//" -e 's/^.//' -e 's/[[.]].*//'`
592 OVS_MICRO=`echo "$PACKAGE_VERSION" | sed -e "s/^$OVS_MAJOR.$OVS_MINOR//" -e 's/^.//' -e 's/[[^0-9]].*//'`
f12e09b7
JS
593 OVS_LT_RELINFO="-release $OVS_MAJOR.$OVS_MINOR"
594 OVS_LT_VERINFO="-version-info $LT_CURRENT:$OVS_MICRO"
cb991590 595 OVS_LTINFO="$OVS_LT_RELINFO $OVS_LT_VERINFO"
f12e09b7 596 AC_MSG_RESULT([libX-$OVS_MAJOR.$OVS_MINOR.so.$LT_CURRENT.0.$OVS_MICRO)])
cb991590
AC
597 AC_SUBST(OVS_LTINFO)
598 ])
994bfc29
BP
599
600dnl OVS does not use C++ itself, but it provides public header files
601dnl that a C++ compiler should accept, so when --enable-Werror is in
602dnl effect and a C++ compiler is available, we enable building a C++
603dnl source file that #includes all the public headers, as a way to
604dnl ensure that they are acceptable as C++.
605AC_DEFUN([OVS_CHECK_CXX],
606 [AC_REQUIRE([AC_PROG_CXX])
607 AC_REQUIRE([OVS_ENABLE_WERROR])
608 AX_CXX_COMPILE_STDCXX([11], [], [optional])
609 if test $enable_Werror = yes && test $HAVE_CXX11 = 1; then
610 enable_cxx=:
adabd65d
BP
611 AC_LANG_PUSH([C++])
612 AC_CHECK_HEADERS([atomic])
613 AC_LANG_POP([C++])
994bfc29
BP
614 else
615 enable_cxx=false
616 fi
617 AM_CONDITIONAL([HAVE_CXX], [$enable_cxx])])
771680d9
YS
618
619dnl Checks for unbound library.
620AC_DEFUN([OVS_CHECK_UNBOUND],
b291eb69 621 [AC_CHECK_LIB(unbound, ub_ctx_create, [HAVE_UNBOUND=yes], [HAVE_UNBOUND=no])
771680d9
YS
622 if test "$HAVE_UNBOUND" = yes; then
623 AC_DEFINE([HAVE_UNBOUND], [1], [Define to 1 if unbound is detected.])
624 LIBS="$LIBS -lunbound"
625 fi
626 AM_CONDITIONAL([HAVE_UNBOUND], [test "$HAVE_UNBOUND" = yes])
627 AC_SUBST([HAVE_UNBOUND])])
e2ed6fbe
WT
628
629dnl Checks for libunwind.
630AC_DEFUN([OVS_CHECK_UNWIND],
81a29c0a
YHW
631 [AC_CHECK_LIB([unwind], [unw_backtrace],
632 [AC_CHECK_HEADERS([libunwind.h], [HAVE_UNWIND=yes], [HAVE_UNWIND=no])],
633 [HAVE_UNWIND=no])
e2ed6fbe
WT
634 if test "$HAVE_UNWIND" = yes; then
635 AC_DEFINE([HAVE_UNWIND], [1], [Define to 1 if unwind is detected.])
636 LIBS="$LIBS -lunwind"
637 fi
638 AM_CONDITIONAL([HAVE_UNWIND], [test "$HAVE_UNWIND" = yes])
639 AC_SUBST([HAVE_UNWIND])])