]> git.proxmox.com Git - ovs.git/blob - acinclude.m4
ofproto: Specialize ofproto_send_packet() for uses the callers really want.
[ovs.git] / acinclude.m4
1 # -*- autoconf -*-
2
3 # Copyright (c) 2008, 2009, 2010, 2011 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 OVS_CHECK_LINUX26
18 dnl
19 dnl Configure linux kernel source tree
20 AC_DEFUN([OVS_CHECK_LINUX26], [
21 AC_ARG_WITH([l26],
22 [AC_HELP_STRING([--with-l26=/path/to/linux-2.6],
23 [Specify the linux 2.6 kernel build directory])],
24 [KBUILD26="$withval"], [KBUILD26=])dnl
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
31 if test -n "$KBUILD26"; then
32 KBUILD26=`eval echo "$KBUILD26"`
33 case $KBUILD26 in
34 /*) ;;
35 *) KBUILD26=`pwd`/$KBUILD26 ;;
36 esac
37
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)
44 else
45 AC_MSG_RESULT([no])
46 AC_ERROR([source dir $KBUILD26 doesn't exist])
47 fi
48
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])
53 if test -n "$KSRC26"; then
54 KSRC26=`eval echo "$KSRC26"`
55 case $KSRC26 in
56 /*) ;;
57 *) KSRC26=`pwd`/$KSRC26 ;;
58 esac
59 if test ! -e $KSRC26/include/linux/kernel.h; then
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)])
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
86 AC_MSG_RESULT([2.$patchlevel.$sublevel])
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
93 fi
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
97 AC_MSG_ERROR([Linux kernel source in $KBUILD26 is not configured])
98 fi
99 OVS_CHECK_LINUX26_COMPAT
100 elif test -n "$KSRC26"; then
101 AC_MSG_ERROR([--with-l26-source may not be specified without --with-l26])
102 fi
103 AM_CONDITIONAL(L26_ENABLED, test -n "$KBUILD26")
104 ])
105
106 dnl OVS_GREP_IFELSE(FILE, REGEX, [IF-MATCH], [IF-NO-MATCH])
107 dnl
108 dnl Greps FILE for REGEX. If it matches, runs IF-MATCH, otherwise IF-NO-MATCH.
109 dnl If IF-MATCH is empty then it defines to OVS_DEFINE(HAVE_<REGEX>), with
110 dnl <REGEX> translated to uppercase.
111 AC_DEFUN([OVS_GREP_IFELSE], [
112 AC_MSG_CHECKING([whether $2 matches in $1])
113 if test -f $1; then
114 grep '$2' $1 >/dev/null 2>&1
115 status=$?
116 case $status in
117 0)
118 AC_MSG_RESULT([yes])
119 m4_if([$3], [], [OVS_DEFINE([HAVE_]m4_toupper([$2]))], [$3])
120 ;;
121 1)
122 AC_MSG_RESULT([no])
123 $4
124 ;;
125 *)
126 AC_MSG_ERROR([grep exited with status $status])
127 ;;
128 esac
129 else
130 AC_MSG_RESULT([file not found])
131 $4
132 fi
133 ])
134
135 dnl OVS_DEFINE(NAME)
136 dnl
137 dnl Defines NAME to 1 in kcompat.h.
138 AC_DEFUN([OVS_DEFINE], [
139 echo '#define $1 1' >> datapath/linux-2.6/kcompat.h.new
140 ])
141
142 AC_DEFUN([OVS_CHECK_LOG2_H], [
143 AC_MSG_CHECKING([for $KSRC26/include/linux/log2.h])
144 if test -e $KSRC26/include/linux/log2.h; then
145 AC_MSG_RESULT([yes])
146 OVS_DEFINE([HAVE_LOG2_H])
147 else
148 AC_MSG_RESULT([no])
149 fi
150 ])
151
152 dnl OVS_CHECK_LINUX26_COMPAT
153 dnl
154 dnl Runs various Autoconf checks on the Linux 2.6 kernel source in
155 dnl the directory in $KBUILD26.
156 AC_DEFUN([OVS_CHECK_LINUX26_COMPAT], [
157 rm -f datapath/linux-2.6/kcompat.h.new
158 mkdir -p datapath/linux-2.6
159 : > datapath/linux-2.6/kcompat.h.new
160
161 OVS_GREP_IFELSE([$KSRC26/arch/x86/include/asm/checksum_32.h], [src_err,],
162 [OVS_DEFINE([HAVE_CSUM_COPY_DBG])])
163
164 OVS_GREP_IFELSE([$KSRC26/include/linux/err.h], [ERR_CAST])
165
166 OVS_GREP_IFELSE([$KSRC26/include/linux/in.h], [ipv4_is_multicast])
167
168 OVS_GREP_IFELSE([$KSRC26/include/linux/netdevice.h], [dev_disable_lro])
169 OVS_GREP_IFELSE([$KSRC26/include/linux/netdevice.h], [dev_get_stats])
170 OVS_GREP_IFELSE([$KSRC26/include/linux/netdevice.h], [dev_get_by_index_rcu])
171
172 OVS_GREP_IFELSE([$KSRC26/include/linux/rcupdate.h], [rcu_read_lock_held], [],
173 [OVS_GREP_IFELSE([$KSRC26/include/linux/rtnetlink.h],
174 [rcu_read_lock_held])])
175
176 # Check for the proto_data_valid member in struct sk_buff. The [^@]
177 # is necessary because some versions of this header remove the
178 # member but retain the kerneldoc comment that describes it (which
179 # starts with @). The brackets must be doubled because of m4
180 # quoting rules.
181 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [[[^@]]proto_data_valid],
182 [OVS_DEFINE([HAVE_PROTO_DATA_VALID])])
183 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [raw],
184 [OVS_DEFINE([HAVE_MAC_RAW])])
185 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_dst(],
186 [OVS_DEFINE([HAVE_SKB_DST_ACCESSOR_FUNCS])])
187 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h],
188 [skb_copy_from_linear_data_offset])
189 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_cow_head])
190 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_transport_header],
191 [OVS_DEFINE([HAVE_SKBUFF_HEADER_HELPERS])])
192 OVS_GREP_IFELSE([$KSRC26/include/linux/icmpv6.h], [icmp6_hdr],
193 [OVS_DEFINE([HAVE_ICMP6_HDR])])
194 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_warn_if_lro],
195 [OVS_DEFINE([HAVE_SKB_WARN_LRO])])
196
197 OVS_GREP_IFELSE([$KSRC26/include/linux/string.h], [kmemdup], [],
198 [OVS_GREP_IFELSE([$KSRC26/include/linux/slab.h], [kmemdup])])
199
200 OVS_GREP_IFELSE([$KSRC26/include/linux/types.h], [bool],
201 [OVS_DEFINE([HAVE_BOOL_TYPE])])
202 OVS_GREP_IFELSE([$KSRC26/include/linux/types.h], [__wsum],
203 [OVS_DEFINE([HAVE_CSUM_TYPES])])
204
205 OVS_GREP_IFELSE([$KSRC26/include/net/checksum.h], [csum_replace4])
206 OVS_GREP_IFELSE([$KSRC26/include/net/checksum.h], [csum_unfold])
207
208 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [NLA_NUL_STRING])
209 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [nla_get_be16])
210 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [nla_find_nested])
211
212 OVS_GREP_IFELSE([$KSRC26/include/linux/if_link.h], [rtnl_link_stats64])
213
214 OVS_GREP_IFELSE([$KSRC26/include/linux/if_vlan.h], [ADD_ALL_VLANS_CMD],
215 [OVS_DEFINE([HAVE_VLAN_BUG_WORKAROUND])])
216
217 OVS_CHECK_LOG2_H
218
219 if cmp -s datapath/linux-2.6/kcompat.h.new \
220 datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then
221 rm datapath/linux-2.6/kcompat.h.new
222 else
223 mv datapath/linux-2.6/kcompat.h.new datapath/linux-2.6/kcompat.h
224 fi
225 ])
226
227 dnl Checks for net/if_packet.h.
228 AC_DEFUN([OVS_CHECK_IF_PACKET],
229 [AC_CHECK_HEADER([net/if_packet.h],
230 [HAVE_IF_PACKET=yes],
231 [HAVE_IF_PACKET=no])
232 AM_CONDITIONAL([HAVE_IF_PACKET], [test "$HAVE_IF_PACKET" = yes])
233 if test "$HAVE_IF_PACKET" = yes; then
234 AC_DEFINE([HAVE_IF_PACKET], [1],
235 [Define to 1 if net/if_packet.h is available.])
236 fi])
237
238 dnl Checks for buggy strtok_r.
239 dnl
240 dnl Some versions of glibc 2.7 has a bug in strtok_r when compiling
241 dnl with optimization that can cause segfaults:
242 dnl
243 dnl http://sources.redhat.com/bugzilla/show_bug.cgi?id=5614.
244 AC_DEFUN([OVS_CHECK_STRTOK_R],
245 [AC_CACHE_CHECK(
246 [whether strtok_r macro segfaults on some inputs],
247 [ovs_cv_strtok_r_bug],
248 [AC_RUN_IFELSE(
249 [AC_LANG_PROGRAM([#include <stdio.h>
250 #include <string.h>
251 ],
252 [[char string[] = ":::";
253 char *save_ptr = (char *) 0xc0ffee;
254 char *token1, *token2;
255 token1 = strtok_r(string, ":", &save_ptr);
256 token2 = strtok_r(NULL, ":", &save_ptr);
257 freopen ("/dev/null", "w", stdout);
258 printf ("%s %s\n", token1, token2);
259 return 0;
260 ]])],
261 [ovs_cv_strtok_r_bug=no],
262 [ovs_cv_strtok_r_bug=yes],
263 [ovs_cv_strtok_r_bug=yes])])
264 if test $ovs_cv_strtok_r_bug = yes; then
265 AC_DEFINE([HAVE_STRTOK_R_BUG], [1],
266 [Define if strtok_r macro segfaults on some inputs])
267 fi
268 ])
269
270 dnl ----------------------------------------------------------------------
271 dnl These macros are from GNU PSPP, with the following original license:
272 dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
273 dnl This file is free software; the Free Software Foundation
274 dnl gives unlimited permission to copy and/or distribute it,
275 dnl with or without modifications, as long as this notice is preserved.
276
277 dnl OVS_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
278 dnl Check whether the given C compiler OPTION is accepted.
279 dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
280 AC_DEFUN([OVS_CHECK_CC_OPTION],
281 [
282 m4_define([ovs_cv_name], [ovs_cv_[]m4_translit([$1], [-], [_])])dnl
283 AC_CACHE_CHECK([whether $CC accepts $1], [ovs_cv_name],
284 [ovs_save_CFLAGS="$CFLAGS"
285 CFLAGS="$CFLAGS $1"
286 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [ovs_cv_name[]=yes], [ovs_cv_name[]=no])
287 CFLAGS="$ovs_save_CFLAGS"])
288 if test $ovs_cv_name = yes; then
289 m4_if([$2], [], [:], [$2])
290 else
291 m4_if([$3], [], [:], [$3])
292 fi
293 ])
294
295 dnl OVS_ENABLE_OPTION([OPTION])
296 dnl Check whether the given C compiler OPTION is accepted.
297 dnl If so, add it to WARNING_FLAGS.
298 dnl Example: OVS_ENABLE_OPTION([-Wdeclaration-after-statement])
299 AC_DEFUN([OVS_ENABLE_OPTION],
300 [OVS_CHECK_CC_OPTION([$1], [WARNING_FLAGS="$WARNING_FLAGS $1"])
301 AC_SUBST([WARNING_FLAGS])])
302
303 dnl OVS_CONDITIONAL_CC_OPTION([OPTION], [CONDITIONAL])
304 dnl Check whether the given C compiler OPTION is accepted.
305 dnl If so, enable the given Automake CONDITIONAL.
306
307 dnl Example: OVS_CONDITIONAL_CC_OPTION([-Wno-unused], [HAVE_WNO_UNUSED])
308 AC_DEFUN([OVS_CONDITIONAL_CC_OPTION],
309 [OVS_CHECK_CC_OPTION(
310 [$1], [ovs_have_cc_option=yes], [ovs_have_cc_option=no])
311 AM_CONDITIONAL([$2], [test $ovs_have_cc_option = yes])])
312 dnl ----------------------------------------------------------------------
313
314 dnl Check for too-old XenServer.
315 AC_DEFUN([OVS_CHECK_XENSERVER_VERSION],
316 [AC_CACHE_CHECK([XenServer release], [ovs_cv_xsversion],
317 [if test -e /etc/redhat-release; then
318 ovs_cv_xsversion=`sed -n 's/^XenServer DDK release \([[^-]]*\)-.*/\1/p' /etc/redhat-release`
319 fi
320 if test -z "$ovs_cv_xsversion"; then
321 ovs_cv_xsversion=none
322 fi])
323 case $ovs_cv_xsversion in
324 none)
325 ;;
326
327 [[1-9]][[0-9]]* | dnl XenServer 10 or later
328 [[6-9]]* | dnl XenServer 6 or later
329 5.[[7-9]]* | dnl XenServer 5.7 or later
330 5.6.[[1-9]][[0-9]][[0-9]][[0-9]]* | dnl XenServer 5.6.1000 or later
331 5.6.[[2-9]][[0-9]][[0-9]]* | dnl XenServer 5.6.200 or later
332 5.6.1[[0-9]][[0-9]]) dnl Xenserver 5.6.100 or later
333 ;;
334
335 *)
336 AC_MSG_ERROR([This appears to be XenServer $ovs_cv_xsversion, but only XenServer 5.6.100 or later is supported. (If you are really using a supported version of XenServer, you may override this error message by specifying 'ovs_cv_xsversion=5.6.100' on the "configure" command line.)])
337 ;;
338 esac])