]> git.proxmox.com Git - mirror_zfs.git/blob - config/kernel.m4
5c97659c7b2598b93f3a4237d04b3c4d95fb58f0
[mirror_zfs.git] / config / kernel.m4
1 dnl #
2 dnl # Default ZFS kernel configuration
3 dnl #
4 AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5 ZFS_AC_KERNEL
6 ZFS_AC_SPL
7 ZFS_AC_TEST_MODULE
8 ZFS_AC_KERNEL_CONFIG
9 ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
10 ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
11 ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
12 ZFS_AC_KERNEL_TYPE_FMODE_T
13 ZFS_AC_KERNEL_KOBJ_NAME_LEN
14 ZFS_AC_KERNEL_3ARG_BLKDEV_GET
15 ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
16 ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
17 ZFS_AC_KERNEL_LOOKUP_BDEV
18 ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
19 ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
20 ZFS_AC_KERNEL_BDEV_PHYSICAL_BLOCK_SIZE
21 ZFS_AC_KERNEL_BIO_BVEC_ITER
22 ZFS_AC_KERNEL_BIO_FAILFAST_DTD
23 ZFS_AC_KERNEL_REQ_FAILFAST_MASK
24 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
25 ZFS_AC_KERNEL_BIO_RW_SYNC
26 ZFS_AC_KERNEL_BIO_RW_SYNCIO
27 ZFS_AC_KERNEL_REQ_SYNC
28 ZFS_AC_KERNEL_BLK_END_REQUEST
29 ZFS_AC_KERNEL_BLK_QUEUE_FLUSH
30 ZFS_AC_KERNEL_BLK_QUEUE_MAX_HW_SECTORS
31 ZFS_AC_KERNEL_BLK_QUEUE_MAX_SEGMENTS
32 ZFS_AC_KERNEL_BLK_QUEUE_PHYSICAL_BLOCK_SIZE
33 ZFS_AC_KERNEL_BLK_QUEUE_IO_OPT
34 ZFS_AC_KERNEL_BLK_QUEUE_NONROT
35 ZFS_AC_KERNEL_BLK_QUEUE_DISCARD
36 ZFS_AC_KERNEL_BLK_FETCH_REQUEST
37 ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
38 ZFS_AC_KERNEL_BLK_RQ_BYTES
39 ZFS_AC_KERNEL_BLK_RQ_POS
40 ZFS_AC_KERNEL_BLK_RQ_SECTORS
41 ZFS_AC_KERNEL_GET_DISK_RO
42 ZFS_AC_KERNEL_GET_GENDISK
43 ZFS_AC_KERNEL_RQ_IS_SYNC
44 ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
45 ZFS_AC_KERNEL_DISCARD_GRANULARITY
46 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
47 ZFS_AC_KERNEL_XATTR_HANDLER_GET
48 ZFS_AC_KERNEL_XATTR_HANDLER_SET
49 ZFS_AC_KERNEL_XATTR_HANDLER_LIST
50 ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
51 ZFS_AC_KERNEL_POSIX_ACL_FROM_XATTR_USERNS
52 ZFS_AC_KERNEL_POSIX_ACL_RELEASE
53 ZFS_AC_KERNEL_POSIX_ACL_CHMOD
54 ZFS_AC_KERNEL_POSIX_ACL_CACHING
55 ZFS_AC_KERNEL_POSIX_ACL_EQUIV_MODE_WANTS_UMODE_T
56 ZFS_AC_KERNEL_INODE_OPERATIONS_PERMISSION
57 ZFS_AC_KERNEL_INODE_OPERATIONS_PERMISSION_WITH_NAMEIDATA
58 ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL
59 ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL_WITH_FLAGS
60 ZFS_AC_KERNEL_INODE_OPERATIONS_GET_ACL
61 ZFS_AC_KERNEL_CURRENT_UMASK
62 ZFS_AC_KERNEL_SHOW_OPTIONS
63 ZFS_AC_KERNEL_FILE_INODE
64 ZFS_AC_KERNEL_FSYNC
65 ZFS_AC_KERNEL_EVICT_INODE
66 ZFS_AC_KERNEL_DIRTY_INODE_WITH_FLAGS
67 ZFS_AC_KERNEL_NR_CACHED_OBJECTS
68 ZFS_AC_KERNEL_FREE_CACHED_OBJECTS
69 ZFS_AC_KERNEL_FALLOCATE
70 ZFS_AC_KERNEL_MKDIR_UMODE_T
71 ZFS_AC_KERNEL_LOOKUP_NAMEIDATA
72 ZFS_AC_KERNEL_CREATE_NAMEIDATA
73 ZFS_AC_KERNEL_FOLLOW_LINK
74 ZFS_AC_KERNEL_PUT_LINK
75 ZFS_AC_KERNEL_TRUNCATE_RANGE
76 ZFS_AC_KERNEL_AUTOMOUNT
77 ZFS_AC_KERNEL_ENCODE_FH_WITH_INODE
78 ZFS_AC_KERNEL_COMMIT_METADATA
79 ZFS_AC_KERNEL_CLEAR_INODE
80 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
81 ZFS_AC_KERNEL_D_MAKE_ROOT
82 ZFS_AC_KERNEL_D_OBTAIN_ALIAS
83 ZFS_AC_KERNEL_D_PRUNE_ALIASES
84 ZFS_AC_KERNEL_D_SET_D_OP
85 ZFS_AC_KERNEL_D_REVALIDATE_NAMEIDATA
86 ZFS_AC_KERNEL_CONST_DENTRY_OPERATIONS
87 ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE
88 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
89 ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
90 ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY
91 ZFS_AC_KERNEL_MOUNT_NODEV
92 ZFS_AC_KERNEL_SHRINK
93 ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID
94 ZFS_AC_KERNEL_S_INSTANCES_LIST_HEAD
95 ZFS_AC_KERNEL_S_D_OP
96 ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER
97 ZFS_AC_KERNEL_SET_NLINK
98 ZFS_AC_KERNEL_ELEVATOR_CHANGE
99 ZFS_AC_KERNEL_5ARG_SGET
100 ZFS_AC_KERNEL_LSEEK_EXECUTE
101 ZFS_AC_KERNEL_VFS_ITERATE
102 ZFS_AC_KERNEL_VFS_RW_ITERATE
103
104 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
105 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
106 ])
107 AC_SUBST(KERNELMAKE_PARAMS)
108
109
110 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
111 dnl # compiler options are added by the kernel build system.
112 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
113 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_BOOL_COMPARE"
114 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
115 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
116
117 AC_SUBST(KERNELCPPFLAGS)
118 ])
119
120 dnl #
121 dnl # Detect name used for Module.symvers file in kernel
122 dnl #
123 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
124 modpost=$LINUX/scripts/Makefile.modpost
125 AC_MSG_CHECKING([kernel file name for module symbols])
126 AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
127 AS_IF([grep -q Modules.symvers $modpost], [
128 LINUX_SYMBOLS=Modules.symvers
129 ], [
130 LINUX_SYMBOLS=Module.symvers
131 ])
132
133 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
134 AC_MSG_ERROR([
135 *** Please make sure the kernel devel package for your distribution
136 *** is installed. If you are building with a custom kernel, make sure the
137 *** kernel is configured, built, and the '--with-linux=PATH' configure
138 *** option refers to the location of the kernel source.])
139 ])
140 ], [
141 LINUX_SYMBOLS=NONE
142 ])
143 AC_MSG_RESULT($LINUX_SYMBOLS)
144 AC_SUBST(LINUX_SYMBOLS)
145 ])
146
147 dnl #
148 dnl # Detect the kernel to be built against
149 dnl #
150 AC_DEFUN([ZFS_AC_KERNEL], [
151 AC_ARG_WITH([linux],
152 AS_HELP_STRING([--with-linux=PATH],
153 [Path to kernel source]),
154 [kernelsrc="$withval"])
155
156 AC_ARG_WITH(linux-obj,
157 AS_HELP_STRING([--with-linux-obj=PATH],
158 [Path to kernel build objects]),
159 [kernelbuild="$withval"])
160
161 AC_MSG_CHECKING([kernel source directory])
162 AS_IF([test -z "$kernelsrc"], [
163 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
164 headersdir="/lib/modules/$(uname -r)/source"
165 sourcelink=$(readlink -f "$headersdir")
166 ], [test -e "/lib/modules/$(uname -r)/build"], [
167 headersdir="/lib/modules/$(uname -r)/build"
168 sourcelink=$(readlink -f "$headersdir")
169 ], [
170 sourcelink=$(ls -1d /usr/src/kernels/* \
171 /usr/src/linux-* \
172 2>/dev/null | grep -v obj | tail -1)
173 ])
174
175 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
176 kernelsrc=`readlink -f ${sourcelink}`
177 ], [
178 kernelsrc="[Not found]"
179 ])
180 ], [
181 AS_IF([test "$kernelsrc" = "NONE"], [
182 kernsrcver=NONE
183 ])
184 ])
185
186 AC_MSG_RESULT([$kernelsrc])
187 AS_IF([test ! -d "$kernelsrc"], [
188 AC_MSG_ERROR([
189 *** Please make sure the kernel devel package for your distribution
190 *** is installed and then try again. If that fails, you can specify the
191 *** location of the kernel source with the '--with-linux=PATH' option.])
192 ])
193
194 AC_MSG_CHECKING([kernel build directory])
195 AS_IF([test -z "$kernelbuild"], [
196 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
197 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
198 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
199 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
200 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
201 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
202 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
203 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
204 ], [
205 kernelbuild=${kernelsrc}
206 ])
207 ])
208 AC_MSG_RESULT([$kernelbuild])
209
210 AC_MSG_CHECKING([kernel source version])
211 utsrelease1=$kernelbuild/include/linux/version.h
212 utsrelease2=$kernelbuild/include/linux/utsrelease.h
213 utsrelease3=$kernelbuild/include/generated/utsrelease.h
214 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
215 utsrelease=linux/version.h
216 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
217 utsrelease=linux/utsrelease.h
218 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
219 utsrelease=generated/utsrelease.h
220 ])
221
222 AS_IF([test "$utsrelease"], [
223 kernsrcver=`(echo "#include <$utsrelease>";
224 echo "kernsrcver=UTS_RELEASE") |
225 cpp -I $kernelbuild/include |
226 grep "^kernsrcver=" | cut -d \" -f 2`
227
228 AS_IF([test -z "$kernsrcver"], [
229 AC_MSG_RESULT([Not found])
230 AC_MSG_ERROR([*** Cannot determine kernel version.])
231 ])
232 ], [
233 AC_MSG_RESULT([Not found])
234 if test "x$enable_linux_builtin" != xyes; then
235 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
236 else
237 AC_MSG_ERROR([
238 *** Cannot find UTS_RELEASE definition.
239 *** Please run 'make prepare' inside the kernel source tree.])
240 fi
241 ])
242
243 AC_MSG_RESULT([$kernsrcver])
244
245 LINUX=${kernelsrc}
246 LINUX_OBJ=${kernelbuild}
247 LINUX_VERSION=${kernsrcver}
248
249 AC_SUBST(LINUX)
250 AC_SUBST(LINUX_OBJ)
251 AC_SUBST(LINUX_VERSION)
252
253 ZFS_AC_MODULE_SYMVERS
254 ])
255
256
257 dnl #
258 dnl # Detect the SPL module to be built against
259 dnl #
260 AC_DEFUN([ZFS_AC_SPL], [
261 AC_ARG_WITH([spl],
262 AS_HELP_STRING([--with-spl=PATH],
263 [Path to spl source]),
264 [splsrc="$withval"])
265
266 AC_ARG_WITH([spl-obj],
267 AS_HELP_STRING([--with-spl-obj=PATH],
268 [Path to spl build objects]),
269 [splbuild="$withval"])
270
271 AC_ARG_WITH([spl-timeout],
272 AS_HELP_STRING([--with-spl-timeout=SECS],
273 [Wait SECS for SPL header and symver file @<:@default=0@:>@]),
274 [timeout="$withval"], [timeout=0])
275
276 dnl #
277 dnl # The existence of spl.release.in is used to identify a valid
278 dnl # source directory. In order of preference:
279 dnl #
280 splsrc0="/var/lib/dkms/spl/${VERSION}/build"
281 splsrc1="/usr/local/src/spl-${VERSION}/${LINUX_VERSION}"
282 splsrc2="/usr/local/src/spl-${VERSION}"
283 splsrc3="/usr/src/spl-${VERSION}/${LINUX_VERSION}"
284 splsrc4="/usr/src/spl-${VERSION}"
285 splsrc5="../spl/"
286 splsrc6="$LINUX"
287
288 AC_MSG_CHECKING([spl source directory])
289 AS_IF([test -z "${splsrc}"], [
290 AS_IF([ test -e "${splsrc0}/spl.release.in"], [
291 splsrc=${splsrc0}
292 ], [ test -e "${splsrc1}/spl.release.in"], [
293 splsrc=${splsrc1}
294 ], [ test -e "${splsrc2}/spl.release.in"], [
295 splsrc=${splsrc2}
296 ], [ test -e "${splsrc3}/spl.release.in"], [
297 splsrc=$(readlink -f "${splsrc3}")
298 ], [ test -e "${splsrc4}/spl.release.in" ], [
299 splsrc=${splsrc4}
300 ], [ test -e "${splsrc5}/spl.release.in"], [
301 splsrc=$(readlink -f "${splsrc5}")
302 ], [ test -e "${splsrc6}/spl.release.in" ], [
303 splsrc=${splsrc6}
304 ], [
305 splsrc="[Not found]"
306 ])
307 ], [
308 AS_IF([test "$splsrc" = "NONE"], [
309 splbuild=NONE
310 splsrcver=NONE
311 ])
312 ])
313
314 AC_MSG_RESULT([$splsrc])
315 AS_IF([ test ! -e "$splsrc/spl.release.in"], [
316 AC_MSG_ERROR([
317 *** Please make sure the kmod spl devel package for your distribution
318 *** is installed then try again. If that fails you can specify the
319 *** location of the spl source with the '--with-spl=PATH' option.])
320 ])
321
322 dnl #
323 dnl # The existence of the spl_config.h is used to identify a valid
324 dnl # spl object directory. In many cases the object and source
325 dnl # directory are the same, however the objects may also reside
326 dnl # is a subdirectory named after the kernel version.
327 dnl #
328 dnl # This file is supposed to be available after DKMS finishes
329 dnl # building the SPL kernel module for the target kernel. The
330 dnl # '--with-spl-timeout' option can be passed to pause here,
331 dnl # waiting for the file to appear from a concurrently building
332 dnl # SPL package.
333 dnl #
334 AC_MSG_CHECKING([spl build directory])
335 while true; do
336 AS_IF([test -z "$splbuild"], [
337 AS_IF([ test -e "${splsrc}/${LINUX_VERSION}/spl_config.h" ], [
338 splbuild="${splsrc}/${LINUX_VERSION}"
339 ], [ test -e "${splsrc}/spl_config.h" ], [
340 splbuild="${splsrc}"
341 ], [
342 splbuild="[Not found]"
343 ])
344 ])
345 AS_IF([test -e "$splbuild/spl_config.h" -o $timeout -le 0], [
346 break;
347 ], [
348 sleep 1
349 timeout=$((timeout-1))
350 ])
351 done
352
353 AC_MSG_RESULT([$splbuild])
354 AS_IF([ ! test -e "$splbuild/spl_config.h"], [
355 AC_MSG_ERROR([
356 *** Please make sure the kmod spl devel <kernel> package for your
357 *** distribution is installed then try again. If that fails you
358 *** can specify the location of the spl objects with the
359 *** '--with-spl-obj=PATH' option.])
360 ])
361
362 AC_MSG_CHECKING([spl source version])
363 AS_IF([test -r $splbuild/spl_config.h &&
364 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
365
366 splsrcver=`(echo "#include <spl_config.h>";
367 echo "splsrcver=SPL_META_VERSION-SPL_META_RELEASE") |
368 cpp -I $splbuild |
369 grep "^splsrcver=" | tr -d \" | cut -d= -f2`
370 ])
371
372 AS_IF([test -z "$splsrcver"], [
373 AC_MSG_RESULT([Not found])
374 AC_MSG_ERROR([
375 *** Cannot determine the version of the spl source.
376 *** Please prepare the spl source before running this script])
377 ])
378
379 AC_MSG_RESULT([$splsrcver])
380
381 SPL=${splsrc}
382 SPL_OBJ=${splbuild}
383 SPL_VERSION=${splsrcver}
384
385 AC_SUBST(SPL)
386 AC_SUBST(SPL_OBJ)
387 AC_SUBST(SPL_VERSION)
388
389 dnl #
390 dnl # Detect the name used for the SPL Module.symvers file. If one
391 dnl # does not exist this is likely because the SPL has been configured
392 dnl # but not built. The '--with-spl-timeout' option can be passed
393 dnl # to pause here, waiting for the file to appear from a concurrently
394 dnl # building SPL package. If the file does not appear in time, a good
395 dnl # guess is made as to what this file will be named based on what it
396 dnl # is named in the kernel build products. This file will first be
397 dnl # used at link time so if the guess is wrong the build will fail
398 dnl # then. This unfortunately means the ZFS package does not contain a
399 dnl # reliable mechanism to detect symbols exported by the SPL at
400 dnl # configure time.
401 dnl #
402 AC_MSG_CHECKING([spl file name for module symbols])
403 SPL_SYMBOLS=NONE
404
405 while true; do
406 AS_IF([test -r $SPL_OBJ/Module.symvers], [
407 SPL_SYMBOLS=Module.symvers
408 ], [test -r $SPL_OBJ/Modules.symvers], [
409 SPL_SYMBOLS=Modules.symvers
410 ], [test -r $SPL_OBJ/module/Module.symvers], [
411 SPL_SYMBOLS=Module.symvers
412 ], [test -r $SPL_OBJ/module/Modules.symvers], [
413 SPL_SYMBOLS=Modules.symvers
414 ])
415
416 AS_IF([test $SPL_SYMBOLS != NONE -o $timeout -le 0], [
417 break;
418 ], [
419 sleep 1
420 timeout=$((timeout-1))
421 ])
422 done
423
424 AS_IF([test "$SPL_SYMBOLS" = NONE], [
425 SPL_SYMBOLS=$LINUX_SYMBOLS
426 ])
427
428 AC_MSG_RESULT([$SPL_SYMBOLS])
429 AC_SUBST(SPL_SYMBOLS)
430 ])
431
432 dnl #
433 dnl # Basic toolchain sanity check.
434 dnl #
435 AC_DEFUN([ZFS_AC_TEST_MODULE], [
436 AC_MSG_CHECKING([whether modules can be built])
437 ZFS_LINUX_TRY_COMPILE([],[],[
438 AC_MSG_RESULT([yes])
439 ],[
440 AC_MSG_RESULT([no])
441 if test "x$enable_linux_builtin" != xyes; then
442 AC_MSG_ERROR([*** Unable to build an empty module.])
443 else
444 AC_MSG_ERROR([
445 *** Unable to build an empty module.
446 *** Please run 'make scripts' inside the kernel source tree.])
447 fi
448 ])
449 ])
450
451 dnl #
452 dnl # Certain kernel build options are not supported. These must be
453 dnl # detected at configure time and cause a build failure. Otherwise
454 dnl # modules may be successfully built that behave incorrectly.
455 dnl #
456 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
457 AC_RUN_IFELSE([
458 AC_LANG_PROGRAM([
459 #include "$LINUX/include/linux/license.h"
460 ], [
461 return !license_is_gpl_compatible("$ZFS_META_LICENSE");
462 ])
463 ], [
464 AC_DEFINE([ZFS_IS_GPL_COMPATIBLE], [1],
465 [Define to 1 if GPL-only symbols can be used])
466 ], [
467 ])
468
469 ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC
470 ])
471
472 dnl #
473 dnl # Check CONFIG_DEBUG_LOCK_ALLOC
474 dnl #
475 dnl # This is typically only set for debug kernels because it comes with
476 dnl # a performance penalty. However, when it is set it maps the non-GPL
477 dnl # symbol mutex_lock() to the GPL-only mutex_lock_nested() symbol.
478 dnl # This will cause a failure at link time which we'd rather know about
479 dnl # at compile time.
480 dnl #
481 dnl # Since we plan to pursue making mutex_lock_nested() a non-GPL symbol
482 dnl # with the upstream community we add a check to detect this case.
483 dnl #
484 AC_DEFUN([ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC], [
485
486 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC], [
487 AC_MSG_CHECKING([whether mutex_lock() is GPL-only])
488 tmp_flags="$EXTRA_KCFLAGS"
489 ZFS_LINUX_TRY_COMPILE([
490 #include <linux/module.h>
491 #include <linux/mutex.h>
492
493 MODULE_LICENSE("$ZFS_META_LICENSE");
494 ],[
495 struct mutex lock;
496
497 mutex_init(&lock);
498 mutex_lock(&lock);
499 mutex_unlock(&lock);
500 ],[
501 AC_MSG_RESULT(no)
502 ],[
503 AC_MSG_RESULT(yes)
504 AC_MSG_ERROR([
505 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is incompatible
506 *** with the CDDL license and will prevent the module linking stage
507 *** from succeeding. You must rebuild your kernel without this
508 *** option enabled.])
509 ])
510 EXTRA_KCFLAGS="$tmp_flags"
511 ], [])
512 ])
513
514 dnl #
515 dnl # ZFS_LINUX_CONFTEST_H
516 dnl #
517 AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
518 cat - <<_ACEOF >conftest.h
519 $1
520 _ACEOF
521 ])
522
523 dnl #
524 dnl # ZFS_LINUX_CONFTEST_C
525 dnl #
526 AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
527 cat confdefs.h - <<_ACEOF >conftest.c
528 $1
529 _ACEOF
530 ])
531
532 dnl #
533 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
534 dnl #
535 m4_define([ZFS_LANG_PROGRAM], [
536 $1
537 int
538 main (void)
539 {
540 dnl Do *not* indent the following line: there may be CPP directives.
541 dnl Don't move the `;' right after for the same reason.
542 $2
543 ;
544 return 0;
545 }
546 ])
547
548 dnl #
549 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
550 dnl #
551 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
552 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1])])
553 m4_ifvaln([$6], [ZFS_LINUX_CONFTEST_H([$6])], [ZFS_LINUX_CONFTEST_H([])])
554 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
555 echo "obj-m := conftest.o" >build/Makefile
556 modpost_flag=''
557 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
558 AS_IF(
559 [AC_TRY_COMMAND(cp conftest.c conftest.h build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
560 [$4],
561 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
562 )
563 rm -Rf build
564 ])
565
566 dnl #
567 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
568 dnl #
569 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
570 [ZFS_LINUX_COMPILE_IFELSE(
571 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
572 [modules],
573 [test -s build/conftest.o],
574 [$3], [$4])
575 ])
576
577 dnl #
578 dnl # ZFS_LINUX_CONFIG
579 dnl #
580 AC_DEFUN([ZFS_LINUX_CONFIG],
581 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
582 ZFS_LINUX_TRY_COMPILE([
583 #include <linux/module.h>
584 ],[
585 #ifndef CONFIG_$1
586 #error CONFIG_$1 not #defined
587 #endif
588 ],[
589 AC_MSG_RESULT([yes])
590 $2
591 ],[
592 AC_MSG_RESULT([no])
593 $3
594 ])
595 ])
596
597 dnl #
598 dnl # ZFS_CHECK_SYMBOL_EXPORT
599 dnl # check symbol exported or not
600 dnl #
601 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
602 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
603 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
604 rc=$?
605 if test $rc -ne 0; then
606 export=0
607 for file in $2; do
608 grep -q -E "EXPORT_SYMBOL.*($1)" \
609 "$LINUX/$file" 2>/dev/null
610 rc=$?
611 if test $rc -eq 0; then
612 export=1
613 break;
614 fi
615 done
616 if test $export -eq 0; then :
617 $4
618 else :
619 $3
620 fi
621 else :
622 $3
623 fi
624 ])
625
626 dnl #
627 dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
628 dnl # like ZFS_LINUX_TRY_COMPILE, except ZFS_CHECK_SYMBOL_EXPORT
629 dnl # is called if not compiling for builtin
630 dnl #
631 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
632 ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
633 if test $rc -ne 0; then :
634 $6
635 else
636 if test "x$enable_linux_builtin" != xyes; then
637 ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
638 fi
639 if test $rc -ne 0; then :
640 $6
641 else :
642 $5
643 fi
644 fi
645 ])
646
647 dnl #
648 dnl # ZFS_LINUX_TRY_COMPILE_HEADER
649 dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
650 dnl # provided via the fifth parameter
651 dnl #
652 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER],
653 [ZFS_LINUX_COMPILE_IFELSE(
654 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
655 [modules],
656 [test -s build/conftest.o],
657 [$3], [$4], [$5])
658 ])