65457170bfd15df7404a86c8bcf18d21e1907478
[openafs.git] / src / cf / linux-test1.m4
1 # AC_TRY_KBUILD26([INCLUDES], [FUNCTION-BODY],
2 #                 [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
3 #
4 AC_DEFUN([AC_TRY_KBUILD26],[  rm -fr conftest.dir
5   if test "x$ac_linux_kbuild_requires_extra_cflags" = "xyes" ; then
6     CFLAGS_PREFIX='EXTRA_'
7   fi
8   if mkdir conftest.dir &&
9     cat >conftest.dir/Makefile <<_ACEOF &&
10 ${CFLAGS_PREFIX}CFLAGS += $CPPFLAGS
11
12 obj-m += conftest.o
13 _ACEOF
14     cat >conftest.dir/conftest.c <<\_ACEOF &&
15 /* confdefs.h */
16 _ACEOF
17     cat confdefs.h >>conftest.dir/conftest.c &&
18     cat >>conftest.dir/conftest.c <<\_ACEOF &&
19 /* end confdefs.h */
20 #include <linux/module.h>
21 $1
22
23 void conftest(void)
24
25 $2
26
27
28 MODULE_LICENSE("http://www.openafs.org/dl/license10.html");
29 _ACEOF
30     echo make -C $LINUX_KERNEL_BUILD M=$SRCDIR_PARENT/conftest.dir modules KBUILD_VERBOSE=1 >&AS_MESSAGE_LOG_FD &&
31     make -C $LINUX_KERNEL_BUILD M=$SRCDIR_PARENT/conftest.dir modules KBUILD_VERBOSE=1 >&AS_MESSAGE_LOG_FD 2>conftest.err &&
32     ! grep -i "WARNING: .* undefined!$" conftest.err >/dev/null 2>&1
33     then [$3]
34     else
35       sed '/^ *+/d' conftest.err >&AS_MESSAGE_LOG_FD
36       echo "$as_me: failed using Makefile:" >&AS_MESSAGE_LOG_FD
37       sed 's/^/| /' conftest.dir/Makefile >&AS_MESSAGE_LOG_FD
38       echo "$as_me: and program was:" >&AS_MESSAGE_LOG_FD
39       sed 's/^/| /' conftest.dir/conftest.c >&AS_MESSAGE_LOG_FD
40       [$4]
41   fi; rm -fr conftest.err conftest.dir])
42
43   
44 # AC_TRY_KBUILD24([INCLUDES], [FUNCTION-BODY],
45 #                 [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
46 #
47 AC_DEFUN([AC_TRY_KBUILD24], [
48   ac_save_CPPFLAGS="$CPPFLAGS"
49   CPPFLAGS="-I$LINUX_KERNEL_PATH/include -D__KERNEL__ -Werror-implicit-function-declaration $CPPFLAGS"
50   AC_TRY_COMPILE([
51 #include <linux/kernel.h>
52 $1], [$2], [$3], [$4])
53   CPPFLAGS="$ac_save_CPPFLAGS"])
54
55
56 # AC_TRY_KBUILD([INCLUDES], [FUNCTION-BODY],
57 #               [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
58 #
59 AC_DEFUN([AC_TRY_KBUILD], [
60   if test $AFS_SYSKVERS -ge 26 ; then
61     AC_TRY_KBUILD26([$1], [$2], [$3], [$4])
62   else
63     AC_TRY_KBUILD24([$1], [$2], [$3], [$4])
64   fi])
65
66 AC_DEFUN([LINUX_KERNEL_COMPILE_WORKS], [
67   AC_MSG_CHECKING([for linux kernel module build works])
68   AC_TRY_KBUILD(
69 [#include <linux/sched.h>
70 #include <linux/fs.h>],
71     [],:,AC_MSG_RESULT(no)
72     AC_MSG_FAILURE([Fix problem or use --disable-kernel-module...]))
73   AC_MSG_RESULT(yes)])
74
75 AC_DEFUN([LINUX_KBUILD_USES_EXTRA_CFLAGS], [
76   AC_MSG_CHECKING([if linux kbuild requires EXTRA_CFLAGS])
77   save_CPPFLAGS="$CPPFLAGS"
78   CPPFLAGS=-Wall
79   AC_TRY_KBUILD(
80 [#include <linux/sched.h>
81 #include <linux/fs.h>],
82     [],
83     ac_linux_kbuild_requires_extra_cflags=no,
84     ac_linux_kbuild_requires_extra_cflags=yes)
85     CPPFLAGS="$save_CPPFLAGS"
86     AC_MSG_RESULT($ac_linux_kbuild_requires_extra_cflags)])
87
88 dnl AC_CHECK_LINUX_HEADER(header)
89 AC_DEFUN([AC_CHECK_LINUX_HEADER],
90  [AS_VAR_PUSHDEF([ac_linux_header], [ac_cv_linux_header_$1])dnl
91   AC_CACHE_CHECK([for linux/$1], [ac_linux_header],
92    [AC_TRY_KBUILD([#include <linux/$1>],
93                   [return;],
94                   AS_VAR_SET([ac_linux_header], [yes]),
95                   AS_VAR_SET([ac_linux_header], [no]))
96    ])
97   AS_IF([test AS_VAR_GET([ac_linux_header]) = yes],
98         [AC_DEFINE(AS_TR_CPP(HAVE_LINUX_$1),
99                   1,
100                   [Define if your kernel has linux/$1])])
101  ])
102
103 dnl AC_CHECK_LINUX_FUNC([function], [includes], [code])
104 AC_DEFUN([AC_CHECK_LINUX_FUNC],
105  [AS_VAR_PUSHDEF([ac_linux_func], [ac_cv_linux_func_$1])dnl
106   AC_CACHE_CHECK([for $1], [ac_linux_func],
107     [save_CPPFLAGS="$CPPFLAGS"
108      CPPFLAGS="$CPPFLAGS -Werror-implicit-function-declaration"
109      AC_TRY_KBUILD([$2], [$3],
110                    AS_VAR_SET([ac_linux_func], [yes]),
111                    AS_VAR_SET([ac_linux_func], [no]))
112      CPPFLAGS="$save_CPPFLAGS"
113     ])
114   AS_IF([test AS_VAR_GET([ac_linux_func]) = yes],
115         [AC_DEFINE(AS_TR_CPP(HAVE_LINUX_$1), 1,
116                    [Define if your kernel has the $1 function])])
117  ])
118
119 dnl AC_CHECK_LINUX_STRUCT([structure], [element], [includes])
120 AC_DEFUN([AC_CHECK_LINUX_STRUCT],
121  [AS_VAR_PUSHDEF([ac_linux_struct], [ac_cv_linux_struct_$1_has_$2])dnl
122   AC_CACHE_CHECK([for $2 in struct $1], [ac_linux_struct],
123    [AC_TRY_KBUILD([#include <linux/$3>],
124                   [struct $1 _test; printk("%x\n", &_test.$2); ],
125                   AS_VAR_SET([ac_linux_struct], [yes]),
126                   AS_VAR_SET([ac_linux_struct], [no]))
127    ])
128   AS_IF([test AS_VAR_GET([ac_linux_struct]) = yes],
129         [AC_DEFINE(AS_TR_CPP(STRUCT_$1_HAS_$2), 1,
130                    [Define if kernel struct $1 has the $2 element])])
131  ])
132