Merge changes from citrix branch into master.
[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-ndebug and defines NDEBUG if it is specified.
18 AC_DEFUN([OVS_CHECK_NDEBUG],
19   [AC_ARG_ENABLE(
20      [ndebug],
21      [AC_HELP_STRING([--enable-ndebug], 
22                      [Disable debugging features for max performance])],
23      [case "${enableval}" in
24         (yes) ndebug=true ;;
25         (no)  ndebug=false ;;
26         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
27       esac],
28      [ndebug=false])
29    AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
30
31 dnl Checks for Netlink support.
32 AC_DEFUN([OVS_CHECK_NETLINK],
33   [AC_CHECK_HEADER([linux/netlink.h],
34                    [HAVE_NETLINK=yes],
35                    [HAVE_NETLINK=no],
36                    [#include <sys/socket.h>
37    #include <linux/types.h>
38    ])
39    AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
40    if test "$HAVE_NETLINK" = yes; then
41       AC_DEFINE([HAVE_NETLINK], [1],
42                 [Define to 1 if Netlink protocol is available.])
43    fi])
44
45 dnl Checks for OpenSSL, if --enable-ssl is passed in.
46 AC_DEFUN([OVS_CHECK_OPENSSL],
47   [AC_ARG_ENABLE(
48      [ssl],
49      [AC_HELP_STRING([--enable-ssl], 
50                      [Enable ssl support (requires libssl)])],
51      [case "${enableval}" in
52         (yes) ssl=true ;;
53         (no)  ssl=false ;;
54         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
55       esac],
56      [ssl=false])
57
58    if test "$ssl" = true; then
59    dnl Make sure that pkg-config is installed.
60    m4_pattern_forbid([PKG_CHECK_MODULES])
61    PKG_CHECK_MODULES([SSL], [libssl], 
62      [HAVE_OPENSSL=yes],
63      [HAVE_OPENSSL=no
64       AC_MSG_WARN([Cannot find libssl:
65
66    $SSL_PKG_ERRORS
67
68    OpenFlow connections over SSL will not be supported.])])
69
70    fi
71    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
72    if test "$HAVE_OPENSSL" = yes; then
73       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
74    fi])
75
76 dnl Checks for libraries needed by lib/fault.c.
77 AC_DEFUN([OVS_CHECK_FAULT_LIBS],
78   [AC_CHECK_LIB([dl], [dladdr], [FAULT_LIBS=-ldl])
79    AC_SUBST([FAULT_LIBS])])
80
81 dnl Checks for libraries needed by lib/socket-util.c.
82 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
83   [AC_CHECK_LIB([socket], [connect])
84    AC_SEARCH_LIBS([gethostbyname], [resolv], [RESOLVER_LIBS=-lresolv])])
85
86 dnl Checks for the directory in which to store the PKI.
87 AC_DEFUN([OVS_CHECK_PKIDIR],
88   [AC_ARG_WITH(
89      [pkidir], 
90      AC_HELP_STRING([--with-pkidir=DIR], 
91                     [PKI hierarchy directory [[DATADIR/openvswitch/pki]]]),
92      [PKIDIR=$withval],
93      [PKIDIR='${pkgdatadir}/pki'])
94    AC_SUBST([PKIDIR])])
95
96 dnl Checks for the directory in which to store pidfiles.
97 AC_DEFUN([OVS_CHECK_RUNDIR],
98   [AC_ARG_WITH(
99      [rundir], 
100      AC_HELP_STRING([--with-rundir=DIR], 
101                     [directory used for pidfiles [[LOCALSTATEDIR/run]]]),
102      [RUNDIR=$withval],
103      [RUNDIR='${localstatedir}/run'])
104    AC_SUBST([RUNDIR])])
105
106 dnl Checks for the directory in which to store logs.
107 AC_DEFUN([OVS_CHECK_LOGDIR],
108   [AC_ARG_WITH(
109      [logdir], 
110      AC_HELP_STRING([--with-logdir=DIR], 
111                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
112      [LOGDIR=$withval],
113      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
114    AC_SUBST([LOGDIR])])
115
116 dnl Checks for __malloc_hook, etc., supported by glibc.
117 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
118   [AC_CACHE_CHECK(
119     [whether libc supports hooks for malloc and related functions],
120     [ovs_cv_malloc_hooks],
121     [AC_COMPILE_IFELSE(
122       [AC_LANG_PROGRAM(
123          [#include <malloc.h>
124          ], 
125          [(void) __malloc_hook;
126           (void) __realloc_hook;
127           (void) __free_hook;])],
128       [ovs_cv_malloc_hooks=yes],
129       [ovs_cv_malloc_hooks=no])])
130    if test $ovs_cv_malloc_hooks = yes; then
131      AC_DEFINE([HAVE_MALLOC_HOOKS], [1], 
132                [Define to 1 if you have __malloc_hook, __realloc_hook, and
133                 __free_hook in <malloc.h>.])
134    fi])
135
136 dnl Checks for valgrind/valgrind.h.
137 AC_DEFUN([OVS_CHECK_VALGRIND], 
138   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
139
140 dnl Searches for a directory to put lockfiles for tty devices.
141 dnl Defines C preprocessor variable TTY_LOCK_DIR to a quoted string
142 dnl for that directory.
143 AC_DEFUN([OVS_CHECK_TTY_LOCK_DIR],
144   [AC_CACHE_CHECK([directory used for serial device lockfiles],
145                   [ovs_cv_path_tty_locks],
146                   [# This list of candidate directories is from minicom.
147                    ovs_cv_path_tty_locks=none
148                    for dir in /etc/locks /var/lock /usr/spool/locks \
149                               /var/spool/locks /var/spool/lock \
150                               /usr/spool/uucp /var/spool/uucp /var/run; do
151                      if test -d $dir; then
152                        ovs_cv_path_tty_locks=$dir
153                        break
154                      fi
155                    done])
156    if test "$ovs_cv_path_tty_locks" = none; then
157      AC_MSG_ERROR([cannot find a directory for tty locks])
158    fi
159    AC_DEFINE_UNQUOTED([TTY_LOCK_DIR], "$ovs_cv_path_tty_locks",
160                       [Directory used for serial device lockfiles])])
161
162 dnl The following check is adapted from GNU PSPP.
163 dnl It searches for the ncurses library.  If it finds it, it sets
164 dnl HAVE_CURSES to yes and sets NCURSES_LIBS and NCURSES_CFLAGS
165 dnl appropriate.  Otherwise, it sets HAVE_CURSES to no. 
166 AC_DEFUN([OVS_CHECK_CURSES],
167   [if test "$cross_compiling" != yes; then
168      AC_CHECK_PROGS([NCURSES_CONFIG], [ncurses5-config ncurses8-config])
169    fi
170    if test "$NCURSES_CONFIG" = ""; then
171      AC_SEARCH_LIBS([tgetent], [ncurses],
172          [AC_CHECK_HEADERS([term.h curses.h], 
173                            [HAVE_CURSES=yes],
174                            [HAVE_CURSES=no])])
175    else
176      save_cflags=$CFLAGS
177      CFLAGS="$CFLAGS $($NCURSES_CONFIG --cflags)"
178      AC_CHECK_HEADERS([term.h curses.h], 
179                       [HAVE_CURSES=yes],
180                       [HAVE_CURSES=no])
181      CFLAGS=$save_cflags
182      if test "$HAVE_CURSES" = yes; then
183        NCURSES_LIBS=$($NCURSES_CONFIG --libs)
184        NCURSES_CFLAGS=$($NCURSES_CONFIG --cflags)
185        AC_SUBST(NCURSES_CFLAGS)
186        AC_SUBST(NCURSES_LIBS)
187      fi
188    fi
189    AM_CONDITIONAL([HAVE_CURSES], [test "$HAVE_CURSES" = yes])])
190
191 dnl Checks for linux/vt.h.
192 AC_DEFUN([OVS_CHECK_LINUX_VT_H],
193   [AC_CHECK_HEADER([linux/vt.h],
194                    [HAVE_LINUX_VT_H=yes],
195                    [HAVE_LINUX_VT_H=no])
196    AM_CONDITIONAL([HAVE_LINUX_VT_H], [test "$HAVE_LINUX_VT_H" = yes])
197    if test "$HAVE_LINUX_VT_H" = yes; then
198       AC_DEFINE([HAVE_LINUX_VT_H], [1],
199                 [Define to 1 if linux/vt.h is available.])
200    fi])
201
202 dnl Checks for libpcre.
203 AC_DEFUN([OVS_CHECK_PCRE],
204   [dnl Make sure that pkg-config is installed.
205    m4_pattern_forbid([PKG_CHECK_MODULES])
206    PKG_CHECK_MODULES([PCRE], [libpcre], [HAVE_PCRE=yes], [HAVE_PCRE=no])
207    AM_CONDITIONAL([HAVE_PCRE], [test "$HAVE_PCRE" = yes])
208    if test "$HAVE_PCRE" = yes; then
209       AC_DEFINE([HAVE_PCRE], [1], [Define to 1 if libpcre is installed.])
210    fi])