]> git.proxmox.com Git - mirror_zfs.git/blob - config/kernel.m4
Support parallel build trees (VPATH builds)
[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 ], [ find -L "${splsrc}" -name spl_config.h 2> /dev/null | grep -wq spl_config.h ], [
342 splbuild=$(find -L "${splsrc}" -name spl_config.h | sed 's,/spl_config.h,,')
343 ], [
344 splbuild="[Not found]"
345 ])
346 ])
347 AS_IF([test -e "$splbuild/spl_config.h" -o $timeout -le 0], [
348 break;
349 ], [
350 sleep 1
351 timeout=$((timeout-1))
352 ])
353 done
354
355 AC_MSG_RESULT([$splbuild])
356 AS_IF([ ! test -e "$splbuild/spl_config.h"], [
357 AC_MSG_ERROR([
358 *** Please make sure the kmod spl devel <kernel> package for your
359 *** distribution is installed then try again. If that fails you
360 *** can specify the location of the spl objects with the
361 *** '--with-spl-obj=PATH' option.])
362 ])
363
364 AC_MSG_CHECKING([spl source version])
365 AS_IF([test -r $splbuild/spl_config.h &&
366 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
367
368 splsrcver=`(echo "#include <spl_config.h>";
369 echo "splsrcver=SPL_META_VERSION-SPL_META_RELEASE") |
370 cpp -I $splbuild |
371 grep "^splsrcver=" | tr -d \" | cut -d= -f2`
372 ])
373
374 AS_IF([test -z "$splsrcver"], [
375 AC_MSG_RESULT([Not found])
376 AC_MSG_ERROR([
377 *** Cannot determine the version of the spl source.
378 *** Please prepare the spl source before running this script])
379 ])
380
381 AC_MSG_RESULT([$splsrcver])
382
383 SPL=${splsrc}
384 SPL_OBJ=${splbuild}
385 SPL_VERSION=${splsrcver}
386
387 AC_SUBST(SPL)
388 AC_SUBST(SPL_OBJ)
389 AC_SUBST(SPL_VERSION)
390
391 dnl #
392 dnl # Detect the name used for the SPL Module.symvers file. If one
393 dnl # does not exist this is likely because the SPL has been configured
394 dnl # but not built. The '--with-spl-timeout' option can be passed
395 dnl # to pause here, waiting for the file to appear from a concurrently
396 dnl # building SPL package. If the file does not appear in time, a good
397 dnl # guess is made as to what this file will be named based on what it
398 dnl # is named in the kernel build products. This file will first be
399 dnl # used at link time so if the guess is wrong the build will fail
400 dnl # then. This unfortunately means the ZFS package does not contain a
401 dnl # reliable mechanism to detect symbols exported by the SPL at
402 dnl # configure time.
403 dnl #
404 AC_MSG_CHECKING([spl file name for module symbols])
405 SPL_SYMBOLS=NONE
406
407 while true; do
408 AS_IF([test -r $SPL_OBJ/Module.symvers], [
409 SPL_SYMBOLS=Module.symvers
410 ], [test -r $SPL_OBJ/Modules.symvers], [
411 SPL_SYMBOLS=Modules.symvers
412 ], [test -r $SPL_OBJ/module/Module.symvers], [
413 SPL_SYMBOLS=Module.symvers
414 ], [test -r $SPL_OBJ/module/Modules.symvers], [
415 SPL_SYMBOLS=Modules.symvers
416 ])
417
418 AS_IF([test $SPL_SYMBOLS != NONE -o $timeout -le 0], [
419 break;
420 ], [
421 sleep 1
422 timeout=$((timeout-1))
423 ])
424 done
425
426 AS_IF([test "$SPL_SYMBOLS" = NONE], [
427 SPL_SYMBOLS=$LINUX_SYMBOLS
428 ])
429
430 AC_MSG_RESULT([$SPL_SYMBOLS])
431 AC_SUBST(SPL_SYMBOLS)
432 ])
433
434 dnl #
435 dnl # Basic toolchain sanity check.
436 dnl #
437 AC_DEFUN([ZFS_AC_TEST_MODULE], [
438 AC_MSG_CHECKING([whether modules can be built])
439 ZFS_LINUX_TRY_COMPILE([],[],[
440 AC_MSG_RESULT([yes])
441 ],[
442 AC_MSG_RESULT([no])
443 if test "x$enable_linux_builtin" != xyes; then
444 AC_MSG_ERROR([*** Unable to build an empty module.])
445 else
446 AC_MSG_ERROR([
447 *** Unable to build an empty module.
448 *** Please run 'make scripts' inside the kernel source tree.])
449 fi
450 ])
451 ])
452
453 dnl #
454 dnl # Certain kernel build options are not supported. These must be
455 dnl # detected at configure time and cause a build failure. Otherwise
456 dnl # modules may be successfully built that behave incorrectly.
457 dnl #
458 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
459 AC_RUN_IFELSE([
460 AC_LANG_PROGRAM([
461 #include "$LINUX/include/linux/license.h"
462 ], [
463 return !license_is_gpl_compatible("$ZFS_META_LICENSE");
464 ])
465 ], [
466 AC_DEFINE([ZFS_IS_GPL_COMPATIBLE], [1],
467 [Define to 1 if GPL-only symbols can be used])
468 ], [
469 ])
470
471 ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC
472 ])
473
474 dnl #
475 dnl # Check CONFIG_DEBUG_LOCK_ALLOC
476 dnl #
477 dnl # This is typically only set for debug kernels because it comes with
478 dnl # a performance penalty. However, when it is set it maps the non-GPL
479 dnl # symbol mutex_lock() to the GPL-only mutex_lock_nested() symbol.
480 dnl # This will cause a failure at link time which we'd rather know about
481 dnl # at compile time.
482 dnl #
483 dnl # Since we plan to pursue making mutex_lock_nested() a non-GPL symbol
484 dnl # with the upstream community we add a check to detect this case.
485 dnl #
486 AC_DEFUN([ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC], [
487
488 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC], [
489 AC_MSG_CHECKING([whether mutex_lock() is GPL-only])
490 tmp_flags="$EXTRA_KCFLAGS"
491 ZFS_LINUX_TRY_COMPILE([
492 #include <linux/module.h>
493 #include <linux/mutex.h>
494
495 MODULE_LICENSE("$ZFS_META_LICENSE");
496 ],[
497 struct mutex lock;
498
499 mutex_init(&lock);
500 mutex_lock(&lock);
501 mutex_unlock(&lock);
502 ],[
503 AC_MSG_RESULT(no)
504 ],[
505 AC_MSG_RESULT(yes)
506 AC_MSG_ERROR([
507 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is incompatible
508 *** with the CDDL license and will prevent the module linking stage
509 *** from succeeding. You must rebuild your kernel without this
510 *** option enabled.])
511 ])
512 EXTRA_KCFLAGS="$tmp_flags"
513 ], [])
514 ])
515
516 dnl #
517 dnl # ZFS_LINUX_CONFTEST_H
518 dnl #
519 AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
520 cat - <<_ACEOF >conftest.h
521 $1
522 _ACEOF
523 ])
524
525 dnl #
526 dnl # ZFS_LINUX_CONFTEST_C
527 dnl #
528 AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
529 cat confdefs.h - <<_ACEOF >conftest.c
530 $1
531 _ACEOF
532 ])
533
534 dnl #
535 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
536 dnl #
537 m4_define([ZFS_LANG_PROGRAM], [
538 $1
539 int
540 main (void)
541 {
542 dnl Do *not* indent the following line: there may be CPP directives.
543 dnl Don't move the `;' right after for the same reason.
544 $2
545 ;
546 return 0;
547 }
548 ])
549
550 dnl #
551 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
552 dnl #
553 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
554 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1])])
555 m4_ifvaln([$6], [ZFS_LINUX_CONFTEST_H([$6])], [ZFS_LINUX_CONFTEST_H([])])
556 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
557 echo "obj-m := conftest.o" >build/Makefile
558 modpost_flag=''
559 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
560 AS_IF(
561 [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])],
562 [$4],
563 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
564 )
565 rm -Rf build
566 ])
567
568 dnl #
569 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
570 dnl #
571 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
572 [ZFS_LINUX_COMPILE_IFELSE(
573 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
574 [modules],
575 [test -s build/conftest.o],
576 [$3], [$4])
577 ])
578
579 dnl #
580 dnl # ZFS_LINUX_CONFIG
581 dnl #
582 AC_DEFUN([ZFS_LINUX_CONFIG],
583 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
584 ZFS_LINUX_TRY_COMPILE([
585 #include <linux/module.h>
586 ],[
587 #ifndef CONFIG_$1
588 #error CONFIG_$1 not #defined
589 #endif
590 ],[
591 AC_MSG_RESULT([yes])
592 $2
593 ],[
594 AC_MSG_RESULT([no])
595 $3
596 ])
597 ])
598
599 dnl #
600 dnl # ZFS_CHECK_SYMBOL_EXPORT
601 dnl # check symbol exported or not
602 dnl #
603 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
604 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
605 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
606 rc=$?
607 if test $rc -ne 0; then
608 export=0
609 for file in $2; do
610 grep -q -E "EXPORT_SYMBOL.*($1)" \
611 "$LINUX/$file" 2>/dev/null
612 rc=$?
613 if test $rc -eq 0; then
614 export=1
615 break;
616 fi
617 done
618 if test $export -eq 0; then :
619 $4
620 else :
621 $3
622 fi
623 else :
624 $3
625 fi
626 ])
627
628 dnl #
629 dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
630 dnl # like ZFS_LINUX_TRY_COMPILE, except ZFS_CHECK_SYMBOL_EXPORT
631 dnl # is called if not compiling for builtin
632 dnl #
633 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
634 ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
635 if test $rc -ne 0; then :
636 $6
637 else
638 if test "x$enable_linux_builtin" != xyes; then
639 ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
640 fi
641 if test $rc -ne 0; then :
642 $6
643 else :
644 $5
645 fi
646 fi
647 ])
648
649 dnl #
650 dnl # ZFS_LINUX_TRY_COMPILE_HEADER
651 dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
652 dnl # provided via the fifth parameter
653 dnl #
654 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER],
655 [ZFS_LINUX_COMPILE_IFELSE(
656 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
657 [modules],
658 [test -s build/conftest.o],
659 [$3], [$4], [$5])
660 ])