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])
36 if test "$kernelsrc" = "NONE"; then
41 AC_MSG_RESULT([$kernelsrc])
42 AC_MSG_CHECKING([kernel build directory])
43 AC_MSG_RESULT([$kernelbuild])
45 AC_MSG_CHECKING([kernel source version])
46 if test -r $kernelbuild/include/linux/version.h &&
47 fgrep -q UTS_RELEASE $kernelbuild/include/linux/version.h; then
49 kernsrcver=`(echo "#include <linux/version.h>";
50 echo "kernsrcver=UTS_RELEASE") |
51 cpp -I $kernelbuild/include |
52 grep "^kernsrcver=" | cut -d \" -f 2`
54 elif test -r $kernelbuild/include/linux/utsrelease.h &&
55 fgrep -q UTS_RELEASE $kernelbuild/include/linux/utsrelease.h; then
57 kernsrcver=`(echo "#include <linux/utsrelease.h>";
58 echo "kernsrcver=UTS_RELEASE") |
59 cpp -I $kernelbuild/include |
60 grep "^kernsrcver=" | cut -d \" -f 2`
63 if test -z "$kernsrcver"; then
64 AC_MSG_RESULT([Not found])
66 *** Cannot determine the version of the linux kernel source.
67 *** Please prepare the kernel before running this script])
70 AC_MSG_RESULT([$kernsrcver])
73 LINUX_OBJ=${kernelbuild}
74 LINUX_VERSION=${kernsrcver}
76 abs_srcdir=`readlink -f ${srcdir}`
77 kerninclude="-I${abs_srcdir} -I${abs_srcdir}/include"
78 kernwarn="-Wstrict-prototypes -Werror"
80 if test "${LINUX_OBJ}" != "${LINUX}"; then
81 kernobjs="O=$kernelbuild"
85 KERNELCPPFLAGS="${kerninclude} ${kernwarn}"
86 KERNELMAKE_PARAMS="${kernobjs}"
90 AC_SUBST(LINUX_VERSION)
91 AC_SUBST(KERNELMAKE_PARAMS)
92 AC_SUBST(KERNELCPPFLAGS)
93 AC_SUBST(KERNELCFLAGS)
96 AC_DEFUN([SPL_AC_LICENSE], [
97 AC_MSG_CHECKING([license])
99 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DHAVE_GPL_ONLY_SYMBOLS"
102 AC_DEFUN([SPL_AC_DEBUG], [
103 AC_MSG_CHECKING([whether debugging is enabled])
104 AC_ARG_ENABLE( [debug],
105 AS_HELP_STRING([--enable-debug],
106 [Enable generic debug support (default off)]),
107 [ case "$enableval" in
108 yes) spl_ac_debug=yes ;;
109 no) spl_ac_debug=no ;;
110 *) AC_MSG_RESULT([Error!])
111 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug]) ;;
114 if test "$spl_ac_debug" = yes; then
116 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG"
119 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
123 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
124 AC_MSG_CHECKING([whether kmem debugging is enabled])
125 AC_ARG_ENABLE( [debug-kmem],
126 AS_HELP_STRING([--enable-debug-kmem],
127 [Enable kmem debug support (default off)]),
128 [ case "$enableval" in
129 yes) spl_ac_debug_kmem=yes ;;
130 no) spl_ac_debug_kmem=no ;;
131 *) AC_MSG_RESULT([Error!])
132 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kmem]) ;;
135 if test "$spl_ac_debug_kmem" = yes; then
137 AC_DEFINE([DEBUG_KMEM], [1],
138 [Define to 1 to enable kmem debugging])
139 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
145 AC_DEFUN([SPL_AC_DEBUG_MUTEX], [
146 AC_MSG_CHECKING([whether mutex debugging is enabled])
147 AC_ARG_ENABLE( [debug-mutex],
148 AS_HELP_STRING([--enable-debug-mutex],
149 [Enable mutex debug support (default off)]),
150 [ case "$enableval" in
151 yes) spl_ac_debug_mutex=yes ;;
152 no) spl_ac_debug_mutex=no ;;
153 *) AC_MSG_RESULT([Error!])
154 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-mutex]) ;;
157 if test "$spl_ac_debug_mutex" = yes; then
159 AC_DEFINE([DEBUG_MUTEX], [1],
160 [Define to 1 to enable mutex debugging])
161 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_MUTEX"
167 AC_DEFUN([SPL_AC_DEBUG_KSTAT], [
168 AC_MSG_CHECKING([whether kstat debugging is enabled])
169 AC_ARG_ENABLE( [debug-kstat],
170 AS_HELP_STRING([--enable-debug-kstat],
171 [Enable kstat debug support (default off)]),
172 [ case "$enableval" in
173 yes) spl_ac_debug_kstat=yes ;;
174 no) spl_ac_debug_kstat=no ;;
175 *) AC_MSG_RESULT([Error!])
176 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kstat]) ;;
179 if test "$spl_ac_debug_kstat" = yes; then
181 AC_DEFINE([DEBUG_KSTAT], [1],
182 [Define to 1 to enable kstat debugging])
183 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KSTAT"
189 AC_DEFUN([SPL_AC_DEBUG_CALLB], [
190 AC_MSG_CHECKING([whether callb debugging is enabled])
191 AC_ARG_ENABLE( [debug-callb],
192 AS_HELP_STRING([--enable-debug-callb],
193 [Enable callb debug support (default off)]),
194 [ case "$enableval" in
195 yes) spl_ac_debug_callb=yes ;;
196 no) spl_ac_debug_callb=no ;;
197 *) AC_MSG_RESULT([Error!])
198 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-callb]) ;;
201 if test "$spl_ac_debug_callb" = yes; then
203 AC_DEFINE([DEBUG_CALLB], [1],
204 [Define to 1 to enable callb debugging])
205 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_CALLB"
212 dnl # SPL_LINUX_CONFTEST
214 AC_DEFUN([SPL_LINUX_CONFTEST], [
215 cat >conftest.c <<_ACEOF
221 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
223 m4_define([SPL_LANG_PROGRAM], [
228 dnl Do *not* indent the following line: there may be CPP directives.
229 dnl Don't move the `;' right after for the same reason.
237 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
239 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
240 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
241 rm -Rf build && mkdir -p build
242 echo "obj-m := conftest.o" >build/Makefile
244 [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])],
246 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
252 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
254 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
255 [SPL_LINUX_COMPILE_IFELSE(
256 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
258 [test -s build/conftest.o],
263 dnl # SPL_LINUX_CONFIG
265 AC_DEFUN([SPL_LINUX_CONFIG],
266 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
267 SPL_LINUX_TRY_COMPILE([
268 #ifndef AUTOCONF_INCLUDED
269 #include <linux/config.h>
273 #error CONFIG_$1 not #defined
285 dnl # SPL_CHECK_SYMBOL_EXPORT
286 dnl # check symbol exported or not
288 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
289 [AC_MSG_CHECKING([whether symbol $1 is exported])
290 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/Module.symvers 2>/dev/null
292 if test $rc -ne 0; then
295 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX_OBJ/$file" 2>/dev/null
297 if test $rc -eq 0; then
302 if test $export -eq 0; then
316 dnl # SPL_CHECK_HEADER
317 dnl # check whether header exists and define HAVE_$2_HEADER
319 AC_DEFUN([SPL_CHECK_HEADER],
320 [AC_MSG_CHECKING([whether header $1 exists])
321 SPL_LINUX_TRY_COMPILE([
326 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
336 dnl # 2.6.24 API change,
337 dnl # check if uintptr_t typedef is defined
339 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
340 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
341 SPL_LINUX_TRY_COMPILE([
342 #include <linux/types.h>
347 AC_DEFINE(HAVE_UINTPTR_T, 1,
348 [kernel defines uintptr_t])
355 dnl # 2.6.x API change,
356 dnl # check if atomic64_t typedef is defined
358 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_T],
359 [AC_MSG_CHECKING([whether kernel defines atomic64_t])
360 SPL_LINUX_TRY_COMPILE([
361 #include <asm/atomic.h>
366 AC_DEFINE(HAVE_ATOMIC64_T, 1,
367 [kernel defines atomic64_t])
374 dnl # 2.6.20 API change,
375 dnl # INIT_WORK use 2 args and not store data inside
377 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
378 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
379 SPL_LINUX_TRY_COMPILE([
380 #include <linux/workqueue.h>
382 struct work_struct work;
383 INIT_WORK(&work, NULL, NULL);
386 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
387 [INIT_WORK wants 3 args])
394 dnl # 2.6.21 API change,
395 dnl # 'register_sysctl_table' use only one argument instead of two
397 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
398 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
399 SPL_LINUX_TRY_COMPILE([
400 #include <linux/sysctl.h>
402 return register_sysctl_table(NULL,0);
405 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
406 [register_sysctl_table() wants 2 args])
413 dnl # 2.6.23 API change
414 dnl # Old set_shrinker API replaced with register_shrinker
416 AC_DEFUN([SPL_AC_SET_SHRINKER], [
417 AC_MSG_CHECKING([whether set_shrinker() available])
418 SPL_LINUX_TRY_COMPILE([
419 #include <linux/mm.h>
421 return set_shrinker(DEFAULT_SEEKS, NULL);
424 AC_DEFINE(HAVE_SET_SHRINKER, 1,
425 [set_shrinker() available])
432 dnl # 2.6.25 API change,
433 dnl # struct path entry added to struct nameidata
435 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
436 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
437 SPL_LINUX_TRY_COMPILE([
438 #include <linux/namei.h>
443 nd.path.dentry = NULL;
446 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
447 [struct path used in struct nameidata])
454 dnl # Custom SPL patch may export this system it is not required
456 AC_DEFUN([SPL_AC_TASK_CURR], [
457 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
458 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
463 dnl # 2.6.19 API change,
464 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
466 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
467 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
468 SPL_LINUX_TRY_COMPILE([
469 #include <linux/sysctl.h>
471 #ifndef CTL_UNNUMBERED
472 #error CTL_UNNUMBERED undefined
476 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
477 [unnumbered sysctl support exists])
484 dnl # 2.6.16 API change.
485 dnl # Check if 'fls64()' is available
487 AC_DEFUN([SPL_AC_FLS64],
488 [AC_MSG_CHECKING([whether fls64() is available])
489 SPL_LINUX_TRY_COMPILE([
490 #include <linux/bitops.h>
495 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
502 dnl # 2.6.18 API change, check whether device_create() is available.
503 dnl # Device_create() was introduced in 2.6.18 and depricated
504 dnl # class_device_create() which was fully removed in 2.6.26.
506 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
507 SPL_CHECK_SYMBOL_EXPORT(
509 [drivers/base/core.c],
510 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
511 [device_create() is available])],
516 dnl # 2.6.13 API change, check whether class_device_create() is available.
517 dnl # Class_device_create() was introduced in 2.6.13 and depricated
518 dnl # class_simple_device_add() which was fully removed in 2.6.13.
520 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
521 SPL_CHECK_SYMBOL_EXPORT(
522 [class_device_create],
523 [drivers/base/class.c],
524 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
525 [class_device_create() is available])],
530 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
532 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
533 SPL_CHECK_SYMBOL_EXPORT(
534 [set_normalized_timespec],
536 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
537 [set_normalized_timespec() is available as export])],
542 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
543 dnl # previously it was available in time.h as an inline.
545 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
546 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
547 SPL_LINUX_TRY_COMPILE([
548 #include <linux/time.h>
549 void set_normalized_timespec(struct timespec *ts,
550 time_t sec, long nsec) { }
557 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
558 [set_normalized_timespec() is available as inline])
563 dnl # 2.6.18 API change,
564 dnl # timespec_sub() inline function available in linux/time.h
566 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
567 AC_MSG_CHECKING([whether timespec_sub() is available])
568 SPL_LINUX_TRY_COMPILE([
569 #include <linux/time.h>
571 struct timespec a, b, c = { 0 };
572 c = timespec_sub(a, b);
575 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
582 dnl # 2.6.19 API change,
583 dnl # check if init_utsname() is available in linux/utsname.h
585 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
586 AC_MSG_CHECKING([whether init_utsname() is available])
587 SPL_LINUX_TRY_COMPILE([
588 #include <linux/utsname.h>
590 struct new_utsname *a = init_utsname();
593 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
600 dnl # 2.6.26 API change,
601 dnl # definition of struct fdtable relocated to linux/fdtable.h
603 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
604 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
608 dnl # 2.6.14 API change,
609 dnl # check whether 'files_fdtable()' exists
611 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
612 AC_MSG_CHECKING([whether files_fdtable() is available])
613 SPL_LINUX_TRY_COMPILE([
614 #include <linux/sched.h>
615 #include <linux/file.h>
616 #ifdef HAVE_FDTABLE_HEADER
617 #include <linux/fdtable.h>
620 struct files_struct *files = current->files;
621 struct fdtable *fdt = files_fdtable(files);
624 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
631 dnl # 2.6.18 API change,
632 dnl # added linux/uaccess.h
634 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
635 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
639 dnl # 2.6.12 API change,
640 dnl # check whether 'kmalloc_node()' is available.
642 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
643 AC_MSG_CHECKING([whether kmalloc_node() is available])
644 SPL_LINUX_TRY_COMPILE([
645 #include <linux/slab.h>
647 void *a = kmalloc_node(1, GFP_KERNEL, 0);
650 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
657 dnl # 2.6.9 API change,
658 dnl # check whether 'monotonic_clock()' is available it may
659 dnl # be available for some archs but not others.
661 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
662 SPL_CHECK_SYMBOL_EXPORT(
665 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
666 [monotonic_clock() is available])],
671 dnl # 2.6.16 API change,
672 dnl # check whether 'struct inode' has i_mutex
674 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
675 AC_MSG_CHECKING([whether struct inode has i_mutex])
676 SPL_LINUX_TRY_COMPILE([
677 #include <linux/fs.h>
678 #include <linux/mutex.h>
681 mutex_init(&i.i_mutex);
684 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
691 dnl # 2.6.14 API change,
692 dnl # check whether 'div64_64()' is available
694 AC_DEFUN([SPL_AC_DIV64_64], [
695 AC_MSG_CHECKING([whether div64_64() is available])
696 SPL_LINUX_TRY_COMPILE([
697 #include <asm/div64.h>
698 #include <linux/types.h>
700 uint64_t i = div64_64(1ULL, 1ULL);
703 AC_DEFINE(HAVE_DIV64_64, 1, [div64_64() is available])
710 dnl # 2.6.27 API change,
711 dnl # on_each_cpu() uses 3 args, no 'retry' argument
713 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
714 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
715 SPL_LINUX_TRY_COMPILE([
716 #include <linux/smp.h>
718 on_each_cpu(NULL, NULL, 0);
721 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
722 [on_each_cpu wants 3 args])
729 dnl # 2.6.18 API change,
730 dnl # kallsyms_lookup_name no longer exported
732 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME], [
733 SPL_CHECK_SYMBOL_EXPORT(
734 [kallsyms_lookup_name],
736 [AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
737 [kallsyms_lookup_name() is available])],
742 dnl # Symbol only available in custom kernels
744 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], [
745 SPL_CHECK_SYMBOL_EXPORT(
748 [AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
749 [get_vmalloc_info() is available])],
754 dnl # Symbol only available in custom kernels
756 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT], [
757 SPL_CHECK_SYMBOL_EXPORT(
758 [first_online_pgdat],
760 [AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
761 [first_online_pgdat() is available])],
766 dnl # Symbol only available in custom kernels
768 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT], [
769 SPL_CHECK_SYMBOL_EXPORT(
772 [AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
773 [next_online_pgdat() is available])],
778 dnl # Symbol only available in custom kernels
780 AC_DEFUN([SPL_AC_NEXT_ZONE], [
781 SPL_CHECK_SYMBOL_EXPORT(
784 [AC_DEFINE(HAVE_NEXT_ZONE, 1,
785 [next_zone() is available])],
790 dnl # Symbol only available in custom kernels
792 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
793 SPL_CHECK_SYMBOL_EXPORT(
796 [AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
797 [get_zone_counts() is available])],