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