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