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_END_IO_T_ARGS
16 ZFS_AC_KERNEL_BIO_RW_SYNCIO
17 ZFS_AC_KERNEL_BLK_END_REQUEST
18 ZFS_AC_KERNEL_BLK_FETCH_REQUEST
19 ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
20 ZFS_AC_KERNEL_BLK_RQ_BYTES
21 ZFS_AC_KERNEL_BLK_RQ_POS
22 ZFS_AC_KERNEL_BLK_RQ_SECTORS
23 ZFS_AC_KERNEL_GET_DISK_RO
24 ZFS_AC_KERNEL_RQ_IS_SYNC
25 ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
27 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
28 dnl # compiler options are added by the kernel build system.
29 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
30 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
31 KERNELCPPFLAGS="$KERNELCPPFLAGS -I$SPL"
32 KERNELCPPFLAGS="$KERNELCPPFLAGS -I$SPL/include"
33 KERNELCPPFLAGS="$KERNELCPPFLAGS -include $SPL/spl_config.h"
34 KERNELCPPFLAGS="$KERNELCPPFLAGS -include $TOPDIR/zfs_config.h"
36 if test "$LINUX_OBJ" != "$LINUX"; then
37 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
40 AC_SUBST(KERNELMAKE_PARAMS)
41 AC_SUBST(KERNELCPPFLAGS)
45 dnl # Detect name used for Module.symvers file in kernel
47 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
48 modpost=$LINUX/scripts/Makefile.modpost
49 AC_MSG_CHECKING([kernel file name for module symbols])
50 if test -f "$modpost"; then
51 if grep -q Modules.symvers $modpost; then
52 LINUX_SYMBOLS=Modules.symvers
54 LINUX_SYMBOLS=Module.symvers
59 AC_MSG_RESULT($LINUX_SYMBOLS)
60 AC_SUBST(LINUX_SYMBOLS)
64 dnl # Detect the kernel to be built against
66 AC_DEFUN([ZFS_AC_KERNEL], [
68 AS_HELP_STRING([--with-linux=PATH],
69 [Path to kernel source]),
70 [kernelsrc="$withval"])
72 AC_ARG_WITH(linux-obj,
73 AS_HELP_STRING([--with-linux-obj=PATH],
74 [Path to kernel build objects]),
75 [kernelbuild="$withval"])
77 AC_MSG_CHECKING([kernel source directory])
78 if test -z "$kernelsrc"; then
79 headersdir="/lib/modules/$(uname -r)/build"
80 if test -e "$headersdir"; then
81 sourcelink=$(readlink -f "$headersdir")
83 sourcelink=$(ls -1d /usr/src/kernels/* \
85 2>/dev/null | grep -v obj | tail -1)
88 if test -n "$sourcelink" && test -e ${sourcelink}; then
89 kernelsrc=`readlink -f ${sourcelink}`
91 AC_MSG_RESULT([Not found])
93 *** Please make sure the kernel devel package for your distribution
94 *** is installed then try again. If that fails you can specify the
95 *** location of the kernel source with the '--with-linux=PATH' option.])
98 if test "$kernelsrc" = "NONE"; then
103 AC_MSG_RESULT([$kernelsrc])
104 AC_MSG_CHECKING([kernel build directory])
105 if test -z "$kernelbuild"; then
106 if test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
107 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
108 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
109 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
110 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
111 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
113 kernelbuild=${kernelsrc}
116 AC_MSG_RESULT([$kernelbuild])
118 AC_MSG_CHECKING([kernel source version])
119 utsrelease1=$kernelbuild/include/linux/version.h
120 utsrelease2=$kernelbuild/include/linux/utsrelease.h
121 utsrelease3=$kernelbuild/include/generated/utsrelease.h
122 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
123 utsrelease=linux/version.h
124 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
125 utsrelease=linux/utsrelease.h
126 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
127 utsrelease=generated/utsrelease.h
130 if test "$utsrelease"; then
131 kernsrcver=`(echo "#include <$utsrelease>";
132 echo "kernsrcver=UTS_RELEASE") |
133 cpp -I $kernelbuild/include |
134 grep "^kernsrcver=" | cut -d \" -f 2`
136 if test -z "$kernsrcver"; then
137 AC_MSG_RESULT([Not found])
138 AC_MSG_ERROR([*** Cannot determine kernel version.])
141 AC_MSG_RESULT([Not found])
142 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
145 AC_MSG_RESULT([$kernsrcver])
148 LINUX_OBJ=${kernelbuild}
149 LINUX_VERSION=${kernsrcver}
153 AC_SUBST(LINUX_VERSION)
155 ZFS_AC_MODULE_SYMVERS
159 dnl # Detect name used for the additional SPL Module.symvers file. If one
160 dnl # does not exist this is likely because the SPL has been configured
161 dnl # but not built. To allow recursive builds a good guess is made as to
162 dnl # what this file will be named based on what it is named in the kernel
163 dnl # build products. This file will first be used at link time so if
164 dnl # the guess is wrong the build will fail then. This unfortunately
165 dnl # means the ZFS package does not contain a reliable mechanism to
166 dnl # detect symbols exported by the SPL at configure time.
168 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
169 AC_MSG_CHECKING([spl file name for module symbols])
170 if test -r $SPL_OBJ/Module.symvers; then
171 SPL_SYMBOLS=Module.symvers
172 elif test -r $SPL_OBJ/Modules.symvers; then
173 SPL_SYMBOLS=Modules.symvers
175 SPL_SYMBOLS=$LINUX_SYMBOLS
178 AC_MSG_RESULT([$SPL_SYMBOLS])
179 AC_SUBST(SPL_SYMBOLS)
183 dnl # Detect the SPL module to be built against
185 AC_DEFUN([ZFS_AC_SPL], [
187 AS_HELP_STRING([--with-spl=PATH],
188 [Path to spl source]),
191 AC_ARG_WITH([spl-obj],
192 AS_HELP_STRING([--with-spl-obj=PATH],
193 [Path to spl build objects]),
194 [splbuild="$withval"])
197 AC_MSG_CHECKING([spl source directory])
198 if test -z "$splsrc"; then
199 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
200 2>/dev/null | tail -1`
202 if test -z "$sourcelink" || test ! -e $sourcelink; then
206 if test -e $sourcelink; then
207 splsrc=`readlink -f ${sourcelink}`
209 AC_MSG_RESULT([Not found])
211 *** Please make sure the spl devel package for your distribution
212 *** is installed then try again. If that fails you can specify the
213 *** location of the spl source with the '--with-spl=PATH' option.])
216 if test "$splsrc" = "NONE"; then
222 AC_MSG_RESULT([$splsrc])
223 AC_MSG_CHECKING([spl build directory])
224 if test -z "$splbuild"; then
225 if test -d ${splsrc}/module; then
226 splbuild=${splsrc}/module
231 AC_MSG_RESULT([$splbuild])
233 AC_MSG_CHECKING([spl source version])
234 if test -r $splsrc/spl_config.h &&
235 fgrep -q SPL_META_VERSION $splsrc/spl_config.h; then
237 splsrcver=`(echo "#include <spl_config.h>";
238 echo "splsrcver=SPL_META_VERSION") |
240 grep "^splsrcver=" | cut -d \" -f 2`
243 if test -z "$splsrcver"; then
244 AC_MSG_RESULT([Not found])
246 *** Cannot determine the version of the spl source.
247 *** Please prepare the spl source before running this script])
250 AC_MSG_RESULT([$splsrcver])
254 SPL_VERSION=${splsrcver}
258 AC_SUBST(SPL_VERSION)
260 ZFS_AC_SPL_MODULE_SYMVERS
264 dnl # There are certain kernel build options which when enabled are
265 dnl # completely incompatible with non GPL kernel modules. It is best
266 dnl # to detect these at configure time and fail with a clear error
267 dnl # rather than build everything and fail during linking.
269 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
271 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
273 if test "$ZFS_META_LICENSE" = CDDL; then
274 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
276 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
277 *** incompatible with the CDDL license. You must rebuild
278 *** your kernel without this option.]), [])
281 if test "$ZFS_META_LICENSE" = GPL; then
282 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
283 [Define to 1 if licensed under the GPL])
288 dnl # ZFS_LINUX_CONFTEST
290 AC_DEFUN([ZFS_LINUX_CONFTEST], [
291 cat confdefs.h - <<_ACEOF >conftest.c
297 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
299 m4_define([ZFS_LANG_PROGRAM], [
304 dnl Do *not* indent the following line: there may be CPP directives.
305 dnl Don't move the `;' right after for the same reason.
313 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
315 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
316 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
317 rm -Rf build && mkdir -p build
318 echo "obj-m := conftest.o" >build/Makefile
320 [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])],
322 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
328 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
330 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
331 [ZFS_LINUX_COMPILE_IFELSE(
332 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
334 [test -s build/conftest.o],
339 dnl # ZFS_LINUX_CONFIG
341 AC_DEFUN([ZFS_LINUX_CONFIG],
342 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
343 ZFS_LINUX_TRY_COMPILE([
344 #ifndef AUTOCONF_INCLUDED
345 #include <linux/config.h>
349 #error CONFIG_$1 not #defined
361 dnl # ZFS_CHECK_SYMBOL_EXPORT
362 dnl # check symbol exported or not
364 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
365 [AC_MSG_CHECKING([whether symbol $1 is exported])
366 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
367 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
369 if test $rc -ne 0; then
372 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
374 if test $rc -eq 0; then
379 if test $export -eq 0; then