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 if test -e "/lib/modules/$(uname -r)/source"; then
82 headersdir="/lib/modules/$(uname -r)/source"
83 sourcelink=$(readlink -f "$headersdir")
84 elif test -e "/lib/modules/$(uname -r)/build"; then
85 headersdir="/lib/modules/$(uname -r)/build"
86 sourcelink=$(readlink -f "$headersdir")
88 sourcelink=$(ls -1d /usr/src/kernels/* \
90 2>/dev/null | grep -v obj | tail -1)
93 if test -n "$sourcelink" && test -e ${sourcelink}; then
94 kernelsrc=`readlink -f ${sourcelink}`
96 AC_MSG_RESULT([Not found])
98 *** Please make sure the kernel devel package for your distribution
99 *** is installed then try again. If that fails you can specify the
100 *** location of the kernel source with the '--with-linux=PATH' option.])
103 if test "$kernelsrc" = "NONE"; then
108 AC_MSG_RESULT([$kernelsrc])
109 AC_MSG_CHECKING([kernel build directory])
110 if test -z "$kernelbuild"; then
111 if test -e "/lib/modules/$(uname -r)/build"; then
112 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
113 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
114 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
115 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
116 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
117 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
118 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
120 kernelbuild=${kernelsrc}
123 AC_MSG_RESULT([$kernelbuild])
125 AC_MSG_CHECKING([kernel source version])
126 utsrelease1=$kernelbuild/include/linux/version.h
127 utsrelease2=$kernelbuild/include/linux/utsrelease.h
128 utsrelease3=$kernelbuild/include/generated/utsrelease.h
129 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
130 utsrelease=linux/version.h
131 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
132 utsrelease=linux/utsrelease.h
133 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
134 utsrelease=generated/utsrelease.h
137 if test "$utsrelease"; then
138 kernsrcver=`(echo "#include <$utsrelease>";
139 echo "kernsrcver=UTS_RELEASE") |
140 cpp -I $kernelbuild/include |
141 grep "^kernsrcver=" | cut -d \" -f 2`
143 if test -z "$kernsrcver"; then
144 AC_MSG_RESULT([Not found])
145 AC_MSG_ERROR([*** Cannot determine kernel version.])
148 AC_MSG_RESULT([Not found])
149 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
152 AC_MSG_RESULT([$kernsrcver])
155 LINUX_OBJ=${kernelbuild}
156 LINUX_VERSION=${kernsrcver}
160 AC_SUBST(LINUX_VERSION)
162 ZFS_AC_MODULE_SYMVERS
166 dnl # Detect name used for the additional SPL Module.symvers file. If one
167 dnl # does not exist this is likely because the SPL has been configured
168 dnl # but not built. To allow recursive builds a good guess is made as to
169 dnl # what this file will be named based on what it is named in the kernel
170 dnl # build products. This file will first be used at link time so if
171 dnl # the guess is wrong the build will fail then. This unfortunately
172 dnl # means the ZFS package does not contain a reliable mechanism to
173 dnl # detect symbols exported by the SPL at configure time.
175 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
176 AC_MSG_CHECKING([spl file name for module symbols])
177 if test -r $SPL_OBJ/Module.symvers; then
178 SPL_SYMBOLS=Module.symvers
179 elif test -r $SPL_OBJ/Modules.symvers; then
180 SPL_SYMBOLS=Modules.symvers
181 elif test -r $SPL_OBJ/module/Module.symvers; then
182 SPL_SYMBOLS=Module.symvers
183 elif test -r $SPL_OBJ/module/Modules.symvers; then
184 SPL_SYMBOLS=Modules.symvers
186 SPL_SYMBOLS=$LINUX_SYMBOLS
189 AC_MSG_RESULT([$SPL_SYMBOLS])
190 AC_SUBST(SPL_SYMBOLS)
194 dnl # Detect the SPL module to be built against
196 AC_DEFUN([ZFS_AC_SPL], [
198 AS_HELP_STRING([--with-spl=PATH],
199 [Path to spl source]),
202 AC_ARG_WITH([spl-obj],
203 AS_HELP_STRING([--with-spl-obj=PATH],
204 [Path to spl build objects]),
205 [splbuild="$withval"])
208 AC_MSG_CHECKING([spl source directory])
209 if test -z "$splsrc"; then
210 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
211 2>/dev/null | tail -1`
213 if test -z "$sourcelink" || test ! -e $sourcelink; then
217 if test -e $sourcelink; then
218 splsrc=`readlink -f ${sourcelink}`
220 AC_MSG_RESULT([Not found])
222 *** Please make sure the spl devel package for your distribution
223 *** is installed then try again. If that fails you can specify the
224 *** location of the spl source with the '--with-spl=PATH' option.])
227 if test "$splsrc" = "NONE"; then
233 AC_MSG_RESULT([$splsrc])
234 AC_MSG_CHECKING([spl build directory])
235 if test -z "$splbuild"; then
238 AC_MSG_RESULT([$splbuild])
240 AC_MSG_CHECKING([spl source version])
241 if test -r $splbuild/spl_config.h &&
242 fgrep -q SPL_META_VERSION $splbuild/spl_config.h; then
244 splsrcver=`(echo "#include <spl_config.h>";
245 echo "splsrcver=SPL_META_VERSION") |
247 grep "^splsrcver=" | cut -d \" -f 2`
250 if test -z "$splsrcver"; then
251 AC_MSG_RESULT([Not found])
253 *** Cannot determine the version of the spl source.
254 *** Please prepare the spl source before running this script])
257 AC_MSG_RESULT([$splsrcver])
261 SPL_VERSION=${splsrcver}
265 AC_SUBST(SPL_VERSION)
267 ZFS_AC_SPL_MODULE_SYMVERS
271 dnl # There are certain kernel build options which when enabled are
272 dnl # completely incompatible with non GPL kernel modules. It is best
273 dnl # to detect these at configure time and fail with a clear error
274 dnl # rather than build everything and fail during linking.
276 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
278 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
280 if test "$ZFS_META_LICENSE" = CDDL; then
281 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
283 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
284 *** incompatible with the CDDL license. You must rebuild
285 *** your kernel without this option.]), [])
288 if test "$ZFS_META_LICENSE" = GPL; then
289 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
290 [Define to 1 if licensed under the GPL])
295 dnl # ZFS_LINUX_CONFTEST
297 AC_DEFUN([ZFS_LINUX_CONFTEST], [
298 cat confdefs.h - <<_ACEOF >conftest.c
304 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
306 m4_define([ZFS_LANG_PROGRAM], [
311 dnl Do *not* indent the following line: there may be CPP directives.
312 dnl Don't move the `;' right after for the same reason.
320 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
322 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
323 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
324 rm -Rf build && mkdir -p build
325 echo "obj-m := conftest.o" >build/Makefile
327 [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])],
329 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
335 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
337 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
338 [ZFS_LINUX_COMPILE_IFELSE(
339 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
341 [test -s build/conftest.o],
346 dnl # ZFS_LINUX_CONFIG
348 AC_DEFUN([ZFS_LINUX_CONFIG],
349 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
350 ZFS_LINUX_TRY_COMPILE([
351 #ifndef AUTOCONF_INCLUDED
352 #include <linux/config.h>
356 #error CONFIG_$1 not #defined
368 dnl # ZFS_CHECK_SYMBOL_EXPORT
369 dnl # check symbol exported or not
371 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
372 [AC_MSG_CHECKING([whether symbol $1 is exported])
373 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
374 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
376 if test $rc -ne 0; then
379 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
381 if test $rc -eq 0; then
386 if test $export -eq 0; then