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