]> git.proxmox.com Git - mirror_ovs.git/blame - acinclude.m4
ovsdb: Fix formatting of ovs.db.Error on Python 2.6.
[mirror_ovs.git] / acinclude.m4
CommitLineData
064af421
BP
1# -*- autoconf -*-
2
b57f675c 3# Copyright (c) 2008, 2009, 2010 Nicira Networks.
064af421 4#
a14bc59f
BP
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:
064af421 8#
a14bc59f
BP
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.
064af421 16
7c9e113b 17dnl OVS_CHECK_LINUX26
064af421
BP
18dnl
19dnl Configure linux kernel source tree
7c9e113b
BP
20AC_DEFUN([OVS_CHECK_LINUX26], [
21 AC_ARG_WITH([l26],
22 [AC_HELP_STRING([--with-l26=/path/to/linux-2.6],
f5fb5de6 23 [Specify the linux 2.6 kernel build directory])],
7c9e113b 24 [KBUILD26="$withval"], [KBUILD26=])dnl
f5fb5de6
BP
25 AC_ARG_WITH([l26-source],
26 [AC_HELP_STRING([--with-l26-source=/path/to/linux-2.6-source],
27 [Specify the linux 2.6 kernel source directory
28 (usually figured out automatically from build
29 directory)])],
30 [KSRC26="$withval"], [KSRC26=])dnl
7c9e113b
BP
31 if test -n "$KBUILD26"; then
32 KBUILD26=`eval echo "$KBUILD26"`
0b6d72fc
BP
33 case $KBUILD26 in
34 /*) ;;
35 *) KBUILD26=`pwd`/$KBUILD26 ;;
36 esac
064af421 37
7c9e113b
BP
38 # The build directory is what the user provided.
39 # Make sure that it exists.
40 AC_MSG_CHECKING([for Linux 2.6 build directory])
41 if test -d "$KBUILD26"; then
42 AC_MSG_RESULT([$KBUILD26])
43 AC_SUBST(KBUILD26)
064af421
BP
44 else
45 AC_MSG_RESULT([no])
7c9e113b 46 AC_ERROR([source dir $KBUILD26 doesn't exist])
064af421
BP
47 fi
48
7c9e113b
BP
49 # Debian breaks kernel headers into "source" header and "build" headers.
50 # We want the source headers, but $KBUILD26 gives us the "build" headers.
51 # Use heuristics to find the source headers.
52 AC_MSG_CHECKING([for Linux 2.6 source directory])
f5fb5de6
BP
53 if test -n "$KSRC26"; then
54 KSRC26=`eval echo "$KSRC26"`
55 case $KSRC26 in
56 /*) ;;
57 *) KSRC26=`pwd`/$KSRC26 ;;
b57f675c 58 esac
7c9e113b 59 if test ! -e $KSRC26/include/linux/kernel.h; then
f5fb5de6
BP
60 AC_MSG_ERROR([$KSRC26 is not a kernel source directory)])
61 fi
62 else
63 KSRC26=$KBUILD26
64 if test ! -e $KSRC26/include/linux/kernel.h; then
65 case `echo "$KBUILD26" | sed 's,/*$,,'` in # (
66 */build)
67 KSRC26=`echo "$KBUILD26" | sed 's,/build/*$,/source,'`
68 ;; # (
69 *)
70 KSRC26=`(cd $KBUILD26 && pwd -P) | sed 's,-[[^-]]*$,-common,'`
71 ;;
72 esac
73 fi
74 if test ! -e $KSRC26/include/linux/kernel.h; then
75 AC_MSG_ERROR([cannot find source directory (please use --with-l26-source)])
7c9e113b
BP
76 fi
77 fi
78 AC_MSG_RESULT([$KSRC26])
79
80 AC_MSG_CHECKING([for kernel version])
81 patchlevel=`sed -n 's/^PATCHLEVEL = //p' "$KSRC26/Makefile"`
82 sublevel=`sed -n 's/^SUBLEVEL = //p' "$KSRC26/Makefile"`
83 if test -z "$patchlevel" || test -z "$sublevel"; then
84 AC_ERROR([cannot determine kernel version])
85 fi
064af421 86 AC_MSG_RESULT([2.$patchlevel.$sublevel])
7c9e113b
BP
87 if test "2.$patchlevel" != '2.6'; then
88 if test "$BUILD26" = "$KSRC26"; then
89 AC_ERROR([Linux kernel in $KBUILD26 is not version 2.6])
90 else
91 AC_ERROR([Linux kernel in build tree $KBUILD26 (source tree $KSRC26) is not version 2.6])
92 fi
064af421 93 fi
e0510a6c
BP
94 if test ! -e "$KBUILD26"/include/linux/version.h || \
95 (test ! -e "$KBUILD26"/include/linux/autoconf.h && \
96 test ! -e "$KBUILD26"/include/generated/autoconf.h); then
7c9e113b 97 AC_MSG_ERROR([Linux kernel source in $KBUILD26 is not configured])
064af421 98 fi
7c9e113b 99 OVS_CHECK_LINUX26_COMPAT
f5fb5de6
BP
100 elif test -n "$KSRC26"; then
101 AC_MSG_ERROR([--with-l26-source may not be specified without --with-l26])
064af421 102 fi
7c9e113b 103 AM_CONDITIONAL(L26_ENABLED, test -n "$KBUILD26")
064af421
BP
104])
105
106dnl OVS_GREP_IFELSE(FILE, REGEX, IF-MATCH, IF-NO-MATCH)
107dnl
108dnl Greps FILE for REGEX. If it matches, runs IF-MATCH, otherwise IF-NO-MATCH.
109AC_DEFUN([OVS_GREP_IFELSE], [
110 AC_MSG_CHECKING([whether $2 matches in $1])
111 grep '$2' $1 >/dev/null 2>&1
112 status=$?
113 case $status in
114 0)
115 AC_MSG_RESULT([yes])
116 $3
117 ;;
118 1)
119 AC_MSG_RESULT([no])
120 $4
121 ;;
122 *)
123 AC_MSG_ERROR([grep exited with status $status])
124 ;;
125 esac
126])
127
128dnl OVS_DEFINE(NAME)
129dnl
130dnl Defines NAME to 1 in kcompat.h.
131AC_DEFUN([OVS_DEFINE], [
132 echo '#define $1 1' >> datapath/linux-2.6/kcompat.h.new
133])
134
064af421
BP
135AC_DEFUN([OVS_CHECK_LOG2_H], [
136 AC_MSG_CHECKING([for $KSRC26/include/linux/log2.h])
137 if test -e $KSRC26/include/linux/log2.h; then
138 AC_MSG_RESULT([yes])
139 OVS_DEFINE([HAVE_LOG2_H])
140 else
141 AC_MSG_RESULT([no])
142 fi
143])
144
145dnl OVS_CHECK_LINUX26_COMPAT
146dnl
147dnl Runs various Autoconf checks on the Linux 2.6 kernel source in
7c9e113b 148dnl the directory in $KBUILD26.
064af421
BP
149AC_DEFUN([OVS_CHECK_LINUX26_COMPAT], [
150 rm -f datapath/linux-2.6/kcompat.h.new
151 mkdir -p datapath/linux-2.6
152 : > datapath/linux-2.6/kcompat.h.new
4aa13c0c 153
064af421
BP
154 OVS_GREP_IFELSE([$KSRC26/include/linux/err.h], [ERR_CAST],
155 [OVS_DEFINE([HAVE_ERR_CAST])])
4aa13c0c 156
8f3a29be
JP
157 OVS_GREP_IFELSE([$KSRC26/include/linux/in.h], [ipv4_is_multicast],
158 [OVS_DEFINE([HAVE_IPV4_IS_MULTICAST])])
4aa13c0c 159
090847a3
JG
160 OVS_GREP_IFELSE([$KSRC26/include/linux/netdevice.h], [dev_disable_lro],
161 [OVS_DEFINE([HAVE_DEV_DISABLE_LRO])])
488a9d17
JP
162 OVS_GREP_IFELSE([$KSRC26/include/linux/netdevice.h], [dev_get_stats],
163 [OVS_DEFINE([HAVE_DEV_GET_STATS])])
4aa13c0c 164
6a33828d
BP
165 # Check for the proto_data_valid member in struct sk_buff. The [^@]
166 # is necessary because some versions of this header remove the
167 # member but retain the kerneldoc comment that describes it (which
168 # starts with @). The brackets must be doubled because of m4
169 # quoting rules.
170 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [[[^@]]proto_data_valid],
171 [OVS_DEFINE([HAVE_PROTO_DATA_VALID])])
4aa13c0c
BP
172 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [raw],
173 [OVS_DEFINE([HAVE_MAC_RAW])])
85444c3f
BP
174 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_dst(],
175 [OVS_DEFINE([HAVE_SKB_DST_ACCESSOR_FUNCS])])
4aa13c0c
BP
176 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h],
177 [skb_copy_from_linear_data_offset],
178 [OVS_DEFINE([HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET])])
4eb26d3c
BP
179 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_cow_head],
180 [OVS_DEFINE([HAVE_SKB_COW_HEAD])])
4aa13c0c
BP
181 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_transport_header],
182 [OVS_DEFINE([HAVE_SKBUFF_HEADER_HELPERS])])
183 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_warn_if_lro],
184 [OVS_DEFINE([HAVE_SKB_WARN_LRO])])
185
186 OVS_GREP_IFELSE([$KSRC26/include/linux/string.h $KSRC26/include/linux/slab.h],
187 [kmemdup], [OVS_DEFINE([HAVE_KMEMDUP])])
188
189 OVS_GREP_IFELSE([$KSRC26/include/linux/types.h], [bool],
190 [OVS_DEFINE([HAVE_BOOL_TYPE])])
e215ebca
JG
191 OVS_GREP_IFELSE([$KSRC26/include/linux/types.h], [__wsum],
192 [OVS_DEFINE([HAVE_CSUM_TYPES])])
4aa13c0c
BP
193
194 OVS_GREP_IFELSE([$KSRC26/include/net/checksum.h], [csum_unfold],
195 [OVS_DEFINE([HAVE_CSUM_UNFOLD])])
196
197 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [NLA_NUL_STRING],
198 [OVS_DEFINE([HAVE_NLA_NUL_STRING])])
199 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [nla_get_be16],
200 [OVS_DEFINE([HAVE_NLA_GET_BE16])])
201
064af421 202 OVS_CHECK_LOG2_H
4aa13c0c 203
064af421
BP
204 if cmp -s datapath/linux-2.6/kcompat.h.new \
205 datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then
206 rm datapath/linux-2.6/kcompat.h.new
207 else
208 mv datapath/linux-2.6/kcompat.h.new datapath/linux-2.6/kcompat.h
209 fi
210])
211
212dnl Checks for net/if_packet.h.
213AC_DEFUN([OVS_CHECK_IF_PACKET],
214 [AC_CHECK_HEADER([net/if_packet.h],
215 [HAVE_IF_PACKET=yes],
216 [HAVE_IF_PACKET=no])
217 AM_CONDITIONAL([HAVE_IF_PACKET], [test "$HAVE_IF_PACKET" = yes])
218 if test "$HAVE_IF_PACKET" = yes; then
219 AC_DEFINE([HAVE_IF_PACKET], [1],
220 [Define to 1 if net/if_packet.h is available.])
221 fi])
222
e50097d2
BP
223dnl Checks for buggy strtok_r.
224dnl
225dnl Some versions of glibc 2.7 has a bug in strtok_r when compiling
226dnl with optimization that can cause segfaults:
227dnl
228dnl http://sources.redhat.com/bugzilla/show_bug.cgi?id=5614.
229AC_DEFUN([OVS_CHECK_STRTOK_R],
230 [AC_CACHE_CHECK(
231 [whether strtok_r macro segfaults on some inputs],
232 [ovs_cv_strtok_r_bug],
233 [AC_RUN_IFELSE(
234 [AC_LANG_PROGRAM([#include <stdio.h>
235 #include <string.h>
236 ],
237 [[char string[] = ":::";
238 char *save_ptr = (char *) 0xc0ffee;
239 char *token1, *token2;
240 token1 = strtok_r(string, ":", &save_ptr);
241 token2 = strtok_r(NULL, ":", &save_ptr);
5819a7cd 242 freopen ("/dev/null", "w", stdout);
e50097d2
BP
243 printf ("%s %s\n", token1, token2);
244 return 0;
245 ]])],
246 [ovs_cv_strtok_r_bug=no],
247 [ovs_cv_strtok_r_bug=yes],
248 [ovs_cv_strtok_r_bug=yes])])
249 if test $ovs_cv_strtok_r_bug = yes; then
250 AC_DEFINE([HAVE_STRTOK_R_BUG], [1],
251 [Define if strtok_r macro segfaults on some inputs])
252 fi
253])
254
064af421
BP
255dnl ----------------------------------------------------------------------
256dnl These macros are from GNU PSPP, with the following original license:
257dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
258dnl This file is free software; the Free Software Foundation
259dnl gives unlimited permission to copy and/or distribute it,
260dnl with or without modifications, as long as this notice is preserved.
261
262dnl OVS_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
263dnl Check whether the given C compiler OPTION is accepted.
264dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
265AC_DEFUN([OVS_CHECK_CC_OPTION],
266[
267 m4_define([ovs_cv_name], [ovs_cv_[]m4_translit([$1], [-], [_])])dnl
268 AC_CACHE_CHECK([whether $CC accepts $1], [ovs_cv_name],
269 [ovs_save_CFLAGS="$CFLAGS"
270 CFLAGS="$CFLAGS $1"
271 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [ovs_cv_name[]=yes], [ovs_cv_name[]=no])
272 CFLAGS="$ovs_save_CFLAGS"])
273 if test $ovs_cv_name = yes; then
83f6c050 274 m4_if([$2], [], [:], [$2])
064af421
BP
275 else
276 m4_if([$3], [], [:], [$3])
277 fi
278])
279
280dnl OVS_ENABLE_OPTION([OPTION])
281dnl Check whether the given C compiler OPTION is accepted.
d161c099 282dnl If so, add it to WARNING_FLAGS.
064af421
BP
283dnl Example: OVS_ENABLE_OPTION([-Wdeclaration-after-statement])
284AC_DEFUN([OVS_ENABLE_OPTION],
d161c099
BP
285 [OVS_CHECK_CC_OPTION([$1], [WARNING_FLAGS="$WARNING_FLAGS $1"])
286 AC_SUBST([WARNING_FLAGS])])
c72e245a
BP
287
288dnl OVS_CONDITIONAL_CC_OPTION([OPTION], [CONDITIONAL])
289dnl Check whether the given C compiler OPTION is accepted.
290dnl If so, enable the given Automake CONDITIONAL.
291
292dnl Example: OVS_CONDITIONAL_CC_OPTION([-Wno-unused], [HAVE_WNO_UNUSED])
293AC_DEFUN([OVS_CONDITIONAL_CC_OPTION],
294 [OVS_CHECK_CC_OPTION(
295 [$1], [ovs_have_cc_option=yes], [ovs_have_cc_option=no])
296 AM_CONDITIONAL([$2], [test $ovs_have_cc_option = yes])])
064af421 297dnl ----------------------------------------------------------------------