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