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
32 if test "$LINUX_OBJ" != "$LINUX"; then
33 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
35 AC_SUBST(KERNELMAKE_PARAMS)
38 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
39 dnl # compiler options are added by the kernel build system.
40 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
41 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
43 AC_SUBST(KERNELCPPFLAGS)
47 dnl # Detect name used for Module.symvers file in kernel
49 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
50 modpost=$LINUX/scripts/Makefile.modpost
51 AC_MSG_CHECKING([kernel file name for module symbols])
52 if test -f "$modpost"; then
53 if grep -q Modules.symvers $modpost; then
54 LINUX_SYMBOLS=Modules.symvers
56 LINUX_SYMBOLS=Module.symvers
61 AC_MSG_RESULT($LINUX_SYMBOLS)
62 AC_SUBST(LINUX_SYMBOLS)
66 dnl # Detect the kernel to be built against
68 AC_DEFUN([ZFS_AC_KERNEL], [
70 AS_HELP_STRING([--with-linux=PATH],
71 [Path to kernel source]),
72 [kernelsrc="$withval"])
74 AC_ARG_WITH(linux-obj,
75 AS_HELP_STRING([--with-linux-obj=PATH],
76 [Path to kernel build objects]),
77 [kernelbuild="$withval"])
79 AC_MSG_CHECKING([kernel source directory])
80 if test -z "$kernelsrc"; then
81 headersdir="/lib/modules/$(uname -r)/build"
82 if test -e "$headersdir"; then
83 sourcelink=$(readlink -f "$headersdir")
85 sourcelink=$(ls -1d /usr/src/kernels/* \
87 2>/dev/null | grep -v obj | tail -1)
90 if test -n "$sourcelink" && test -e ${sourcelink}; then
91 kernelsrc=`readlink -f ${sourcelink}`
93 AC_MSG_RESULT([Not found])
95 *** Please make sure the kernel devel package for your distribution
96 *** is installed then try again. If that fails you can specify the
97 *** location of the kernel source with the '--with-linux=PATH' option.])
100 if test "$kernelsrc" = "NONE"; then
105 AC_MSG_RESULT([$kernelsrc])
106 AC_MSG_CHECKING([kernel build directory])
107 if test -z "$kernelbuild"; then
108 if test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
109 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
110 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
111 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
112 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
113 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
115 kernelbuild=${kernelsrc}
118 AC_MSG_RESULT([$kernelbuild])
120 AC_MSG_CHECKING([kernel source version])
121 utsrelease1=$kernelbuild/include/linux/version.h
122 utsrelease2=$kernelbuild/include/linux/utsrelease.h
123 utsrelease3=$kernelbuild/include/generated/utsrelease.h
124 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
125 utsrelease=linux/version.h
126 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
127 utsrelease=linux/utsrelease.h
128 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
129 utsrelease=generated/utsrelease.h
132 if test "$utsrelease"; then
133 kernsrcver=`(echo "#include <$utsrelease>";
134 echo "kernsrcver=UTS_RELEASE") |
135 cpp -I $kernelbuild/include |
136 grep "^kernsrcver=" | cut -d \" -f 2`
138 if test -z "$kernsrcver"; then
139 AC_MSG_RESULT([Not found])
140 AC_MSG_ERROR([*** Cannot determine kernel version.])
143 AC_MSG_RESULT([Not found])
144 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
147 AC_MSG_RESULT([$kernsrcver])
150 LINUX_OBJ=${kernelbuild}
151 LINUX_VERSION=${kernsrcver}
155 AC_SUBST(LINUX_VERSION)
157 ZFS_AC_MODULE_SYMVERS
161 dnl # Detect name used for the additional SPL Module.symvers file. If one
162 dnl # does not exist this is likely because the SPL has been configured
163 dnl # but not built. To allow recursive builds a good guess is made as to
164 dnl # what this file will be named based on what it is named in the kernel
165 dnl # build products. This file will first be used at link time so if
166 dnl # the guess is wrong the build will fail then. This unfortunately
167 dnl # means the ZFS package does not contain a reliable mechanism to
168 dnl # detect symbols exported by the SPL at configure time.
170 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
171 AC_MSG_CHECKING([spl file name for module symbols])
172 if test -r $SPL_OBJ/Module.symvers; then
173 SPL_SYMBOLS=Module.symvers
174 elif test -r $SPL_OBJ/Modules.symvers; then
175 SPL_SYMBOLS=Modules.symvers
176 elif test -r $SPL_OBJ/module/Module.symvers; then
177 SPL_SYMBOLS=Module.symvers
178 elif test -r $SPL_OBJ/module/Modules.symvers; then
179 SPL_SYMBOLS=Modules.symvers
181 SPL_SYMBOLS=$LINUX_SYMBOLS
184 AC_MSG_RESULT([$SPL_SYMBOLS])
185 AC_SUBST(SPL_SYMBOLS)
189 dnl # Detect the SPL module to be built against
191 AC_DEFUN([ZFS_AC_SPL], [
193 AS_HELP_STRING([--with-spl=PATH],
194 [Path to spl source]),
197 AC_ARG_WITH([spl-obj],
198 AS_HELP_STRING([--with-spl-obj=PATH],
199 [Path to spl build objects]),
200 [splbuild="$withval"])
203 AC_MSG_CHECKING([spl source directory])
204 if test -z "$splsrc"; then
205 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
206 2>/dev/null | tail -1`
208 if test -z "$sourcelink" || test ! -e $sourcelink; then
212 if test -e $sourcelink; then
213 splsrc=`readlink -f ${sourcelink}`
215 AC_MSG_RESULT([Not found])
217 *** Please make sure the spl devel package for your distribution
218 *** is installed then try again. If that fails you can specify the
219 *** location of the spl source with the '--with-spl=PATH' option.])
222 if test "$splsrc" = "NONE"; then
228 AC_MSG_RESULT([$splsrc])
229 AC_MSG_CHECKING([spl build directory])
230 if test -z "$splbuild"; then
233 AC_MSG_RESULT([$splbuild])
235 AC_MSG_CHECKING([spl source version])
236 if test -r $splbuild/spl_config.h &&
237 fgrep -q SPL_META_VERSION $splbuild/spl_config.h; then
239 splsrcver=`(echo "#include <spl_config.h>";
240 echo "splsrcver=SPL_META_VERSION") |
242 grep "^splsrcver=" | cut -d \" -f 2`
245 if test -z "$splsrcver"; then
246 AC_MSG_RESULT([Not found])
248 *** Cannot determine the version of the spl source.
249 *** Please prepare the spl source before running this script])
252 AC_MSG_RESULT([$splsrcver])
256 SPL_VERSION=${splsrcver}
260 AC_SUBST(SPL_VERSION)
262 ZFS_AC_SPL_MODULE_SYMVERS
266 dnl # There are certain kernel build options which when enabled are
267 dnl # completely incompatible with non GPL kernel modules. It is best
268 dnl # to detect these at configure time and fail with a clear error
269 dnl # rather than build everything and fail during linking.
271 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
273 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
275 if test "$ZFS_META_LICENSE" = CDDL; then
276 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
278 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
279 *** incompatible with the CDDL license. You must rebuild
280 *** your kernel without this option.]), [])
283 if test "$ZFS_META_LICENSE" = GPL; then
284 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
285 [Define to 1 if licensed under the GPL])
290 dnl # ZFS_LINUX_CONFTEST
292 AC_DEFUN([ZFS_LINUX_CONFTEST], [
293 cat confdefs.h - <<_ACEOF >conftest.c
299 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
301 m4_define([ZFS_LANG_PROGRAM], [
306 dnl Do *not* indent the following line: there may be CPP directives.
307 dnl Don't move the `;' right after for the same reason.
315 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
317 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
318 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
319 rm -Rf build && mkdir -p build
320 echo "obj-m := conftest.o" >build/Makefile
322 [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])],
324 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
330 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
332 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
333 [ZFS_LINUX_COMPILE_IFELSE(
334 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
336 [test -s build/conftest.o],
341 dnl # ZFS_LINUX_CONFIG
343 AC_DEFUN([ZFS_LINUX_CONFIG],
344 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
345 ZFS_LINUX_TRY_COMPILE([
346 #ifndef AUTOCONF_INCLUDED
347 #include <linux/config.h>
351 #error CONFIG_$1 not #defined
363 dnl # ZFS_CHECK_SYMBOL_EXPORT
364 dnl # check symbol exported or not
366 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
367 [AC_MSG_CHECKING([whether symbol $1 is exported])
368 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
369 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
371 if test $rc -ne 0; then
374 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
376 if test $rc -eq 0; then
381 if test $export -eq 0; then