autoconf: Remove/update obsolete autoconf macros
[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 $SPARSE_MAKEFLAGS modules KBUILD_VERBOSE=1 >&AS_MESSAGE_LOG_FD &&
31     make -C $LINUX_KERNEL_BUILD M=$SRCDIR_PARENT/conftest.dir $SPARSE_MAKEFLAGS 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_COMPILE_IFELSE([AC_LANG_PROGRAM([[
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([if 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 AC_DEFUN([LINUX_KBUILD_SPARSE_CHECKS], [
89   AC_ARG_WITH([sparse],
90               AS_HELP_STRING([--with-sparse@<:@=PATH@:>@],
91                              [Location of the 'sparse' tool]),
92               [SPARSE="$withval"],
93               [SPARSE=check])
94
95   AS_CASE([$SPARSE],
96           [check], [AC_PATH_PROG([SPARSE], [sparse], [])],
97           [yes],   [AC_PATH_PROG([SPARSE], [sparse], [])
98                     AS_IF([test "x$SPARSE" = "x"], [AC_MSG_ERROR([sparse not found])])],
99           [no],    [SPARSE=])
100
101   AS_IF([test x"$SPARSE" != x],
102         [SPARSE_MAKEFLAGS="C=2 CHECK=$SPARSE"])
103
104   AC_SUBST([SPARSE_MAKEFLAGS])
105
106   AC_ARG_VAR([SPARSE], [Path to the 'sparse' tool])
107 ])
108
109
110 dnl AC_CHECK_LINUX_BUILD([msg], [var], [includes], [code], [define], [CFLAGS])
111 AC_DEFUN([AC_CHECK_LINUX_BUILD],
112  [AS_VAR_PUSHDEF([ac_linux_build], [$2])dnl
113   AC_CACHE_CHECK([$1], [ac_linux_build],
114    [save_CPPFLAGS="$CPPFLAGS"
115      CPPFLAGS="$CPPFLAGS $7"
116      AC_TRY_KBUILD([$3], [$4],
117                   AS_VAR_SET([ac_linux_build], [yes]),
118                   AS_VAR_SET([ac_linux_build], [no]))
119      CPPFLAGS="$save_CPPFLAGS"
120    ])
121   AS_IF([test AS_VAR_GET([ac_linux_build]) = yes],
122         [AC_DEFINE([$5],1,[$6])])
123  ])
124
125 dnl AC_CHECK_LINUX_HEADER(header)
126 AC_DEFUN([AC_CHECK_LINUX_HEADER],
127  [AC_CHECK_LINUX_BUILD([for linux/$1], [ac_cv_linux_header_$1],
128                        [#include <linux/$1>],
129                        [return;],
130                        AS_TR_CPP(HAVE_LINUX_$1),
131                        [Define if your kernel has linux/$1])
132  ])
133
134 dnl AC_CHECK_LINUX_FUNC([function], [includes], [code])
135 AC_DEFUN([AC_CHECK_LINUX_FUNC],
136  [AS_VAR_PUSHDEF([ac_linux_func], [ac_cv_linux_func_$1])dnl
137   AC_CACHE_CHECK([for $1], [ac_linux_func],
138     [save_CPPFLAGS="$CPPFLAGS"
139      CPPFLAGS="$CPPFLAGS -Werror-implicit-function-declaration"
140      AC_TRY_KBUILD([$2], [$3],
141                    AS_VAR_SET([ac_linux_func], [yes]),
142                    AS_VAR_SET([ac_linux_func], [no]))
143      CPPFLAGS="$save_CPPFLAGS"
144     ])
145   AS_IF([test AS_VAR_GET([ac_linux_func]) = yes],
146         [AC_DEFINE(AS_TR_CPP(HAVE_LINUX_$1), 1,
147                    [Define if your kernel has the $1 function])])
148  ])
149
150 dnl AC_CHECK_LINUX_TYPE([type], [includes])
151 AC_DEFUN([AC_CHECK_LINUX_TYPE],
152  [AC_CHECK_LINUX_BUILD([for $1],
153                        [ac_cv_linux_type_$1_exists],
154                        [#include <linux/$2>],
155                        [$1 _test; ],
156                        AS_TR_CPP(HAVE_LINUX_$1),
157                        [Define if kernel defines $1])
158  ])
159
160 dnl AC_CHECK_LINUX_STRUCT([structure], [element], [includes])
161 AC_DEFUN([AC_CHECK_LINUX_STRUCT],
162  [AC_CHECK_LINUX_TYPED_STRUCT([struct $1], [$2], [$3])
163  ])
164
165 dnl AC_CHECK_LINUX_TYPED_STRUCT([structure], [element], [includes])
166 AC_DEFUN([AC_CHECK_LINUX_TYPED_STRUCT],
167  [AC_CHECK_LINUX_BUILD([for $2 in $1],
168                        [ac_cv_linux_$1_has_$2],
169                        [#include <linux/$3>],
170                        [$1 _test; printk("%x\n", &_test.$2); ],
171                        AS_TR_CPP($1_HAS_$2),
172                        [Define if kernel $1 has the $2 element])
173  ])
174
175 dnl AC_CHECK_LINUX_OPERATION([structure], [operation], [label], [includes], [return_type], [args])
176 AC_DEFUN([AC_CHECK_LINUX_OPERATION],
177  [AS_VAR_PUSHDEF([ac_linux_operation], [ac_cv_linux_operation_$1_$2_$3])
178   AC_CACHE_CHECK([operation $2 in $1], [ac_linux_operation],
179     [save_CPPFLAGS="$CPPFLAGS"
180      CPPFLAGS="$CPPFLAGS -Werror"
181      AC_TRY_KBUILD([$4], [struct $1 ops; $5 op($6) { return ($5)0; }; ops.$2 = op;],
182                    AS_VAR_SET([ac_linux_operation], [yes]),
183                    AS_VAR_SET([ac_linux_operation], [no]))
184      CPPFLAGS="$save_CPPFLAGS"
185     ])
186   AS_IF([test AS_VAR_GET([ac_linux_operation]) = yes],
187         [AC_DEFINE(AS_TR_CPP(HAVE_LINUX_$1_$2_$3), 1,
188                    [Define if $1 has $2 operation of form $6])])
189  ])