tests: Make test-vconn build and pass tests without OpenSSL.
[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) coverage=true lcov=true ;;
26         (yes) coverage=true lcov=false ;;
27         (no)  coverage=false lcov=false ;;
28         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;;
29       esac],
30      [coverage=false lcov=false])
31    if $coverage; then
32      CFLAGS="$CFLAGS -O0 --coverage"
33      LDFLAGS="$LDFLAGS --coverage"
34    fi
35    if $lcov; then
36      if lcov --version >/dev/null 2>&1; then :; else
37        AC_MSG_ERROR([--enable-coverage=lcov was specified but lcov is not in \$PATH])
38      fi
39    fi
40    AC_SUBST([LCOV], [$lcov])])
41
42 dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
43 AC_DEFUN([OVS_CHECK_NDEBUG],
44   [AC_ARG_ENABLE(
45      [ndebug],
46      [AC_HELP_STRING([--enable-ndebug], 
47                      [Disable debugging features for max performance])],
48      [case "${enableval}" in
49         (yes) ndebug=true ;;
50         (no)  ndebug=false ;;
51         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
52       esac],
53      [ndebug=false])
54    AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
55
56 dnl Checks for Netlink support.
57 AC_DEFUN([OVS_CHECK_NETLINK],
58   [AC_CHECK_HEADER([linux/netlink.h],
59                    [HAVE_NETLINK=yes],
60                    [HAVE_NETLINK=no],
61                    [#include <sys/socket.h>
62    #include <linux/types.h>
63    ])
64    AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
65    if test "$HAVE_NETLINK" = yes; then
66       AC_DEFINE([HAVE_NETLINK], [1],
67                 [Define to 1 if Netlink protocol is available.])
68    fi])
69
70 dnl Checks for OpenSSL, if --enable-ssl is passed in.
71 AC_DEFUN([OVS_CHECK_OPENSSL],
72   [AC_ARG_ENABLE(
73      [ssl],
74      [AC_HELP_STRING([--enable-ssl], 
75                      [Enable ssl support (requires libssl)])],
76      [case "${enableval}" in
77         (yes) ssl=true ;;
78         (no)  ssl=false ;;
79         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
80       esac],
81      [ssl=false])
82
83    if test "$ssl" = true; then
84    dnl Make sure that pkg-config is installed.
85    m4_pattern_forbid([PKG_CHECK_MODULES])
86    PKG_CHECK_MODULES([SSL], [libssl], 
87      [HAVE_OPENSSL=yes],
88      [HAVE_OPENSSL=no
89       AC_MSG_WARN([Cannot find libssl:
90
91    $SSL_PKG_ERRORS
92
93    OpenFlow connections over SSL will not be supported.])])
94
95    else
96        HAVE_OPENSSL=no
97    fi
98    AC_SUBST([HAVE_OPENSSL])
99    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
100    if test "$HAVE_OPENSSL" = yes; then
101       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
102    fi])
103
104 dnl Checks for libraries needed by lib/socket-util.c.
105 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
106   [AC_CHECK_LIB([socket], [connect])
107    AC_SEARCH_LIBS([gethostbyname], [resolv], [RESOLVER_LIBS=-lresolv])])
108
109 dnl Checks for the directory in which to store the PKI.
110 AC_DEFUN([OVS_CHECK_PKIDIR],
111   [AC_ARG_WITH(
112      [pkidir], 
113      AC_HELP_STRING([--with-pkidir=DIR], 
114                     [PKI hierarchy directory [[DATADIR/openvswitch/pki]]]),
115      [PKIDIR=$withval],
116      [PKIDIR='${pkgdatadir}/pki'])
117    AC_SUBST([PKIDIR])])
118
119 dnl Checks for the directory in which to store pidfiles.
120 AC_DEFUN([OVS_CHECK_RUNDIR],
121   [AC_ARG_WITH(
122      [rundir], 
123      AC_HELP_STRING([--with-rundir=DIR], 
124                     [directory used for pidfiles [[LOCALSTATEDIR/run]]]),
125      [RUNDIR=$withval],
126      [RUNDIR='${localstatedir}/run'])
127    AC_SUBST([RUNDIR])])
128
129 dnl Checks for the directory in which to store logs.
130 AC_DEFUN([OVS_CHECK_LOGDIR],
131   [AC_ARG_WITH(
132      [logdir], 
133      AC_HELP_STRING([--with-logdir=DIR], 
134                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
135      [LOGDIR=$withval],
136      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
137    AC_SUBST([LOGDIR])])
138
139 dnl Checks for __malloc_hook, etc., supported by glibc.
140 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
141   [AC_CACHE_CHECK(
142     [whether libc supports hooks for malloc and related functions],
143     [ovs_cv_malloc_hooks],
144     [AC_COMPILE_IFELSE(
145       [AC_LANG_PROGRAM(
146          [#include <malloc.h>
147          ], 
148          [(void) __malloc_hook;
149           (void) __realloc_hook;
150           (void) __free_hook;])],
151       [ovs_cv_malloc_hooks=yes],
152       [ovs_cv_malloc_hooks=no])])
153    if test $ovs_cv_malloc_hooks = yes; then
154      AC_DEFINE([HAVE_MALLOC_HOOKS], [1], 
155                [Define to 1 if you have __malloc_hook, __realloc_hook, and
156                 __free_hook in <malloc.h>.])
157    fi])
158
159 dnl Checks for valgrind/valgrind.h.
160 AC_DEFUN([OVS_CHECK_VALGRIND], 
161   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
162
163 dnl Searches for a directory to put lockfiles for tty devices.
164 dnl Defines C preprocessor variable TTY_LOCK_DIR to a quoted string
165 dnl for that directory.
166 AC_DEFUN([OVS_CHECK_TTY_LOCK_DIR],
167   [AC_CACHE_CHECK([directory used for serial device lockfiles],
168                   [ovs_cv_path_tty_locks],
169                   [# This list of candidate directories is from minicom.
170                    ovs_cv_path_tty_locks=none
171                    for dir in /etc/locks /var/lock /usr/spool/locks \
172                               /var/spool/locks /var/spool/lock \
173                               /usr/spool/uucp /var/spool/uucp /var/run; do
174                      if test -d $dir; then
175                        ovs_cv_path_tty_locks=$dir
176                        break
177                      fi
178                    done])
179    if test "$ovs_cv_path_tty_locks" = none; then
180      AC_MSG_ERROR([cannot find a directory for tty locks])
181    fi
182    AC_DEFINE_UNQUOTED([TTY_LOCK_DIR], "$ovs_cv_path_tty_locks",
183                       [Directory used for serial device lockfiles])])
184
185 dnl The following check is adapted from GNU PSPP.
186 dnl It searches for the ncurses library.  If it finds it, it sets
187 dnl HAVE_CURSES to yes and sets NCURSES_LIBS and NCURSES_CFLAGS
188 dnl appropriate.  Otherwise, it sets HAVE_CURSES to no. 
189 AC_DEFUN([OVS_CHECK_CURSES],
190   [if test "$cross_compiling" != yes; then
191      AC_CHECK_PROGS([NCURSES_CONFIG], [ncurses5-config ncurses8-config])
192    fi
193    if test "$NCURSES_CONFIG" = ""; then
194      AC_SEARCH_LIBS([tgetent], [ncurses],
195          [AC_CHECK_HEADERS([term.h curses.h], 
196                            [HAVE_CURSES=yes],
197                            [HAVE_CURSES=no])])
198    else
199      save_cflags=$CFLAGS
200      CFLAGS="$CFLAGS $($NCURSES_CONFIG --cflags)"
201      AC_CHECK_HEADERS([term.h curses.h], 
202                       [HAVE_CURSES=yes],
203                       [HAVE_CURSES=no])
204      CFLAGS=$save_cflags
205      if test "$HAVE_CURSES" = yes; then
206        NCURSES_LIBS=$($NCURSES_CONFIG --libs)
207        NCURSES_CFLAGS=$($NCURSES_CONFIG --cflags)
208        AC_SUBST(NCURSES_CFLAGS)
209        AC_SUBST(NCURSES_LIBS)
210      fi
211    fi
212    AM_CONDITIONAL([HAVE_CURSES], [test "$HAVE_CURSES" = yes])])
213
214 dnl Checks for linux/vt.h.
215 AC_DEFUN([OVS_CHECK_LINUX_VT_H],
216   [AC_CHECK_HEADER([linux/vt.h],
217                    [HAVE_LINUX_VT_H=yes],
218                    [HAVE_LINUX_VT_H=no])
219    AM_CONDITIONAL([HAVE_LINUX_VT_H], [test "$HAVE_LINUX_VT_H" = yes])
220    if test "$HAVE_LINUX_VT_H" = yes; then
221       AC_DEFINE([HAVE_LINUX_VT_H], [1],
222                 [Define to 1 if linux/vt.h is available.])
223    fi])
224
225 dnl Checks for libpcre.
226 AC_DEFUN([OVS_CHECK_PCRE],
227   [dnl Make sure that pkg-config is installed.
228    m4_pattern_forbid([PKG_CHECK_MODULES])
229    PKG_CHECK_MODULES([PCRE], [libpcre >= 7.2], [HAVE_PCRE=yes], [HAVE_PCRE=no])
230    AM_CONDITIONAL([HAVE_PCRE], [test "$HAVE_PCRE" = yes])
231    if test "$HAVE_PCRE" = yes; then
232       AC_DEFINE([HAVE_PCRE], [1], [Define to 1 if libpcre is installed.])
233    fi])
234
235 dnl Checks for Python 2.x, x >= 4.
236 AC_DEFUN([OVS_CHECK_PYTHON],
237   [AC_CACHE_CHECK(
238      [for Python 2.x for x >= 4],
239      [ovs_cv_python],
240      [if test -n "$PYTHON"; then
241         ovs_cv_python=$PYTHON
242       else
243         ovs_cv_python=no
244         for binary in python python2.4 python2.5; do
245           ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
246           for dir in $PATH; do
247             IFS=$ovs_save_IFS
248             test -z "$dir" && dir=.
249             if test -x $dir/$binary && $dir/$binary -c 'import sys
250 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
251     sys.exit(0)
252 else:
253     sys.exit(1)'; then
254               ovs_cv_python=$dir/$binary
255               break 2
256             fi
257           done
258         done
259       fi])
260    AM_MISSING_PROG([PYTHON], [python])
261    if test $ovs_cv_python != no; then
262      PYTHON=$ovs_cv_python
263    fi])