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