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