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