DEVEL15-linux-2-6-27-20080816
[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_PATH M=$SRCDIR_PARENT/conftest.dir modules KBUILD_VERBOSE=1 >&AS_MESSAGE_LOG_FD &&
31     make -C $LINUX_KERNEL_PATH 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)])