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
36 if test "$LINUX_OBJ" != "$LINUX"; then
37 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
39 AC_SUBST(KERNELMAKE_PARAMS)
42 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
43 dnl # compiler options are added by the kernel build system.
44 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
45 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
47 AC_SUBST(KERNELCPPFLAGS)
51 dnl # Detect name used for Module.symvers file in kernel
53 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
54 modpost=$LINUX/scripts/Makefile.modpost
55 AC_MSG_CHECKING([kernel file name for module symbols])
56 if test -f "$modpost"; then
57 if grep -q Modules.symvers $modpost; then
58 LINUX_SYMBOLS=Modules.symvers
60 LINUX_SYMBOLS=Module.symvers
65 AC_MSG_RESULT($LINUX_SYMBOLS)
66 AC_SUBST(LINUX_SYMBOLS)
70 dnl # Detect the kernel to be built against
72 AC_DEFUN([ZFS_AC_KERNEL], [
74 AS_HELP_STRING([--with-linux=PATH],
75 [Path to kernel source]),
76 [kernelsrc="$withval"])
78 AC_ARG_WITH(linux-obj,
79 AS_HELP_STRING([--with-linux-obj=PATH],
80 [Path to kernel build objects]),
81 [kernelbuild="$withval"])
83 AC_MSG_CHECKING([kernel source directory])
84 if test -z "$kernelsrc"; then
85 if test -e "/lib/modules/$(uname -r)/source"; then
86 headersdir="/lib/modules/$(uname -r)/source"
87 sourcelink=$(readlink -f "$headersdir")
88 elif test -e "/lib/modules/$(uname -r)/build"; then
89 headersdir="/lib/modules/$(uname -r)/build"
90 sourcelink=$(readlink -f "$headersdir")
92 sourcelink=$(ls -1d /usr/src/kernels/* \
94 2>/dev/null | grep -v obj | tail -1)
97 if test -n "$sourcelink" && test -e ${sourcelink}; then
98 kernelsrc=`readlink -f ${sourcelink}`
100 AC_MSG_RESULT([Not found])
102 *** Please make sure the kernel devel package for your distribution
103 *** is installed then try again. If that fails you can specify the
104 *** location of the kernel source with the '--with-linux=PATH' option.])
107 if test "$kernelsrc" = "NONE"; then
112 AC_MSG_RESULT([$kernelsrc])
113 AC_MSG_CHECKING([kernel build directory])
114 if test -z "$kernelbuild"; then
115 if test -e "/lib/modules/$(uname -r)/build"; then
116 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
117 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
118 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
119 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
120 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
121 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
122 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
124 kernelbuild=${kernelsrc}
127 AC_MSG_RESULT([$kernelbuild])
129 AC_MSG_CHECKING([kernel source version])
130 utsrelease1=$kernelbuild/include/linux/version.h
131 utsrelease2=$kernelbuild/include/linux/utsrelease.h
132 utsrelease3=$kernelbuild/include/generated/utsrelease.h
133 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
134 utsrelease=linux/version.h
135 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
136 utsrelease=linux/utsrelease.h
137 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
138 utsrelease=generated/utsrelease.h
141 if test "$utsrelease"; then
142 kernsrcver=`(echo "#include <$utsrelease>";
143 echo "kernsrcver=UTS_RELEASE") |
144 cpp -I $kernelbuild/include |
145 grep "^kernsrcver=" | cut -d \" -f 2`
147 if test -z "$kernsrcver"; then
148 AC_MSG_RESULT([Not found])
149 AC_MSG_ERROR([*** Cannot determine kernel version.])
152 AC_MSG_RESULT([Not found])
153 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
156 AC_MSG_RESULT([$kernsrcver])
159 LINUX_OBJ=${kernelbuild}
160 LINUX_VERSION=${kernsrcver}
164 AC_SUBST(LINUX_VERSION)
166 ZFS_AC_MODULE_SYMVERS
170 dnl # Detect name used for the additional SPL Module.symvers file. If one
171 dnl # does not exist this is likely because the SPL has been configured
172 dnl # but not built. To allow recursive builds a good guess is made as to
173 dnl # what this file will be named based on what it is named in the kernel
174 dnl # build products. This file will first be used at link time so if
175 dnl # the guess is wrong the build will fail then. This unfortunately
176 dnl # means the ZFS package does not contain a reliable mechanism to
177 dnl # detect symbols exported by the SPL at configure time.
179 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
180 AC_MSG_CHECKING([spl file name for module symbols])
181 if test -r $SPL_OBJ/Module.symvers; then
182 SPL_SYMBOLS=Module.symvers
183 elif test -r $SPL_OBJ/Modules.symvers; then
184 SPL_SYMBOLS=Modules.symvers
185 elif test -r $SPL_OBJ/module/Module.symvers; then
186 SPL_SYMBOLS=Module.symvers
187 elif test -r $SPL_OBJ/module/Modules.symvers; then
188 SPL_SYMBOLS=Modules.symvers
190 SPL_SYMBOLS=$LINUX_SYMBOLS
193 AC_MSG_RESULT([$SPL_SYMBOLS])
194 AC_SUBST(SPL_SYMBOLS)
198 dnl # Detect the SPL module to be built against
200 AC_DEFUN([ZFS_AC_SPL], [
202 AS_HELP_STRING([--with-spl=PATH],
203 [Path to spl source]),
206 AC_ARG_WITH([spl-obj],
207 AS_HELP_STRING([--with-spl-obj=PATH],
208 [Path to spl build objects]),
209 [splbuild="$withval"])
212 AC_MSG_CHECKING([spl source directory])
213 if test -z "$splsrc"; then
214 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
215 2>/dev/null | tail -1`
217 if test -z "$sourcelink" || test ! -e $sourcelink; then
221 if test -e $sourcelink; then
222 splsrc=`readlink -f ${sourcelink}`
224 AC_MSG_RESULT([Not found])
226 *** Please make sure the spl devel package for your distribution
227 *** is installed then try again. If that fails you can specify the
228 *** location of the spl source with the '--with-spl=PATH' option.])
231 if test "$splsrc" = "NONE"; then
237 AC_MSG_RESULT([$splsrc])
238 AC_MSG_CHECKING([spl build directory])
239 if test -z "$splbuild"; then
242 AC_MSG_RESULT([$splbuild])
244 AC_MSG_CHECKING([spl source version])
245 if test -r $splbuild/spl_config.h &&
246 fgrep -q SPL_META_VERSION $splbuild/spl_config.h; then
248 splsrcver=`(echo "#include <spl_config.h>";
249 echo "splsrcver=SPL_META_VERSION") |
251 grep "^splsrcver=" | cut -d \" -f 2`
254 if test -z "$splsrcver"; then
255 AC_MSG_RESULT([Not found])
257 *** Cannot determine the version of the spl source.
258 *** Please prepare the spl source before running this script])
261 AC_MSG_RESULT([$splsrcver])
265 SPL_VERSION=${splsrcver}
269 AC_SUBST(SPL_VERSION)
271 ZFS_AC_SPL_MODULE_SYMVERS
275 dnl # There are certain kernel build options which when enabled are
276 dnl # completely incompatible with non GPL kernel modules. It is best
277 dnl # to detect these at configure time and fail with a clear error
278 dnl # rather than build everything and fail during linking.
280 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
282 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
284 if test "$ZFS_META_LICENSE" = CDDL; then
285 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
287 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
288 *** incompatible with the CDDL license. You must rebuild
289 *** your kernel without this option.]), [])
292 if test "$ZFS_META_LICENSE" = GPL; then
293 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
294 [Define to 1 if licensed under the GPL])
299 dnl # ZFS_LINUX_CONFTEST
301 AC_DEFUN([ZFS_LINUX_CONFTEST], [
302 cat confdefs.h - <<_ACEOF >conftest.c
308 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
310 m4_define([ZFS_LANG_PROGRAM], [
315 dnl Do *not* indent the following line: there may be CPP directives.
316 dnl Don't move the `;' right after for the same reason.
324 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
326 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
327 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
328 rm -Rf build && mkdir -p build
329 echo "obj-m := conftest.o" >build/Makefile
331 [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])],
333 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
339 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
341 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
342 [ZFS_LINUX_COMPILE_IFELSE(
343 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
345 [test -s build/conftest.o],
350 dnl # ZFS_LINUX_CONFIG
352 AC_DEFUN([ZFS_LINUX_CONFIG],
353 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
354 ZFS_LINUX_TRY_COMPILE([
355 #ifndef AUTOCONF_INCLUDED
356 #include <linux/config.h>
360 #error CONFIG_$1 not #defined
372 dnl # ZFS_CHECK_SYMBOL_EXPORT
373 dnl # check symbol exported or not
375 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
376 [AC_MSG_CHECKING([whether symbol $1 is exported])
377 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
378 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
380 if test $rc -ne 0; then
383 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
385 if test $rc -eq 0; then
390 if test $export -eq 0; then