d3e9f9f0ed53cfc0ca78ff814bfc26df9d5d697e
[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, 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
117                     [[LOCALSTATEDIR/run/openvswitch]]]),
118      [RUNDIR=$withval],
119      [RUNDIR='${localstatedir}/run/openvswitch'])
120    AC_SUBST([RUNDIR])])
121
122 dnl Checks for the directory in which to store logs.
123 AC_DEFUN([OVS_CHECK_LOGDIR],
124   [AC_ARG_WITH(
125      [logdir], 
126      AC_HELP_STRING([--with-logdir=DIR], 
127                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
128      [LOGDIR=$withval],
129      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
130    AC_SUBST([LOGDIR])])
131
132 dnl Checks for __malloc_hook, etc., supported by glibc.
133 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
134   [AC_CACHE_CHECK(
135     [whether libc supports hooks for malloc and related functions],
136     [ovs_cv_malloc_hooks],
137     [AC_COMPILE_IFELSE(
138       [AC_LANG_PROGRAM(
139          [#include <malloc.h>
140          ], 
141          [(void) __malloc_hook;
142           (void) __realloc_hook;
143           (void) __free_hook;])],
144       [ovs_cv_malloc_hooks=yes],
145       [ovs_cv_malloc_hooks=no])])
146    if test $ovs_cv_malloc_hooks = yes; then
147      AC_DEFINE([HAVE_MALLOC_HOOKS], [1], 
148                [Define to 1 if you have __malloc_hook, __realloc_hook, and
149                 __free_hook in <malloc.h>.])
150    fi])
151
152 dnl Checks for valgrind/valgrind.h.
153 AC_DEFUN([OVS_CHECK_VALGRIND], 
154   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
155
156 dnl Checks for Python 2.x, x >= 4.
157 AC_DEFUN([OVS_CHECK_PYTHON],
158   [AC_CACHE_CHECK(
159      [for Python 2.x for x >= 4],
160      [ovs_cv_python],
161      [if test -n "$PYTHON"; then
162         ovs_cv_python=$PYTHON
163       else
164         ovs_cv_python=no
165         for binary in python python2.4 python2.5; do
166           ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
167           for dir in $PATH; do
168             IFS=$ovs_save_IFS
169             test -z "$dir" && dir=.
170             if test -x $dir/$binary && $dir/$binary -c 'import sys
171 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
172     sys.exit(0)
173 else:
174     sys.exit(1)'; then
175               ovs_cv_python=$dir/$binary
176               break 2
177             fi
178           done
179         done
180       fi])
181    AC_SUBST([HAVE_PYTHON])
182    AM_MISSING_PROG([PYTHON], [python])
183    if test $ovs_cv_python != no; then
184      PYTHON=$ovs_cv_python
185      HAVE_PYTHON=yes
186    else
187      HAVE_PYTHON=no
188    fi
189    AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
190
191 dnl Checks for dot.
192 AC_DEFUN([OVS_CHECK_DOT],
193   [AC_CACHE_CHECK(
194     [for dot],
195     [ovs_cv_dot],
196     [dnl "dot" writes -V output to stderr:
197      if (dot -V) 2>&1 | grep '^dot - [gG]raphviz version' >/dev/null 2>&1; then
198        ovs_cv_dot=yes
199      else
200        ovs_cv_dot=no
201      fi])])
202
203 dnl Check whether to build E-R diagrams.
204 AC_DEFUN([OVS_CHECK_ER_DIAGRAMS],
205   [AC_REQUIRE([OVS_CHECK_DOT])
206    AC_REQUIRE([OVS_CHECK_PYTHON])
207    AC_CACHE_CHECK(
208     [whether to build E-R diagrams for database],
209     [ovs_cv_er_diagrams],
210     [if test $ovs_cv_dot != no && test $ovs_cv_python != no; then
211        ovs_cv_er_diagrams=yes
212      else
213        ovs_cv_er_diagrams=no
214      fi])
215    AM_CONDITIONAL([BUILD_ER_DIAGRAMS], [test $ovs_cv_er_diagrams = yes])])
216
217 dnl Checks for pyuic4.
218 AC_DEFUN([OVS_CHECK_PYUIC4],
219   [AC_CACHE_CHECK(
220     [for pyuic4],
221     [ovs_cv_pyuic4],
222     [if (pyuic4 --version) >/dev/null 2>&1; then
223        ovs_cv_pyuic4=pyuic4
224      else
225        ovs_cv_pyuic4=no
226      fi])
227    AM_MISSING_PROG([PYUIC4], [pyuic4])
228    if test $ovs_cv_pyuic4 != no; then
229      PYUIC4=$ovs_cv_pyuic4
230    fi])
231
232 dnl Checks whether $PYTHON supports the module given as $1
233 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
234   [AC_REQUIRE([OVS_CHECK_PYTHON])
235    AC_CACHE_CHECK(
236      [for $1 Python module],
237      [ovs_cv_py_[]AS_TR_SH([$1])],
238      [ovs_cv_py_[]AS_TR_SH([$1])=no
239       if test $HAVE_PYTHON = yes; then
240         AS_ECHO(["running $PYTHON -c 'import $1
241 import sys
242 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
243         if $PYTHON -c 'import $1
244 import sys
245 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
246           ovs_cv_py_[]AS_TR_SH([$1])=yes
247         fi
248       fi])])
249
250 dnl Checks for Python modules needed by ovsdbmonitor.
251 AC_DEFUN([OVS_CHECK_OVSDBMONITOR],
252   [OVS_CHECK_PYTHON_MODULE([PySide.QtCore])
253    OVS_CHECK_PYTHON_MODULE([PyQt4.QtCore])
254    OVS_CHECK_PYTHON_MODULE([twisted.conch.ssh])
255    OVS_CHECK_PYTHON_MODULE([twisted.internet])
256    OVS_CHECK_PYTHON_MODULE([twisted.application])
257    OVS_CHECK_PYTHON_MODULE([json])
258    OVS_CHECK_PYTHON_MODULE([zope.interface])
259    if (test $ovs_cv_py_PySide_QtCore = yes \
260        || test $ovs_cv_py_PyQt4_QtCore = yes) \
261       && test $ovs_cv_py_twisted_conch_ssh = yes \
262       && test $ovs_cv_py_twisted_internet = yes \
263       && test $ovs_cv_py_twisted_application = yes \
264       && test $ovs_cv_py_json = yes \
265       && test $ovs_cv_py_zope_interface = yes; then
266      BUILD_OVSDBMONITOR=yes
267    else
268      BUILD_OVSDBMONITOR=no
269    fi
270    AC_MSG_CHECKING([whether to build ovsdbmonitor])
271    AC_MSG_RESULT([$BUILD_OVSDBMONITOR])
272    AM_CONDITIONAL([BUILD_OVSDBMONITOR], [test $BUILD_OVSDBMONITOR = yes])])
273
274 # OVS_LINK2_IFELSE(SOURCE1, SOURCE2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
275 # -------------------------------------------------------------
276 # Based on AC_LINK_IFELSE, but tries to link both SOURCE1 and SOURCE2
277 # into a program.
278 #
279 # This macro is borrowed from acinclude.m4 in GNU PSPP, which has the
280 # following license:
281 #
282 #     Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
283 #     This file is free software; the Free Software Foundation
284 #     gives unlimited permission to copy and/or distribute it,
285 #     with or without modifications, as long as this notice is preserved.
286 #
287 m4_define([OVS_LINK2_IFELSE],
288 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
289 mv conftest.$ac_ext conftest1.$ac_ext
290 m4_ifvaln([$2], [AC_LANG_CONFTEST([$2])])dnl
291 mv conftest.$ac_ext conftest2.$ac_ext
292 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
293 ovs_link2='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest1.$ac_ext conftest2.$ac_ext $LIBS >&5'
294 AS_IF([_AC_DO_STDERR($ovs_link2) && {
295          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
296          test ! -s conftest.err
297        } && test -s conftest$ac_exeext && {
298          test "$cross_compiling" = yes ||
299          AS_TEST_X([conftest$ac_exeext])
300        }],
301       [$3],
302       [echo "$as_me: failed source file 1 of 2 was:" >&5
303 sed 's/^/| /' conftest1.$ac_ext >&5
304 echo "$as_me: failed source file 2 of 2 was:" >&5
305 sed 's/^/| /' conftest2.$ac_ext >&5
306         $4])
307 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
308 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
309 dnl as it would interfere with the next link command.
310 rm -rf conftest.dSYM conftest1.dSYM conftest2.dSYM
311 rm -f core conftest.err conftest1.err conftest2.err
312 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest*_ipa8_conftest*.oo
313 rm -f conftest$ac_exeext
314 rm -f m4_ifval([$1], [conftest1.$ac_ext]) m4_ifval([$2], [conftest1.$ac_ext])[]dnl
315 ])# OVS_LINK2_IFELSE
316
317 dnl Defines USE_LINKER_SECTIONS to 1 if the compiler supports putting
318 dnl variables in sections with user-defined names and the linker
319 dnl automatically defines __start_SECNAME and __stop_SECNAME symbols
320 dnl that designate the start and end of the sections.
321 AC_DEFUN([OVS_CHECK_LINKER_SECTIONS],
322   [AC_CACHE_CHECK(
323     [for user-defined linker section support],
324     [ovs_cv_use_linker_sections],
325     [OVS_LINK2_IFELSE(
326       [AC_LANG_SOURCE(
327         [int a __attribute__((__section__("mysection"))) = 1;
328          int b __attribute__((__section__("mysection"))) = 2;
329          int c __attribute__((__section__("mysection"))) = 3;])],
330       [AC_LANG_PROGRAM(
331         [#include <stdio.h>
332          extern int __start_mysection;
333          extern int __stop_mysection;],
334         [int n_ints = &__stop_mysection - &__start_mysection;
335          int *i;
336          for (i = &__start_mysection; i < &__start_mysection + n_ints; i++) {
337              printf("%d\n", *i);
338          }])],
339       [ovs_cv_use_linker_sections=yes],
340       [ovs_cv_use_linker_sections=no])])
341    if test $ovs_cv_use_linker_sections = yes; then
342      AC_DEFINE([USE_LINKER_SECTIONS], [1],
343                [Define to 1 if the compiler support putting variables
344                 into sections with user-defined names and the linker
345                 automatically defines __start_SECNAME and __stop_SECNAME
346                 symbols that designate the start and end of the section.])
347    fi])