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