m4: Remove trailing whitespace.
[sliver-openvswitch.git] / m4 / openvswitch.m4
1 # -*- autoconf -*-
2
3 # Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
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         (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 ESX.
50 AC_DEFUN([OVS_CHECK_ESX],
51   [AC_CHECK_HEADER([vmware.h],
52                    [ESX=yes],
53                    [ESX=no])
54    AM_CONDITIONAL([ESX], [test "$ESX" = yes])
55    if test "$ESX" = yes; then
56       AC_DEFINE([ESX], [1], [Define to 1 if building on ESX.])
57    fi])
58
59 dnl Checks for Netlink support.
60 AC_DEFUN([OVS_CHECK_NETLINK],
61   [AC_CHECK_HEADER([linux/netlink.h],
62                    [HAVE_NETLINK=yes],
63                    [HAVE_NETLINK=no],
64                    [#include <sys/socket.h>
65    #include <linux/types.h>
66    ])
67    AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
68    if test "$HAVE_NETLINK" = yes; then
69       AC_DEFINE([HAVE_NETLINK], [1],
70                 [Define to 1 if Netlink protocol is available.])
71    fi])
72
73 dnl Checks for OpenSSL.
74 AC_DEFUN([OVS_CHECK_OPENSSL],
75   [AC_ARG_ENABLE(
76      [ssl],
77      [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
78      [case "${enableval}" in
79         (yes) ssl=true ;;
80         (no)  ssl=false ;;
81         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
82       esac],
83      [ssl=check])
84
85    if test "$ssl" != false; then
86        m4_ifndef([PKG_CHECK_MODULES], [m4_fatal([Please install pkg-config.])])
87        PKG_CHECK_MODULES([SSL], [openssl],
88          [HAVE_OPENSSL=yes],
89          [HAVE_OPENSSL=no
90           if test "$ssl" = check; then
91             AC_MSG_WARN([Cannot find openssl:
92
93 $SSL_PKG_ERRORS
94
95 OpenFlow connections over SSL will not be supported.
96 (You may use --disable-ssl to suppress this warning.)])
97           else
98             AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
99           fi])
100    else
101        HAVE_OPENSSL=no
102    fi
103    AC_SUBST([HAVE_OPENSSL])
104    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
105    if test "$HAVE_OPENSSL" = yes; then
106       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
107    fi])
108
109 dnl Checks for libraries needed by lib/socket-util.c.
110 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
111   [AC_CHECK_LIB([socket], [connect])
112    AC_SEARCH_LIBS([gethostbyname], [resolv], [RESOLVER_LIBS=-lresolv])])
113
114 dnl Checks for the directory in which to store the PKI.
115 AC_DEFUN([OVS_CHECK_PKIDIR],
116   [AC_ARG_WITH(
117      [pkidir],
118      AC_HELP_STRING([--with-pkidir=DIR],
119                     [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
120      [PKIDIR=$withval],
121      [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
122    AC_SUBST([PKIDIR])])
123
124 dnl Checks for the directory in which to store pidfiles.
125 AC_DEFUN([OVS_CHECK_RUNDIR],
126   [AC_ARG_WITH(
127      [rundir],
128      AC_HELP_STRING([--with-rundir=DIR],
129                     [directory used for pidfiles
130                     [[LOCALSTATEDIR/run/openvswitch]]]),
131      [RUNDIR=$withval],
132      [RUNDIR='${localstatedir}/run/openvswitch'])
133    AC_SUBST([RUNDIR])])
134
135 dnl Checks for the directory in which to store logs.
136 AC_DEFUN([OVS_CHECK_LOGDIR],
137   [AC_ARG_WITH(
138      [logdir],
139      AC_HELP_STRING([--with-logdir=DIR],
140                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
141      [LOGDIR=$withval],
142      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
143    AC_SUBST([LOGDIR])])
144
145 dnl Checks for the directory in which to store the Open vSwitch database.
146 AC_DEFUN([OVS_CHECK_DBDIR],
147   [AC_ARG_WITH(
148      [dbdir],
149      AC_HELP_STRING([--with-dbdir=DIR],
150                     [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
151      [DBDIR=$withval],
152      [DBDIR='${sysconfdir}/${PACKAGE}'])
153    AC_SUBST([DBDIR])])
154
155 dnl Defines HAVE_BACKTRACE if backtrace() is declared in <execinfo.h>
156 dnl and exists in libc.
157 AC_DEFUN([OVS_CHECK_BACKTRACE],
158   [AC_CHECK_HEADER([execinfo.h], [AC_CHECK_FUNCS([backtrace])])])
159
160 dnl Checks for __malloc_hook, etc., supported by glibc.
161 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
162   [AC_CACHE_CHECK(
163     [whether libc supports hooks for malloc and related functions],
164     [ovs_cv_malloc_hooks],
165     [AC_COMPILE_IFELSE(
166       [AC_LANG_PROGRAM(
167          [#include <malloc.h>
168          ],
169          [(void) __malloc_hook;
170           (void) __realloc_hook;
171           (void) __free_hook;])],
172       [ovs_cv_malloc_hooks=yes],
173       [ovs_cv_malloc_hooks=no])])
174    if test $ovs_cv_malloc_hooks = yes; then
175      AC_DEFINE([HAVE_MALLOC_HOOKS], [1],
176                [Define to 1 if you have __malloc_hook, __realloc_hook, and
177                 __free_hook in <malloc.h>.])
178    fi])
179
180 dnl Checks for valgrind/valgrind.h.
181 AC_DEFUN([OVS_CHECK_VALGRIND],
182   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
183
184 dnl Checks for Python 2.x, x >= 4.
185 AC_DEFUN([OVS_CHECK_PYTHON],
186   [AC_CACHE_CHECK(
187      [for Python 2.x for x >= 4],
188      [ovs_cv_python],
189      [if test -n "$PYTHON"; then
190         ovs_cv_python=$PYTHON
191       else
192         ovs_cv_python=no
193         for binary in python python2.4 python2.5; do
194           ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
195           for dir in $PATH; do
196             IFS=$ovs_save_IFS
197             test -z "$dir" && dir=.
198             if test -x $dir/$binary && $dir/$binary -c 'import sys
199 if sys.hexversion >= 0x02040000 and sys.hexversion < 0x03000000:
200     sys.exit(0)
201 else:
202     sys.exit(1)'; then
203               ovs_cv_python=$dir/$binary
204               break 2
205             fi
206           done
207         done
208       fi])
209    AC_SUBST([HAVE_PYTHON])
210    AM_MISSING_PROG([PYTHON], [python])
211    if test $ovs_cv_python != no; then
212      PYTHON=$ovs_cv_python
213      HAVE_PYTHON=yes
214    else
215      HAVE_PYTHON=no
216    fi
217    AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
218
219 dnl Checks for dot.
220 AC_DEFUN([OVS_CHECK_DOT],
221   [AC_CACHE_CHECK(
222     [for dot],
223     [ovs_cv_dot],
224     [dnl "dot" writes -V output to stderr:
225      if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
226        ovs_cv_dot=yes
227      else
228        ovs_cv_dot=no
229      fi])
230    AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
231
232 dnl Checks for pyuic4.
233 AC_DEFUN([OVS_CHECK_PYUIC4],
234   [AC_CACHE_CHECK(
235     [for pyuic4],
236     [ovs_cv_pyuic4],
237     [if (pyuic4 --version) >/dev/null 2>&1; then
238        ovs_cv_pyuic4=pyuic4
239      else
240        ovs_cv_pyuic4=no
241      fi])
242    AM_MISSING_PROG([PYUIC4], [pyuic4])
243    if test $ovs_cv_pyuic4 != no; then
244      PYUIC4=$ovs_cv_pyuic4
245    fi])
246
247 dnl Checks whether $PYTHON supports the module given as $1
248 AC_DEFUN([OVS_CHECK_PYTHON_MODULE],
249   [AC_REQUIRE([OVS_CHECK_PYTHON])
250    AC_CACHE_CHECK(
251      [for $1 Python module],
252      [ovs_cv_py_[]AS_TR_SH([$1])],
253      [ovs_cv_py_[]AS_TR_SH([$1])=no
254       if test $HAVE_PYTHON = yes; then
255         AS_ECHO(["running $PYTHON -c 'import $1
256 import sys
257 sys.exit(0)'..."]) >&AS_MESSAGE_LOG_FD 2>&1
258         if $PYTHON -c 'import $1
259 import sys
260 sys.exit(0)' >&AS_MESSAGE_LOG_FD 2>&1; then
261           ovs_cv_py_[]AS_TR_SH([$1])=yes
262         fi
263       fi])])
264
265 dnl Checks for Python modules needed by ovsdbmonitor.
266 AC_DEFUN([OVS_CHECK_OVSDBMONITOR],
267   [OVS_CHECK_PYTHON_MODULE([PySide.QtCore])
268    OVS_CHECK_PYTHON_MODULE([PyQt4.QtCore])
269    OVS_CHECK_PYTHON_MODULE([twisted.conch.ssh])
270    OVS_CHECK_PYTHON_MODULE([twisted.internet])
271    OVS_CHECK_PYTHON_MODULE([twisted.application])
272    OVS_CHECK_PYTHON_MODULE([json])
273    OVS_CHECK_PYTHON_MODULE([zope.interface])
274    if (test $ovs_cv_py_PySide_QtCore = yes \
275        || test $ovs_cv_py_PyQt4_QtCore = yes) \
276       && test $ovs_cv_py_twisted_conch_ssh = yes \
277       && test $ovs_cv_py_twisted_internet = yes \
278       && test $ovs_cv_py_twisted_application = yes \
279       && test $ovs_cv_py_json = yes \
280       && test $ovs_cv_py_zope_interface = yes; then
281      BUILD_OVSDBMONITOR=yes
282    else
283      BUILD_OVSDBMONITOR=no
284    fi
285    AC_MSG_CHECKING([whether to build ovsdbmonitor])
286    AC_MSG_RESULT([$BUILD_OVSDBMONITOR])
287    AM_CONDITIONAL([BUILD_OVSDBMONITOR], [test $BUILD_OVSDBMONITOR = yes])])
288
289 # OVS_LINK2_IFELSE(SOURCE1, SOURCE2, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
290 # -------------------------------------------------------------
291 # Based on AC_LINK_IFELSE, but tries to link both SOURCE1 and SOURCE2
292 # into a program.
293 #
294 # This macro is borrowed from acinclude.m4 in GNU PSPP, which has the
295 # following license:
296 #
297 #     Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
298 #     This file is free software; the Free Software Foundation
299 #     gives unlimited permission to copy and/or distribute it,
300 #     with or without modifications, as long as this notice is preserved.
301 #
302 m4_define([OVS_LINK2_IFELSE],
303 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
304 mv conftest.$ac_ext conftest1.$ac_ext
305 m4_ifvaln([$2], [AC_LANG_CONFTEST([$2])])dnl
306 mv conftest.$ac_ext conftest2.$ac_ext
307 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
308 ovs_link2='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest1.$ac_ext conftest2.$ac_ext $LIBS >&5'
309 AS_IF([_AC_DO_STDERR($ovs_link2) && {
310          test -z "$ac_[]_AC_LANG_ABBREV[]_werror_flag" ||
311          test ! -s conftest.err
312        } && test -s conftest$ac_exeext && {
313          test "$cross_compiling" = yes ||
314          AS_TEST_X([conftest$ac_exeext])
315        }],
316       [$3],
317       [echo "$as_me: failed source file 1 of 2 was:" >&5
318 sed 's/^/| /' conftest1.$ac_ext >&5
319 echo "$as_me: failed source file 2 of 2 was:" >&5
320 sed 's/^/| /' conftest2.$ac_ext >&5
321         $4])
322 dnl Delete also the IPA/IPO (Inter Procedural Analysis/Optimization)
323 dnl information created by the PGI compiler (conftest_ipa8_conftest.oo),
324 dnl as it would interfere with the next link command.
325 rm -rf conftest.dSYM conftest1.dSYM conftest2.dSYM
326 rm -f core conftest.err conftest1.err conftest2.err
327 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest*_ipa8_conftest*.oo
328 rm -f conftest$ac_exeext
329 rm -f m4_ifval([$1], [conftest1.$ac_ext]) m4_ifval([$2], [conftest1.$ac_ext])[]dnl
330 ])# OVS_LINK2_IFELSE
331
332 dnl Defines USE_LINKER_SECTIONS to 1 if the compiler supports putting
333 dnl variables in sections with user-defined names and the linker
334 dnl automatically defines __start_SECNAME and __stop_SECNAME symbols
335 dnl that designate the start and end of the sections.
336 AC_DEFUN([OVS_CHECK_LINKER_SECTIONS],
337   [AC_CACHE_CHECK(
338     [for user-defined linker section support],
339     [ovs_cv_use_linker_sections],
340     [OVS_LINK2_IFELSE(
341       [AC_LANG_SOURCE(
342         [int a __attribute__((__section__("mysection"))) = 1;
343          int b __attribute__((__section__("mysection"))) = 2;
344          int c __attribute__((__section__("mysection"))) = 3;])],
345       [AC_LANG_PROGRAM(
346         [#include <stdio.h>
347          extern int __start_mysection;
348          extern int __stop_mysection;],
349         [int n_ints = &__stop_mysection - &__start_mysection;
350          int *i;
351          for (i = &__start_mysection; i < &__start_mysection + n_ints; i++) {
352              printf("%d\n", *i);
353          }])],
354       [ovs_cv_use_linker_sections=yes],
355       [ovs_cv_use_linker_sections=no])])
356    if test $ovs_cv_use_linker_sections = yes; then
357      AC_DEFINE([USE_LINKER_SECTIONS], [1],
358                [Define to 1 if the compiler support putting variables
359                 into sections with user-defined names and the linker
360                 automatically defines __start_SECNAME and __stop_SECNAME
361                 symbols that designate the start and end of the section.])
362    fi
363    AM_CONDITIONAL(
364      [USE_LINKER_SECTIONS], [test $ovs_cv_use_linker_sections = yes])])
365
366 dnl Checks for groff.
367 AC_DEFUN([OVS_CHECK_GROFF],
368   [AC_CACHE_CHECK(
369     [for groff],
370     [ovs_cv_groff],
371     [if (groff -v) >/dev/null 2>&1; then
372        ovs_cv_groff=yes
373      else
374        ovs_cv_groff=no
375      fi])
376    AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
377
378 dnl Checks for --disable-brcompat and undefines BUILD_BRCOMPAT if it is specified.
379 AC_DEFUN([OVS_CHECK_BRCOMPAT],
380   [AC_ARG_ENABLE(
381      [brcompat],
382      [AC_HELP_STRING([--disable-brcompat],
383                      [Disable building brcompat])],
384      [case "${enableval}" in
385         (yes) brcompat=true ;;
386         (no)  brcompat=false ;;
387         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-brcompat]) ;;
388       esac],
389      [brcompat=true])
390    if test x$brcompat = xtrue; then
391       BUILD_BRCOMPAT=yes
392    else
393       BUILD_BRCOMPAT=""
394    fi
395    AC_SUBST([BUILD_BRCOMPAT])
396    AM_CONDITIONAL([BUILD_BRCOMPAT], [test x$brcompat = xtrue])])