3 # Copyright (c) 2008, 2009, 2010 Nicira Networks.
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:
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 dnl Configure linux kernel source tree
20 AC_DEFUN([OVS_CHECK_LINUX26], [
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
30 [KSRC26="$withval"], [KSRC26=])dnl
31 if test -n "$KBUILD26"; then
32 KBUILD26=`eval echo "$KBUILD26"`
35 *) KBUILD26=`pwd`/$KBUILD26 ;;
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])
46 AC_ERROR([source dir $KBUILD26 doesn't exist])
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"`
57 *) KSRC26=`pwd`/$KSRC26 ;;
59 if test ! -e $KSRC26/include/linux/kernel.h; then
60 AC_MSG_ERROR([$KSRC26 is not a kernel source directory)])
64 if test ! -e $KSRC26/include/linux/kernel.h; then
65 case `echo "$KBUILD26" | sed 's,/*$,,'` in # (
67 KSRC26=`echo "$KBUILD26" | sed 's,/build/*$,/source,'`
70 KSRC26=`(cd $KBUILD26 && pwd -P) | sed 's,-[[^-]]*$,-common,'`
74 if test ! -e $KSRC26/include/linux/kernel.h; then
75 AC_MSG_ERROR([cannot find source directory (please use --with-l26-source)])
78 AC_MSG_RESULT([$KSRC26])
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])
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])
91 AC_ERROR([Linux kernel in build tree $KBUILD26 (source tree $KSRC26) is not version 2.6])
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])
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])
103 AM_CONDITIONAL(L26_ENABLED, test -n "$KBUILD26")
106 dnl OVS_GREP_IFELSE(FILE, REGEX, IF-MATCH, IF-NO-MATCH)
108 dnl Greps FILE for REGEX. If it matches, runs IF-MATCH, otherwise IF-NO-MATCH.
109 AC_DEFUN([OVS_GREP_IFELSE], [
110 AC_MSG_CHECKING([whether $2 matches in $1])
112 grep '$2' $1 >/dev/null 2>&1
124 AC_MSG_ERROR([grep exited with status $status])
128 AC_MSG_RESULT([file not found])
135 dnl Defines NAME to 1 in kcompat.h.
136 AC_DEFUN([OVS_DEFINE], [
137 echo '#define $1 1' >> datapath/linux-2.6/kcompat.h.new
140 AC_DEFUN([OVS_CHECK_LOG2_H], [
141 AC_MSG_CHECKING([for $KSRC26/include/linux/log2.h])
142 if test -e $KSRC26/include/linux/log2.h; then
144 OVS_DEFINE([HAVE_LOG2_H])
150 dnl OVS_CHECK_LINUX26_COMPAT
152 dnl Runs various Autoconf checks on the Linux 2.6 kernel source in
153 dnl the directory in $KBUILD26.
154 AC_DEFUN([OVS_CHECK_LINUX26_COMPAT], [
155 rm -f datapath/linux-2.6/kcompat.h.new
156 mkdir -p datapath/linux-2.6
157 : > datapath/linux-2.6/kcompat.h.new
159 OVS_GREP_IFELSE([$KSRC26/arch/x86/include/asm/checksum_32.h], [src_err,],
160 [OVS_DEFINE([HAVE_CSUM_COPY_DBG])])
162 OVS_GREP_IFELSE([$KSRC26/include/linux/err.h], [ERR_CAST],
163 [OVS_DEFINE([HAVE_ERR_CAST])])
165 OVS_GREP_IFELSE([$KSRC26/include/linux/in.h], [ipv4_is_multicast],
166 [OVS_DEFINE([HAVE_IPV4_IS_MULTICAST])])
168 OVS_GREP_IFELSE([$KSRC26/include/linux/netdevice.h], [dev_disable_lro],
169 [OVS_DEFINE([HAVE_DEV_DISABLE_LRO])])
170 OVS_GREP_IFELSE([$KSRC26/include/linux/netdevice.h], [dev_get_stats],
171 [OVS_DEFINE([HAVE_DEV_GET_STATS])])
173 # Check for the proto_data_valid member in struct sk_buff. The [^@]
174 # is necessary because some versions of this header remove the
175 # member but retain the kerneldoc comment that describes it (which
176 # starts with @). The brackets must be doubled because of m4
178 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [[[^@]]proto_data_valid],
179 [OVS_DEFINE([HAVE_PROTO_DATA_VALID])])
180 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [raw],
181 [OVS_DEFINE([HAVE_MAC_RAW])])
182 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_dst(],
183 [OVS_DEFINE([HAVE_SKB_DST_ACCESSOR_FUNCS])])
184 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h],
185 [skb_copy_from_linear_data_offset],
186 [OVS_DEFINE([HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET])])
187 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_cow_head],
188 [OVS_DEFINE([HAVE_SKB_COW_HEAD])])
189 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_transport_header],
190 [OVS_DEFINE([HAVE_SKBUFF_HEADER_HELPERS])])
191 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_warn_if_lro],
192 [OVS_DEFINE([HAVE_SKB_WARN_LRO])])
194 OVS_GREP_IFELSE([$KSRC26/include/linux/string.h], [kmemdup],
195 [OVS_DEFINE([HAVE_KMEMDUP])],
196 [OVS_GREP_IFELSE([$KSRC26/include/linux/slab.h], [kmemdup],
197 [OVS_DEFINE([HAVE_KMEMDUP])])])
199 OVS_GREP_IFELSE([$KSRC26/include/linux/types.h], [bool],
200 [OVS_DEFINE([HAVE_BOOL_TYPE])])
201 OVS_GREP_IFELSE([$KSRC26/include/linux/types.h], [__wsum],
202 [OVS_DEFINE([HAVE_CSUM_TYPES])])
204 OVS_GREP_IFELSE([$KSRC26/include/net/checksum.h], [csum_unfold],
205 [OVS_DEFINE([HAVE_CSUM_UNFOLD])])
207 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [NLA_NUL_STRING],
208 [OVS_DEFINE([HAVE_NLA_NUL_STRING])])
209 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [nla_get_be16],
210 [OVS_DEFINE([HAVE_NLA_GET_BE16])])
214 if cmp -s datapath/linux-2.6/kcompat.h.new \
215 datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then
216 rm datapath/linux-2.6/kcompat.h.new
218 mv datapath/linux-2.6/kcompat.h.new datapath/linux-2.6/kcompat.h
222 dnl Checks for net/if_packet.h.
223 AC_DEFUN([OVS_CHECK_IF_PACKET],
224 [AC_CHECK_HEADER([net/if_packet.h],
225 [HAVE_IF_PACKET=yes],
227 AM_CONDITIONAL([HAVE_IF_PACKET], [test "$HAVE_IF_PACKET" = yes])
228 if test "$HAVE_IF_PACKET" = yes; then
229 AC_DEFINE([HAVE_IF_PACKET], [1],
230 [Define to 1 if net/if_packet.h is available.])
233 dnl Checks for buggy strtok_r.
235 dnl Some versions of glibc 2.7 has a bug in strtok_r when compiling
236 dnl with optimization that can cause segfaults:
238 dnl http://sources.redhat.com/bugzilla/show_bug.cgi?id=5614.
239 AC_DEFUN([OVS_CHECK_STRTOK_R],
241 [whether strtok_r macro segfaults on some inputs],
242 [ovs_cv_strtok_r_bug],
244 [AC_LANG_PROGRAM([#include <stdio.h>
247 [[char string[] = ":::";
248 char *save_ptr = (char *) 0xc0ffee;
249 char *token1, *token2;
250 token1 = strtok_r(string, ":", &save_ptr);
251 token2 = strtok_r(NULL, ":", &save_ptr);
252 freopen ("/dev/null", "w", stdout);
253 printf ("%s %s\n", token1, token2);
256 [ovs_cv_strtok_r_bug=no],
257 [ovs_cv_strtok_r_bug=yes],
258 [ovs_cv_strtok_r_bug=yes])])
259 if test $ovs_cv_strtok_r_bug = yes; then
260 AC_DEFINE([HAVE_STRTOK_R_BUG], [1],
261 [Define if strtok_r macro segfaults on some inputs])
265 dnl ----------------------------------------------------------------------
266 dnl These macros are from GNU PSPP, with the following original license:
267 dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
268 dnl This file is free software; the Free Software Foundation
269 dnl gives unlimited permission to copy and/or distribute it,
270 dnl with or without modifications, as long as this notice is preserved.
272 dnl OVS_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
273 dnl Check whether the given C compiler OPTION is accepted.
274 dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
275 AC_DEFUN([OVS_CHECK_CC_OPTION],
277 m4_define([ovs_cv_name], [ovs_cv_[]m4_translit([$1], [-], [_])])dnl
278 AC_CACHE_CHECK([whether $CC accepts $1], [ovs_cv_name],
279 [ovs_save_CFLAGS="$CFLAGS"
281 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [ovs_cv_name[]=yes], [ovs_cv_name[]=no])
282 CFLAGS="$ovs_save_CFLAGS"])
283 if test $ovs_cv_name = yes; then
284 m4_if([$2], [], [:], [$2])
286 m4_if([$3], [], [:], [$3])
290 dnl OVS_ENABLE_OPTION([OPTION])
291 dnl Check whether the given C compiler OPTION is accepted.
292 dnl If so, add it to WARNING_FLAGS.
293 dnl Example: OVS_ENABLE_OPTION([-Wdeclaration-after-statement])
294 AC_DEFUN([OVS_ENABLE_OPTION],
295 [OVS_CHECK_CC_OPTION([$1], [WARNING_FLAGS="$WARNING_FLAGS $1"])
296 AC_SUBST([WARNING_FLAGS])])
298 dnl OVS_CONDITIONAL_CC_OPTION([OPTION], [CONDITIONAL])
299 dnl Check whether the given C compiler OPTION is accepted.
300 dnl If so, enable the given Automake CONDITIONAL.
302 dnl Example: OVS_CONDITIONAL_CC_OPTION([-Wno-unused], [HAVE_WNO_UNUSED])
303 AC_DEFUN([OVS_CONDITIONAL_CC_OPTION],
304 [OVS_CHECK_CC_OPTION(
305 [$1], [ovs_have_cc_option=yes], [ovs_have_cc_option=no])
306 AM_CONDITIONAL([$2], [test $ovs_have_cc_option = yes])])
307 dnl ----------------------------------------------------------------------