1 AC_DEFUN([SPL_AC_KERNEL], [
3 AS_HELP_STRING([--with-linux=PATH],
4 [Path to kernel source]),
5 [kernelsrc="$withval"; kernelbuild="$withval"])
7 AC_ARG_WITH([linux-obj],
8 AS_HELP_STRING([--with-linux-obj=PATH],
9 [Path to kernel build objects]),
10 [kernelbuild="$withval"])
12 AC_MSG_CHECKING([kernel source directory])
13 if test -z "$kernelsrc"; then
15 sourcelink=`ls -1d /usr/src/kernels/* /usr/src/linux-* 2>/dev/null | tail -1`
17 if test -e ${sourcelink}; then
18 kernelsrc=`readlink -f ${sourcelink}`
19 kernelbuild=${kernelsrc}
21 AC_MSG_RESULT([Not found])
23 *** Please specify the location of the kernel source
24 *** with the '--with-linux=PATH' option])
27 if test "$kernelsrc" = "NONE"; then
32 AC_MSG_RESULT([$kernelsrc])
33 AC_MSG_CHECKING([kernel build directory])
34 AC_MSG_RESULT([$kernelbuild])
36 AC_MSG_CHECKING([kernel source version])
37 if test -r $kernelbuild/include/linux/version.h &&
38 fgrep -q UTS_RELEASE $kernelbuild/include/linux/version.h; then
40 kernsrcver=`(echo "#include <linux/version.h>";
41 echo "kernsrcver=UTS_RELEASE") |
42 cpp -I $kernelbuild/include |
43 grep "^kernsrcver=" | cut -d \" -f 2`
45 elif test -r $kernelbuild/include/linux/utsrelease.h &&
46 fgrep -q UTS_RELEASE $kernelbuild/include/linux/utsrelease.h; then
48 kernsrcver=`(echo "#include <linux/utsrelease.h>";
49 echo "kernsrcver=UTS_RELEASE") |
50 cpp -I $kernelbuild/include |
51 grep "^kernsrcver=" | cut -d \" -f 2`
54 if test -z "$kernsrcver"; then
55 AC_MSG_RESULT([Not found])
57 *** Cannot determine the version of the linux kernel source.
58 *** Please prepare the kernel before running this script])
61 AC_MSG_RESULT([$kernsrcver])
64 LINUX_OBJ=${kernelbuild}
65 LINUX_VERSION=${kernsrcver}
67 abs_srcdir=`readlink -f ${srcdir}`
68 kerninclude="-I${abs_srcdir} -I${abs_srcdir}/include"
69 kernwarn="-Wstrict-prototypes -Werror"
71 if test "${LINUX_OBJ}" != "${LINUX}"; then
72 kernobjs="O=$kernelbuild"
76 KERNELCPPFLAGS="${kerninclude} ${kernwarn}"
77 KERNELMAKE_PARAMS="${kernobjs}"
81 AC_SUBST(LINUX_VERSION)
82 AC_SUBST(KERNELMAKE_PARAMS)
83 AC_SUBST(KERNELCPPFLAGS)
84 AC_SUBST(KERNELCFLAGS)
87 AC_DEFUN([SPL_AC_LICENSE], [
88 AC_MSG_CHECKING([license])
90 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DHAVE_GPL_ONLY_SYMBOLS"
93 AC_DEFUN([SPL_AC_DEBUG], [
94 AC_MSG_CHECKING([whether debugging is enabled])
95 AC_ARG_ENABLE( [debug],
96 AS_HELP_STRING([--enable-debug],
97 [Enable generic debug support (default off)]),
98 [ case "$enableval" in
99 yes) spl_ac_debug=yes ;;
100 no) spl_ac_debug=no ;;
101 *) AC_MSG_RESULT([Error!])
102 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug]) ;;
105 if test "$spl_ac_debug" = yes; then
107 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG"
110 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
114 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
115 AC_MSG_CHECKING([whether kmem debugging is enabled])
116 AC_ARG_ENABLE( [debug-kmem],
117 AS_HELP_STRING([--enable-debug-kmem],
118 [Enable kmem debug support (default off)]),
119 [ case "$enableval" in
120 yes) spl_ac_debug_kmem=yes ;;
121 no) spl_ac_debug_kmem=no ;;
122 *) AC_MSG_RESULT([Error!])
123 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kmem]) ;;
126 if test "$spl_ac_debug_kmem" = yes; then
128 AC_DEFINE([DEBUG_KMEM], [1],
129 [Define to 1 to enable kmem debugging])
130 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
136 AC_DEFUN([SPL_AC_DEBUG_MUTEX], [
137 AC_MSG_CHECKING([whether mutex debugging is enabled])
138 AC_ARG_ENABLE( [debug-mutex],
139 AS_HELP_STRING([--enable-debug-mutex],
140 [Enable mutex debug support (default off)]),
141 [ case "$enableval" in
142 yes) spl_ac_debug_mutex=yes ;;
143 no) spl_ac_debug_mutex=no ;;
144 *) AC_MSG_RESULT([Error!])
145 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-mutex]) ;;
148 if test "$spl_ac_debug_mutex" = yes; then
150 AC_DEFINE([DEBUG_MUTEX], [1],
151 [Define to 1 to enable mutex debugging])
152 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_MUTEX"
158 AC_DEFUN([SPL_AC_DEBUG_KSTAT], [
159 AC_MSG_CHECKING([whether kstat debugging is enabled])
160 AC_ARG_ENABLE( [debug-kstat],
161 AS_HELP_STRING([--enable-debug-kstat],
162 [Enable kstat debug support (default off)]),
163 [ case "$enableval" in
164 yes) spl_ac_debug_kstat=yes ;;
165 no) spl_ac_debug_kstat=no ;;
166 *) AC_MSG_RESULT([Error!])
167 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kstat]) ;;
170 if test "$spl_ac_debug_kstat" = yes; then
172 AC_DEFINE([DEBUG_KSTAT], [1],
173 [Define to 1 to enable kstat debugging])
174 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KSTAT"
180 AC_DEFUN([SPL_AC_DEBUG_CALLB], [
181 AC_MSG_CHECKING([whether callb debugging is enabled])
182 AC_ARG_ENABLE( [debug-callb],
183 AS_HELP_STRING([--enable-debug-callb],
184 [Enable callb debug support (default off)]),
185 [ case "$enableval" in
186 yes) spl_ac_debug_callb=yes ;;
187 no) spl_ac_debug_callb=no ;;
188 *) AC_MSG_RESULT([Error!])
189 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-callb]) ;;
192 if test "$spl_ac_debug_callb" = yes; then
194 AC_DEFINE([DEBUG_CALLB], [1],
195 [Define to 1 to enable callb debugging])
196 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_CALLB"
203 dnl # SPL_LINUX_CONFTEST
205 AC_DEFUN([SPL_LINUX_CONFTEST], [
206 cat >conftest.c <<_ACEOF
212 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
214 m4_define([SPL_LANG_PROGRAM], [
219 dnl Do *not* indent the following line: there may be CPP directives.
220 dnl Don't move the `;' right after for the same reason.
228 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
230 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
231 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
232 rm -Rf build && mkdir -p build
233 echo "obj-m := conftest.o" >build/Makefile
235 [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])],
237 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
243 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
245 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
246 [SPL_LINUX_COMPILE_IFELSE(
247 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
249 [test -s build/conftest.o],
254 dnl # SPL_LINUX_CONFIG
256 AC_DEFUN([SPL_LINUX_CONFIG],
257 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
258 SPL_LINUX_TRY_COMPILE([
259 #ifndef AUTOCONF_INCLUDED
260 #include <linux/config.h>
264 #error CONFIG_$1 not #defined
276 dnl # SPL_CHECK_SYMBOL_EXPORT
277 dnl # check symbol exported or not
279 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
280 [AC_MSG_CHECKING([whether symbol $1 is exported])
281 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/Module.symvers 2>/dev/null
283 if test $rc -ne 0; then
286 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX_OBJ/$file" 2>/dev/null
288 if test $rc -eq 0; then
293 if test $export -eq 0; then
307 dnl # SPL_CHECK_HEADER
308 dnl # check whether header exists and define HAVE_$2_HEADER
310 AC_DEFUN([SPL_CHECK_HEADER],
311 [AC_MSG_CHECKING([whether header $1 exists])
312 SPL_LINUX_TRY_COMPILE([
317 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
327 dnl # 2.6.24 API change,
328 dnl # check if uintptr_t typedef is defined
330 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
331 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
332 SPL_LINUX_TRY_COMPILE([
333 #include <linux/types.h>
338 AC_DEFINE(HAVE_UINTPTR_T, 1,
339 [kernel defines uintptr_t])
346 dnl # 2.6.x API change,
347 dnl # check if atomic64_t typedef is defined
349 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_T],
350 [AC_MSG_CHECKING([whether kernel defines atomic64_t])
351 SPL_LINUX_TRY_COMPILE([
352 #include <asm/atomic.h>
357 AC_DEFINE(HAVE_ATOMIC64_T, 1,
358 [kernel defines atomic64_t])
365 dnl # 2.6.20 API change,
366 dnl # INIT_WORK use 2 args and not store data inside
368 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
369 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
370 SPL_LINUX_TRY_COMPILE([
371 #include <linux/workqueue.h>
373 struct work_struct work;
374 INIT_WORK(&work, NULL, NULL);
377 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
378 [INIT_WORK wants 3 args])
385 dnl # 2.6.21 API change,
386 dnl # 'register_sysctl_table' use only one argument instead of two
388 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
389 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
390 SPL_LINUX_TRY_COMPILE([
391 #include <linux/sysctl.h>
393 return register_sysctl_table(NULL,0);
396 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
397 [register_sysctl_table() wants 2 args])
404 dnl # 2.6.23 API change
405 dnl # Old set_shrinker API replaced with register_shrinker
407 AC_DEFUN([SPL_AC_SET_SHRINKER], [
408 AC_MSG_CHECKING([whether set_shrinker() available])
409 SPL_LINUX_TRY_COMPILE([
410 #include <linux/mm.h>
412 return set_shrinker(DEFAULT_SEEKS, NULL);
415 AC_DEFINE(HAVE_SET_SHRINKER, 1,
416 [set_shrinker() available])
423 dnl # 2.6.25 API change,
424 dnl # struct path entry added to struct nameidata
426 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
427 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
428 SPL_LINUX_TRY_COMPILE([
429 #include <linux/namei.h>
434 nd.path.dentry = NULL;
437 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
438 [struct path used in struct nameidata])
445 dnl # Custom SPL patch may export this system it is not required
447 AC_DEFUN([SPL_AC_TASK_CURR], [
448 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
449 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
454 dnl # 2.6.19 API change,
455 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
457 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
458 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
459 SPL_LINUX_TRY_COMPILE([
460 #include <linux/sysctl.h>
462 #ifndef CTL_UNNUMBERED
463 #error CTL_UNNUMBERED undefined
467 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
468 [unnumbered sysctl support exists])
475 dnl # 2.6.16 API change.
476 dnl # Check if 'fls64()' is available
478 AC_DEFUN([SPL_AC_FLS64],
479 [AC_MSG_CHECKING([whether fls64() is available])
480 SPL_LINUX_TRY_COMPILE([
481 #include <linux/bitops.h>
486 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
493 dnl # 2.6.18 API change, check whether device_create() is available.
494 dnl # Device_create() was introduced in 2.6.18 and depricated
495 dnl # class_device_create() which was fully removed in 2.6.26.
497 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
498 SPL_CHECK_SYMBOL_EXPORT(
500 [drivers/base/core.c],
501 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
502 [device_create() is available])],
507 dnl # 2.6.13 API change, check whether class_device_create() is available.
508 dnl # Class_device_create() was introduced in 2.6.13 and depricated
509 dnl # class_simple_device_add() which was fully removed in 2.6.13.
511 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
512 SPL_CHECK_SYMBOL_EXPORT(
513 [class_device_create],
514 [drivers/base/class.c],
515 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
516 [class_device_create() is available])],
521 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
523 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
524 SPL_CHECK_SYMBOL_EXPORT(
525 [set_normalized_timespec],
527 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
528 [set_normalized_timespec() is available as export])],
533 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
534 dnl # previously it was available in time.h as an inline.
536 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
537 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
538 SPL_LINUX_TRY_COMPILE([
539 #include <linux/time.h>
540 void set_normalized_timespec(struct timespec *ts,
541 time_t sec, long nsec) { }
548 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
549 [set_normalized_timespec() is available as inline])
554 dnl # 2.6.18 API change,
555 dnl # timespec_sub() inline function available in linux/time.h
557 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
558 AC_MSG_CHECKING([whether timespec_sub() is available])
559 SPL_LINUX_TRY_COMPILE([
560 #include <linux/time.h>
562 struct timespec a, b, c = { 0 };
563 c = timespec_sub(a, b);
566 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
573 dnl # 2.6.19 API change,
574 dnl # check if init_utsname() is available in linux/utsname.h
576 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
577 AC_MSG_CHECKING([whether init_utsname() is available])
578 SPL_LINUX_TRY_COMPILE([
579 #include <linux/utsname.h>
581 struct new_utsname *a = init_utsname();
584 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
591 dnl # 2.6.26 API change,
592 dnl # definition of struct fdtable relocated to linux/fdtable.h
594 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
595 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
599 dnl # 2.6.14 API change,
600 dnl # check whether 'files_fdtable()' exists
602 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
603 AC_MSG_CHECKING([whether files_fdtable() is available])
604 SPL_LINUX_TRY_COMPILE([
605 #include <linux/sched.h>
606 #include <linux/file.h>
607 #ifdef HAVE_FDTABLE_HEADER
608 #include <linux/fdtable.h>
611 struct files_struct *files = current->files;
612 struct fdtable *fdt = files_fdtable(files);
615 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
622 dnl # 2.6.18 API change,
623 dnl # added linux/uaccess.h
625 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
626 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
630 dnl # 2.6.12 API change,
631 dnl # check whether 'kmalloc_node()' is available.
633 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
634 AC_MSG_CHECKING([whether kmalloc_node() is available])
635 SPL_LINUX_TRY_COMPILE([
636 #include <linux/slab.h>
638 void *a = kmalloc_node(1, GFP_KERNEL, 0);
641 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
648 dnl # 2.6.9 API change,
649 dnl # check whether 'monotonic_clock()' is available it may
650 dnl # be available for some archs but not others.
652 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
653 SPL_CHECK_SYMBOL_EXPORT(
656 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
657 [monotonic_clock() is available])],
662 dnl # 2.6.16 API change,
663 dnl # check whether 'struct inode' has i_mutex
665 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
666 AC_MSG_CHECKING([whether struct inode has i_mutex])
667 SPL_LINUX_TRY_COMPILE([
668 #include <linux/fs.h>
669 #include <linux/mutex.h>
672 mutex_init(&i.i_mutex);
675 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
682 dnl # 2.6.14 API change,
683 dnl # check whether 'div64_64()' is available
685 AC_DEFUN([SPL_AC_DIV64_64], [
686 AC_MSG_CHECKING([whether div64_64() is available])
687 SPL_LINUX_TRY_COMPILE([
688 #include <asm/div64.h>
689 #include <linux/types.h>
691 uint64_t i = div64_64(1ULL, 1ULL);
694 AC_DEFINE(HAVE_DIV64_64, 1, [div64_64() is available])
701 dnl # 2.6.27 API change,
702 dnl # on_each_cpu() uses 3 args, no 'retry' argument
704 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
705 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
706 SPL_LINUX_TRY_COMPILE([
707 #include <linux/smp.h>
709 on_each_cpu(NULL, NULL, 0);
712 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
713 [on_each_cpu wants 3 args])
720 dnl # 2.6.18 API change,
721 dnl # kallsyms_lookup_name no longer exported
723 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME], [
724 SPL_CHECK_SYMBOL_EXPORT(
725 [kallsyms_lookup_name],
727 [AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
728 [kallsyms_lookup_name() is available])],
733 dnl # Symbol only available in custom kernels
735 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], [
736 SPL_CHECK_SYMBOL_EXPORT(
739 [AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
740 [get_vmalloc_info() is available])],
745 dnl # Symbol only available in custom kernels
747 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT], [
748 SPL_CHECK_SYMBOL_EXPORT(
749 [first_online_pgdat],
751 [AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
752 [first_online_pgdat() is available])],
757 dnl # Symbol only available in custom kernels
759 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT], [
760 SPL_CHECK_SYMBOL_EXPORT(
763 [AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
764 [next_online_pgdat() is available])],
769 dnl # Symbol only available in custom kernels
771 AC_DEFUN([SPL_AC_NEXT_ZONE], [
772 SPL_CHECK_SYMBOL_EXPORT(
775 [AC_DEFINE(HAVE_NEXT_ZONE, 1,
776 [next_zone() is available])],
781 dnl # Symbol only available in custom kernels
783 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
784 SPL_CHECK_SYMBOL_EXPORT(
787 [AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
788 [get_zone_counts() is available])],