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