switch UI: Only build ovs-switchui if PCRE 7.2 or later is available.
[cascardo/ovs.git] / m4 / openvswitch.m4
1 # -*- autoconf -*-
2
3 # Copyright (c) 2008, 2009 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    fi
96    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
97    if test "$HAVE_OPENSSL" = yes; then
98       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
99    fi])
100
101 dnl Checks for libraries needed by lib/fault.c.
102 AC_DEFUN([OVS_CHECK_FAULT_LIBS],
103   [AC_CHECK_LIB([dl], [dladdr], [FAULT_LIBS=-ldl])
104    AC_SUBST([FAULT_LIBS])])
105
106 dnl Checks for libraries needed by lib/socket-util.c.
107 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
108   [AC_CHECK_LIB([socket], [connect])
109    AC_SEARCH_LIBS([gethostbyname], [resolv], [RESOLVER_LIBS=-lresolv])])
110
111 dnl Checks for the directory in which to store the PKI.
112 AC_DEFUN([OVS_CHECK_PKIDIR],
113   [AC_ARG_WITH(
114      [pkidir], 
115      AC_HELP_STRING([--with-pkidir=DIR], 
116                     [PKI hierarchy directory [[DATADIR/openvswitch/pki]]]),
117      [PKIDIR=$withval],
118      [PKIDIR='${pkgdatadir}/pki'])
119    AC_SUBST([PKIDIR])])
120
121 dnl Checks for the directory in which to store pidfiles.
122 AC_DEFUN([OVS_CHECK_RUNDIR],
123   [AC_ARG_WITH(
124      [rundir], 
125      AC_HELP_STRING([--with-rundir=DIR], 
126                     [directory used for pidfiles [[LOCALSTATEDIR/run]]]),
127      [RUNDIR=$withval],
128      [RUNDIR='${localstatedir}/run'])
129    AC_SUBST([RUNDIR])])
130
131 dnl Checks for the directory in which to store logs.
132 AC_DEFUN([OVS_CHECK_LOGDIR],
133   [AC_ARG_WITH(
134      [logdir], 
135      AC_HELP_STRING([--with-logdir=DIR], 
136                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
137      [LOGDIR=$withval],
138      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
139    AC_SUBST([LOGDIR])])
140
141 dnl Checks for __malloc_hook, etc., supported by glibc.
142 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
143   [AC_CACHE_CHECK(
144     [whether libc supports hooks for malloc and related functions],
145     [ovs_cv_malloc_hooks],
146     [AC_COMPILE_IFELSE(
147       [AC_LANG_PROGRAM(
148          [#include <malloc.h>
149          ], 
150          [(void) __malloc_hook;
151           (void) __realloc_hook;
152           (void) __free_hook;])],
153       [ovs_cv_malloc_hooks=yes],
154       [ovs_cv_malloc_hooks=no])])
155    if test $ovs_cv_malloc_hooks = yes; then
156      AC_DEFINE([HAVE_MALLOC_HOOKS], [1], 
157                [Define to 1 if you have __malloc_hook, __realloc_hook, and
158                 __free_hook in <malloc.h>.])
159    fi])
160
161 dnl Checks for valgrind/valgrind.h.
162 AC_DEFUN([OVS_CHECK_VALGRIND], 
163   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
164
165 dnl Searches for a directory to put lockfiles for tty devices.
166 dnl Defines C preprocessor variable TTY_LOCK_DIR to a quoted string
167 dnl for that directory.
168 AC_DEFUN([OVS_CHECK_TTY_LOCK_DIR],
169   [AC_CACHE_CHECK([directory used for serial device lockfiles],
170                   [ovs_cv_path_tty_locks],
171                   [# This list of candidate directories is from minicom.
172                    ovs_cv_path_tty_locks=none
173                    for dir in /etc/locks /var/lock /usr/spool/locks \
174                               /var/spool/locks /var/spool/lock \
175                               /usr/spool/uucp /var/spool/uucp /var/run; do
176                      if test -d $dir; then
177                        ovs_cv_path_tty_locks=$dir
178                        break
179                      fi
180                    done])
181    if test "$ovs_cv_path_tty_locks" = none; then
182      AC_MSG_ERROR([cannot find a directory for tty locks])
183    fi
184    AC_DEFINE_UNQUOTED([TTY_LOCK_DIR], "$ovs_cv_path_tty_locks",
185                       [Directory used for serial device lockfiles])])
186
187 dnl The following check is adapted from GNU PSPP.
188 dnl It searches for the ncurses library.  If it finds it, it sets
189 dnl HAVE_CURSES to yes and sets NCURSES_LIBS and NCURSES_CFLAGS
190 dnl appropriate.  Otherwise, it sets HAVE_CURSES to no. 
191 AC_DEFUN([OVS_CHECK_CURSES],
192   [if test "$cross_compiling" != yes; then
193      AC_CHECK_PROGS([NCURSES_CONFIG], [ncurses5-config ncurses8-config])
194    fi
195    if test "$NCURSES_CONFIG" = ""; then
196      AC_SEARCH_LIBS([tgetent], [ncurses],
197          [AC_CHECK_HEADERS([term.h curses.h], 
198                            [HAVE_CURSES=yes],
199                            [HAVE_CURSES=no])])
200    else
201      save_cflags=$CFLAGS
202      CFLAGS="$CFLAGS $($NCURSES_CONFIG --cflags)"
203      AC_CHECK_HEADERS([term.h curses.h], 
204                       [HAVE_CURSES=yes],
205                       [HAVE_CURSES=no])
206      CFLAGS=$save_cflags
207      if test "$HAVE_CURSES" = yes; then
208        NCURSES_LIBS=$($NCURSES_CONFIG --libs)
209        NCURSES_CFLAGS=$($NCURSES_CONFIG --cflags)
210        AC_SUBST(NCURSES_CFLAGS)
211        AC_SUBST(NCURSES_LIBS)
212      fi
213    fi
214    AM_CONDITIONAL([HAVE_CURSES], [test "$HAVE_CURSES" = yes])])
215
216 dnl Checks for linux/vt.h.
217 AC_DEFUN([OVS_CHECK_LINUX_VT_H],
218   [AC_CHECK_HEADER([linux/vt.h],
219                    [HAVE_LINUX_VT_H=yes],
220                    [HAVE_LINUX_VT_H=no])
221    AM_CONDITIONAL([HAVE_LINUX_VT_H], [test "$HAVE_LINUX_VT_H" = yes])
222    if test "$HAVE_LINUX_VT_H" = yes; then
223       AC_DEFINE([HAVE_LINUX_VT_H], [1],
224                 [Define to 1 if linux/vt.h is available.])
225    fi])
226
227 dnl Checks for libpcre.
228 AC_DEFUN([OVS_CHECK_PCRE],
229   [dnl Make sure that pkg-config is installed.
230    m4_pattern_forbid([PKG_CHECK_MODULES])
231    PKG_CHECK_MODULES([PCRE], [libpcre >= 7.2], [HAVE_PCRE=yes], [HAVE_PCRE=no])
232    AM_CONDITIONAL([HAVE_PCRE], [test "$HAVE_PCRE" = yes])
233    if test "$HAVE_PCRE" = yes; then
234       AC_DEFINE([HAVE_PCRE], [1], [Define to 1 if libpcre is installed.])
235    fi])