autoconf: add test for typedef'd structs
[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([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 dnl AC_CHECK_LINUX_BUILD([msg], [var], [includes], [code], [define], [CFLAGS])
89 AC_DEFUN([AC_CHECK_LINUX_BUILD],
90  [AS_VAR_PUSHDEF([ac_linux_build], [$2])dnl
91   AC_CACHE_CHECK([$1], [ac_linux_build],
92    [save_CPPFLAGS="$CPPFLAGS"
93      CPPFLAGS="$CPPFLAGS $7"
94      AC_TRY_KBUILD([$3], [$4],
95                   AS_VAR_SET([ac_linux_build], [yes]),
96                   AS_VAR_SET([ac_linux_build], [no]))
97      CPPFLAGS="$save_CPPFLAGS"
98    ])
99   AS_IF([test AS_VAR_GET([ac_linux_build]) = yes],
100         [AC_DEFINE([$5],1,[$6])])
101  ])
102
103 dnl AC_CHECK_LINUX_HEADER(header)
104 AC_DEFUN([AC_CHECK_LINUX_HEADER],
105  [AC_CHECK_LINUX_BUILD([for linux/$1], [ac_cv_linux_header_$1],
106                        [#include <linux/$1>],
107                        [return;],
108                        AS_TR_CPP(HAVE_LINUX_$1),
109                        [Define if your kernel has linux/$1])
110  ])
111
112 dnl AC_CHECK_LINUX_FUNC([function], [includes], [code])
113 AC_DEFUN([AC_CHECK_LINUX_FUNC],
114  [AS_VAR_PUSHDEF([ac_linux_func], [ac_cv_linux_func_$1])dnl
115   AC_CACHE_CHECK([for $1], [ac_linux_func],
116     [save_CPPFLAGS="$CPPFLAGS"
117      CPPFLAGS="$CPPFLAGS -Werror-implicit-function-declaration"
118      AC_TRY_KBUILD([$2], [$3],
119                    AS_VAR_SET([ac_linux_func], [yes]),
120                    AS_VAR_SET([ac_linux_func], [no]))
121      CPPFLAGS="$save_CPPFLAGS"
122     ])
123   AS_IF([test AS_VAR_GET([ac_linux_func]) = yes],
124         [AC_DEFINE(AS_TR_CPP(HAVE_LINUX_$1), 1,
125                    [Define if your kernel has the $1 function])])
126  ])
127
128 dnl AC_CHECK_LINUX_STRUCT([structure], [element], [includes])
129 AC_DEFUN([AC_CHECK_LINUX_STRUCT],
130  [AC_CHECK_LINUX_TYPED_STRUCT([struct $1], [$2], [$3])
131  ])
132
133 dnl AC_CHECK_LINUX_TYPED_STRUCT([structure], [element], [includes])
134 AC_DEFUN([AC_CHECK_LINUX_TYPED_STRUCT],
135  [AC_CHECK_LINUX_BUILD([for $2 in $1],
136                        [ac_cv_linux_$1_has_$2],
137                        [#include <linux/$3>],
138                        [$1 _test; printk("%x\n", &_test.$2); ],
139                        AS_TR_CPP($1_HAS_$2),
140                        [Define if kernel typedef'd $1 has the $2 element])
141  ])
142