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_BLKDEV_GET_BY_PATH
12 ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
13 ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
14 ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
15 ZFS_AC_KERNEL_BIO_EMPTY_BARRIER
16 ZFS_AC_KERNEL_BIO_FAILFAST
17 ZFS_AC_KERNEL_BIO_FAILFAST_DTD
18 ZFS_AC_KERNEL_REQ_FAILFAST_MASK
19 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
20 ZFS_AC_KERNEL_BIO_RW_SYNC
21 ZFS_AC_KERNEL_BIO_RW_SYNCIO
22 ZFS_AC_KERNEL_REQ_SYNC
23 ZFS_AC_KERNEL_BLK_END_REQUEST
24 ZFS_AC_KERNEL_BLK_FETCH_REQUEST
25 ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
26 ZFS_AC_KERNEL_BLK_RQ_BYTES
27 ZFS_AC_KERNEL_BLK_RQ_POS
28 ZFS_AC_KERNEL_BLK_RQ_SECTORS
29 ZFS_AC_KERNEL_GET_DISK_RO
30 ZFS_AC_KERNEL_RQ_IS_SYNC
31 ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
32 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
33 ZFS_AC_KERNEL_XATTR_HANDLER_GET
34 ZFS_AC_KERNEL_XATTR_HANDLER_SET
35 ZFS_AC_KERNEL_FSYNC_2ARGS
36 ZFS_AC_KERNEL_EVICT_INODE
37 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
38 ZFS_AC_KERNEL_D_OBTAIN_ALIAS
39 ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE
40 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
41 ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
42 ZFS_AC_KERNEL_MOUNT_NODEV
45 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
46 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
48 AC_SUBST(KERNELMAKE_PARAMS)
51 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
52 dnl # compiler options are added by the kernel build system.
53 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
54 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
55 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
57 AC_SUBST(KERNELCPPFLAGS)
61 dnl # Detect name used for Module.symvers file in kernel
63 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
64 modpost=$LINUX/scripts/Makefile.modpost
65 AC_MSG_CHECKING([kernel file name for module symbols])
66 AS_IF([test -f "$modpost"], [
67 AS_IF([grep -q Modules.symvers $modpost], [
68 LINUX_SYMBOLS=Modules.symvers
70 LINUX_SYMBOLS=Module.symvers
73 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
75 *** Please make sure the kernel devel package for your distribution
76 *** is installed. If your building with a custom kernel make sure the
77 *** kernel is configured, built, and the '--with-linux=PATH' configure
78 *** option refers to the location of the kernel source.])
83 AC_MSG_RESULT($LINUX_SYMBOLS)
84 AC_SUBST(LINUX_SYMBOLS)
88 dnl # Detect the kernel to be built against
90 AC_DEFUN([ZFS_AC_KERNEL], [
92 AS_HELP_STRING([--with-linux=PATH],
93 [Path to kernel source]),
94 [kernelsrc="$withval"])
96 AC_ARG_WITH(linux-obj,
97 AS_HELP_STRING([--with-linux-obj=PATH],
98 [Path to kernel build objects]),
99 [kernelbuild="$withval"])
101 AC_MSG_CHECKING([kernel source directory])
102 AS_IF([test -z "$kernelsrc"], [
103 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
104 headersdir="/lib/modules/$(uname -r)/source"
105 sourcelink=$(readlink -f "$headersdir")
106 ], [test -e "/lib/modules/$(uname -r)/build"], [
107 headersdir="/lib/modules/$(uname -r)/build"
108 sourcelink=$(readlink -f "$headersdir")
110 sourcelink=$(ls -1d /usr/src/kernels/* \
112 2>/dev/null | grep -v obj | tail -1)
115 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
116 kernelsrc=`readlink -f ${sourcelink}`
118 AC_MSG_RESULT([Not found])
120 *** Please make sure the kernel devel package for your distribution
121 *** is installed then try again. If that fails you can specify the
122 *** location of the kernel source with the '--with-linux=PATH' option.])
125 AS_IF([test "$kernelsrc" = "NONE"], [
130 AC_MSG_RESULT([$kernelsrc])
131 AC_MSG_CHECKING([kernel build directory])
132 AS_IF([test -z "$kernelbuild"], [
133 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
134 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
135 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
136 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
137 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
138 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
139 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
140 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
142 kernelbuild=${kernelsrc}
145 AC_MSG_RESULT([$kernelbuild])
147 AC_MSG_CHECKING([kernel source version])
148 utsrelease1=$kernelbuild/include/linux/version.h
149 utsrelease2=$kernelbuild/include/linux/utsrelease.h
150 utsrelease3=$kernelbuild/include/generated/utsrelease.h
151 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
152 utsrelease=linux/version.h
153 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
154 utsrelease=linux/utsrelease.h
155 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
156 utsrelease=generated/utsrelease.h
159 AS_IF([test "$utsrelease"], [
160 kernsrcver=`(echo "#include <$utsrelease>";
161 echo "kernsrcver=UTS_RELEASE") |
162 cpp -I $kernelbuild/include |
163 grep "^kernsrcver=" | cut -d \" -f 2`
165 AS_IF([test -z "$kernsrcver"], [
166 AC_MSG_RESULT([Not found])
167 AC_MSG_ERROR([*** Cannot determine kernel version.])
170 AC_MSG_RESULT([Not found])
171 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
174 AC_MSG_RESULT([$kernsrcver])
177 LINUX_OBJ=${kernelbuild}
178 LINUX_VERSION=${kernsrcver}
182 AC_SUBST(LINUX_VERSION)
184 ZFS_AC_MODULE_SYMVERS
188 dnl # Detect name used for the additional SPL Module.symvers file. If one
189 dnl # does not exist this is likely because the SPL has been configured
190 dnl # but not built. To allow recursive builds a good guess is made as to
191 dnl # what this file will be named based on what it is named in the kernel
192 dnl # build products. This file will first be used at link time so if
193 dnl # the guess is wrong the build will fail then. This unfortunately
194 dnl # means the ZFS package does not contain a reliable mechanism to
195 dnl # detect symbols exported by the SPL at configure time.
197 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
198 AC_MSG_CHECKING([spl file name for module symbols])
199 AS_IF([test -r $SPL_OBJ/Module.symvers], [
200 SPL_SYMBOLS=Module.symvers
201 ], [test -r $SPL_OBJ/Modules.symvers], [
202 SPL_SYMBOLS=Modules.symvers
203 ], [test -r $SPL_OBJ/module/Module.symvers], [
204 SPL_SYMBOLS=Module.symvers
205 ], [test -r $SPL_OBJ/module/Modules.symvers], [
206 SPL_SYMBOLS=Modules.symvers
208 SPL_SYMBOLS=$LINUX_SYMBOLS
211 AC_MSG_RESULT([$SPL_SYMBOLS])
212 AC_SUBST(SPL_SYMBOLS)
216 dnl # Detect the SPL module to be built against
218 AC_DEFUN([ZFS_AC_SPL], [
220 AS_HELP_STRING([--with-spl=PATH],
221 [Path to spl source]),
224 AC_ARG_WITH([spl-obj],
225 AS_HELP_STRING([--with-spl-obj=PATH],
226 [Path to spl build objects]),
227 [splbuild="$withval"])
230 AC_MSG_CHECKING([spl source directory])
231 AS_IF([test -z "$splsrc"], [
232 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
233 2>/dev/null | tail -1`
235 AS_IF([test -z "$sourcelink" || test ! -e $sourcelink], [
239 AS_IF([test -e $sourcelink], [
240 splsrc=`readlink -f ${sourcelink}`
242 AC_MSG_RESULT([Not found])
244 *** Please make sure the spl devel package for your distribution
245 *** is installed then try again. If that fails you can specify the
246 *** location of the spl source with the '--with-spl=PATH' option.])
249 AS_IF([test "$splsrc" = "NONE"], [
255 AC_MSG_RESULT([$splsrc])
256 AC_MSG_CHECKING([spl build directory])
257 AS_IF([test -z "$splbuild"], [
260 AC_MSG_RESULT([$splbuild])
262 AC_MSG_CHECKING([spl source version])
263 AS_IF([test -r $splbuild/spl_config.h &&
264 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
266 splsrcver=`(echo "#include <spl_config.h>";
267 echo "splsrcver=SPL_META_VERSION") |
269 grep "^splsrcver=" | cut -d \" -f 2`
272 AS_IF([test -z "$splsrcver"], [
273 AC_MSG_RESULT([Not found])
275 *** Cannot determine the version of the spl source.
276 *** Please prepare the spl source before running this script])
279 AC_MSG_RESULT([$splsrcver])
283 SPL_VERSION=${splsrcver}
287 AC_SUBST(SPL_VERSION)
289 ZFS_AC_SPL_MODULE_SYMVERS
293 dnl # Certain kernel build options are not supported. These must be
294 dnl # detected at configure time and cause a build failure. Otherwise
295 dnl # modules may be successfully built that behave incorrectly.
297 dnl # CONFIG_PREEMPT - Preempt kernels require special handling.
299 dnl # There are certain kernel build options which when enabled are
300 dnl # completely incompatible with non GPL kernel modules. It is best
301 dnl # to detect these at configure time and fail with a clear error
302 dnl # rather than build everything and fail during linking.
304 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
306 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
308 ZFS_LINUX_CONFIG([PREEMPT],
310 *** Kernel built with CONFIG_PREEMPT which is not supported.
311 *** You must rebuild your kernel without this option.]), [])
313 AS_IF([test "$ZFS_META_LICENSE" = CDDL], [
314 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
316 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
317 *** incompatible with the CDDL license. You must rebuild
318 *** your kernel without this option.]), [])
321 AS_IF([test "$ZFS_META_LICENSE" = GPL], [
322 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
323 [Define to 1 if licensed under the GPL])
328 dnl # ZFS_LINUX_CONFTEST
330 AC_DEFUN([ZFS_LINUX_CONFTEST], [
331 cat confdefs.h - <<_ACEOF >conftest.c
337 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
339 m4_define([ZFS_LANG_PROGRAM], [
344 dnl Do *not* indent the following line: there may be CPP directives.
345 dnl Don't move the `;' right after for the same reason.
353 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
355 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
356 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
357 rm -Rf build && mkdir -p build
358 echo "obj-m := conftest.o" >build/Makefile
360 [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])],
362 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
368 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
370 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
371 [ZFS_LINUX_COMPILE_IFELSE(
372 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
374 [test -s build/conftest.o],
379 dnl # ZFS_LINUX_CONFIG
381 AC_DEFUN([ZFS_LINUX_CONFIG],
382 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
383 ZFS_LINUX_TRY_COMPILE([
384 #include <linux/module.h>
387 #error CONFIG_$1 not #defined
399 dnl # ZFS_CHECK_SYMBOL_EXPORT
400 dnl # check symbol exported or not
402 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
403 [AC_MSG_CHECKING([whether symbol $1 is exported])
404 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
405 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
407 AS_IF([test $rc -ne 0], [
410 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
412 AS_IF([test $rc -eq 0], [
417 AS_IF([test $export -eq 0], [