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