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