7aaf67a209402b38aecc65c90a747dbd433399a0
[sliver-openvswitch.git] / m4 / openvswitch.m4
1 # -*- autoconf -*-
2
3 # Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
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 dnl Checks for --enable-coverage and updates CFLAGS and LDFLAGS appropriately.
18 AC_DEFUN([OVS_CHECK_COVERAGE],
19   [AC_REQUIRE([AC_PROG_CC])
20    AC_ARG_ENABLE(
21      [coverage],
22      [AC_HELP_STRING([--enable-coverage], 
23                      [Enable gcov coverage tool.])],
24      [case "${enableval}" in
25         (lcov|yes) coverage=true ;;
26         (no)  coverage=false ;;
27         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;;
28       esac],
29      [coverage=false])
30    if $coverage; then
31      CFLAGS="$CFLAGS -O0 --coverage"
32      LDFLAGS="$LDFLAGS --coverage"
33    fi])
34
35 dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
36 AC_DEFUN([OVS_CHECK_NDEBUG],
37   [AC_ARG_ENABLE(
38      [ndebug],
39      [AC_HELP_STRING([--enable-ndebug], 
40                      [Disable debugging features for max performance])],
41      [case "${enableval}" in
42         (yes) ndebug=true ;;
43         (no)  ndebug=false ;;
44         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
45       esac],
46      [ndebug=false])
47    AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
48
49 dnl Checks for struct rtnl_link_stats64.
50 dnl
51 dnl (OVS checks for this structure in both kernel and userspace headers.  This
52 dnl is not redundant, because the kernel and userspace builds have completely
53 dnl different include paths.  It is possible for the kernel to have this
54 dnl structure but not userspace, and vice versa.)
55 AC_DEFUN([OVS_CHECK_RTNL_LINK_STATS64],
56   [AC_REQUIRE([OVS_CHECK_NETLINK])
57    if test $HAVE_NETLINK = yes; then
58      AC_CHECK_MEMBER(
59        [struct rtnl_link_stats64.tx_packets],
60        [AC_DEFINE([HAVE_RTNL_LINK_STATS64], [1],
61                   [Define to 1 if <linux/if_link.h> defines
62                    struct rtnl_link_stats64.])],
63        [], [#include <sys/socket.h>     /* Provides sa_family_t. */
64 #include <linux/if_link.h>
65 ])
66    fi])
67
68 dnl Checks for Netlink support.
69 AC_DEFUN([OVS_CHECK_NETLINK],
70   [AC_CHECK_HEADER([linux/netlink.h],
71                    [HAVE_NETLINK=yes],
72                    [HAVE_NETLINK=no],
73                    [#include <sys/socket.h>
74    #include <linux/types.h>
75    ])
76    AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
77    if test "$HAVE_NETLINK" = yes; then
78       AC_DEFINE([HAVE_NETLINK], [1],
79                 [Define to 1 if Netlink protocol is available.])
80    fi])
81
82 dnl Checks for OpenSSL.
83 AC_DEFUN([OVS_CHECK_OPENSSL],
84   [AC_ARG_ENABLE(
85      [ssl],
86      [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
87      [case "${enableval}" in
88         (yes) ssl=true ;;
89         (no)  ssl=false ;;
90         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
91       esac],
92      [ssl=check])
93
94    if test "$ssl" != false; then
95        m4_ifndef([PKG_CHECK_MODULES], [m4_fatal([Please install pkg-config.])])
96        PKG_CHECK_MODULES([SSL], [openssl], 
97          [HAVE_OPENSSL=yes],
98          [HAVE_OPENSSL=no
99           if test "$ssl" = check; then
100             AC_MSG_WARN([Cannot find openssl:
101
102 $SSL_PKG_ERRORS
103
104 OpenFlow connections over SSL will not be supported.
105 (You may use --disable-ssl to suppress this warning.)])
106           else
107             AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
108           fi])
109    else
110        HAVE_OPENSSL=no
111    fi
112    AC_SUBST([HAVE_OPENSSL])
113    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
114    if test "$HAVE_OPENSSL" = yes; then
115       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
116    fi])
117
118 dnl Checks for libraries needed by lib/socket-util.c.
119 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
120   [AC_CHECK_LIB([socket], [connect])
121    AC_SEARCH_LIBS([gethostbyname], [resolv], [RESOLVER_LIBS=-lresolv])])
122
123 dnl Checks for the directory in which to store the PKI.
124 AC_DEFUN([OVS_CHECK_PKIDIR],
125   [AC_ARG_WITH(
126      [pkidir], 
127      AC_HELP_STRING([--with-pkidir=DIR], 
128                     [PKI hierarchy directory [[DATADIR/openvswitch/pki]]]),
129      [PKIDIR=$withval],
130      [PKIDIR='${pkgdatadir}/pki'])
131    AC_SUBST([PKIDIR])])
132
133 dnl Checks for the directory in which to store pidfiles.
134 AC_DEFUN([OVS_CHECK_RUNDIR],
135   [AC_ARG_WITH(
136      [rundir], 
137      AC_HELP_STRING([--with-rundir=DIR], 
138                     [directory used for pidfiles
139                     [[LOCALSTATEDIR/run/openvswitch]]]),
140      [RUNDIR=$withval],
141      [RUNDIR='${localstatedir}/run/openvswitch'])
142    AC_SUBST([RUNDIR])])
143
144 dnl Checks for the directory in which to store logs.
145 AC_DEFUN([OVS_CHECK_LOGDIR],
146   [AC_ARG_WITH(
147      [logdir], 
148      AC_HELP_STRING([--with-logdir=DIR], 
149                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
150      [LOGDIR=$withval],
151      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
152    AC_SUBST([LOGDIR])])
153
154 dnl Defines HAVE_BACKTRACE if backtrace() is declared in <execinfo.h>
155 dnl and exists in libc.
156 AC_DEFUN([OVS_CHECK_BACKTRACE],
157   [AC_CHECK_HEADER([execinfo.h], [AC_CHECK_FUNCS([backtrace])])])
158
159 dnl Checks for __malloc_hook, etc., supported by glibc.
160 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
161   [AC_CACHE_CHECK(
162     [whether libc supports hooks for malloc and related functions],
163     [ovs_cv_malloc_hooks],
164     [AC_COMPILE_IFELSE(
165       [AC_LANG_PROGRAM(
166          [#include <malloc.h>
167          ], 
168          [(void) __malloc_hook;
169           (void) __realloc_hook;
170           (void) __free_hook;])],
171       [ovs_cv_malloc_hooks=yes],
172       [ovs_cv_malloc_hooks=no])])
173    if test $ovs_cv_malloc_hooks = yes; then
174      AC_DEFINE([HAVE_MALLOC_HOOKS], [1], 
175                [Define to 1 if you have __malloc_hook, __realloc_hook, and
176                 __free_hook in <malloc.h>.])
177    fi])
178
179 dnl Checks for valgrind/valgrind.h.
180 AC_DEFUN([OVS_CHECK_VALGRIND], 
181   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
182
183 dnl Checks for Python 2.x, x >= 4.
184 AC_DEFUN([OVS_CHECK_PYTHON],
185   [AC_CACHE_CHECK(
186      [for Python 2.x for x >= 4],
187      [ovs_cv_python],
188      [if test -n "$PYTHON"; then
189         ovs_cv_python=$PYTHON
190       else
191         ovs_cv_python=no
192         for binary in python python2.4 python2.5; do
193           ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
194           for dir in $PATH; do
195             IFS=$ovs_save_IFS
196             test -z "$dir" && dir=.
197             if test -x $dir/$binary && $dir/$binary -c 'import sys
198 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
199     sys.exit(0)
200 else:
201     sys.exit(1)'; then
202               ovs_cv_python=$dir/$binary
203               break 2
204             fi
205           done
206         done
207       fi])
208    AC_SUBST([HAVE_PYTHON])
209    AM_MISSING_PROG([PYTHON], [python])
210    if test $ovs_cv_python != no; then
211      PYTHON=$ovs_cv_python
212      HAVE_PYTHON=yes
213    else
214      HAVE_PYTHON=no
215    fi
216    AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
217
218 dnl Checks for dot.
219 AC_DEFUN([OVS_CHECK_DOT],
220   [AC_CACHE_CHECK(
221     [for dot],
222     [ovs_cv_dot],
223     [dnl "dot" writes -V output to stderr:
224      if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
225        ovs_cv_dot=yes
226      else
227        ovs_cv_dot=no
228      fi])
229    AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
230
231 dnl Checks for pyuic4.
232 AC_DEFUN([OVS_CHECK_PYUIC4],
233   [AC_CACHE_CHECK(
234     [for pyuic4],
235     [ovs_cv_pyuic4],
236     [if (pyuic4 --version) >/dev/null 2>&1; then
237        ovs_cv_pyuic4=pyuic4
238      else
239        ovs_cv_pyuic4=no
240      fi])
241    AM_MISSING_PROG([PYUIC4], [pyuic4])
242    if test $ovs_cv_pyuic4 != no; then
243      PYUIC4=$ovs_cv_pyuic4
244    fi])
245
246 dnl Checks whether $PYTHON supports the module given as $1
247 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
248   [AC_REQUIRE([OVS_CHECK_PYTHON])
249    AC_CACHE_CHECK(
250      [for $1 Python module],
251      [ovs_cv_py_[]AS_TR_SH([$1])],
252      [ovs_cv_py_[]AS_TR_SH([$1])=no
253       if test $HAVE_PYTHON = yes; then
254         AS_ECHO(["running $PYTHON -c 'import $1
255 import sys
256 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
257         if $PYTHON -c 'import $1
258 import sys
259 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
260           ovs_cv_py_[]AS_TR_SH([$1])=yes
261         fi
262       fi])])
263
264 dnl Checks for Python modules needed by ovsdbmonitor.
265 AC_DEFUN([OVS_CHECK_OVSDBMONITOR],
266   [OVS_CHECK_PYTHON_MODULE([PySide.QtCore])
267    OVS_CHECK_PYTHON_MODULE([PyQt4.QtCore])
268    OVS_CHECK_PYTHON_MODULE([twisted.conch.ssh])
269    OVS_CHECK_PYTHON_MODULE([twisted.internet])
270    OVS_CHECK_PYTHON_MODULE([twisted.application])
271    OVS_CHECK_PYTHON_MODULE([json])
272    OVS_CHECK_PYTHON_MODULE([zope.interface])
273    if (test $ovs_cv_py_PySide_QtCore = yes \
274        || test $ovs_cv_py_PyQt4_QtCore = yes) \
275       && test $ovs_cv_py_twisted_conch_ssh = yes \
276       && test $ovs_cv_py_twisted_internet = yes \
277       && test $ovs_cv_py_twisted_application = yes \
278       && test $ovs_cv_py_json = yes \
279       && test $ovs_cv_py_zope_interface = yes; then
280      BUILD_OVSDBMONITOR=yes
281    else
282      BUILD_OVSDBMONITOR=no
283    fi
284    AC_MSG_CHECKING([whether to build ovsdbmonitor])
285    AC_MSG_RESULT([$BUILD_OVSDBMONITOR])
286    AM_CONDITIONAL([BUILD_OVSDBMONITOR], [test $BUILD_OVSDBMONITOR = yes])])
287
288 # OVS_LINK2_IFELSE(SOURCE1, SOURCE2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
289 # -------------------------------------------------------------
290 # Based on AC_LINK_IFELSE, but tries to link both SOURCE1 and SOURCE2
291 # into a program.
292 #
293 # This macro is borrowed from acinclude.m4 in GNU PSPP, which has the
294 # following license:
295 #
296 #     Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
297 #     This file is free software; the Free Software Foundation
298 #     gives unlimited permission to copy and/or distribute it,
299 #     with or without modifications, as long as this notice is preserved.
300 #
301 m4_define([OVS_LINK2_IFELSE],
302 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
303 mv conftest.$ac_ext conftest1.$ac_ext
304 m4_ifvaln([$2], [AC_LANG_CONFTEST([$2])])dnl
305 mv conftest.$ac_ext conftest2.$ac_ext
306 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
307 ovs_link2='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest1.$ac_ext conftest2.$ac_ext $LIBS >&5'
308 AS_IF([_AC_DO_STDERR($ovs_link2) && {
309          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
310          test ! -s conftest.err
311        } && test -s conftest$ac_exeext && {
312          test "$cross_compiling" = yes ||
313          AS_TEST_X([conftest$ac_exeext])
314        }],
315       [$3],
316       [echo "$as_me: failed source file 1 of 2 was:" >&5
317 sed 's/^/| /' conftest1.$ac_ext >&5
318 echo "$as_me: failed source file 2 of 2 was:" >&5
319 sed 's/^/| /' conftest2.$ac_ext >&5
320         $4])
321 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
322 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
323 dnl as it would interfere with the next link command.
324 rm -rf conftest.dSYM conftest1.dSYM conftest2.dSYM
325 rm -f core conftest.err conftest1.err conftest2.err
326 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest*_ipa8_conftest*.oo
327 rm -f conftest$ac_exeext
328 rm -f m4_ifval([$1], [conftest1.$ac_ext]) m4_ifval([$2], [conftest1.$ac_ext])[]dnl
329 ])# OVS_LINK2_IFELSE
330
331 dnl Defines USE_LINKER_SECTIONS to 1 if the compiler supports putting
332 dnl variables in sections with user-defined names and the linker
333 dnl automatically defines __start_SECNAME and __stop_SECNAME symbols
334 dnl that designate the start and end of the sections.
335 AC_DEFUN([OVS_CHECK_LINKER_SECTIONS],
336   [AC_CACHE_CHECK(
337     [for user-defined linker section support],
338     [ovs_cv_use_linker_sections],
339     [OVS_LINK2_IFELSE(
340       [AC_LANG_SOURCE(
341         [int a __attribute__((__section__("mysection"))) = 1;
342          int b __attribute__((__section__("mysection"))) = 2;
343          int c __attribute__((__section__("mysection"))) = 3;])],
344       [AC_LANG_PROGRAM(
345         [#include <stdio.h>
346          extern int __start_mysection;
347          extern int __stop_mysection;],
348         [int n_ints = &__stop_mysection - &__start_mysection;
349          int *i;
350          for (i = &__start_mysection; i < &__start_mysection + n_ints; i++) {
351              printf("%d\n", *i);
352          }])],
353       [ovs_cv_use_linker_sections=yes],
354       [ovs_cv_use_linker_sections=no])])
355    if test $ovs_cv_use_linker_sections = yes; then
356      AC_DEFINE([USE_LINKER_SECTIONS], [1],
357                [Define to 1 if the compiler support putting variables
358                 into sections with user-defined names and the linker
359                 automatically defines __start_SECNAME and __stop_SECNAME
360                 symbols that designate the start and end of the section.])
361    fi
362    AM_CONDITIONAL(
363      [USE_LINKER_SECTIONS], [test $ovs_cv_use_linker_sections = yes])])
364
365 dnl Checks for groff.
366 AC_DEFUN([OVS_CHECK_GROFF],
367   [AC_CACHE_CHECK(
368     [for groff],
369     [ovs_cv_groff],
370     [if (groff -v) >/dev/null 2>&1; then
371        ovs_cv_groff=yes
372      else
373        ovs_cv_groff=no
374      fi])
375    AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])