1 AC_DEFUN([SPL_AC_KERNEL], [
5 AS_HELP_STRING([--with-linux=PATH],
6 [Path to kernel source]),
7 [kernelsrc="$withval"; kernelbuild="$withval"])
9 AC_ARG_WITH([linux-obj],
10 AS_HELP_STRING([--with-linux-obj=PATH],
11 [Path to kernel build objects]),
12 [kernelbuild="$withval"])
14 AC_MSG_CHECKING([kernel source directory])
15 if test -z "$kernelsrc"; then
17 sourcelink=/lib/modules/${ver}/source
18 buildlink=/lib/modules/${ver}/build
20 if test -e $sourcelink; then
21 kernelsrc=`(cd $sourcelink; /bin/pwd)`
23 if test -e $buildlink; then
24 kernelbuild=`(cd $buildlink; /bin/pwd)`
26 if test -z "$kernelsrc"; then
27 kernelsrc=$kernelbuild
29 if test -z "$kernelsrc" -o -z "$kernelbuild"; then
30 AC_MSG_RESULT([Not found])
32 *** Please specify the location of the kernel source
33 *** with the '--with-linux=PATH' option])
37 AC_MSG_RESULT([$kernelsrc])
38 AC_MSG_CHECKING([kernel build directory])
39 AC_MSG_RESULT([$kernelbuild])
41 AC_MSG_CHECKING([kernel source version])
42 if test -r $kernelbuild/include/linux/version.h &&
43 fgrep -q UTS_RELEASE $kernelbuild/include/linux/version.h; then
45 kernsrcver=`(echo "#include <linux/version.h>";
46 echo "kernsrcver=UTS_RELEASE") |
47 cpp -I $kernelbuild/include |
48 grep "^kernsrcver=" | cut -d \" -f 2`
50 elif test -r $kernelbuild/include/linux/utsrelease.h &&
51 fgrep -q UTS_RELEASE $kernelbuild/include/linux/utsrelease.h; then
53 kernsrcver=`(echo "#include <linux/utsrelease.h>";
54 echo "kernsrcver=UTS_RELEASE") |
55 cpp -I $kernelbuild/include |
56 grep "^kernsrcver=" | cut -d \" -f 2`
59 if test -z "$kernsrcver"; then
60 AC_MSG_RESULT([Not found])
62 *** Cannot determine the version of the linux kernel source.
63 *** Please prepare the kernel before running this script])
66 AC_MSG_RESULT([$kernsrcver])
68 kmoduledir=${INSTALL_MOD_PATH}/lib/modules/$kernsrcver
70 LINUX_OBJ=${kernelbuild}
77 AC_DEFUN([SPL_AC_LICENSE], [
78 AC_MSG_CHECKING([license])
80 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DHAVE_GPL_ONLY_SYMBOLS"
83 AC_DEFUN([SPL_AC_DEBUG], [
84 AC_MSG_CHECKING([whether debugging is enabled])
85 AC_ARG_ENABLE( [debug],
86 AS_HELP_STRING([--enable-debug],
87 [Enable generic debug support (default off)]),
88 [ case "$enableval" in
89 yes) spl_ac_debug=yes ;;
90 no) spl_ac_debug=no ;;
91 *) AC_MSG_RESULT([Error!])
92 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug]) ;;
95 if test "$spl_ac_debug" = yes; then
97 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG"
100 AC_DEFINE([NDEBUG], [1],
101 [Define to 1 to disable debug tracing])
102 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
106 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
107 AC_MSG_CHECKING([whether kmem debugging is enabled])
108 AC_ARG_ENABLE( [debug-kmem],
109 AS_HELP_STRING([--enable-debug-kmem],
110 [Enable kmem debug support (default off)]),
111 [ case "$enableval" in
112 yes) spl_ac_debug_kmem=yes ;;
113 no) spl_ac_debug_kmem=no ;;
114 *) AC_MSG_RESULT([Error!])
115 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kmem]) ;;
118 if test "$spl_ac_debug_kmem" = yes; then
120 AC_DEFINE([DEBUG_KMEM], [1],
121 [Define to 1 to enable kmem debugging])
122 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
128 AC_DEFUN([SPL_AC_DEBUG_MUTEX], [
129 AC_MSG_CHECKING([whether mutex debugging is enabled])
130 AC_ARG_ENABLE( [debug-mutex],
131 AS_HELP_STRING([--enable-debug-mutex],
132 [Enable mutex debug support (default off)]),
133 [ case "$enableval" in
134 yes) spl_ac_debug_mutex=yes ;;
135 no) spl_ac_debug_mutex=no ;;
136 *) AC_MSG_RESULT([Error!])
137 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-mutex]) ;;
140 if test "$spl_ac_debug_mutex" = yes; then
142 AC_DEFINE([DEBUG_MUTEX], [1],
143 [Define to 1 to enable mutex debugging])
144 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_MUTEX"
150 AC_DEFUN([SPL_AC_DEBUG_KSTAT], [
151 AC_MSG_CHECKING([whether kstat debugging is enabled])
152 AC_ARG_ENABLE( [debug-kstat],
153 AS_HELP_STRING([--enable-debug-kstat],
154 [Enable kstat debug support (default off)]),
155 [ case "$enableval" in
156 yes) spl_ac_debug_kstat=yes ;;
157 no) spl_ac_debug_kstat=no ;;
158 *) AC_MSG_RESULT([Error!])
159 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kstat]) ;;
162 if test "$spl_ac_debug_kstat" = yes; then
164 AC_DEFINE([DEBUG_KSTAT], [1],
165 [Define to 1 to enable kstat debugging])
166 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KSTAT"
172 AC_DEFUN([SPL_AC_DEBUG_CALLB], [
173 AC_MSG_CHECKING([whether callb debugging is enabled])
174 AC_ARG_ENABLE( [debug-callb],
175 AS_HELP_STRING([--enable-debug-callb],
176 [Enable callb debug support (default off)]),
177 [ case "$enableval" in
178 yes) spl_ac_debug_callb=yes ;;
179 no) spl_ac_debug_callb=no ;;
180 *) AC_MSG_RESULT([Error!])
181 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-callb]) ;;
184 if test "$spl_ac_debug_callb" = yes; then
186 AC_DEFINE([DEBUG_CALLB], [1],
187 [Define to 1 to enable callb debugging])
188 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_CALLB"
195 dnl # SPL_LINUX_CONFTEST
197 AC_DEFUN([SPL_LINUX_CONFTEST], [
198 cat >conftest.c <<_ACEOF
204 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
206 m4_define([SPL_LANG_PROGRAM], [
211 dnl Do *not* indent the following line: there may be CPP directives.
212 dnl Don't move the `;' right after for the same reason.
220 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
222 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
223 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])dnl
224 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko build/Makefile
225 echo "obj-m := conftest.o" >build/Makefile
226 dnl AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" -f $PWD/build/Makefile LINUXINCLUDE="-Iinclude -include include/linux/autoconf.h" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM SUBDIRS=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
227 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" LINUXINCLUDE="-Iinclude -include include/linux/autoconf.h" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
229 [_AC_MSG_LOG_CONFTEST
230 m4_ifvaln([$5],[$5])dnl])dnl
231 rm -f build/conftest.o build/conftest.mod.c build/conftest.mod.o build/conftest.ko m4_ifval([$1], [build/conftest.c conftest.c])[]dnl
235 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
237 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
238 [SPL_LINUX_COMPILE_IFELSE(
239 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
241 [test -s build/conftest.o],
246 dnl # SPL_LINUX_CONFIG
248 AC_DEFUN([SPL_LINUX_CONFIG],
249 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
250 SPL_LINUX_TRY_COMPILE([
251 #ifndef AUTOCONF_INCLUDED
252 #include <linux/config.h>
256 #error CONFIG_$1 not #defined
268 dnl # SPL_CHECK_SYMBOL_EXPORT
269 dnl # check symbol exported or not
271 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
272 [AC_MSG_CHECKING([whether symbol $1 is exported])
273 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/Module.symvers 2>/dev/null
275 if test $rc -ne 0; then
278 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
280 if test $rc -eq 0; then
285 if test $export -eq 0; then
299 dnl # SPL_CHECK_HEADER
300 dnl # check whether header exists and define HAVE_$2_HEADER
302 AC_DEFUN([SPL_CHECK_HEADER],
303 [AC_MSG_CHECKING([whether header $1 exists])
304 SPL_LINUX_TRY_COMPILE([
309 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
319 dnl # 2.6.24 API change,
320 dnl # check if uintptr_t typedef is defined
322 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
323 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
324 SPL_LINUX_TRY_COMPILE([
325 #include <linux/types.h>
330 AC_DEFINE(HAVE_UINTPTR_T, 1,
331 [kernel defines uintptr_t])
338 dnl # 2.6.x API change,
339 dnl # check if atomic64_t typedef is defined
341 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_T],
342 [AC_MSG_CHECKING([whether kernel defines atomic64_t])
343 SPL_LINUX_TRY_COMPILE([
344 #include <asm/atomic.h>
349 AC_DEFINE(HAVE_ATOMIC64_T, 1,
350 [kernel defines atomic64_t])
357 dnl # 2.6.20 API change,
358 dnl # INIT_WORK use 2 args and not store data inside
360 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
361 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
362 SPL_LINUX_TRY_COMPILE([
363 #include <linux/workqueue.h>
365 struct work_struct work;
366 INIT_WORK(&work, NULL, NULL);
369 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
370 [INIT_WORK wants 3 args])
377 dnl # 2.6.21 API change,
378 dnl # 'register_sysctl_table' use only one argument instead of two
380 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
381 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
382 SPL_LINUX_TRY_COMPILE([
383 #include <linux/sysctl.h>
385 return register_sysctl_table(NULL,0);
388 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
389 [register_sysctl_table() wants 2 args])
396 dnl # 2.6.23 API change
397 dnl # Old set_shrinker API replaced with register_shrinker
399 AC_DEFUN([SPL_AC_SET_SHRINKER], [
400 AC_MSG_CHECKING([whether set_shrinker() available])
401 SPL_LINUX_TRY_COMPILE([
402 #include <linux/mm.h>
404 return set_shrinker(DEFAULT_SEEKS, NULL);
407 AC_DEFINE(HAVE_SET_SHRINKER, 1,
408 [set_shrinker() available])
415 dnl # 2.6.25 API change,
416 dnl # struct path entry added to struct nameidata
418 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
419 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
420 SPL_LINUX_TRY_COMPILE([
421 #include <linux/namei.h>
426 nd.path.dentry = NULL;
429 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
430 [struct path used in struct nameidata])
437 dnl # Custom SPL patch may export this system it is not required
439 AC_DEFUN([SPL_AC_TASK_CURR], [
440 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
441 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
446 dnl # 2.6.19 API change,
447 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
449 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
450 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
451 SPL_LINUX_TRY_COMPILE([
452 #include <linux/sysctl.h>
454 #ifndef CTL_UNNUMBERED
455 #error CTL_UNNUMBERED undefined
459 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
460 [unnumbered sysctl support exists])
467 dnl # 2.6.16 API change.
468 dnl # Check if 'fls64()' is available
470 AC_DEFUN([SPL_AC_FLS64],
471 [AC_MSG_CHECKING([whether fls64() is available])
472 SPL_LINUX_TRY_COMPILE([
473 #include <linux/bitops.h>
478 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
485 dnl # 2.6.18 API change, check whether device_create() is available.
486 dnl # Device_create() was introduced in 2.6.18 and depricated
487 dnl # class_device_create() which was fully removed in 2.6.26.
489 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
490 SPL_CHECK_SYMBOL_EXPORT(
492 [drivers/base/core.c],
493 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
494 [device_create() is available])],
499 dnl # 2.6.13 API change, check whether class_device_create() is available.
500 dnl # Class_device_create() was introduced in 2.6.13 and depricated
501 dnl # class_simple_device_add() which was fully removed in 2.6.13.
503 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
504 SPL_CHECK_SYMBOL_EXPORT(
505 [class_device_create],
506 [drivers/base/class.c],
507 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
508 [class_device_create() is available])],
513 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
515 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
516 SPL_CHECK_SYMBOL_EXPORT(
517 [set_normalized_timespec],
519 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
520 [set_normalized_timespec() is available as export])],
525 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
526 dnl # previously it was available in time.h as an inline.
528 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
529 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
530 SPL_LINUX_TRY_COMPILE([
531 #include <linux/time.h>
532 void set_normalized_timespec(struct timespec *ts,
533 time_t sec, long nsec) { }
540 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
541 [set_normalized_timespec() is available as inline])
546 dnl # 2.6.18 API change,
547 dnl # timespec_sub() inline function available in linux/time.h
549 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
550 AC_MSG_CHECKING([whether timespec_sub() is available])
551 SPL_LINUX_TRY_COMPILE([
552 #include <linux/time.h>
554 struct timespec a, b, c = { 0 };
555 c = timespec_sub(a, b);
558 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
565 dnl # 2.6.19 API change,
566 dnl # check if init_utsname() is available in linux/utsname.h
568 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
569 AC_MSG_CHECKING([whether init_utsname() is available])
570 SPL_LINUX_TRY_COMPILE([
571 #include <linux/utsname.h>
573 struct new_utsname *a = init_utsname();
576 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
583 dnl # 2.6.26 API change,
584 dnl # definition of struct fdtable relocated to linux/fdtable.h
586 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
587 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
591 dnl # 2.6.14 API change,
592 dnl # check whether 'files_fdtable()' exists
594 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
595 AC_MSG_CHECKING([whether files_fdtable() is available])
596 SPL_LINUX_TRY_COMPILE([
597 #include <linux/sched.h>
598 #include <linux/file.h>
599 #ifdef HAVE_FDTABLE_HEADER
600 #include <linux/fdtable.h>
603 struct files_struct *files = current->files;
604 struct fdtable *fdt = files_fdtable(files);
607 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
614 dnl # 2.6.18 API change,
615 dnl # added linux/uaccess.h
617 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
618 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
622 dnl # 2.6.12 API change,
623 dnl # check whether 'kmalloc_node()' is available.
625 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
626 AC_MSG_CHECKING([whether kmalloc_node() is available])
627 SPL_LINUX_TRY_COMPILE([
628 #include <linux/slab.h>
630 void *a = kmalloc_node(1, GFP_KERNEL, 0);
633 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
640 dnl # 2.6.9 API change,
641 dnl # check whether 'monotonic_clock()' is available it may
642 dnl # be available for some archs but not others.
644 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
645 SPL_CHECK_SYMBOL_EXPORT(
648 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
649 [monotonic_clock() is available])],
654 dnl # 2.6.16 API change,
655 dnl # check whether 'struct inode' has i_mutex
657 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
658 AC_MSG_CHECKING([whether struct inode has i_mutex])
659 SPL_LINUX_TRY_COMPILE([
660 #include <linux/fs.h>
661 #include <linux/mutex.h>
664 mutex_init(&i.i_mutex);
667 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
674 dnl # 2.6.14 API change,
675 dnl # check whether 'div64_64()' is available
677 AC_DEFUN([SPL_AC_DIV64_64], [
678 AC_MSG_CHECKING([whether div64_64() is available])
679 SPL_LINUX_TRY_COMPILE([
680 #include <asm/div64.h>
681 #include <linux/types.h>
683 uint64_t i = div64_64(1ULL, 1ULL);
686 AC_DEFINE(HAVE_DIV64_64, 1, [div64_64() is available])