]> git.proxmox.com Git - mirror_ovs.git/blame - acinclude.m4
Document userspace switch.
[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
064af421
BP
17dnl OVS_CHECK_LINUX(OPTION, VERSION, VARIABLE, CONDITIONAL)
18dnl
19dnl Configure linux kernel source tree
20AC_DEFUN([OVS_CHECK_LINUX], [
21 AC_ARG_WITH([$1],
22 [AC_HELP_STRING([--with-$1=/path/to/linux-$2],
23 [Specify the linux $2 kernel sources])],
24 [path="$withval"], [path=])dnl
25 if test -n "$path"; then
26 path=`eval echo "$path"`
27
28 AC_MSG_CHECKING([for $path directory])
29 if test -d "$path"; then
30 AC_MSG_RESULT([yes])
31 $3=$path
32 AC_SUBST($3)
33 else
34 AC_MSG_RESULT([no])
35 AC_ERROR([source dir $path doesn't exist])
36 fi
37
38 AC_MSG_CHECKING([for $path kernel version])
39 patchlevel=`sed -n 's/^PATCHLEVEL = //p' "$path/Makefile"`
40 sublevel=`sed -n 's/^SUBLEVEL = //p' "$path/Makefile"`
41 AC_MSG_RESULT([2.$patchlevel.$sublevel])
42 if test "2.$patchlevel" != '$2'; then
43 AC_ERROR([Linux kernel source in $path is not version $2])
44 fi
45 if ! test -e "$path"/include/linux/version.h || \
46 ! test -e "$path"/include/linux/autoconf.h; then
47 AC_MSG_ERROR([Linux kernel source in $path is not configured])
48 fi
49 m4_if($2, [2.6], [OVS_CHECK_LINUX26_COMPAT])
50 fi
51 AM_CONDITIONAL($4, test -n "$path")
52])
53
54dnl OVS_GREP_IFELSE(FILE, REGEX, IF-MATCH, IF-NO-MATCH)
55dnl
56dnl Greps FILE for REGEX. If it matches, runs IF-MATCH, otherwise IF-NO-MATCH.
57AC_DEFUN([OVS_GREP_IFELSE], [
58 AC_MSG_CHECKING([whether $2 matches in $1])
59 grep '$2' $1 >/dev/null 2>&1
60 status=$?
61 case $status in
62 0)
63 AC_MSG_RESULT([yes])
64 $3
65 ;;
66 1)
67 AC_MSG_RESULT([no])
68 $4
69 ;;
70 *)
71 AC_MSG_ERROR([grep exited with status $status])
72 ;;
73 esac
74])
75
76dnl OVS_DEFINE(NAME)
77dnl
78dnl Defines NAME to 1 in kcompat.h.
79AC_DEFUN([OVS_DEFINE], [
80 echo '#define $1 1' >> datapath/linux-2.6/kcompat.h.new
81])
82
83AC_DEFUN([OVS_CHECK_VETH], [
84 AC_MSG_CHECKING([whether to build veth module])
85 if test "$sublevel" = 18; then
86 AC_MSG_RESULT([yes])
87 AC_SUBST([BUILD_VETH], 1)
88 else
89 AC_MSG_RESULT([no])
90 fi
91])
92
93AC_DEFUN([OVS_CHECK_LOG2_H], [
94 AC_MSG_CHECKING([for $KSRC26/include/linux/log2.h])
95 if test -e $KSRC26/include/linux/log2.h; then
96 AC_MSG_RESULT([yes])
97 OVS_DEFINE([HAVE_LOG2_H])
98 else
99 AC_MSG_RESULT([no])
100 fi
101])
102
103dnl OVS_CHECK_LINUX26_COMPAT
104dnl
105dnl Runs various Autoconf checks on the Linux 2.6 kernel source in
106dnl the directory in $KSRC26.
107AC_DEFUN([OVS_CHECK_LINUX26_COMPAT], [
108 rm -f datapath/linux-2.6/kcompat.h.new
109 mkdir -p datapath/linux-2.6
110 : > datapath/linux-2.6/kcompat.h.new
111 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_transport_header],
112 [OVS_DEFINE([HAVE_SKBUFF_HEADER_HELPERS])])
113 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [raw],
114 [OVS_DEFINE([HAVE_MAC_RAW])])
115 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h],
116 [skb_copy_from_linear_data_offset],
117 [OVS_DEFINE([HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET])])
118 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [NLA_NUL_STRING],
119 [OVS_DEFINE([HAVE_NLA_NUL_STRING])])
120 OVS_GREP_IFELSE([$KSRC26/include/linux/err.h], [ERR_CAST],
121 [OVS_DEFINE([HAVE_ERR_CAST])])
aed94495
BP
122 OVS_GREP_IFELSE([$KSRC26/include/net/checksum.h], [csum_unfold],
123 [OVS_DEFINE([HAVE_CSUM_UNFOLD])])
124 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_cow],
125 [OVS_DEFINE([HAVE_SKB_COW])])
064af421
BP
126 OVS_CHECK_LOG2_H
127 OVS_CHECK_VETH
128 if cmp -s datapath/linux-2.6/kcompat.h.new \
129 datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then
130 rm datapath/linux-2.6/kcompat.h.new
131 else
132 mv datapath/linux-2.6/kcompat.h.new datapath/linux-2.6/kcompat.h
133 fi
134])
135
136dnl Checks for net/if_packet.h.
137AC_DEFUN([OVS_CHECK_IF_PACKET],
138 [AC_CHECK_HEADER([net/if_packet.h],
139 [HAVE_IF_PACKET=yes],
140 [HAVE_IF_PACKET=no])
141 AM_CONDITIONAL([HAVE_IF_PACKET], [test "$HAVE_IF_PACKET" = yes])
142 if test "$HAVE_IF_PACKET" = yes; then
143 AC_DEFINE([HAVE_IF_PACKET], [1],
144 [Define to 1 if net/if_packet.h is available.])
145 fi])
146
e50097d2
BP
147dnl Checks for buggy strtok_r.
148dnl
149dnl Some versions of glibc 2.7 has a bug in strtok_r when compiling
150dnl with optimization that can cause segfaults:
151dnl
152dnl http://sources.redhat.com/bugzilla/show_bug.cgi?id=5614.
153AC_DEFUN([OVS_CHECK_STRTOK_R],
154 [AC_CACHE_CHECK(
155 [whether strtok_r macro segfaults on some inputs],
156 [ovs_cv_strtok_r_bug],
157 [AC_RUN_IFELSE(
158 [AC_LANG_PROGRAM([#include <stdio.h>
159 #include <string.h>
160 ],
161 [[char string[] = ":::";
162 char *save_ptr = (char *) 0xc0ffee;
163 char *token1, *token2;
164 token1 = strtok_r(string, ":", &save_ptr);
165 token2 = strtok_r(NULL, ":", &save_ptr);
166 printf ("%s %s\n", token1, token2);
167 return 0;
168 ]])],
169 [ovs_cv_strtok_r_bug=no],
170 [ovs_cv_strtok_r_bug=yes],
171 [ovs_cv_strtok_r_bug=yes])])
172 if test $ovs_cv_strtok_r_bug = yes; then
173 AC_DEFINE([HAVE_STRTOK_R_BUG], [1],
174 [Define if strtok_r macro segfaults on some inputs])
175 fi
176])
177
064af421
BP
178dnl ----------------------------------------------------------------------
179dnl These macros are from GNU PSPP, with the following original license:
180dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
181dnl This file is free software; the Free Software Foundation
182dnl gives unlimited permission to copy and/or distribute it,
183dnl with or without modifications, as long as this notice is preserved.
184
185dnl OVS_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
186dnl Check whether the given C compiler OPTION is accepted.
187dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
188AC_DEFUN([OVS_CHECK_CC_OPTION],
189[
190 m4_define([ovs_cv_name], [ovs_cv_[]m4_translit([$1], [-], [_])])dnl
191 AC_CACHE_CHECK([whether $CC accepts $1], [ovs_cv_name],
192 [ovs_save_CFLAGS="$CFLAGS"
193 CFLAGS="$CFLAGS $1"
194 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [ovs_cv_name[]=yes], [ovs_cv_name[]=no])
195 CFLAGS="$ovs_save_CFLAGS"])
196 if test $ovs_cv_name = yes; then
197 m4_if([$2], [], [;], [$2])
198 else
199 m4_if([$3], [], [:], [$3])
200 fi
201])
202
203dnl OVS_ENABLE_OPTION([OPTION])
204dnl Check whether the given C compiler OPTION is accepted.
205dnl If so, add it to CFLAGS.
206dnl Example: OVS_ENABLE_OPTION([-Wdeclaration-after-statement])
207AC_DEFUN([OVS_ENABLE_OPTION],
208 [OVS_CHECK_CC_OPTION([$1], [CFLAGS="$CFLAGS $1"])])
209dnl ----------------------------------------------------------------------