From 05523b1ef53855aef894d5009b92a7ec7331f57a Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 6 Jul 2006 16:06:32 +0000 Subject: [PATCH] Avoid using AC_RUN_IFELSE to check the kernel major.minor version, as it doesn't work when cross-compiling. Every kernel Makefile I've looked at (at least for 2.4 and 2.6, including those for separate kernel build directories) includes the "VERSION = x" and "PATCHLEVEL = y" lines, so use 'sed' to extract the information from those lines. --- m4/as-linux.m4 | 49 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/m4/as-linux.m4 b/m4/as-linux.m4 index c4ba11d0..5449fa25 100644 --- a/m4/as-linux.m4 +++ b/m4/as-linux.m4 @@ -651,7 +651,7 @@ AC_DEFUN([AS_LINUX_CONFIG_OPTION_MODULE], ]) dnl check for the major/minor version of the Linux source by checking -dnl the headers +dnl the Makefile dnl first argument is the linux directory dnl sets LINUX_VERSION_MAJOR and LINUX_VERSION_MINOR AC_DEFUN([AS_LINUX_VERSION_MAJOR_MINOR], @@ -659,48 +659,17 @@ AC_DEFUN([AS_LINUX_VERSION_MAJOR_MINOR], LINUX_DIR=[$1] AC_MSG_CHECKING([Linux major/minor version]) - if [[ ! -f "${LINUX_DIR}/include/linux/version.h" ]];then - AC_MSG_ERROR([The header file include/linux/version.h does not exist. -For 2.6 kernels, it can be generated by running 'make prepare' in -the kernel source directory.]) + if [[ ! -f "${LINUX_DIR}/Makefile" ]];then + AC_MSG_ERROR([The Linux kernel Makefile does not exist.]) fi dnl the next set of tests is for figuring out version major/minor - dnl we make sure we have the right version.h by faking out CFLAGS - dnl since we want to avoid including linux/version.h and acidentally - dnl pick up /usr/include/linux - dnl we still add ${LINUX_DIR}/include so the Red Hat version can pick - dnl up linux/rhversion.h - ac_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -I${LINUX_DIR}/include/linux -I${LINUX_DIR}/include" - dnl make sure we find version.h and it contains LINUX_VERSION_CODE - AC_COMPILE_IFELSE(AC_LANG_PROGRAM([ -#include "version.h" -int code = LINUX_VERSION_CODE; -]), - :, AC_MSG_ERROR([${LINUX_DIR}/include/linux/version.h does not contain LINUX_VERSION_CODE])) - - - dnl figure out the linux kernel version major and minor - dnl using the LINUX_VERSION_CODE defined in include/linux/version.h - AC_RUN_IFELSE(AC_LANG_PROGRAM([ -#include "version.h" -#define KERNEL_VERSION_MAJOR(code) ((code) >> 16) -],[ - return KERNEL_VERSION_MAJOR(LINUX_VERSION_CODE); -]), - LINUX_VERSION_MAJOR=0, - LINUX_VERSION_MAJOR=$?) - AC_RUN_IFELSE(AC_LANG_PROGRAM([ -#include "version.h" -#define KERNEL_VERSION_MINOR(code) (((code) >> 8) % (2 << 8)) -],[ - return KERNEL_VERSION_MINOR(LINUX_VERSION_CODE); -]), - LINUX_VERSION_MINOR=0, - LINUX_VERSION_MINOR=$?) + dnl use VERSION and PATCHLEVEL in the kernel Makefile + LINUX_VERSION_MAJOR=`sed -n 's/^VERSION = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"` + LINUX_VERSION_MINOR=`sed -n 's/^PATCHLEVEL = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"` + if [[ -z "$LINUX_VERSION_MAJOR" -o -z "$LINUX_VERSION_MINOR" ]]; then + AC_MSG_ERROR([No major/minor version information found in Linux kernel Makefile.]) + fi AC_MSG_RESULT($LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR) - dnl restore CFLAGS - CFLAGS="$ac_save_CFLAGS" ]) # COMEDI_CHECK_LINUX_KBUILD([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) -- 2.26.2