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