autoconf: refactor ostype.m4
[openafs.git] / src / cf / linux-kernel-path.m4
1 AC_DEFUN([OPENAFS_LINUX_KERNEL_PATH],[
2 if test "x$with_linux_kernel_headers" != "x"; then
3   LINUX_KERNEL_PATH="$with_linux_kernel_headers"
4 else
5   for utsdir in "/lib/modules/`uname -r`/build" \
6                 "/lib/modules/`uname -r`/source" \
7                 "/usr/src/linux-2.4" \
8                 "/usr/src/linux"; do
9     LINUX_KERNEL_PATH="$utsdir"
10     for utsfile in "include/generated/utsrelease.h" \
11                    "include/linux/utsrelease.h" \
12                    "include/linux/version.h" \
13                    "include/linux/version-up.h"; do
14       if grep "UTS_RELEASE" "$utsdir/$utsfile" >/dev/null 2>&1; then
15         break 2
16       fi
17     done
18   done
19 fi
20 if test "x$with_linux_kernel_build" != "x"; then
21   LINUX_KERNEL_BUILD="$with_linux_kernel_build"
22 else
23   LINUX_KERNEL_BUILD=$LINUX_KERNEL_PATH
24 fi
25 if test -f "$LINUX_KERNEL_BUILD/include/generated/utsrelease.h"; then
26   linux_kvers=`fgrep UTS_RELEASE $LINUX_KERNEL_BUILD/include/generated/utsrelease.h |awk 'BEGIN { FS="\"" } { print $[]2 }'|tail -n 1`
27   LINUX_VERSION="$linux_kvers"
28 else
29   if test -f "$LINUX_KERNEL_BUILD/include/linux/utsrelease.h"; then
30     linux_kvers=`fgrep UTS_RELEASE $LINUX_KERNEL_BUILD/include/linux/utsrelease.h |awk 'BEGIN { FS="\"" } { print $[]2 }'|tail -n 1`
31     LINUX_VERSION="$linux_kvers"
32   else
33     if test -f "$LINUX_KERNEL_BUILD/include/linux/version.h"; then
34       linux_kvers=`fgrep UTS_RELEASE $LINUX_KERNEL_BUILD/include/linux/version.h |awk 'BEGIN { FS="\"" } { print $[]2 }'|tail -n 1`
35       if test "x$linux_kvers" = "x"; then
36         if test -f "$LINUX_KERNEL_BUILD/include/linux/version-up.h"; then
37           linux_kvers=`fgrep UTS_RELEASE $LINUX_KERNEL_BUILD/include/linux/version-up.h |awk 'BEGIN { FS="\"" } { print $[]2 }'|tail -n 1`
38           if test "x$linux_kvers" = "x"; then
39             AC_MSG_ERROR(Linux headers lack version definition [2])
40             exit 1
41           else
42             LINUX_VERSION="$linux_kvers"
43           fi
44         else
45           AC_MSG_ERROR(Linux headers lack version definition)
46           exit 1
47         fi
48       else
49         LINUX_VERSION="$linux_kvers"
50       fi
51     else
52       enable_kernel_module="no"
53     fi
54   fi
55 fi
56 if test ! -f "$LINUX_KERNEL_BUILD/include/generated/autoconf.h" &&
57    test ! -f "$LINUX_KERNEL_BUILD/include/linux/autoconf.h"; then
58     enable_kernel_module="no"
59 fi
60 if test "x$enable_kernel_module" = "xno"; then
61  if test "x$with_linux_kernel_headers" != "x"; then
62   AC_MSG_ERROR(No usable linux headers found at $LINUX_KERNEL_PATH)
63   exit 1
64  else
65   AC_MSG_WARN(No usable linux headers found at $LINUX_KERNEL_PATH so disabling kernel module)
66  fi
67 fi
68 dnl do we need to determine SUBARCH from autoconf.h
69 SUBARCH=default
70 ])