2 dnl # Default ZFS kernel configuration
4 AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
8 ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
9 ZFS_AC_KERNEL_TYPE_FMODE_T
10 ZFS_AC_KERNEL_KOBJ_NAME_LEN
11 ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
12 ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
13 ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
14 ZFS_AC_KERNEL_BIO_EMPTY_BARRIER
15 ZFS_AC_KERNEL_BIO_FAILFAST
16 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
17 ZFS_AC_KERNEL_BIO_RW_SYNCIO
18 ZFS_AC_KERNEL_BLK_END_REQUEST
19 ZFS_AC_KERNEL_BLK_FETCH_REQUEST
20 ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
21 ZFS_AC_KERNEL_BLK_RQ_BYTES
22 ZFS_AC_KERNEL_BLK_RQ_POS
23 ZFS_AC_KERNEL_BLK_RQ_SECTORS
24 ZFS_AC_KERNEL_GET_DISK_RO
25 ZFS_AC_KERNEL_RQ_IS_SYNC
26 ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
28 if test "$LINUX_OBJ" != "$LINUX"; then
29 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
31 AC_SUBST(KERNELMAKE_PARAMS)
34 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
35 dnl # compiler options are added by the kernel build system.
36 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
37 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
39 AC_SUBST(KERNELCPPFLAGS)
43 dnl # Detect name used for Module.symvers file in kernel
45 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
46 modpost=$LINUX/scripts/Makefile.modpost
47 AC_MSG_CHECKING([kernel file name for module symbols])
48 if test -f "$modpost"; then
49 if grep -q Modules.symvers $modpost; then
50 LINUX_SYMBOLS=Modules.symvers
52 LINUX_SYMBOLS=Module.symvers
57 AC_MSG_RESULT($LINUX_SYMBOLS)
58 AC_SUBST(LINUX_SYMBOLS)
62 dnl # Detect the kernel to be built against
64 AC_DEFUN([ZFS_AC_KERNEL], [
66 AS_HELP_STRING([--with-linux=PATH],
67 [Path to kernel source]),
68 [kernelsrc="$withval"])
70 AC_ARG_WITH(linux-obj,
71 AS_HELP_STRING([--with-linux-obj=PATH],
72 [Path to kernel build objects]),
73 [kernelbuild="$withval"])
75 AC_MSG_CHECKING([kernel source directory])
76 if test -z "$kernelsrc"; then
77 headersdir="/lib/modules/$(uname -r)/build"
78 if test -e "$headersdir"; then
79 sourcelink=$(readlink -f "$headersdir")
81 sourcelink=$(ls -1d /usr/src/kernels/* \
83 2>/dev/null | grep -v obj | tail -1)
86 if test -n "$sourcelink" && test -e ${sourcelink}; then
87 kernelsrc=`readlink -f ${sourcelink}`
89 AC_MSG_RESULT([Not found])
91 *** Please make sure the kernel devel package for your distribution
92 *** is installed then try again. If that fails you can specify the
93 *** location of the kernel source with the '--with-linux=PATH' option.])
96 if test "$kernelsrc" = "NONE"; then
101 AC_MSG_RESULT([$kernelsrc])
102 AC_MSG_CHECKING([kernel build directory])
103 if test -z "$kernelbuild"; then
104 if test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
105 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
106 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
107 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
108 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
109 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
111 kernelbuild=${kernelsrc}
114 AC_MSG_RESULT([$kernelbuild])
116 AC_MSG_CHECKING([kernel source version])
117 utsrelease1=$kernelbuild/include/linux/version.h
118 utsrelease2=$kernelbuild/include/linux/utsrelease.h
119 utsrelease3=$kernelbuild/include/generated/utsrelease.h
120 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
121 utsrelease=linux/version.h
122 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
123 utsrelease=linux/utsrelease.h
124 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
125 utsrelease=generated/utsrelease.h
128 if test "$utsrelease"; then
129 kernsrcver=`(echo "#include <$utsrelease>";
130 echo "kernsrcver=UTS_RELEASE") |
131 cpp -I $kernelbuild/include |
132 grep "^kernsrcver=" | cut -d \" -f 2`
134 if test -z "$kernsrcver"; then
135 AC_MSG_RESULT([Not found])
136 AC_MSG_ERROR([*** Cannot determine kernel version.])
139 AC_MSG_RESULT([Not found])
140 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
143 AC_MSG_RESULT([$kernsrcver])
146 LINUX_OBJ=${kernelbuild}
147 LINUX_VERSION=${kernsrcver}
151 AC_SUBST(LINUX_VERSION)
153 ZFS_AC_MODULE_SYMVERS
157 dnl # Detect name used for the additional SPL Module.symvers file. If one
158 dnl # does not exist this is likely because the SPL has been configured
159 dnl # but not built. To allow recursive builds a good guess is made as to
160 dnl # what this file will be named based on what it is named in the kernel
161 dnl # build products. This file will first be used at link time so if
162 dnl # the guess is wrong the build will fail then. This unfortunately
163 dnl # means the ZFS package does not contain a reliable mechanism to
164 dnl # detect symbols exported by the SPL at configure time.
166 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
167 AC_MSG_CHECKING([spl file name for module symbols])
168 if test -r $SPL_OBJ/Module.symvers; then
169 SPL_SYMBOLS=Module.symvers
170 elif test -r $SPL_OBJ/Modules.symvers; then
171 SPL_SYMBOLS=Modules.symvers
172 elif test -r $SPL_OBJ/module/Module.symvers; then
173 SPL_SYMBOLS=Module.symvers
174 elif test -r $SPL_OBJ/module/Modules.symvers; then
175 SPL_SYMBOLS=Modules.symvers
177 SPL_SYMBOLS=$LINUX_SYMBOLS
180 AC_MSG_RESULT([$SPL_SYMBOLS])
181 AC_SUBST(SPL_SYMBOLS)
185 dnl # Detect the SPL module to be built against
187 AC_DEFUN([ZFS_AC_SPL], [
189 AS_HELP_STRING([--with-spl=PATH],
190 [Path to spl source]),
193 AC_ARG_WITH([spl-obj],
194 AS_HELP_STRING([--with-spl-obj=PATH],
195 [Path to spl build objects]),
196 [splbuild="$withval"])
199 AC_MSG_CHECKING([spl source directory])
200 if test -z "$splsrc"; then
201 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
202 2>/dev/null | tail -1`
204 if test -z "$sourcelink" || test ! -e $sourcelink; then
208 if test -e $sourcelink; then
209 splsrc=`readlink -f ${sourcelink}`
211 AC_MSG_RESULT([Not found])
213 *** Please make sure the spl devel package for your distribution
214 *** is installed then try again. If that fails you can specify the
215 *** location of the spl source with the '--with-spl=PATH' option.])
218 if test "$splsrc" = "NONE"; then
224 AC_MSG_RESULT([$splsrc])
225 AC_MSG_CHECKING([spl build directory])
226 if test -z "$splbuild"; then
229 AC_MSG_RESULT([$splbuild])
231 AC_MSG_CHECKING([spl source version])
232 if test -r $splbuild/spl_config.h &&
233 fgrep -q SPL_META_VERSION $splbuild/spl_config.h; then
235 splsrcver=`(echo "#include <spl_config.h>";
236 echo "splsrcver=SPL_META_VERSION") |
238 grep "^splsrcver=" | cut -d \" -f 2`
241 if test -z "$splsrcver"; then
242 AC_MSG_RESULT([Not found])
244 *** Cannot determine the version of the spl source.
245 *** Please prepare the spl source before running this script])
248 AC_MSG_RESULT([$splsrcver])
252 SPL_VERSION=${splsrcver}
256 AC_SUBST(SPL_VERSION)
258 ZFS_AC_SPL_MODULE_SYMVERS
262 dnl # There are certain kernel build options which when enabled are
263 dnl # completely incompatible with non GPL kernel modules. It is best
264 dnl # to detect these at configure time and fail with a clear error
265 dnl # rather than build everything and fail during linking.
267 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
269 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
271 if test "$ZFS_META_LICENSE" = CDDL; then
272 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
274 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
275 *** incompatible with the CDDL license. You must rebuild
276 *** your kernel without this option.]), [])
279 if test "$ZFS_META_LICENSE" = GPL; then
280 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
281 [Define to 1 if licensed under the GPL])
286 dnl # ZFS_LINUX_CONFTEST
288 AC_DEFUN([ZFS_LINUX_CONFTEST], [
289 cat confdefs.h - <<_ACEOF >conftest.c
295 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
297 m4_define([ZFS_LANG_PROGRAM], [
302 dnl Do *not* indent the following line: there may be CPP directives.
303 dnl Don't move the `;' right after for the same reason.
311 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
313 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
314 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
315 rm -Rf build && mkdir -p build
316 echo "obj-m := conftest.o" >build/Makefile
318 [AC_TRY_COMMAND(cp conftest.c build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
320 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
326 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
328 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
329 [ZFS_LINUX_COMPILE_IFELSE(
330 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
332 [test -s build/conftest.o],
337 dnl # ZFS_LINUX_CONFIG
339 AC_DEFUN([ZFS_LINUX_CONFIG],
340 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
341 ZFS_LINUX_TRY_COMPILE([
342 #ifndef AUTOCONF_INCLUDED
343 #include <linux/config.h>
347 #error CONFIG_$1 not #defined
359 dnl # ZFS_CHECK_SYMBOL_EXPORT
360 dnl # check symbol exported or not
362 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
363 [AC_MSG_CHECKING([whether symbol $1 is exported])
364 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
365 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
367 if test $rc -ne 0; then
370 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
372 if test $rc -eq 0; then
377 if test $export -eq 0; then