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_FAILFAST_DTD
17 ZFS_AC_KERNEL_REQ_FAILFAST_MASK
18 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
19 ZFS_AC_KERNEL_BIO_RW_SYNC
20 ZFS_AC_KERNEL_BIO_RW_SYNCIO
21 ZFS_AC_KERNEL_REQ_SYNC
22 ZFS_AC_KERNEL_BLK_END_REQUEST
23 ZFS_AC_KERNEL_BLK_FETCH_REQUEST
24 ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
25 ZFS_AC_KERNEL_BLK_RQ_BYTES
26 ZFS_AC_KERNEL_BLK_RQ_POS
27 ZFS_AC_KERNEL_BLK_RQ_SECTORS
28 ZFS_AC_KERNEL_GET_DISK_RO
29 ZFS_AC_KERNEL_RQ_IS_SYNC
30 ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
31 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
32 ZFS_AC_KERNEL_XATTR_HANDLER_GET
33 ZFS_AC_KERNEL_XATTR_HANDLER_SET
34 ZFS_AC_KERNEL_FSYNC_2ARGS
35 ZFS_AC_KERNEL_EVICT_INODE
37 if test "$LINUX_OBJ" != "$LINUX"; then
38 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
40 AC_SUBST(KERNELMAKE_PARAMS)
43 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
44 dnl # compiler options are added by the kernel build system.
45 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
46 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
48 AC_SUBST(KERNELCPPFLAGS)
52 dnl # Detect name used for Module.symvers file in kernel
54 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
55 modpost=$LINUX/scripts/Makefile.modpost
56 AC_MSG_CHECKING([kernel file name for module symbols])
57 if test -f "$modpost"; then
58 if grep -q Modules.symvers $modpost; then
59 LINUX_SYMBOLS=Modules.symvers
61 LINUX_SYMBOLS=Module.symvers
66 AC_MSG_RESULT($LINUX_SYMBOLS)
67 AC_SUBST(LINUX_SYMBOLS)
71 dnl # Detect the kernel to be built against
73 AC_DEFUN([ZFS_AC_KERNEL], [
75 AS_HELP_STRING([--with-linux=PATH],
76 [Path to kernel source]),
77 [kernelsrc="$withval"])
79 AC_ARG_WITH(linux-obj,
80 AS_HELP_STRING([--with-linux-obj=PATH],
81 [Path to kernel build objects]),
82 [kernelbuild="$withval"])
84 AC_MSG_CHECKING([kernel source directory])
85 if test -z "$kernelsrc"; then
86 if test -e "/lib/modules/$(uname -r)/source"; then
87 headersdir="/lib/modules/$(uname -r)/source"
88 sourcelink=$(readlink -f "$headersdir")
89 elif test -e "/lib/modules/$(uname -r)/build"; then
90 headersdir="/lib/modules/$(uname -r)/build"
91 sourcelink=$(readlink -f "$headersdir")
93 sourcelink=$(ls -1d /usr/src/kernels/* \
95 2>/dev/null | grep -v obj | tail -1)
98 if test -n "$sourcelink" && test -e ${sourcelink}; then
99 kernelsrc=`readlink -f ${sourcelink}`
101 AC_MSG_RESULT([Not found])
103 *** Please make sure the kernel devel package for your distribution
104 *** is installed then try again. If that fails you can specify the
105 *** location of the kernel source with the '--with-linux=PATH' option.])
108 if test "$kernelsrc" = "NONE"; then
113 AC_MSG_RESULT([$kernelsrc])
114 AC_MSG_CHECKING([kernel build directory])
115 if test -z "$kernelbuild"; then
116 if test -e "/lib/modules/$(uname -r)/build"; then
117 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
118 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
119 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
120 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
121 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
122 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
123 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
125 kernelbuild=${kernelsrc}
128 AC_MSG_RESULT([$kernelbuild])
130 AC_MSG_CHECKING([kernel source version])
131 utsrelease1=$kernelbuild/include/linux/version.h
132 utsrelease2=$kernelbuild/include/linux/utsrelease.h
133 utsrelease3=$kernelbuild/include/generated/utsrelease.h
134 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
135 utsrelease=linux/version.h
136 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
137 utsrelease=linux/utsrelease.h
138 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
139 utsrelease=generated/utsrelease.h
142 if test "$utsrelease"; then
143 kernsrcver=`(echo "#include <$utsrelease>";
144 echo "kernsrcver=UTS_RELEASE") |
145 cpp -I $kernelbuild/include |
146 grep "^kernsrcver=" | cut -d \" -f 2`
148 if test -z "$kernsrcver"; then
149 AC_MSG_RESULT([Not found])
150 AC_MSG_ERROR([*** Cannot determine kernel version.])
153 AC_MSG_RESULT([Not found])
154 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
157 AC_MSG_RESULT([$kernsrcver])
160 LINUX_OBJ=${kernelbuild}
161 LINUX_VERSION=${kernsrcver}
165 AC_SUBST(LINUX_VERSION)
167 ZFS_AC_MODULE_SYMVERS
171 dnl # Detect name used for the additional SPL Module.symvers file. If one
172 dnl # does not exist this is likely because the SPL has been configured
173 dnl # but not built. To allow recursive builds a good guess is made as to
174 dnl # what this file will be named based on what it is named in the kernel
175 dnl # build products. This file will first be used at link time so if
176 dnl # the guess is wrong the build will fail then. This unfortunately
177 dnl # means the ZFS package does not contain a reliable mechanism to
178 dnl # detect symbols exported by the SPL at configure time.
180 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
181 AC_MSG_CHECKING([spl file name for module symbols])
182 if test -r $SPL_OBJ/Module.symvers; then
183 SPL_SYMBOLS=Module.symvers
184 elif test -r $SPL_OBJ/Modules.symvers; then
185 SPL_SYMBOLS=Modules.symvers
186 elif test -r $SPL_OBJ/module/Module.symvers; then
187 SPL_SYMBOLS=Module.symvers
188 elif test -r $SPL_OBJ/module/Modules.symvers; then
189 SPL_SYMBOLS=Modules.symvers
191 SPL_SYMBOLS=$LINUX_SYMBOLS
194 AC_MSG_RESULT([$SPL_SYMBOLS])
195 AC_SUBST(SPL_SYMBOLS)
199 dnl # Detect the SPL module to be built against
201 AC_DEFUN([ZFS_AC_SPL], [
203 AS_HELP_STRING([--with-spl=PATH],
204 [Path to spl source]),
207 AC_ARG_WITH([spl-obj],
208 AS_HELP_STRING([--with-spl-obj=PATH],
209 [Path to spl build objects]),
210 [splbuild="$withval"])
213 AC_MSG_CHECKING([spl source directory])
214 if test -z "$splsrc"; then
215 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
216 2>/dev/null | tail -1`
218 if test -z "$sourcelink" || test ! -e $sourcelink; then
222 if test -e $sourcelink; then
223 splsrc=`readlink -f ${sourcelink}`
225 AC_MSG_RESULT([Not found])
227 *** Please make sure the spl devel package for your distribution
228 *** is installed then try again. If that fails you can specify the
229 *** location of the spl source with the '--with-spl=PATH' option.])
232 if test "$splsrc" = "NONE"; then
238 AC_MSG_RESULT([$splsrc])
239 AC_MSG_CHECKING([spl build directory])
240 if test -z "$splbuild"; then
243 AC_MSG_RESULT([$splbuild])
245 AC_MSG_CHECKING([spl source version])
246 if test -r $splbuild/spl_config.h &&
247 fgrep -q SPL_META_VERSION $splbuild/spl_config.h; then
249 splsrcver=`(echo "#include <spl_config.h>";
250 echo "splsrcver=SPL_META_VERSION") |
252 grep "^splsrcver=" | cut -d \" -f 2`
255 if test -z "$splsrcver"; then
256 AC_MSG_RESULT([Not found])
258 *** Cannot determine the version of the spl source.
259 *** Please prepare the spl source before running this script])
262 AC_MSG_RESULT([$splsrcver])
266 SPL_VERSION=${splsrcver}
270 AC_SUBST(SPL_VERSION)
272 ZFS_AC_SPL_MODULE_SYMVERS
276 dnl # There are certain kernel build options which when enabled are
277 dnl # completely incompatible with non GPL kernel modules. It is best
278 dnl # to detect these at configure time and fail with a clear error
279 dnl # rather than build everything and fail during linking.
281 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
283 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
285 if test "$ZFS_META_LICENSE" = CDDL; then
286 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
288 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
289 *** incompatible with the CDDL license. You must rebuild
290 *** your kernel without this option.]), [])
293 if test "$ZFS_META_LICENSE" = GPL; then
294 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
295 [Define to 1 if licensed under the GPL])
300 dnl # ZFS_LINUX_CONFTEST
302 AC_DEFUN([ZFS_LINUX_CONFTEST], [
303 cat confdefs.h - <<_ACEOF >conftest.c
309 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
311 m4_define([ZFS_LANG_PROGRAM], [
316 dnl Do *not* indent the following line: there may be CPP directives.
317 dnl Don't move the `;' right after for the same reason.
325 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
327 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
328 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
329 rm -Rf build && mkdir -p build
330 echo "obj-m := conftest.o" >build/Makefile
332 [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])],
334 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
340 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
342 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
343 [ZFS_LINUX_COMPILE_IFELSE(
344 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
346 [test -s build/conftest.o],
351 dnl # ZFS_LINUX_CONFIG
353 AC_DEFUN([ZFS_LINUX_CONFIG],
354 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
355 ZFS_LINUX_TRY_COMPILE([
356 #ifndef AUTOCONF_INCLUDED
357 #include <linux/config.h>
361 #error CONFIG_$1 not #defined
373 dnl # ZFS_CHECK_SYMBOL_EXPORT
374 dnl # check symbol exported or not
376 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
377 [AC_MSG_CHECKING([whether symbol $1 is exported])
378 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
379 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
381 if test $rc -ne 0; then
384 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
386 if test $rc -eq 0; then
391 if test $export -eq 0; then