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