]> git.proxmox.com Git - mirror_ovs.git/blame - m4/openvswitch.m4
Add common definitions for Windows builds.
[mirror_ovs.git] / m4 / openvswitch.m4
CommitLineData
064af421
BP
1# -*- autoconf -*-
2
c22095a5 3# Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 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.
064af421 16
c2b07021
BP
17dnl Checks for --enable-coverage and updates CFLAGS and LDFLAGS appropriately.
18AC_DEFUN([OVS_CHECK_COVERAGE],
19 [AC_REQUIRE([AC_PROG_CC])
20 AC_ARG_ENABLE(
21 [coverage],
2e22e1c7 22 [AC_HELP_STRING([--enable-coverage],
c2b07021
BP
23 [Enable gcov coverage tool.])],
24 [case "${enableval}" in
8faa5a21 25 (yes) coverage=true ;;
7c126fbb 26 (no) coverage=false ;;
c2b07021
BP
27 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;;
28 esac],
7c126fbb 29 [coverage=false])
c2b07021
BP
30 if $coverage; then
31 CFLAGS="$CFLAGS -O0 --coverage"
32 LDFLAGS="$LDFLAGS --coverage"
7c126fbb 33 fi])
c2b07021 34
064af421
BP
35dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
36AC_DEFUN([OVS_CHECK_NDEBUG],
37 [AC_ARG_ENABLE(
38 [ndebug],
2e22e1c7 39 [AC_HELP_STRING([--enable-ndebug],
064af421
BP
40 [Disable debugging features for max performance])],
41 [case "${enableval}" in
42 (yes) ndebug=true ;;
43 (no) ndebug=false ;;
44 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
45 esac],
46 [ndebug=false])
47 AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
48
361906b1
EJ
49dnl Checks for ESX.
50AC_DEFUN([OVS_CHECK_ESX],
51 [AC_CHECK_HEADER([vmware.h],
52 [ESX=yes],
53 [ESX=no])
54 AM_CONDITIONAL([ESX], [test "$ESX" = yes])
55 if test "$ESX" = yes; then
56 AC_DEFINE([ESX], [1], [Define to 1 if building on ESX.])
57 fi])
58
db6964bb
GS
59dnl Checks for WINDOWS.
60AC_DEFUN([OVS_CHECK_WIN32],
61 [AC_CHECK_HEADER([windows.h],
62 [WIN32=yes],
63 [WIN32=no])
64 AM_CONDITIONAL([WIN32], [test "$WIN32" = yes])
65 if test "$WIN32" = yes; then
66 AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
e42dfc72
AS
67 AH_BOTTOM([#ifdef WIN32
68#include "include/windows/windefs.h"
69#endif])
db6964bb
GS
70 fi])
71
064af421
BP
72dnl Checks for Netlink support.
73AC_DEFUN([OVS_CHECK_NETLINK],
74 [AC_CHECK_HEADER([linux/netlink.h],
75 [HAVE_NETLINK=yes],
76 [HAVE_NETLINK=no],
77 [#include <sys/socket.h>
78 #include <linux/types.h>
79 ])
80 AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
81 if test "$HAVE_NETLINK" = yes; then
82 AC_DEFINE([HAVE_NETLINK], [1],
83 [Define to 1 if Netlink protocol is available.])
84 fi])
85
f272ec73 86dnl Checks for OpenSSL.
064af421
BP
87AC_DEFUN([OVS_CHECK_OPENSSL],
88 [AC_ARG_ENABLE(
89 [ssl],
f272ec73 90 [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
064af421
BP
91 [case "${enableval}" in
92 (yes) ssl=true ;;
93 (no) ssl=false ;;
94 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
95 esac],
f272ec73 96 [ssl=check])
064af421 97
f272ec73 98 if test "$ssl" != false; then
0f31bef5 99 AX_CHECK_OPENSSL(
48b9616a
BP
100 [HAVE_OPENSSL=yes],
101 [HAVE_OPENSSL=no
f272ec73 102 if test "$ssl" = check; then
924c2434 103 AC_MSG_WARN([Cannot find openssl:
064af421 104
48b9616a 105$SSL_PKG_ERRORS
064af421 106
f272ec73
BP
107OpenFlow connections over SSL will not be supported.
108(You may use --disable-ssl to suppress this warning.)])
109 else
924c2434 110 AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
f272ec73 111 fi])
869decd4
BP
112 else
113 HAVE_OPENSSL=no
064af421 114 fi
d27ce529 115 AC_SUBST([HAVE_OPENSSL])
064af421
BP
116 AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
117 if test "$HAVE_OPENSSL" = yes; then
118 AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
119 fi])
120
064af421
BP
121dnl Checks for libraries needed by lib/socket-util.c.
122AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
123 [AC_CHECK_LIB([socket], [connect])
c6e02a5c 124 AC_SEARCH_LIBS([gethostbyname], [resolv])])
064af421
BP
125
126dnl Checks for the directory in which to store the PKI.
127AC_DEFUN([OVS_CHECK_PKIDIR],
128 [AC_ARG_WITH(
2e22e1c7
EJ
129 [pkidir],
130 AC_HELP_STRING([--with-pkidir=DIR],
14bd2d51 131 [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
064af421 132 [PKIDIR=$withval],
14bd2d51 133 [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
064af421
BP
134 AC_SUBST([PKIDIR])])
135
136dnl Checks for the directory in which to store pidfiles.
137AC_DEFUN([OVS_CHECK_RUNDIR],
138 [AC_ARG_WITH(
2e22e1c7
EJ
139 [rundir],
140 AC_HELP_STRING([--with-rundir=DIR],
bc391960
JP
141 [directory used for pidfiles
142 [[LOCALSTATEDIR/run/openvswitch]]]),
064af421 143 [RUNDIR=$withval],
bc391960 144 [RUNDIR='${localstatedir}/run/openvswitch'])
064af421
BP
145 AC_SUBST([RUNDIR])])
146
147dnl Checks for the directory in which to store logs.
148AC_DEFUN([OVS_CHECK_LOGDIR],
149 [AC_ARG_WITH(
2e22e1c7
EJ
150 [logdir],
151 AC_HELP_STRING([--with-logdir=DIR],
064af421
BP
152 [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
153 [LOGDIR=$withval],
154 [LOGDIR='${localstatedir}/log/${PACKAGE}'])
155 AC_SUBST([LOGDIR])])
156
f973f2af
BP
157dnl Checks for the directory in which to store the Open vSwitch database.
158AC_DEFUN([OVS_CHECK_DBDIR],
159 [AC_ARG_WITH(
160 [dbdir],
161 AC_HELP_STRING([--with-dbdir=DIR],
162 [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
163 [DBDIR=$withval],
164 [DBDIR='${sysconfdir}/${PACKAGE}'])
165 AC_SUBST([DBDIR])])
166
92f75e60 167dnl Defines HAVE_BACKTRACE if backtrace() is found.
0e6644c3 168AC_DEFUN([OVS_CHECK_BACKTRACE],
3453ed24
YT
169 [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
170 [AC_DEFINE([HAVE_BACKTRACE], [1],
171 [Define to 1 if you have backtrace(3).])])])
0e6644c3 172
064af421
BP
173dnl Checks for __malloc_hook, etc., supported by glibc.
174AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
175 [AC_CACHE_CHECK(
176 [whether libc supports hooks for malloc and related functions],
177 [ovs_cv_malloc_hooks],
178 [AC_COMPILE_IFELSE(
179 [AC_LANG_PROGRAM(
180 [#include <malloc.h>
2e22e1c7 181 ],
064af421
BP
182 [(void) __malloc_hook;
183 (void) __realloc_hook;
184 (void) __free_hook;])],
185 [ovs_cv_malloc_hooks=yes],
186 [ovs_cv_malloc_hooks=no])])
187 if test $ovs_cv_malloc_hooks = yes; then
2e22e1c7 188 AC_DEFINE([HAVE_MALLOC_HOOKS], [1],
064af421
BP
189 [Define to 1 if you have __malloc_hook, __realloc_hook, and
190 __free_hook in <malloc.h>.])
191 fi])
192
193dnl Checks for valgrind/valgrind.h.
2e22e1c7 194AC_DEFUN([OVS_CHECK_VALGRIND],
064af421
BP
195 [AC_CHECK_HEADERS([valgrind/valgrind.h])])
196
3b135da3
BP
197dnl Checks for Python 2.x, x >= 4.
198AC_DEFUN([OVS_CHECK_PYTHON],
195b5c35 199 [AC_CACHE_CHECK(
3b135da3
BP
200 [for Python 2.x for x >= 4],
201 [ovs_cv_python],
202 [if test -n "$PYTHON"; then
203 ovs_cv_python=$PYTHON
204 else
205 ovs_cv_python=no
206 for binary in python python2.4 python2.5; do
207 ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
208 for dir in $PATH; do
209 IFS=$ovs_save_IFS
210 test -z "$dir" && dir=.
4a6ba437 211 if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
3b135da3
BP
212if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
213 sys.exit(0)
214else:
215 sys.exit(1)'; then
216 ovs_cv_python=$dir/$binary
217 break 2
218 fi
219 done
220 done
221 fi])
05b3c97b 222 AC_SUBST([HAVE_PYTHON])
195b5c35
BP
223 AM_MISSING_PROG([PYTHON], [python])
224 if test $ovs_cv_python != no; then
225 PYTHON=$ovs_cv_python
05b3c97b
BP
226 HAVE_PYTHON=yes
227 else
228 HAVE_PYTHON=no
229 fi
230 AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
436f27dd 231
f8d739a9
BP
232dnl Checks for dot.
233AC_DEFUN([OVS_CHECK_DOT],
234 [AC_CACHE_CHECK(
235 [for dot],
236 [ovs_cv_dot],
237 [dnl "dot" writes -V output to stderr:
a5eef57e 238 if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
f8d739a9
BP
239 ovs_cv_dot=yes
240 else
241 ovs_cv_dot=no
f8d739a9 242 fi])
7c9b0073 243 AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
f8d739a9 244
436f27dd
AS
245dnl Checks for pyuic4.
246AC_DEFUN([OVS_CHECK_PYUIC4],
247 [AC_CACHE_CHECK(
248 [for pyuic4],
249 [ovs_cv_pyuic4],
250 [if (pyuic4 --version) >/dev/null 2>&1; then
251 ovs_cv_pyuic4=pyuic4
252 else
253 ovs_cv_pyuic4=no
254 fi])
255 AM_MISSING_PROG([PYUIC4], [pyuic4])
256 if test $ovs_cv_pyuic4 != no; then
257 PYUIC4=$ovs_cv_pyuic4
258 fi])
259
260dnl Checks whether $PYTHON supports the module given as $1
261AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
262 [AC_REQUIRE([OVS_CHECK_PYTHON])
263 AC_CACHE_CHECK(
264 [for $1 Python module],
265 [ovs_cv_py_[]AS_TR_SH([$1])],
266 [ovs_cv_py_[]AS_TR_SH([$1])=no
267 if test $HAVE_PYTHON = yes; then
268 AS_ECHO(["running $PYTHON -c 'import $1
269import sys
1df624e6 270sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
436f27dd
AS
271 if $PYTHON -c 'import $1
272import sys
1df624e6 273sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
436f27dd
AS
274 ovs_cv_py_[]AS_TR_SH([$1])=yes
275 fi
276 fi])])
277
278dnl Checks for Python modules needed by ovsdbmonitor.
279AC_DEFUN([OVS_CHECK_OVSDBMONITOR],
280 [OVS_CHECK_PYTHON_MODULE([PySide.QtCore])
281 OVS_CHECK_PYTHON_MODULE([PyQt4.QtCore])
282 OVS_CHECK_PYTHON_MODULE([twisted.conch.ssh])
283 OVS_CHECK_PYTHON_MODULE([twisted.internet])
284 OVS_CHECK_PYTHON_MODULE([twisted.application])
285 OVS_CHECK_PYTHON_MODULE([json])
286 OVS_CHECK_PYTHON_MODULE([zope.interface])
287 if (test $ovs_cv_py_PySide_QtCore = yes \
288 || test $ovs_cv_py_PyQt4_QtCore = yes) \
289 && test $ovs_cv_py_twisted_conch_ssh = yes \
290 && test $ovs_cv_py_twisted_internet = yes \
291 && test $ovs_cv_py_twisted_application = yes \
292 && test $ovs_cv_py_json = yes \
293 && test $ovs_cv_py_zope_interface = yes; then
294 BUILD_OVSDBMONITOR=yes
295 else
296 BUILD_OVSDBMONITOR=no
297 fi
298 AC_MSG_CHECKING([whether to build ovsdbmonitor])
299 AC_MSG_RESULT([$BUILD_OVSDBMONITOR])
300 AM_CONDITIONAL([BUILD_OVSDBMONITOR], [test $BUILD_OVSDBMONITOR = yes])])
480ce8ab 301
9b4a5392
AA
302dnl Checks for missing python modules at build time
303AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
304 [OVS_CHECK_PYTHON_MODULE([uuid])
305 if test $ovs_cv_py_uuid = yes; then
306 INCLUDE_PYTHON_COMPAT=no
307 else
308 INCLUDE_PYTHON_COMPAT=yes
309 fi
310 AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
311 AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
312 AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
313
0027492d
BP
314dnl Checks for groff.
315AC_DEFUN([OVS_CHECK_GROFF],
316 [AC_CACHE_CHECK(
317 [for groff],
318 [ovs_cv_groff],
319 [if (groff -v) >/dev/null 2>&1; then
320 ovs_cv_groff=yes
321 else
322 ovs_cv_groff=no
323 fi])
324 AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
c22095a5
BP
325
326dnl Checks for thread-local storage support.
327dnl
328dnl Checks whether the compiler and linker support the C11
329dnl thread_local macro from <threads.h>, and if so defines
330dnl HAVE_THREAD_LOCAL. If not, checks whether the compiler and linker
331dnl support the GCC __thread extension, and if so defines
332dnl HAVE___THREAD.
333AC_DEFUN([OVS_CHECK_TLS],
334 [AC_CACHE_CHECK(
335 [whether $CC has <threads.h> that supports thread_local],
336 [ovs_cv_thread_local],
337 [AC_LINK_IFELSE(
338 [AC_LANG_PROGRAM([#include <threads.h>
339static thread_local int var;], [return var;])],
340 [ovs_cv_thread_local=yes],
341 [ovs_cv_thread_local=no])])
342 if test $ovs_cv_thread_local = yes; then
343 AC_DEFINE([HAVE_THREAD_LOCAL], [1],
344 [Define to 1 if the C compiler and linker supports the C11
345 thread_local matcro defined in <threads.h>.])
346 else
347 AC_CACHE_CHECK(
348 [whether $CC supports __thread],
349 [ovs_cv___thread],
350 [AC_LINK_IFELSE(
351 [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
352 [ovs_cv___thread=yes],
353 [ovs_cv___thread=no])])
354 if test $ovs_cv___thread = yes; then
355 AC_DEFINE([HAVE___THREAD], [1],
356 [Define to 1 if the C compiler and linker supports the
357 GCC __thread extenions.])
358 fi
359 fi])
31a3fc6e 360
fd2e50cd
JP
361dnl OVS_CHECK_ATOMIC_LIBS
362dnl
363dnl Check to see if -latomic is need for GCC atomic built-ins.
364AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
365 [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
366
15248032
BP
367dnl OVS_CHECK_GCC4_ATOMICS
368dnl
369dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
370dnl A compile-time only check is not enough because the compiler defers
371dnl unimplemented built-ins to libgcc, which sometimes also lacks
372dnl implementations.
373AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
374 [AC_CACHE_CHECK(
375 [whether $CC supports GCC 4.0+ atomic built-ins],
376 [ovs_cv_gcc4_atomics],
377 [AC_LINK_IFELSE(
378 [AC_LANG_PROGRAM([[#include <stdlib.h>
379
380#define ovs_assert(expr) if (!(expr)) abort();
381#define TEST_ATOMIC_TYPE(TYPE) \
382 { \
383 TYPE x = 1; \
384 TYPE orig; \
385 \
386 __sync_synchronize(); \
387 ovs_assert(x == 1); \
388 \
389 __sync_synchronize(); \
390 x = 3; \
391 __sync_synchronize(); \
392 ovs_assert(x == 3); \
393 \
394 orig = __sync_fetch_and_add(&x, 1); \
395 ovs_assert(orig == 3); \
396 __sync_synchronize(); \
397 ovs_assert(x == 4); \
398 \
399 orig = __sync_fetch_and_sub(&x, 2); \
400 ovs_assert(orig == 4); \
401 __sync_synchronize(); \
402 ovs_assert(x == 2); \
403 \
404 orig = __sync_fetch_and_or(&x, 6); \
405 ovs_assert(orig == 2); \
406 __sync_synchronize(); \
407 ovs_assert(x == 6); \
408 \
409 orig = __sync_fetch_and_and(&x, 10); \
410 ovs_assert(orig == 6); \
411 __sync_synchronize(); \
412 ovs_assert(x == 2); \
413 \
414 orig = __sync_fetch_and_xor(&x, 10); \
415 ovs_assert(orig == 2); \
416 __sync_synchronize(); \
417 ovs_assert(x == 8); \
418 }]], [dnl
419TEST_ATOMIC_TYPE(char);
420TEST_ATOMIC_TYPE(unsigned char);
421TEST_ATOMIC_TYPE(signed char);
422TEST_ATOMIC_TYPE(short);
423TEST_ATOMIC_TYPE(unsigned short);
424TEST_ATOMIC_TYPE(int);
425TEST_ATOMIC_TYPE(unsigned int);
426TEST_ATOMIC_TYPE(long int);
427TEST_ATOMIC_TYPE(unsigned long int);
428TEST_ATOMIC_TYPE(long long int);
429TEST_ATOMIC_TYPE(unsigned long long int);
430])],
431 [ovs_cv_gcc4_atomics=yes],
432 [ovs_cv_gcc4_atomics=no])])
433 if test $ovs_cv_gcc4_atomics = yes; then
434 AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
435 [Define to 1 if the C compiler and linker supports the GCC 4.0+
436 atomic built-ins.])
437 fi])
438
31a3fc6e
BP
439dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
440dnl
441dnl Checks __atomic_always_lock_free(SIZE, 0)
442AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE],
443 [AC_CACHE_CHECK(
444 [value of __atomic_always_lock_free($1)],
445 [ovs_cv_atomic_always_lock_free_$1],
446 [AC_COMPUTE_INT(
447 [ovs_cv_atomic_always_lock_free_$1],
448 [__atomic_always_lock_free($1, 0)],
449 [],
450 [ovs_cv_atomic_always_lock_free_$1=unsupported])])
451 if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
452 AC_DEFINE_UNQUOTED(
453 [ATOMIC_ALWAYS_LOCK_FREE_$1B],
454 [$ovs_cv_atomic_always_lock_free_$1],
455 [If the C compiler is GCC 4.7 or later, define to the return value of
456 __atomic_always_lock_free($1, 0). If the C compiler is not GCC or is
457 an older version of GCC, the value does not matter.])
458 fi])
97eba8fc
BP
459
460dnl OVS_CHECK_POSIX_AIO
461AC_DEFUN([OVS_CHECK_POSIX_AIO],
462 [AC_SEARCH_LIBS([aio_write], [rt])
463 AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
ed1be787
BP
464
465dnl OVS_CHECK_INCLUDE_NEXT
466AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
467 [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
468 gl_CHECK_NEXT_HEADERS([$1])])