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