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 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
104 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
105 AC_MSG_CHECKING([whether kmem debugging is enabled])
106 AC_ARG_ENABLE( [debug-kmem],
107 AS_HELP_STRING([--enable-debug-kmem],
108 [Enable kmem debug support (default off)]),
109 [ case "$enableval" in
110 yes) spl_ac_debug_kmem=yes ;;
111 no) spl_ac_debug_kmem=no ;;
112 *) AC_MSG_RESULT([Error!])
113 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kmem]) ;;
116 if test "$spl_ac_debug_kmem" = yes; then
118 AC_DEFINE([DEBUG_KMEM], [1],
119 [Define to 1 to enable kmem debugging])
120 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
126 AC_DEFUN([SPL_AC_DEBUG_MUTEX], [
127 AC_MSG_CHECKING([whether mutex debugging is enabled])
128 AC_ARG_ENABLE( [debug-mutex],
129 AS_HELP_STRING([--enable-debug-mutex],
130 [Enable mutex debug support (default off)]),
131 [ case "$enableval" in
132 yes) spl_ac_debug_mutex=yes ;;
133 no) spl_ac_debug_mutex=no ;;
134 *) AC_MSG_RESULT([Error!])
135 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-mutex]) ;;
138 if test "$spl_ac_debug_mutex" = yes; then
140 AC_DEFINE([DEBUG_MUTEX], [1],
141 [Define to 1 to enable mutex debugging])
142 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_MUTEX"
148 AC_DEFUN([SPL_AC_DEBUG_KSTAT], [
149 AC_MSG_CHECKING([whether kstat debugging is enabled])
150 AC_ARG_ENABLE( [debug-kstat],
151 AS_HELP_STRING([--enable-debug-kstat],
152 [Enable kstat debug support (default off)]),
153 [ case "$enableval" in
154 yes) spl_ac_debug_kstat=yes ;;
155 no) spl_ac_debug_kstat=no ;;
156 *) AC_MSG_RESULT([Error!])
157 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kstat]) ;;
160 if test "$spl_ac_debug_kstat" = yes; then
162 AC_DEFINE([DEBUG_KSTAT], [1],
163 [Define to 1 to enable kstat debugging])
164 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KSTAT"
170 AC_DEFUN([SPL_AC_DEBUG_CALLB], [
171 AC_MSG_CHECKING([whether callb debugging is enabled])
172 AC_ARG_ENABLE( [debug-callb],
173 AS_HELP_STRING([--enable-debug-callb],
174 [Enable callb debug support (default off)]),
175 [ case "$enableval" in
176 yes) spl_ac_debug_callb=yes ;;
177 no) spl_ac_debug_callb=no ;;
178 *) AC_MSG_RESULT([Error!])
179 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-callb]) ;;
182 if test "$spl_ac_debug_callb" = yes; then
184 AC_DEFINE([DEBUG_CALLB], [1],
185 [Define to 1 to enable callb debugging])
186 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_CALLB"
193 dnl # SPL_LINUX_CONFTEST
195 AC_DEFUN([SPL_LINUX_CONFTEST], [
196 cat >conftest.c <<_ACEOF
202 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
204 m4_define([SPL_LANG_PROGRAM], [
209 dnl Do *not* indent the following line: there may be CPP directives.
210 dnl Don't move the `;' right after for the same reason.
218 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
220 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
221 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])dnl
222 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko build/Makefile
223 echo "obj-m := conftest.o" >build/Makefile
224 dnl AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" -f $PWD/build/Makefile LINUXINCLUDE="-Iinclude -Iinclude2 -I$LINUX/include -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])],
225 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" LINUXINCLUDE="-Iinclude -Iinclude2 -I$LINUX/include -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])],
227 [_AC_MSG_LOG_CONFTEST
228 m4_ifvaln([$5],[$5])dnl])dnl
229 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
233 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
235 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
236 [SPL_LINUX_COMPILE_IFELSE(
237 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
239 [test -s build/conftest.o],
244 dnl # SPL_LINUX_CONFIG
246 AC_DEFUN([SPL_LINUX_CONFIG],
247 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
248 SPL_LINUX_TRY_COMPILE([
249 #ifndef AUTOCONF_INCLUDED
250 #include <linux/config.h>
254 #error CONFIG_$1 not #defined
266 dnl # SPL_CHECK_SYMBOL_EXPORT
267 dnl # check symbol exported or not
269 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
270 [AC_MSG_CHECKING([whether symbol $1 is exported])
271 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/Module.symvers 2>/dev/null
273 if test $rc -ne 0; then
276 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX_OBJ/$file" 2>/dev/null
278 if test $rc -eq 0; then
283 if test $export -eq 0; then
297 dnl # SPL_CHECK_HEADER
298 dnl # check whether header exists and define HAVE_$2_HEADER
300 AC_DEFUN([SPL_CHECK_HEADER],
301 [AC_MSG_CHECKING([whether header $1 exists])
302 SPL_LINUX_TRY_COMPILE([
307 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
317 dnl # 2.6.24 API change,
318 dnl # check if uintptr_t typedef is defined
320 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
321 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
322 SPL_LINUX_TRY_COMPILE([
323 #include <linux/types.h>
328 AC_DEFINE(HAVE_UINTPTR_T, 1,
329 [kernel defines uintptr_t])
336 dnl # 2.6.x API change,
337 dnl # check if atomic64_t typedef is defined
339 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_T],
340 [AC_MSG_CHECKING([whether kernel defines atomic64_t])
341 SPL_LINUX_TRY_COMPILE([
342 #include <asm/atomic.h>
347 AC_DEFINE(HAVE_ATOMIC64_T, 1,
348 [kernel defines atomic64_t])
355 dnl # 2.6.20 API change,
356 dnl # INIT_WORK use 2 args and not store data inside
358 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
359 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
360 SPL_LINUX_TRY_COMPILE([
361 #include <linux/workqueue.h>
363 struct work_struct work;
364 INIT_WORK(&work, NULL, NULL);
367 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
368 [INIT_WORK wants 3 args])
375 dnl # 2.6.21 API change,
376 dnl # 'register_sysctl_table' use only one argument instead of two
378 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
379 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
380 SPL_LINUX_TRY_COMPILE([
381 #include <linux/sysctl.h>
383 return register_sysctl_table(NULL,0);
386 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
387 [register_sysctl_table() wants 2 args])
394 dnl # 2.6.23 API change
395 dnl # Old set_shrinker API replaced with register_shrinker
397 AC_DEFUN([SPL_AC_SET_SHRINKER], [
398 AC_MSG_CHECKING([whether set_shrinker() available])
399 SPL_LINUX_TRY_COMPILE([
400 #include <linux/mm.h>
402 return set_shrinker(DEFAULT_SEEKS, NULL);
405 AC_DEFINE(HAVE_SET_SHRINKER, 1,
406 [set_shrinker() available])
413 dnl # 2.6.25 API change,
414 dnl # struct path entry added to struct nameidata
416 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
417 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
418 SPL_LINUX_TRY_COMPILE([
419 #include <linux/namei.h>
424 nd.path.dentry = NULL;
427 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
428 [struct path used in struct nameidata])
435 dnl # Custom SPL patch may export this system it is not required
437 AC_DEFUN([SPL_AC_TASK_CURR], [
438 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
439 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
444 dnl # 2.6.19 API change,
445 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
447 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
448 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
449 SPL_LINUX_TRY_COMPILE([
450 #include <linux/sysctl.h>
452 #ifndef CTL_UNNUMBERED
453 #error CTL_UNNUMBERED undefined
457 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
458 [unnumbered sysctl support exists])
465 dnl # 2.6.16 API change.
466 dnl # Check if 'fls64()' is available
468 AC_DEFUN([SPL_AC_FLS64],
469 [AC_MSG_CHECKING([whether fls64() is available])
470 SPL_LINUX_TRY_COMPILE([
471 #include <linux/bitops.h>
476 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
483 dnl # 2.6.18 API change, check whether device_create() is available.
484 dnl # Device_create() was introduced in 2.6.18 and depricated
485 dnl # class_device_create() which was fully removed in 2.6.26.
487 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
488 SPL_CHECK_SYMBOL_EXPORT(
490 [drivers/base/core.c],
491 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
492 [device_create() is available])],
497 dnl # 2.6.13 API change, check whether class_device_create() is available.
498 dnl # Class_device_create() was introduced in 2.6.13 and depricated
499 dnl # class_simple_device_add() which was fully removed in 2.6.13.
501 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
502 SPL_CHECK_SYMBOL_EXPORT(
503 [class_device_create],
504 [drivers/base/class.c],
505 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
506 [class_device_create() is available])],
511 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
513 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
514 SPL_CHECK_SYMBOL_EXPORT(
515 [set_normalized_timespec],
517 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
518 [set_normalized_timespec() is available as export])],
523 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
524 dnl # previously it was available in time.h as an inline.
526 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
527 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
528 SPL_LINUX_TRY_COMPILE([
529 #include <linux/time.h>
530 void set_normalized_timespec(struct timespec *ts,
531 time_t sec, long nsec) { }
538 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
539 [set_normalized_timespec() is available as inline])
544 dnl # 2.6.18 API change,
545 dnl # timespec_sub() inline function available in linux/time.h
547 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
548 AC_MSG_CHECKING([whether timespec_sub() is available])
549 SPL_LINUX_TRY_COMPILE([
550 #include <linux/time.h>
552 struct timespec a, b, c = { 0 };
553 c = timespec_sub(a, b);
556 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
563 dnl # 2.6.19 API change,
564 dnl # check if init_utsname() is available in linux/utsname.h
566 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
567 AC_MSG_CHECKING([whether init_utsname() is available])
568 SPL_LINUX_TRY_COMPILE([
569 #include <linux/utsname.h>
571 struct new_utsname *a = init_utsname();
574 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
581 dnl # 2.6.26 API change,
582 dnl # definition of struct fdtable relocated to linux/fdtable.h
584 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
585 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
589 dnl # 2.6.14 API change,
590 dnl # check whether 'files_fdtable()' exists
592 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
593 AC_MSG_CHECKING([whether files_fdtable() is available])
594 SPL_LINUX_TRY_COMPILE([
595 #include <linux/sched.h>
596 #include <linux/file.h>
597 #ifdef HAVE_FDTABLE_HEADER
598 #include <linux/fdtable.h>
601 struct files_struct *files = current->files;
602 struct fdtable *fdt = files_fdtable(files);
605 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
612 dnl # 2.6.18 API change,
613 dnl # added linux/uaccess.h
615 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
616 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
620 dnl # 2.6.12 API change,
621 dnl # check whether 'kmalloc_node()' is available.
623 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
624 AC_MSG_CHECKING([whether kmalloc_node() is available])
625 SPL_LINUX_TRY_COMPILE([
626 #include <linux/slab.h>
628 void *a = kmalloc_node(1, GFP_KERNEL, 0);
631 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
638 dnl # 2.6.9 API change,
639 dnl # check whether 'monotonic_clock()' is available it may
640 dnl # be available for some archs but not others.
642 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
643 SPL_CHECK_SYMBOL_EXPORT(
646 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
647 [monotonic_clock() is available])],
652 dnl # 2.6.16 API change,
653 dnl # check whether 'struct inode' has i_mutex
655 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
656 AC_MSG_CHECKING([whether struct inode has i_mutex])
657 SPL_LINUX_TRY_COMPILE([
658 #include <linux/fs.h>
659 #include <linux/mutex.h>
662 mutex_init(&i.i_mutex);
665 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
672 dnl # 2.6.14 API change,
673 dnl # check whether 'div64_64()' is available
675 AC_DEFUN([SPL_AC_DIV64_64], [
676 AC_MSG_CHECKING([whether div64_64() is available])
677 SPL_LINUX_TRY_COMPILE([
678 #include <asm/div64.h>
679 #include <linux/types.h>
681 uint64_t i = div64_64(1ULL, 1ULL);
684 AC_DEFINE(HAVE_DIV64_64, 1, [div64_64() is available])
691 dnl # 2.6.27 API change,
692 dnl # on_each_cpu() uses 3 args, no 'retry' argument
694 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
695 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
696 SPL_LINUX_TRY_COMPILE([
697 #include <linux/smp.h>
699 on_each_cpu(NULL, NULL, 0);
702 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
703 [on_each_cpu wants 3 args])
710 dnl # 2.6.18 API change,
711 dnl # kallsyms_lookup_name no longer exported
713 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME], [
714 SPL_CHECK_SYMBOL_EXPORT(
715 [kallsyms_lookup_name],
717 [AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
718 [kallsyms_lookup_name() is available])],
723 dnl # Symbol only available in custom kernels
725 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], [
726 SPL_CHECK_SYMBOL_EXPORT(
729 [AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
730 [get_vmalloc_info() is available])],
735 dnl # Symbol only available in custom kernels
737 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT], [
738 SPL_CHECK_SYMBOL_EXPORT(
739 [first_online_pgdat],
741 [AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
742 [first_online_pgdat() is available])],
747 dnl # Symbol only available in custom kernels
749 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT], [
750 SPL_CHECK_SYMBOL_EXPORT(
753 [AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
754 [next_online_pgdat() is available])],
759 dnl # Symbol only available in custom kernels
761 AC_DEFUN([SPL_AC_NEXT_ZONE], [
762 SPL_CHECK_SYMBOL_EXPORT(
765 [AC_DEFINE(HAVE_NEXT_ZONE, 1,
766 [next_zone() is available])],
771 dnl # Symbol only available in custom kernels
773 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
774 SPL_CHECK_SYMBOL_EXPORT(
777 [AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
778 [get_zone_counts() is available])],