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