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