]> git.proxmox.com Git - mirror_zfs-debian.git/blame - config/kernel.m4
Move Arch Linux's VENDOR check above Ubuntu's
[mirror_zfs-debian.git] / config / kernel.m4
CommitLineData
c9c0d073
BB
1dnl #
2dnl # Default ZFS kernel configuration
3dnl #
4AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5 ZFS_AC_KERNEL
6 ZFS_AC_SPL
7 ZFS_AC_KERNEL_CONFIG
8 ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
9 ZFS_AC_KERNEL_TYPE_FMODE_T
10 ZFS_AC_KERNEL_KOBJ_NAME_LEN
45066d1f 11 ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
c9c0d073
BB
12 ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
13 ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
14 ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
15 ZFS_AC_KERNEL_BIO_EMPTY_BARRIER
2959d94a 16 ZFS_AC_KERNEL_BIO_FAILFAST
f4af6bb7
BB
17 ZFS_AC_KERNEL_BIO_FAILFAST_DTD
18 ZFS_AC_KERNEL_REQ_FAILFAST_MASK
c9c0d073 19 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
675de5aa 20 ZFS_AC_KERNEL_BIO_RW_SYNC
c9c0d073 21 ZFS_AC_KERNEL_BIO_RW_SYNCIO
675de5aa 22 ZFS_AC_KERNEL_REQ_SYNC
c9c0d073
BB
23 ZFS_AC_KERNEL_BLK_END_REQUEST
24 ZFS_AC_KERNEL_BLK_FETCH_REQUEST
25 ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
26 ZFS_AC_KERNEL_BLK_RQ_BYTES
27 ZFS_AC_KERNEL_BLK_RQ_POS
28 ZFS_AC_KERNEL_BLK_RQ_SECTORS
29 ZFS_AC_KERNEL_GET_DISK_RO
30 ZFS_AC_KERNEL_RQ_IS_SYNC
31 ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
777d4af8 32 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
f9637c6c
BB
33 ZFS_AC_KERNEL_XATTR_HANDLER_GET
34 ZFS_AC_KERNEL_XATTR_HANDLER_SET
adcd70bd 35 ZFS_AC_KERNEL_FSYNC
2c395def 36 ZFS_AC_KERNEL_EVICT_INODE
bdf4328b 37 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
055656d4 38 ZFS_AC_KERNEL_D_OBTAIN_ALIAS
df554c14 39 ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE
b3129792 40 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
5c03efc3 41 ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
2cf7f52b 42 ZFS_AC_KERNEL_MOUNT_NODEV
76659dc1 43 ZFS_AC_KERNEL_BDI
5547c2f1 44 ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER
28eb9213 45 ZFS_AC_KERNEL_SET_NLINK
c9c0d073 46
8366cd6a 47 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
6283f55e 48 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
8366cd6a 49 ])
6283f55e
BB
50 AC_SUBST(KERNELMAKE_PARAMS)
51
52
c9c0d073
BB
53 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
54 dnl # compiler options are added by the kernel build system.
8a7e1cee 55 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
c9c0d073
BB
56 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
57 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
c9c0d073 58
c9c0d073
BB
59 AC_SUBST(KERNELCPPFLAGS)
60])
61
62dnl #
63dnl # Detect name used for Module.symvers file in kernel
64dnl #
65AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
66 modpost=$LINUX/scripts/Makefile.modpost
67 AC_MSG_CHECKING([kernel file name for module symbols])
8366cd6a
PS
68 AS_IF([test -f "$modpost"], [
69 AS_IF([grep -q Modules.symvers $modpost], [
c9c0d073 70 LINUX_SYMBOLS=Modules.symvers
8366cd6a 71 ], [
c9c0d073 72 LINUX_SYMBOLS=Module.symvers
8366cd6a 73 ])
a60b1c0a 74
8366cd6a 75 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
a60b1c0a
BB
76 AC_MSG_ERROR([
77 *** Please make sure the kernel devel package for your distribution
78 *** is installed. If your building with a custom kernel make sure the
79 *** kernel is configured, built, and the '--with-linux=PATH' configure
80 *** option refers to the location of the kernel source.])
8366cd6a
PS
81 ])
82 ], [
c9c0d073 83 LINUX_SYMBOLS=NONE
8366cd6a 84 ])
c9c0d073
BB
85 AC_MSG_RESULT($LINUX_SYMBOLS)
86 AC_SUBST(LINUX_SYMBOLS)
87])
88
89dnl #
90dnl # Detect the kernel to be built against
91dnl #
92AC_DEFUN([ZFS_AC_KERNEL], [
93 AC_ARG_WITH([linux],
94 AS_HELP_STRING([--with-linux=PATH],
95 [Path to kernel source]),
96 [kernelsrc="$withval"])
97
98 AC_ARG_WITH(linux-obj,
99 AS_HELP_STRING([--with-linux-obj=PATH],
100 [Path to kernel build objects]),
101 [kernelbuild="$withval"])
102
103 AC_MSG_CHECKING([kernel source directory])
8366cd6a
PS
104 AS_IF([test -z "$kernelsrc"], [
105 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
1b94c25c
BB
106 headersdir="/lib/modules/$(uname -r)/source"
107 sourcelink=$(readlink -f "$headersdir")
8366cd6a 108 ], [test -e "/lib/modules/$(uname -r)/build"], [
1b94c25c 109 headersdir="/lib/modules/$(uname -r)/build"
c9c0d073 110 sourcelink=$(readlink -f "$headersdir")
8366cd6a 111 ], [
c9c0d073 112 sourcelink=$(ls -1d /usr/src/kernels/* \
8366cd6a 113 /usr/src/linux-* \
c9c0d073 114 2>/dev/null | grep -v obj | tail -1)
8366cd6a 115 ])
c9c0d073 116
8366cd6a 117 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
c9c0d073 118 kernelsrc=`readlink -f ${sourcelink}`
8366cd6a 119 ], [
c9c0d073
BB
120 AC_MSG_RESULT([Not found])
121 AC_MSG_ERROR([
122 *** Please make sure the kernel devel package for your distribution
123 *** is installed then try again. If that fails you can specify the
124 *** location of the kernel source with the '--with-linux=PATH' option.])
8366cd6a
PS
125 ])
126 ], [
127 AS_IF([test "$kernelsrc" = "NONE"], [
c9c0d073 128 kernsrcver=NONE
8366cd6a
PS
129 ])
130 ])
c9c0d073
BB
131
132 AC_MSG_RESULT([$kernelsrc])
133 AC_MSG_CHECKING([kernel build directory])
8366cd6a
PS
134 AS_IF([test -z "$kernelbuild"], [
135 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
1b94c25c 136 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
8366cd6a 137 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
c9c0d073 138 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
8366cd6a 139 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
c9c0d073 140 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
8366cd6a 141 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
c9c0d073 142 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
8366cd6a 143 ], [
c9c0d073 144 kernelbuild=${kernelsrc}
8366cd6a
PS
145 ])
146 ])
c9c0d073
BB
147 AC_MSG_RESULT([$kernelbuild])
148
149 AC_MSG_CHECKING([kernel source version])
150 utsrelease1=$kernelbuild/include/linux/version.h
151 utsrelease2=$kernelbuild/include/linux/utsrelease.h
152 utsrelease3=$kernelbuild/include/generated/utsrelease.h
8366cd6a 153 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
c9c0d073 154 utsrelease=linux/version.h
8366cd6a 155 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
c9c0d073 156 utsrelease=linux/utsrelease.h
8366cd6a 157 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
c9c0d073 158 utsrelease=generated/utsrelease.h
8366cd6a 159 ])
c9c0d073 160
8366cd6a 161 AS_IF([test "$utsrelease"], [
c9c0d073
BB
162 kernsrcver=`(echo "#include <$utsrelease>";
163 echo "kernsrcver=UTS_RELEASE") |
164 cpp -I $kernelbuild/include |
165 grep "^kernsrcver=" | cut -d \" -f 2`
166
8366cd6a 167 AS_IF([test -z "$kernsrcver"], [
c9c0d073
BB
168 AC_MSG_RESULT([Not found])
169 AC_MSG_ERROR([*** Cannot determine kernel version.])
8366cd6a
PS
170 ])
171 ], [
c9c0d073
BB
172 AC_MSG_RESULT([Not found])
173 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
8366cd6a 174 ])
c9c0d073
BB
175
176 AC_MSG_RESULT([$kernsrcver])
177
178 LINUX=${kernelsrc}
179 LINUX_OBJ=${kernelbuild}
180 LINUX_VERSION=${kernsrcver}
181
182 AC_SUBST(LINUX)
183 AC_SUBST(LINUX_OBJ)
184 AC_SUBST(LINUX_VERSION)
185
186 ZFS_AC_MODULE_SYMVERS
187])
188
189dnl #
190dnl # Detect name used for the additional SPL Module.symvers file. If one
191dnl # does not exist this is likely because the SPL has been configured
192dnl # but not built. To allow recursive builds a good guess is made as to
193dnl # what this file will be named based on what it is named in the kernel
194dnl # build products. This file will first be used at link time so if
195dnl # the guess is wrong the build will fail then. This unfortunately
196dnl # means the ZFS package does not contain a reliable mechanism to
197dnl # detect symbols exported by the SPL at configure time.
198dnl #
199AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
200 AC_MSG_CHECKING([spl file name for module symbols])
8366cd6a 201 AS_IF([test -r $SPL_OBJ/Module.symvers], [
c9c0d073 202 SPL_SYMBOLS=Module.symvers
8366cd6a 203 ], [test -r $SPL_OBJ/Modules.symvers], [
c9c0d073 204 SPL_SYMBOLS=Modules.symvers
8366cd6a 205 ], [test -r $SPL_OBJ/module/Module.symvers], [
6283f55e 206 SPL_SYMBOLS=Module.symvers
8366cd6a 207 ], [test -r $SPL_OBJ/module/Modules.symvers], [
6283f55e 208 SPL_SYMBOLS=Modules.symvers
8366cd6a 209 ], [
c9c0d073 210 SPL_SYMBOLS=$LINUX_SYMBOLS
8366cd6a 211 ])
c9c0d073
BB
212
213 AC_MSG_RESULT([$SPL_SYMBOLS])
214 AC_SUBST(SPL_SYMBOLS)
215])
216
217dnl #
218dnl # Detect the SPL module to be built against
219dnl #
220AC_DEFUN([ZFS_AC_SPL], [
221 AC_ARG_WITH([spl],
222 AS_HELP_STRING([--with-spl=PATH],
223 [Path to spl source]),
224 [splsrc="$withval"])
225
226 AC_ARG_WITH([spl-obj],
227 AS_HELP_STRING([--with-spl-obj=PATH],
228 [Path to spl build objects]),
229 [splbuild="$withval"])
230
231
232 AC_MSG_CHECKING([spl source directory])
8366cd6a 233 AS_IF([test -z "$splsrc"], [
c9c0d073
BB
234 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
235 2>/dev/null | tail -1`
236
8366cd6a 237 AS_IF([test -z "$sourcelink" || test ! -e $sourcelink], [
c9c0d073 238 sourcelink=../spl
8366cd6a 239 ])
c9c0d073 240
8366cd6a 241 AS_IF([test -e $sourcelink], [
c9c0d073 242 splsrc=`readlink -f ${sourcelink}`
8366cd6a 243 ], [
c9c0d073
BB
244 AC_MSG_RESULT([Not found])
245 AC_MSG_ERROR([
246 *** Please make sure the spl devel package for your distribution
247 *** is installed then try again. If that fails you can specify the
248 *** location of the spl source with the '--with-spl=PATH' option.])
8366cd6a
PS
249 ])
250 ], [
251 AS_IF([test "$splsrc" = "NONE"], [
c9c0d073
BB
252 splbuild=NONE
253 splsrcver=NONE
8366cd6a
PS
254 ])
255 ])
c9c0d073
BB
256
257 AC_MSG_RESULT([$splsrc])
258 AC_MSG_CHECKING([spl build directory])
8366cd6a 259 AS_IF([test -z "$splbuild"], [
6283f55e 260 splbuild=${splsrc}
8366cd6a 261 ])
c9c0d073
BB
262 AC_MSG_RESULT([$splbuild])
263
264 AC_MSG_CHECKING([spl source version])
8366cd6a
PS
265 AS_IF([test -r $splbuild/spl_config.h &&
266 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
c9c0d073
BB
267
268 splsrcver=`(echo "#include <spl_config.h>";
269 echo "splsrcver=SPL_META_VERSION") |
5e612145 270 cpp -I $splbuild |
c9c0d073 271 grep "^splsrcver=" | cut -d \" -f 2`
8366cd6a 272 ])
c9c0d073 273
8366cd6a 274 AS_IF([test -z "$splsrcver"], [
c9c0d073
BB
275 AC_MSG_RESULT([Not found])
276 AC_MSG_ERROR([
2984e0bb
PS
277 *** Cannot determine the version of the spl source.
278 *** Please prepare the spl source before running this script])
8366cd6a 279 ])
c9c0d073
BB
280
281 AC_MSG_RESULT([$splsrcver])
282
283 SPL=${splsrc}
284 SPL_OBJ=${splbuild}
285 SPL_VERSION=${splsrcver}
286
287 AC_SUBST(SPL)
288 AC_SUBST(SPL_OBJ)
289 AC_SUBST(SPL_VERSION)
290
291 ZFS_AC_SPL_MODULE_SYMVERS
292])
293
15805c77
BB
294dnl #
295dnl # Certain kernel build options are not supported. These must be
296dnl # detected at configure time and cause a build failure. Otherwise
297dnl # modules may be successfully built that behave incorrectly.
298dnl #
299dnl # CONFIG_PREEMPT - Preempt kernels require special handling.
c9c0d073
BB
300dnl #
301dnl # There are certain kernel build options which when enabled are
302dnl # completely incompatible with non GPL kernel modules. It is best
303dnl # to detect these at configure time and fail with a clear error
304dnl # rather than build everything and fail during linking.
305dnl #
306dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
307dnl #
308AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
309
15805c77
BB
310 ZFS_LINUX_CONFIG([PREEMPT],
311 AC_MSG_ERROR([
2984e0bb
PS
312 *** Kernel built with CONFIG_PREEMPT which is not supported.
313 *** You must rebuild your kernel without this option.]), [])
15805c77 314
8366cd6a 315 AS_IF([test "$ZFS_META_LICENSE" = CDDL], [
c9c0d073
BB
316 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
317 AC_MSG_ERROR([
2984e0bb
PS
318 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
319 *** incompatible with the CDDL license. You must rebuild
320 *** your kernel without this option.]), [])
8366cd6a 321 ])
c9c0d073 322
8366cd6a 323 AS_IF([test "$ZFS_META_LICENSE" = GPL], [
c9c0d073
BB
324 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
325 [Define to 1 if licensed under the GPL])
8366cd6a 326 ])
c9c0d073
BB
327])
328
329dnl #
330dnl # ZFS_LINUX_CONFTEST
331dnl #
332AC_DEFUN([ZFS_LINUX_CONFTEST], [
333cat confdefs.h - <<_ACEOF >conftest.c
334$1
335_ACEOF
336])
337
338dnl #
339dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
340dnl #
341m4_define([ZFS_LANG_PROGRAM], [
342$1
343int
344main (void)
345{
346dnl Do *not* indent the following line: there may be CPP directives.
347dnl Don't move the `;' right after for the same reason.
348$2
349 ;
350 return 0;
351}
352])
353
354dnl #
355dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
356dnl #
357AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
358 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
359 rm -Rf build && mkdir -p build
360 echo "obj-m := conftest.o" >build/Makefile
361 AS_IF(
362 [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])],
363 [$4],
364 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
365 )
366 rm -Rf build
367])
368
369dnl #
370dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
371dnl #
372AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
373 [ZFS_LINUX_COMPILE_IFELSE(
374 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
375 [modules],
376 [test -s build/conftest.o],
377 [$3], [$4])
378])
379
380dnl #
381dnl # ZFS_LINUX_CONFIG
382dnl #
383AC_DEFUN([ZFS_LINUX_CONFIG],
384 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
385 ZFS_LINUX_TRY_COMPILE([
0da78696 386 #include <linux/module.h>
c9c0d073
BB
387 ],[
388 #ifndef CONFIG_$1
389 #error CONFIG_$1 not #defined
390 #endif
391 ],[
392 AC_MSG_RESULT([yes])
393 $2
394 ],[
395 AC_MSG_RESULT([no])
396 $3
397 ])
398])
399
400dnl #
401dnl # ZFS_CHECK_SYMBOL_EXPORT
402dnl # check symbol exported or not
403dnl #
404AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
405 [AC_MSG_CHECKING([whether symbol $1 is exported])
406 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
407 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
408 rc=$?
8366cd6a 409 AS_IF([test $rc -ne 0], [
c9c0d073
BB
410 export=0
411 for file in $2; do
412 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
413 rc=$?
8366cd6a
PS
414 AS_IF([test $rc -eq 0], [
415 export=1
416 break;
417 ])
c9c0d073 418 done
8366cd6a 419 AS_IF([test $export -eq 0], [
c9c0d073
BB
420 AC_MSG_RESULT([no])
421 $4
8366cd6a 422 ], [
c9c0d073
BB
423 AC_MSG_RESULT([yes])
424 $3
8366cd6a
PS
425 ])
426 ], [
c9c0d073
BB
427 AC_MSG_RESULT([yes])
428 $3
8366cd6a 429 ])
c9c0d073 430])