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