configure: Don't check for malloc hooks that we no longer use.
[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 valgrind/valgrind.h.
196 AC_DEFUN([OVS_CHECK_VALGRIND],
197   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
198
199 dnl Checks for Python 2.x, x >= 4.
200 AC_DEFUN([OVS_CHECK_PYTHON],
201   [AC_CACHE_CHECK(
202      [for Python 2.x for x >= 4],
203      [ovs_cv_python],
204      [if test -n "$PYTHON"; then
205         ovs_cv_python=$PYTHON
206       else
207         ovs_cv_python=no
208         for binary in python python2.4 python2.5; do
209           ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
210           for dir in $PATH; do
211             IFS=$ovs_save_IFS
212             test -z "$dir" && dir=.
213             if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
214 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
215     sys.exit(0)
216 else:
217     sys.exit(1)'; then
218               ovs_cv_python=$dir/$binary
219               break 2
220             fi
221           done
222         done
223       fi])
224    AC_SUBST([HAVE_PYTHON])
225    AM_MISSING_PROG([PYTHON], [python])
226    if test $ovs_cv_python != no; then
227      PYTHON=$ovs_cv_python
228      HAVE_PYTHON=yes
229    else
230      HAVE_PYTHON=no
231    fi
232    AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
233
234 dnl Checks for dot.
235 AC_DEFUN([OVS_CHECK_DOT],
236   [AC_CACHE_CHECK(
237     [for dot],
238     [ovs_cv_dot],
239     [dnl "dot" writes -V output to stderr:
240      if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
241        ovs_cv_dot=yes
242      else
243        ovs_cv_dot=no
244      fi])
245    AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
246
247 dnl Checks whether $PYTHON supports the module given as $1
248 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
249   [AC_REQUIRE([OVS_CHECK_PYTHON])
250    AC_CACHE_CHECK(
251      [for $1 Python module],
252      [ovs_cv_py_[]AS_TR_SH([$1])],
253      [ovs_cv_py_[]AS_TR_SH([$1])=no
254       if test $HAVE_PYTHON = yes; then
255         AS_ECHO(["running $PYTHON -c 'import $1
256 import sys
257 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
258         if $PYTHON -c 'import $1
259 import sys
260 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
261           ovs_cv_py_[]AS_TR_SH([$1])=yes
262         fi
263       fi])])
264
265 dnl Checks for missing python modules at build time
266 AC_DEFUN([OVS_CHECK_PYTHON_COMPAT],
267   [OVS_CHECK_PYTHON_MODULE([uuid])
268    if test $ovs_cv_py_uuid = yes; then
269      INCLUDE_PYTHON_COMPAT=no
270    else
271      INCLUDE_PYTHON_COMPAT=yes
272    fi
273    AC_MSG_CHECKING([whether to add python/compat to PYTHONPATH])
274    AC_MSG_RESULT([$INCLUDE_PYTHON_COMPAT])
275    AM_CONDITIONAL([INCLUDE_PYTHON_COMPAT], [test $INCLUDE_PYTHON_COMPAT = yes])])
276
277 dnl Checks for groff.
278 AC_DEFUN([OVS_CHECK_GROFF],
279   [AC_CACHE_CHECK(
280     [for groff],
281     [ovs_cv_groff],
282     [if (groff -v) >/dev/null 2>&1; then
283        ovs_cv_groff=yes
284      else
285        ovs_cv_groff=no
286      fi])
287    AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
288
289 dnl Checks for thread-local storage support.
290 dnl
291 dnl Checks whether the compiler and linker support the C11
292 dnl thread_local macro from <threads.h>, and if so defines
293 dnl HAVE_THREAD_LOCAL.  If not, checks whether the compiler and linker
294 dnl support the GCC __thread extension, and if so defines
295 dnl HAVE___THREAD.
296 AC_DEFUN([OVS_CHECK_TLS],
297   [AC_CACHE_CHECK(
298      [whether $CC has <threads.h> that supports thread_local],
299      [ovs_cv_thread_local],
300      [AC_LINK_IFELSE(
301         [AC_LANG_PROGRAM([#include <threads.h>
302 static thread_local int var;], [return var;])],
303         [ovs_cv_thread_local=yes],
304         [ovs_cv_thread_local=no])])
305    if test $ovs_cv_thread_local = yes; then
306      AC_DEFINE([HAVE_THREAD_LOCAL], [1],
307                [Define to 1 if the C compiler and linker supports the C11
308                 thread_local matcro defined in <threads.h>.])
309    else
310      AC_CACHE_CHECK(
311        [whether $CC supports __thread],
312        [ovs_cv___thread],
313        [AC_LINK_IFELSE(
314           [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
315           [ovs_cv___thread=yes],
316           [ovs_cv___thread=no])])
317      if test $ovs_cv___thread = yes; then
318        AC_DEFINE([HAVE___THREAD], [1],
319                  [Define to 1 if the C compiler and linker supports the
320                   GCC __thread extenions.])
321      fi
322    fi])
323
324 dnl OVS_CHECK_ATOMIC_LIBS
325 dnl
326 dnl Check to see if -latomic is need for GCC atomic built-ins.
327 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
328    [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
329
330 dnl OVS_CHECK_GCC4_ATOMICS
331 dnl
332 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
333 dnl A compile-time only check is not enough because the compiler defers
334 dnl unimplemented built-ins to libgcc, which sometimes also lacks
335 dnl implementations.
336 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
337   [AC_CACHE_CHECK(
338      [whether $CC supports GCC 4.0+ atomic built-ins],
339      [ovs_cv_gcc4_atomics],
340      [AC_LINK_IFELSE(
341         [AC_LANG_PROGRAM([[#include <stdlib.h>
342
343 #define ovs_assert(expr) if (!(expr)) abort();
344 #define TEST_ATOMIC_TYPE(TYPE)                  \
345     {                                           \
346         TYPE x = 1;                             \
347         TYPE orig;                              \
348                                                 \
349         __sync_synchronize();                   \
350         ovs_assert(x == 1);                     \
351                                                 \
352         __sync_synchronize();                   \
353         x = 3;                                  \
354         __sync_synchronize();                   \
355         ovs_assert(x == 3);                     \
356                                                 \
357         orig = __sync_fetch_and_add(&x, 1);     \
358         ovs_assert(orig == 3);                  \
359         __sync_synchronize();                   \
360         ovs_assert(x == 4);                     \
361                                                 \
362         orig = __sync_fetch_and_sub(&x, 2);     \
363         ovs_assert(orig == 4);                  \
364         __sync_synchronize();                   \
365         ovs_assert(x == 2);                     \
366                                                 \
367         orig = __sync_fetch_and_or(&x, 6);      \
368         ovs_assert(orig == 2);                  \
369         __sync_synchronize();                   \
370         ovs_assert(x == 6);                     \
371                                                 \
372         orig = __sync_fetch_and_and(&x, 10);    \
373         ovs_assert(orig == 6);                  \
374         __sync_synchronize();                   \
375         ovs_assert(x == 2);                     \
376                                                 \
377         orig = __sync_fetch_and_xor(&x, 10);    \
378         ovs_assert(orig == 2);                  \
379         __sync_synchronize();                   \
380         ovs_assert(x == 8);                     \
381     }]], [dnl
382 TEST_ATOMIC_TYPE(char);
383 TEST_ATOMIC_TYPE(unsigned char);
384 TEST_ATOMIC_TYPE(signed char);
385 TEST_ATOMIC_TYPE(short);
386 TEST_ATOMIC_TYPE(unsigned short);
387 TEST_ATOMIC_TYPE(int);
388 TEST_ATOMIC_TYPE(unsigned int);
389 TEST_ATOMIC_TYPE(long int);
390 TEST_ATOMIC_TYPE(unsigned long int);
391 TEST_ATOMIC_TYPE(long long int);
392 TEST_ATOMIC_TYPE(unsigned long long int);
393 ])],
394         [ovs_cv_gcc4_atomics=yes],
395         [ovs_cv_gcc4_atomics=no])])
396    if test $ovs_cv_gcc4_atomics = yes; then
397      AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
398                [Define to 1 if the C compiler and linker supports the GCC 4.0+
399                 atomic built-ins.])
400    fi])
401
402 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
403 dnl
404 dnl Checks __atomic_always_lock_free(SIZE, 0)
405 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE], 
406   [AC_CACHE_CHECK(
407     [value of __atomic_always_lock_free($1)],
408     [ovs_cv_atomic_always_lock_free_$1],
409     [AC_COMPUTE_INT(
410         [ovs_cv_atomic_always_lock_free_$1],
411         [__atomic_always_lock_free($1, 0)],
412         [],
413         [ovs_cv_atomic_always_lock_free_$1=unsupported])])
414    if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
415      AC_DEFINE_UNQUOTED(
416        [ATOMIC_ALWAYS_LOCK_FREE_$1B],
417        [$ovs_cv_atomic_always_lock_free_$1],
418        [If the C compiler is GCC 4.7 or later, define to the return value of
419         __atomic_always_lock_free($1, 0).  If the C compiler is not GCC or is
420         an older version of GCC, the value does not matter.])
421    fi])
422
423 dnl OVS_CHECK_POSIX_AIO
424 AC_DEFUN([OVS_CHECK_POSIX_AIO],
425   [AC_SEARCH_LIBS([aio_write], [rt])
426    AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
427
428 dnl OVS_CHECK_INCLUDE_NEXT
429 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
430   [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
431    gl_CHECK_NEXT_HEADERS([$1])])