3 # Copyright (c) 2008, 2009 Nicira Networks.
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 dnl Checks for --disable-userspace.
18 AC_DEFUN([OVS_CHECK_USERSPACE],
21 [AC_HELP_STRING([--disable-userspace],
22 [Disable building userspace components.])],
23 [case "${enableval}" in
24 (yes) build_userspace=true ;;
25 (no) build_userspace=false ;;
26 (*) AC_MSG_ERROR([bad value ${enableval} for --enable-userspace]) ;;
28 [build_userspace=true])
29 AM_CONDITIONAL([ENABLE_USERSPACE], [$build_userspace])])
31 dnl OVS_CHECK_LINUX(OPTION, VERSION, VARIABLE, CONDITIONAL)
33 dnl Configure linux kernel source tree
34 AC_DEFUN([OVS_CHECK_LINUX], [
36 [AC_HELP_STRING([--with-$1=/path/to/linux-$2],
37 [Specify the linux $2 kernel sources])],
38 [path="$withval"], [path=])dnl
39 if test -n "$path"; then
40 path=`eval echo "$path"`
42 AC_MSG_CHECKING([for $path directory])
43 if test -d "$path"; then
49 AC_ERROR([source dir $path doesn't exist])
52 AC_MSG_CHECKING([for $path kernel version])
53 patchlevel=`sed -n 's/^PATCHLEVEL = //p' "$path/Makefile"`
54 sublevel=`sed -n 's/^SUBLEVEL = //p' "$path/Makefile"`
55 AC_MSG_RESULT([2.$patchlevel.$sublevel])
56 if test "2.$patchlevel" != '$2'; then
57 AC_ERROR([Linux kernel source in $path is not version $2])
59 if ! test -e "$path"/include/linux/version.h || \
60 ! test -e "$path"/include/linux/autoconf.h; then
61 AC_MSG_ERROR([Linux kernel source in $path is not configured])
63 m4_if($2, [2.6], [OVS_CHECK_LINUX26_COMPAT])
65 AM_CONDITIONAL($4, test -n "$path")
68 dnl OVS_GREP_IFELSE(FILE, REGEX, IF-MATCH, IF-NO-MATCH)
70 dnl Greps FILE for REGEX. If it matches, runs IF-MATCH, otherwise IF-NO-MATCH.
71 AC_DEFUN([OVS_GREP_IFELSE], [
72 AC_MSG_CHECKING([whether $2 matches in $1])
73 grep '$2' $1 >/dev/null 2>&1
85 AC_MSG_ERROR([grep exited with status $status])
92 dnl Defines NAME to 1 in kcompat.h.
93 AC_DEFUN([OVS_DEFINE], [
94 echo '#define $1 1' >> datapath/linux-2.6/kcompat.h.new
97 AC_DEFUN([OVS_CHECK_VETH], [
98 AC_MSG_CHECKING([whether to build veth module])
99 if test "$sublevel" = 18; then
101 AC_SUBST([BUILD_VETH], 1)
107 AC_DEFUN([OVS_CHECK_LOG2_H], [
108 AC_MSG_CHECKING([for $KSRC26/include/linux/log2.h])
109 if test -e $KSRC26/include/linux/log2.h; then
111 OVS_DEFINE([HAVE_LOG2_H])
117 dnl OVS_CHECK_LINUX26_COMPAT
119 dnl Runs various Autoconf checks on the Linux 2.6 kernel source in
120 dnl the directory in $KSRC26.
121 AC_DEFUN([OVS_CHECK_LINUX26_COMPAT], [
122 rm -f datapath/linux-2.6/kcompat.h.new
123 mkdir -p datapath/linux-2.6
124 : > datapath/linux-2.6/kcompat.h.new
125 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_transport_header],
126 [OVS_DEFINE([HAVE_SKBUFF_HEADER_HELPERS])])
127 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [raw],
128 [OVS_DEFINE([HAVE_MAC_RAW])])
129 OVS_GREP_IFELSE([$KSRC26/include/linux/skbuff.h],
130 [skb_copy_from_linear_data_offset],
131 [OVS_DEFINE([HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET])])
132 OVS_GREP_IFELSE([$KSRC26/include/net/netlink.h], [NLA_NUL_STRING],
133 [OVS_DEFINE([HAVE_NLA_NUL_STRING])])
134 OVS_GREP_IFELSE([$KSRC26/include/linux/err.h], [ERR_CAST],
135 [OVS_DEFINE([HAVE_ERR_CAST])])
138 if cmp -s datapath/linux-2.6/kcompat.h.new \
139 datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then
140 rm datapath/linux-2.6/kcompat.h.new
142 mv datapath/linux-2.6/kcompat.h.new datapath/linux-2.6/kcompat.h
146 dnl Checks for net/if_packet.h.
147 AC_DEFUN([OVS_CHECK_IF_PACKET],
148 [AC_CHECK_HEADER([net/if_packet.h],
149 [HAVE_IF_PACKET=yes],
151 AM_CONDITIONAL([HAVE_IF_PACKET], [test "$HAVE_IF_PACKET" = yes])
152 if test "$HAVE_IF_PACKET" = yes; then
153 AC_DEFINE([HAVE_IF_PACKET], [1],
154 [Define to 1 if net/if_packet.h is available.])
157 dnl Checks for dpkg-buildpackage. If this is available then we check
158 dnl that the Debian packaging is functional at "make distcheck" time.
159 AC_DEFUN([OVS_CHECK_DPKG_BUILDPACKAGE],
160 [AC_CHECK_PROG([HAVE_DPKG_BUILDPACKAGE], [dpkg-buildpackage], [yes], [no])
161 AM_CONDITIONAL([HAVE_DPKG_BUILDPACKAGE],
162 [test $HAVE_DPKG_BUILDPACKAGE = yes])])
164 dnl ----------------------------------------------------------------------
165 dnl These macros are from GNU PSPP, with the following original license:
166 dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
167 dnl This file is free software; the Free Software Foundation
168 dnl gives unlimited permission to copy and/or distribute it,
169 dnl with or without modifications, as long as this notice is preserved.
171 dnl OVS_CHECK_CC_OPTION([OPTION], [ACTION-IF-ACCEPTED], [ACTION-IF-REJECTED])
172 dnl Check whether the given C compiler OPTION is accepted.
173 dnl If so, execute ACTION-IF-ACCEPTED, otherwise ACTION-IF-REJECTED.
174 AC_DEFUN([OVS_CHECK_CC_OPTION],
176 m4_define([ovs_cv_name], [ovs_cv_[]m4_translit([$1], [-], [_])])dnl
177 AC_CACHE_CHECK([whether $CC accepts $1], [ovs_cv_name],
178 [ovs_save_CFLAGS="$CFLAGS"
180 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [ovs_cv_name[]=yes], [ovs_cv_name[]=no])
181 CFLAGS="$ovs_save_CFLAGS"])
182 if test $ovs_cv_name = yes; then
183 m4_if([$2], [], [;], [$2])
185 m4_if([$3], [], [:], [$3])
189 dnl OVS_ENABLE_OPTION([OPTION])
190 dnl Check whether the given C compiler OPTION is accepted.
191 dnl If so, add it to CFLAGS.
192 dnl Example: OVS_ENABLE_OPTION([-Wdeclaration-after-statement])
193 AC_DEFUN([OVS_ENABLE_OPTION],
194 [OVS_CHECK_CC_OPTION([$1], [CFLAGS="$CFLAGS $1"])])
195 dnl ----------------------------------------------------------------------