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
33 if test "$LINUX_OBJ" != "$LINUX"; then
34 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
36 AC_SUBST(KERNELMAKE_PARAMS)
39 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
40 dnl # compiler options are added by the kernel build system.
41 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
42 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
44 AC_SUBST(KERNELCPPFLAGS)
48 dnl # Detect name used for Module.symvers file in kernel
50 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
51 modpost=$LINUX/scripts/Makefile.modpost
52 AC_MSG_CHECKING([kernel file name for module symbols])
53 if test -f "$modpost"; then
54 if grep -q Modules.symvers $modpost; then
55 LINUX_SYMBOLS=Modules.symvers
57 LINUX_SYMBOLS=Module.symvers
62 AC_MSG_RESULT($LINUX_SYMBOLS)
63 AC_SUBST(LINUX_SYMBOLS)
67 dnl # Detect the kernel to be built against
69 AC_DEFUN([ZFS_AC_KERNEL], [
71 AS_HELP_STRING([--with-linux=PATH],
72 [Path to kernel source]),
73 [kernelsrc="$withval"])
75 AC_ARG_WITH(linux-obj,
76 AS_HELP_STRING([--with-linux-obj=PATH],
77 [Path to kernel build objects]),
78 [kernelbuild="$withval"])
80 AC_MSG_CHECKING([kernel source directory])
81 if test -z "$kernelsrc"; then
82 if test -e "/lib/modules/$(uname -r)/source"; then
83 headersdir="/lib/modules/$(uname -r)/source"
84 sourcelink=$(readlink -f "$headersdir")
85 elif test -e "/lib/modules/$(uname -r)/build"; then
86 headersdir="/lib/modules/$(uname -r)/build"
87 sourcelink=$(readlink -f "$headersdir")
89 sourcelink=$(ls -1d /usr/src/kernels/* \
91 2>/dev/null | grep -v obj | tail -1)
94 if test -n "$sourcelink" && test -e ${sourcelink}; then
95 kernelsrc=`readlink -f ${sourcelink}`
97 AC_MSG_RESULT([Not found])
99 *** Please make sure the kernel devel package for your distribution
100 *** is installed then try again. If that fails you can specify the
101 *** location of the kernel source with the '--with-linux=PATH' option.])
104 if test "$kernelsrc" = "NONE"; then
109 AC_MSG_RESULT([$kernelsrc])
110 AC_MSG_CHECKING([kernel build directory])
111 if test -z "$kernelbuild"; then
112 if test -e "/lib/modules/$(uname -r)/build"; then
113 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
114 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
115 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
116 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
117 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
118 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
119 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
121 kernelbuild=${kernelsrc}
124 AC_MSG_RESULT([$kernelbuild])
126 AC_MSG_CHECKING([kernel source version])
127 utsrelease1=$kernelbuild/include/linux/version.h
128 utsrelease2=$kernelbuild/include/linux/utsrelease.h
129 utsrelease3=$kernelbuild/include/generated/utsrelease.h
130 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
131 utsrelease=linux/version.h
132 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
133 utsrelease=linux/utsrelease.h
134 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
135 utsrelease=generated/utsrelease.h
138 if test "$utsrelease"; then
139 kernsrcver=`(echo "#include <$utsrelease>";
140 echo "kernsrcver=UTS_RELEASE") |
141 cpp -I $kernelbuild/include |
142 grep "^kernsrcver=" | cut -d \" -f 2`
144 if test -z "$kernsrcver"; then
145 AC_MSG_RESULT([Not found])
146 AC_MSG_ERROR([*** Cannot determine kernel version.])
149 AC_MSG_RESULT([Not found])
150 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
153 AC_MSG_RESULT([$kernsrcver])
156 LINUX_OBJ=${kernelbuild}
157 LINUX_VERSION=${kernsrcver}
161 AC_SUBST(LINUX_VERSION)
163 ZFS_AC_MODULE_SYMVERS
167 dnl # Detect name used for the additional SPL Module.symvers file. If one
168 dnl # does not exist this is likely because the SPL has been configured
169 dnl # but not built. To allow recursive builds a good guess is made as to
170 dnl # what this file will be named based on what it is named in the kernel
171 dnl # build products. This file will first be used at link time so if
172 dnl # the guess is wrong the build will fail then. This unfortunately
173 dnl # means the ZFS package does not contain a reliable mechanism to
174 dnl # detect symbols exported by the SPL at configure time.
176 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
177 AC_MSG_CHECKING([spl file name for module symbols])
178 if test -r $SPL_OBJ/Module.symvers; then
179 SPL_SYMBOLS=Module.symvers
180 elif test -r $SPL_OBJ/Modules.symvers; then
181 SPL_SYMBOLS=Modules.symvers
182 elif test -r $SPL_OBJ/module/Module.symvers; then
183 SPL_SYMBOLS=Module.symvers
184 elif test -r $SPL_OBJ/module/Modules.symvers; then
185 SPL_SYMBOLS=Modules.symvers
187 SPL_SYMBOLS=$LINUX_SYMBOLS
190 AC_MSG_RESULT([$SPL_SYMBOLS])
191 AC_SUBST(SPL_SYMBOLS)
195 dnl # Detect the SPL module to be built against
197 AC_DEFUN([ZFS_AC_SPL], [
199 AS_HELP_STRING([--with-spl=PATH],
200 [Path to spl source]),
203 AC_ARG_WITH([spl-obj],
204 AS_HELP_STRING([--with-spl-obj=PATH],
205 [Path to spl build objects]),
206 [splbuild="$withval"])
209 AC_MSG_CHECKING([spl source directory])
210 if test -z "$splsrc"; then
211 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
212 2>/dev/null | tail -1`
214 if test -z "$sourcelink" || test ! -e $sourcelink; then
218 if test -e $sourcelink; then
219 splsrc=`readlink -f ${sourcelink}`
221 AC_MSG_RESULT([Not found])
223 *** Please make sure the spl devel package for your distribution
224 *** is installed then try again. If that fails you can specify the
225 *** location of the spl source with the '--with-spl=PATH' option.])
228 if test "$splsrc" = "NONE"; then
234 AC_MSG_RESULT([$splsrc])
235 AC_MSG_CHECKING([spl build directory])
236 if test -z "$splbuild"; then
239 AC_MSG_RESULT([$splbuild])
241 AC_MSG_CHECKING([spl source version])
242 if test -r $splbuild/spl_config.h &&
243 fgrep -q SPL_META_VERSION $splbuild/spl_config.h; then
245 splsrcver=`(echo "#include <spl_config.h>";
246 echo "splsrcver=SPL_META_VERSION") |
248 grep "^splsrcver=" | cut -d \" -f 2`
251 if test -z "$splsrcver"; then
252 AC_MSG_RESULT([Not found])
254 *** Cannot determine the version of the spl source.
255 *** Please prepare the spl source before running this script])
258 AC_MSG_RESULT([$splsrcver])
262 SPL_VERSION=${splsrcver}
266 AC_SUBST(SPL_VERSION)
268 ZFS_AC_SPL_MODULE_SYMVERS
272 dnl # There are certain kernel build options which when enabled are
273 dnl # completely incompatible with non GPL kernel modules. It is best
274 dnl # to detect these at configure time and fail with a clear error
275 dnl # rather than build everything and fail during linking.
277 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
279 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
281 if test "$ZFS_META_LICENSE" = CDDL; then
282 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
284 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
285 *** incompatible with the CDDL license. You must rebuild
286 *** your kernel without this option.]), [])
289 if test "$ZFS_META_LICENSE" = GPL; then
290 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
291 [Define to 1 if licensed under the GPL])
296 dnl # ZFS_LINUX_CONFTEST
298 AC_DEFUN([ZFS_LINUX_CONFTEST], [
299 cat confdefs.h - <<_ACEOF >conftest.c
305 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
307 m4_define([ZFS_LANG_PROGRAM], [
312 dnl Do *not* indent the following line: there may be CPP directives.
313 dnl Don't move the `;' right after for the same reason.
321 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
323 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
324 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
325 rm -Rf build && mkdir -p build
326 echo "obj-m := conftest.o" >build/Makefile
328 [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])],
330 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
336 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
338 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
339 [ZFS_LINUX_COMPILE_IFELSE(
340 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
342 [test -s build/conftest.o],
347 dnl # ZFS_LINUX_CONFIG
349 AC_DEFUN([ZFS_LINUX_CONFIG],
350 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
351 ZFS_LINUX_TRY_COMPILE([
352 #ifndef AUTOCONF_INCLUDED
353 #include <linux/config.h>
357 #error CONFIG_$1 not #defined
369 dnl # ZFS_CHECK_SYMBOL_EXPORT
370 dnl # check symbol exported or not
372 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
373 [AC_MSG_CHECKING([whether symbol $1 is exported])
374 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
375 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
377 if test $rc -ne 0; then
380 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
382 if test $rc -eq 0; then
387 if test $export -eq 0; then