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